Skip to content
Permalink
Browse files

Make sure we serialize fractional seconds in Oracle queries.

  • Loading branch information...
cyrusdaboo committed Jul 1, 2016
1 parent df056fc commit 07c6d4506256626eb0ed0995987dbf5b8546d8d0
Showing with 25 additions and 3 deletions.
  1. +25 −3 txdav/base/datastore/dbapiclient.py
@@ -23,6 +23,8 @@

from txdav.common.icommondatastore import InternalDataStoreError

import datetime

import pg8000 as postgres

try:
@@ -124,7 +126,7 @@ def var(self, *args):
return self.realCursor.var(*args)


def execute(self, sql, args=()):
def mapArgs(self, args):
realArgs = []
for arg in args:
if isinstance(arg, str):
@@ -133,6 +135,7 @@ def execute(self, sql, args=()):
# application layer as they consume less memory, so do the
# conversion here.
arg = arg.decode('utf-8')

if isinstance(arg, unicode) and len(arg) > 1024:
# This *may* cause a type mismatch, but none of the non-CLOB
# strings that we're passing would allow a value this large
@@ -143,18 +146,37 @@ def execute(self, sql, args=()):
# it is:
v = self.var(cx_Oracle.NCLOB, len(arg) + 1)
v.setvalue(0, arg)

elif isinstance(arg, datetime.datetime):
# By default when cx_Oracle is passed a datetime object it maps it to a
# cx_Oracle.DATETIME variable which does not serialize fraction seconds
# into the query, or call, arguments. However, for high volume systems,
# we really want sub-second resolution for things like the job queue,
# so we want to serialize datetime as cx_Oracle.TIMESTAMP.
v = self.var(cx_Oracle.TIMESTAMP)
v.setvalue(0, arg)

else:
v = arg

realArgs.append(v)

return realArgs


def execute(self, sql, args=()):
realArgs = self.mapArgs(args)
return super(OracleCursorWrapper, self).execute(sql, realArgs)


def callproc(self, name, args=()):
return self.realCursor.callproc(name, args)
realArgs = self.mapArgs(args)
return self.realCursor.callproc(name, realArgs)


def callfunc(self, name, returnType, args=()):
return self.realCursor.callfunc(name, returnType, args)
realArgs = self.mapArgs(args)
return self.realCursor.callfunc(name, returnType, realArgs)



0 comments on commit 07c6d45

Please sign in to comment.
You can’t perform that action at this time.