On Tuesday, December 2, 2014 6:19:23 PM UTC+1, Nico de Groot wrote:
>
> The function _update_or_insert(... returns the sql that is generated.


@nico: unfortunately there isn't (it's a two-step phase that isn't resolved 
to a single SQL statement) 

however, it made me spot the actual error in the posted code
@TR:
the update_or_insert "pseudo-code" is

db.table.update_or_insert(condition, field1=value1,field2=value2, etc)

where condition is a Query, you're instead passing a Set

to sum up...
db.table.update_or_insert(db.table.field1 == value1, 
field1=value1,field2=value2, etc)
or, with "multiple conditions"
db.table.update_or_insert((db.table.field1 == value1) & (db.table.field2 == 
value2), field1=value1,field2=value2, etc)
you're using instead
db.table.update_or_insert(db((db.table.field1 == value1) & (db.table.field2 
== value2)), field1=value1,field2=value2, etc)

the red part is not allowed

BTW: read that kind of code sucks. Python (and DAL) is coded to be easy to 
read..... just refactoring as

tb = db.cms_meas_details

cond = (tb.agt_no==session.agt_no) & 
       (tb.jcod==session.jcod) & 
       (tb.meas_date==session.meas_date) & 
       (tb.shift==session.shift) & 
       (tb.line_no==j)


tb.update_or_insert(cond,
                    meas_id=m_id,
                    agt_no=session.agt_no,
                    jcod=session.jcod,
                    meas_date=session.meas_date,
                    shift=session.shift,
                    loc_of_work=form.vars['txt%s%s' % (i,1)],
                    m_no=form.vars['txt%s%s' %(i,2)],
                    m_times=form.vars['txt%s%s' %(i,3)],
                    m_length=form.vars['txt%s%s' %(i,4)],
                    m_breadth=form.vars['txt%s%s' %(i,5)],
                    m_depth=form.vars['txt%s%s' %(i,6)],
                    mat_code=form.vars['cmbMat%s%s' %(1,7)],
                    unit_weight=form.vars['txt%s%s' %(i,8)],
                    m_content=form.vars['txt%s%s' %(i,9)],
                    remarks=form.vars['txt%s%s' %(i,10)],
                    update_uid="e34789",
                    update_dt=request.now,
                    line_no=j
)


takes just a little bit of time but it'll be much easier to read and to 
spot errors in the future

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to