Don't use now() in SQL statement as it doesn't work on SQLite
This commit is contained in:
1 parent
792dfefc82
commit
ddbd7b2be1
4 files changed
+16
-21
No files matched your search
@@ -70,9 +70,6 @@ def date_trunc(_type, date):
|
||||
def split_part(text, delimiter, count):
|
||||
return (text.split(delimiter) + [''] * (count - 1))[count - 1]
|
||||
|
||||
def now():
|
||||
return mx.DateTime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
|
||||
class Database(DatabaseInterface):
|
||||
|
||||
@@ -104,7 +101,6 @@ class Database(DatabaseInterface):
|
||||
self._conn.create_function('extract', 2, extract)
|
||||
self._conn.create_function('date_trunc', 2, date_trunc)
|
||||
self._conn.create_function('split_part', 3, split_part)
|
||||
self._conn.create_function('now', 0, now)
|
||||
return self
|
||||
|
||||
def cursor(self, autocommit=False):
|
||||
@@ -212,8 +208,8 @@ class Database(DatabaseInterface):
|
||||
cursor.execute('INSERT INTO ir_module_module ' \
|
||||
'(create_uid, create_date, author, website, name, ' \
|
||||
'shortdesc, description, state) ' \
|
||||
'VALUES (%s, now(), %s, %s, %s, %s, %s, %s)',
|
||||
(0, info.get('author', ''),
|
||||
'VALUES (%s, %s, %s, %s, %s, %s, %s, %s)',
|
||||
(0, datetime.datetime.now(), info.get('author', ''),
|
||||
info.get('website', ''), i, info.get('name', False),
|
||||
info.get('description', ''), state))
|
||||
cursor.execute('SELECT last_insert_rowid()')
|
||||
@@ -222,8 +218,8 @@ class Database(DatabaseInterface):
|
||||
for dependency in dependencies:
|
||||
cursor.execute('INSERT INTO ir_module_module_dependency ' \
|
||||
'(create_uid, create_date, module, name) ' \
|
||||
'VALUES (%s, now(), %s, %s) ',
|
||||
(0, module_id, dependency))
|
||||
'VALUES (%s, %s, %s, %s) ',
|
||||
(0, datetime.datetime.now(), module_id, dependency))
|
||||
|
||||
|
||||
class _Cursor(sqlite.Cursor):
|
||||
|
||||
+2
-2
@@ -160,9 +160,9 @@ class Cron(ModelSQL, ModelView):
|
||||
cursor.execute('SELECT * FROM ir_cron ' \
|
||||
'WHERE numbercall <> 0 ' \
|
||||
'AND active ' \
|
||||
'AND nextcall <= now() ' \
|
||||
'AND nextcall <= %s ' \
|
||||
'AND NOT running ' \
|
||||
'ORDER BY priority')
|
||||
'ORDER BY priority', (datetime.datetime.now(),))
|
||||
crons = cursor.dictfetchall()
|
||||
|
||||
for cron in crons:
|
||||
|
||||
@@ -311,8 +311,9 @@ class ModelSQL(ModelStorage):
|
||||
'is not in the selection' % \
|
||||
(val, field))
|
||||
upd0 += ', create_uid, create_date'
|
||||
upd1 += ', %s, now()'
|
||||
upd1 += ', %s, %s'
|
||||
upd2.append(user)
|
||||
upd2.append(datetime.datetime.now())
|
||||
try:
|
||||
id_new = cursor.nextid(self._table)
|
||||
if id_new:
|
||||
@@ -483,8 +484,6 @@ class ModelSQL(ModelStorage):
|
||||
if not self.table_query(context):
|
||||
fields_pre2 += ['(COALESCE(write_date, create_date)) ' \
|
||||
'AS _timestamp']
|
||||
else:
|
||||
fields_pre2 += ['now()::timestamp AS _timestamp']
|
||||
|
||||
for i in range(0, len(ids), in_max):
|
||||
sub_ids = ids[i:i + in_max]
|
||||
@@ -808,8 +807,9 @@ class ModelSQL(ModelStorage):
|
||||
(val, field))
|
||||
|
||||
upd0.append(('write_uid', '%s'))
|
||||
upd0.append(('write_date', 'now()'))
|
||||
upd0.append(('write_date', '%s'))
|
||||
upd1.append(user)
|
||||
upd1.append(datetime.datetime.now())
|
||||
|
||||
domain1, domain2 = self.pool.get('ir.rule').domain_get(cursor,
|
||||
user, self._name, mode='write', context=context)
|
||||
@@ -1121,8 +1121,8 @@ class ModelSQL(ModelStorage):
|
||||
if self._history:
|
||||
for obj_id in ids:
|
||||
cursor.execute('INSERT INTO "' + self._table + '__history" ' \
|
||||
'(id, write_uid, write_date) VALUES (%s, %s, now())',
|
||||
(obj_id, user))
|
||||
'(id, write_uid, write_date) VALUES (%s, %s, %s)',
|
||||
(obj_id, user, datetime.datetime.now()))
|
||||
|
||||
for k in tree_ids.keys():
|
||||
field = self._columns[k]
|
||||
@@ -1205,8 +1205,6 @@ class ModelSQL(ModelStorage):
|
||||
select_fields += ['(COALESCE("' + self._table + '".write_date,'\
|
||||
'"' + self._table + '".create_date)) ' \
|
||||
'AS _timestamp']
|
||||
else:
|
||||
select_fields += ['now()::timestamp AS _timestamp']
|
||||
query_str = cursor.limit_clause(
|
||||
'SELECT ' + ','.join(select_fields) + ' FROM ' + \
|
||||
' '.join(tables) + (qu1 and ' WHERE ' + qu1 or '') + \
|
||||
|
||||
@@ -19,6 +19,7 @@ try:
|
||||
except ImportError:
|
||||
import StringIO
|
||||
import dis
|
||||
import datetime
|
||||
|
||||
def find_in_path(name):
|
||||
if os.name == "nt":
|
||||
@@ -323,11 +324,11 @@ class Cache(object):
|
||||
cursor.execute('SELECT name FROM ir_cache WHERE name = %s',
|
||||
(name,))
|
||||
if cursor.fetchone():
|
||||
cursor.execute('UPDATE ir_cache SET "timestamp" = now() '\
|
||||
'WHERE name = %s', (name,))
|
||||
cursor.execute('UPDATE ir_cache SET "timestamp" = %s '\
|
||||
'WHERE name = %s', (datetime.datetime.now(), name))
|
||||
else:
|
||||
cursor.execute('INSERT INTO ir_cache ("timestamp", "name") ' \
|
||||
'VALUES (now(), %s)', (name,))
|
||||
'VALUES (%s, %s)', (datetime.datetime.now(), name))
|
||||
Cache._resets[dbname].clear()
|
||||
finally:
|
||||
cursor.commit()
|
||||
|
||||
Reference in new issue
Block a user