adodbapi (or perhaps SQL Server in general) doesn't seem to like the isoformat() output
when used as follows:

start_datetime = datetime.datetime.now() - datetime.timedelta(days=7)

debug(start_datetime.strftime('%Y-%m-%d %H:%M:%S'))

query = select([table.c.somedatetime], table.c.somedatetime >= start_datetime)
query.execute()

produced the following exception.

com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider for SQL Server', 'Syntax error converting datetime from character string.', None, 0, -2147217913), None)

Changing the following method in MSDateTime resolved the error but it meant eliminating the millisecond resolution of the datetime field, therefore
I'm not sure if this is a good change or if there is a better way to do this without losing granularity.  Since my data is only granular to seconds, this
works for me...                                                    

# BEFORE
    def convert_bind_param(self, value, engine):
        if hasattr(value, "isoformat"):
            return value.isoformat(' ')
        else:
            return value

# AFTER
    def convert_bind_param(self, value, engine):
        if hasattr(value, "isoformat"):
            return value.strftime('%Y-%m-%d %H:%M:%S')
        else:
            return value

Thoughts?

--PLB

Reply via email to