Description:
When I try to use prepared statements with types SQL_TYPE_TIME, SQL_TYPE_DATE, SQL_TYPE_TIMESTAMP the application crashes on SQLExecute. The workaround is to use these types as strings rather than SQLBindParameter/SQLBindCol to them.
How to repeat:
create table testtable (a int, b varchar (256), c text, d time, e date, f datetime, g int);
In your code,
Set conformance (doesn't matter) rc = SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);
Have a;
SQL_TIME_STRUCT d;
Prepare the statement;
rc = SQLPrepare (hstmt, (SQLCHAR *) "INSERT INTO testtable (d) VALUES (?)", SQL_NTS);
Then;
rc = SQLBindParameter (hstmt, id++, SQL_PARAM_INPUT, SQL_C_TYPE_TIME, SQL_TYPE_TIME, 0, 0, & d, 0, (SQLINTEGER *) cbD);
or
rc = SQLBindParameter (hstmt, id++, SQL_PARAM_INPUT, SQL_C_TIME, SQL_TIME, 0, 0, & d, 0, (SQLINTEGER *) cbD);
whatever takes your fancy.
Now execute;
rc = SQLExecute(hstmt);
Crash stack trace;
myodbc3.dll!10008087()
> newmain.exe!simple_insert() Line 154 + 0x9 C++
newmain.exe!main() Line 328 C++
newmain.exe!mainCRTStartup() Line 259 + 0x12 C
kernel32.dll!7c816d4f()
Suggested fix:
My workaround simply to send the data as text rather than bind the parameter from native type
INSERT INTO testtable (d) VALUES ('11:23:45')
d is of type TIME
Description: When I try to use prepared statements with types SQL_TYPE_TIME, SQL_TYPE_DATE, SQL_TYPE_TIMESTAMP the application crashes on SQLExecute. The workaround is to use these types as strings rather than SQLBindParameter/SQLBindCol to them. How to repeat: create table testtable (a int, b varchar (256), c text, d time, e date, f datetime, g int); In your code, Set conformance (doesn't matter) rc = SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0); Have a; SQL_TIME_STRUCT d; Prepare the statement; rc = SQLPrepare (hstmt, (SQLCHAR *) "INSERT INTO testtable (d) VALUES (?)", SQL_NTS); Then; rc = SQLBindParameter (hstmt, id++, SQL_PARAM_INPUT, SQL_C_TYPE_TIME, SQL_TYPE_TIME, 0, 0, & d, 0, (SQLINTEGER *) cbD); or rc = SQLBindParameter (hstmt, id++, SQL_PARAM_INPUT, SQL_C_TIME, SQL_TIME, 0, 0, & d, 0, (SQLINTEGER *) cbD); whatever takes your fancy. Now execute; rc = SQLExecute(hstmt); Crash stack trace; myodbc3.dll!10008087() > newmain.exe!simple_insert() Line 154 + 0x9 C++ newmain.exe!main() Line 328 C++ newmain.exe!mainCRTStartup() Line 259 + 0x12 C kernel32.dll!7c816d4f() Suggested fix: My workaround simply to send the data as text rather than bind the parameter from native type INSERT INTO testtable (d) VALUES ('11:23:45') d is of type TIME