Binding a null value to a date field in pyobbc

Using pyodbc if I try to execute this code in a date field:

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

... I get 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)') , and if I do this:

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

... it works. Is there any other way to accomplish this, which means that I don't need to check the arguments that I pass?

+4
source share
1 answer

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

 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.

+2
source

Source: https://habr.com/ru/post/1310792/


All Articles