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.
精彩评论