开发者

Binding a null value to a date field in pyodbc

Using pyodbc, if I try and execute this code on a date field:

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

... I get pyodbc.Error: ('HY000', '[HY000] [SAS][SAS ODBC Driver][SAS Server]ERROR: 开发者_Python百科Value 1 of VALUES clause 1 does not match the data type of the corresponding column in (-1) (SQLExecDirectW)'), while if I execute this:

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

... it works. Is there another way to be executing this, that means I don't need to check the arguments I'm passing?


In my source (Python 2.71 / pyodbc 2.1.8), with a MS Access base, the following code is OK

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

Where mydate is a Timestamp column with no default value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜