我试图在我的类中调用一个需要携带sql语句的create函数。我需要在该查询中传递一些参数,但我不知道该怎么做。
roster_substitute类中的create函数
def create(self, cr, uid, values, context=None):
rec_id=values['id']
sub_day=values['roster_day']
ros_time=values['time_slot']
cr.execute("""UPDATE roster_days_allocation SET roster_allocation_connection = (SELECT MAX(ra.id) FROM roster_allocation ra, roster_substitution rs
WHERE ra.emp_id=rs.sub_employee)
WHERE allocation_start_day = **'sub_day'** AND roster_time_list = **ros_time**""")
return super(roster_substitution, self).create(cr, uid, values, context=context)
答案 0 :(得分:1)
如果您正在使用标准的psycopg2库,那么
cr.execute("""UPDATE roster_days_allocation SET roster_allocation_connection = (SELECT MAX(ra.id) FROM roster_allocation ra, roster_substitution rs
WHERE ra.emp_id=rs.sub_employee)
WHERE allocation_start_day = %s AND roster_time_list = %s""", (sub_day, ros_time))