2010-05-24 39 views
4

使用pyodbc,如果我尝试并执行日期字段验证码:在pyodbc绑定一个空值日期字段

cursor.execute('insert into test VALUES (?)', None) 

...我得到pyodbc.Error: ('HY000', '[HY000] [SAS][SAS ODBC Driver][SAS Server]ERROR: Value 1 of VALUES clause 1 does not match the data type of the corresponding column in (-1) (SQLExecDirectW)'),而如果我执行此:

cursor.execute('insert into test VALUES (null)') 

...它的工作原理。是否有另一种方式来执行这个,这意味着我不需要检查我传递的参数?

回答

2

以我源(的Python 2.71/pyodbc 2.1.8)中,用一个MS访问的基础上,下面的代码是OK

st_dt=None 
sql = 'insert into COM(poste,mydate) values (?,?)' 
cursor.execute(sql,'1254',st_dt) 
cnxn.commit() 

凡指明MyDate与没有默认值的时间戳列。