14 last_id:是否需要返回最后一行数据,默认False
24 many_flay =
'many' in kwargs.keys()
and kwargs[
'many']
25 if 'print_sql' in kwargs.keys()
and kwargs[
'print_sql']
is True:
26 _l = sys._getframe().f_back.f_lineno
27 msg = f
'{kwargs["sql"]} - many=True' if many_flay
else kwargs[
'sql']
28 ALog.log(obj=db, line=_l, task_name=
'ASQL', msg=msg,
29 LogObject=kwargs[
'log_obj']
if 'log_obj' in kwargs.keys()
else None)
31 cursor.executemany(kwargs[
'sql'], kwargs[
'params'])
33 if 'params' in kwargs
and kwargs[
'params']:
34 cursor.execute(kwargs[
'sql'], tuple(kwargs[
'params']))
36 cursor.execute(kwargs[
'sql'])
42 except Exception
as e:
48 mysql_err.raise_exception()
53 if 'POOL' not in kwargs
or kwargs[
'POOL']
is None:
55 if 'POOL' in kwargs.keys():
58 super(Db_opera, self).
__init__(*args, **kwargs)
71 last_id:是否需要返回最后一行数据,默认False
81 col = cursor.description
82 data = cursor.fetchall()
85 for data_index, data_value
in enumerate(data):
87 for item_index, item_value
in enumerate(data_value):
88 _messy[col[item_index][0]] = item_value
89 _result.append(_messy)
91 except Exception
as e:
94 msg=
'The pojo object has not been initialized yet, and no configuration items have been obtained',
95 obj=e, LogObject=kwargs[
'log_obj']
if 'log_obj' in kwargs.keys()
else None, raise_exception=
True)
99 def insert(self, many=False, **kwargs):
102 :param kwargs:包含所有参数:
103 last_id:是否需要返回最后一行数据,默认False
110 cursor =
parse_kwa(db=db, many=many, **kwargs)
113 rowcount = cursor.rowcount
115 if kwargs[
'last_id']:
116 return rowcount, cursor.lastrowid
119 except Exception
as e:
122 msg=
'The pojo object has not been initialized yet, and no configuration items have been obtained',
123 obj=e, LogObject=kwargs[
'log_obj']
if 'log_obj' in kwargs.keys()
else None, raise_exception=
True)
130 :param kwargs:包含所有参数:
131 last_id:是否需要返回最后一行数据,默认False
135 return self.
insert(**kwargs)
140 :param kwargs:包含所有参数:
141 last_id:是否需要返回最后一行数据,默认False