4

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)')

... できます。これを実行する別の方法はありますか?つまり、渡した引数をチェックする必要はありませんか?

4

1 に答える 1

2

私のソース (Python 2.71 / pyodbc 2.1.8) では、MS Access ベースで、次のコードは問題ありません

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

mydate はデフォルト値のない Timestamp 列です。

于 2011-03-09T16:45:22.283 に答える