On Oct 31, 2011, at 1:18 AM, Simon Haines wrote:

> I think I've found a bug--can anyone else confirm this? It appears that 
> SQLAlchemy cannot query SQLServer time columns because Python datetime.time 
> objects are always promoted to full datetime types. Once promoted the 
> SQLServer returns the error: 'The data types time and datetime are 
> incompatible in the greater than operator. (402) (SQLExecDirectW)'.

> 
> The type promotion occurs in sqlalchemy/dialects/mssql/base.py:268-276.

What DBAPI are you using ?     The date/time behavior there is all tailored to 
suit what the DBAPIs want.   Also some comparisons aren't possible with SQL 
server, it has extremely limited date functionality.

Basically SQLAlchemy can only do what the DBAPI allows.   As the comments there 
indicate, Pyodbc crashes if a datetime.time() is passed directly, this might be 
considered a Pyodbc bug if that behavior can be re-confirmed ,as this code is a 
few years old.   Assuming you're using pyodbc, you'd need to get your query to 
work as follows first:

import pyodbc
import datetime

conn = pyodbc.connect("dsn=ms_2005;UID=scott;PWD=tiger")

cursor = conn.cursor()

# example:
cursor.execute("SELECT ?", datetime.time(12, 15, 0))
print cursor.fetchall()

# put your statement here using ? for bound parameters
cursor.execute("<your statement goes here>", <your time/etc. parameters go 
here>)

print cursor.fetchall()

show me a working query with the DBAPI (again assuming pyodbc here) and I will 
adjust any incompatibilities on the SQLAlchemy side.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to