Add has_multirow_insert
There are still many databases that doesn't support this SQL-92 syntax. issue4881 review19331002
This commit is contained in:
1 parent
a19d1b7614
commit
6cd05ed6fe
5 files changed
+21
-2
No files matched your search
@@ -220,6 +220,10 @@ class CursorInterface(object):
|
||||
:return: a boolean
|
||||
'''
|
||||
|
||||
def has_multirow_insert(self):
|
||||
'Return True if database supports multirow insert'
|
||||
return False
|
||||
|
||||
def __build_dict(self, row):
|
||||
return dict((desc[0], row[i])
|
||||
for i, desc in enumerate(self.description))
|
||||
|
||||
@@ -308,6 +308,9 @@ class Cursor(CursorInterface):
|
||||
def has_constraint(self):
|
||||
return False
|
||||
|
||||
def has_multirow_insert(self):
|
||||
return True
|
||||
|
||||
def limit_clause(self, select, limit=None, offset=None):
|
||||
if offset and limit is None:
|
||||
limit = 18446744073709551610 # max bigint
|
||||
|
||||
@@ -361,6 +361,9 @@ class Cursor(CursorInterface):
|
||||
# RETURNING clause is available since PostgreSQL 8.2
|
||||
return self._database.get_version(self) >= (8, 2)
|
||||
|
||||
def has_multirow_insert(self):
|
||||
return True
|
||||
|
||||
register_type(UNICODE)
|
||||
if PYDATE:
|
||||
register_type(PYDATE)
|
||||
|
||||
@@ -392,6 +392,9 @@ class Cursor(CursorInterface):
|
||||
def has_constraint(self):
|
||||
return False
|
||||
|
||||
def has_multirow_insert(self):
|
||||
return True
|
||||
|
||||
sqlite.register_converter('NUMERIC', lambda val: Decimal(val.decode('utf-8')))
|
||||
if sys.version_info[0] == 2:
|
||||
sqlite.register_adapter(Decimal, lambda val: buffer(str(val)))
|
||||
|
||||
@@ -353,8 +353,14 @@ class ModelSQL(ModelStorage):
|
||||
cursor.execute(*history.insert(hcolumns,
|
||||
table.select(*columns, where=where)))
|
||||
else:
|
||||
cursor.execute(*history.insert(hcolumns,
|
||||
[[id_, CurrentTimestamp(), user] for id_ in sub_ids]))
|
||||
if cursor.has_multirow_insert():
|
||||
cursor.execute(*history.insert(hcolumns,
|
||||
[[id_, CurrentTimestamp(), user]
|
||||
for id_ in sub_ids]))
|
||||
else:
|
||||
for id_ in sub_ids:
|
||||
cursor.execute(*history.insert(hcolumns,
|
||||
[[id_, CurrentTimestamp(), user]]))
|
||||
|
||||
@classmethod
|
||||
def _restore_history(cls, ids, datetime, _before=False):
|
||||
|
||||
Reference in new issue
Block a user