今日使用python写sql语句时 发现使用in查询 频繁报错 解决后记录一下 小的知识点
class t_templet_joom_wait_upload():
def __init__(self, db_conn):
self.db_conn = db_conn
def DataById(self, ids):
result = {}
try:
cursor = self.db_conn.cursor()
sql = 'select id, MainSKU, Title ,Description,Tags,MainImage, ExtraImages, Status, Variants, CreateTime,' \
'CreateStaff, UpdateTime, UpdateStaff, CoreWords, CoreTags,SrcProductID, SkuState, B_cost_weight, Source ' \
'from t_templet_joom_wait_upload where id in %s;'
cursor.execute(sql,ids)
result['datasrc'] = cursor.fetchall()
result['errorcode'] = 0
cursor.close()
return result
except Exception as ex:
result['errorcode'] = -1
result['errortext'] = '%s:Exception = %s ex=%s __LINE__=%s' % (
traceback.print_exc(), Exception, ex, sys._getframe().f_lineno)
参数ids 需要传二维列表的形式 如:ids = [[1, 2, 3]]