1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
23 import subprocess |
23 import subprocess |
24 from datetime import datetime, date |
24 from datetime import datetime, date |
25 |
25 |
26 from logilab import database as db, common as lgc |
26 from logilab import database as db, common as lgc |
27 from logilab.common.shellutils import ProgressBar |
27 from logilab.common.shellutils import ProgressBar |
28 from logilab.common.date import todate, todatetime |
28 from logilab.common.date import todate, todatetime, utcdatetime, utctime |
29 from logilab.database.sqlgen import SQLGenerator |
29 from logilab.database.sqlgen import SQLGenerator |
30 |
30 |
31 from cubicweb import Binary, ConfigurationError |
31 from cubicweb import Binary, ConfigurationError |
32 from cubicweb.uilib import remove_html_tags |
32 from cubicweb.uilib import remove_html_tags |
33 from cubicweb.schema import PURE_VIRTUAL_RTYPES |
33 from cubicweb.schema import PURE_VIRTUAL_RTYPES |
272 value = value.getvalue() |
272 value = value.getvalue() |
273 else: |
273 else: |
274 value = crypt_password(value) |
274 value = crypt_password(value) |
275 value = self._binary(value) |
275 value = self._binary(value) |
276 # XXX needed for sqlite but I don't think it is for other backends |
276 # XXX needed for sqlite but I don't think it is for other backends |
277 elif atype == 'Datetime' and isinstance(value, date): |
277 # Note: use is __class__ since issubclass(datetime, date) |
|
278 elif atype in ('Datetime', 'TZDatetime') and value.__class__ is date: |
278 value = todatetime(value) |
279 value = todatetime(value) |
279 elif atype == 'Date' and isinstance(value, datetime): |
280 elif atype == 'Date' and isinstance(value, datetime): |
280 value = todate(value) |
281 value = todate(value) |
|
282 elif atype == 'TZDatetime' and getattr(value, 'tzinfo', None): |
|
283 value = utcdatetime(value) |
|
284 elif atype == 'TZTime' and getattr(value, 'tzinfo', None): |
|
285 value = utctime(value) |
281 elif isinstance(value, Binary): |
286 elif isinstance(value, Binary): |
282 value = self._binary(value.getvalue()) |
287 value = self._binary(value.getvalue()) |
283 attrs[SQL_PREFIX+str(attr)] = value |
288 attrs[SQL_PREFIX+str(attr)] = value |
284 attrs[SQL_PREFIX+'eid'] = entity.eid |
289 attrs[SQL_PREFIX+'eid'] = entity.eid |
285 return attrs |
290 return attrs |
324 import yams.constraints |
329 import yams.constraints |
325 yams.constraints.patch_sqlite_decimal() |
330 yams.constraints.patch_sqlite_decimal() |
326 |
331 |
327 sqlite_hooks = SQL_CONNECT_HOOKS.setdefault('sqlite', []) |
332 sqlite_hooks = SQL_CONNECT_HOOKS.setdefault('sqlite', []) |
328 sqlite_hooks.append(init_sqlite_connexion) |
333 sqlite_hooks.append(init_sqlite_connexion) |
|
334 |
|
335 |
|
336 def init_postgres_connexion(cnx): |
|
337 cnx.cursor().execute('SET TIME ZONE UTC') |
|
338 |
|
339 postgres_hooks = SQL_CONNECT_HOOKS.setdefault('postgres', []) |
|
340 postgres_hooks.append(init_postgres_connexion) |