Line data Source code
1 : #include "common.h"
2 :
3 : /* test error on prepared statement, from Nathaniel Talbott test */
4 :
5 : static char software_version[] = "$Id: preperror.c,v 1.10 2011-07-12 10:16:59 freddy77 Exp $";
6 : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
7 :
8 : int
9 8 : main(int argc, char *argv[])
10 : {
11 8 : SQLLEN cbInString = SQL_NTS;
12 : char buf[256];
13 : SQLTCHAR msg[256];
14 : SQLTCHAR sqlstate[6];
15 :
16 8 : odbc_connect();
17 :
18 8 : odbc_command("CREATE TABLE #urls ( recdate DATETIME ) ");
19 :
20 : /* test implicit conversion error */
21 8 : CHKExecDirect(T("INSERT INTO #urls ( recdate ) VALUES ( '2003-10-1 10:11:1 0' )"), SQL_NTS, "E");
22 :
23 : /* test prepared implicit conversion error */
24 8 : CHKPrepare(T("INSERT INTO #urls ( recdate ) VALUES ( ? )"), SQL_NTS, "SI");
25 :
26 8 : strcpy(buf, "2003-10-1 10:11:1 0");
27 8 : CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 128, 0, buf, sizeof(buf), &cbInString, "SI");
28 :
29 8 : CHKExecute("E");
30 :
31 8 : CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, sqlstate, NULL, msg, TDS_VECTOR_SIZE(buf), NULL, "SI");
32 8 : printf("err=%s\n", C(msg));
33 :
34 : /* assure initial state */
35 8 : odbc_reset_statement();
36 :
37 : /* try to prepare and execute a statement with error (from DBD::ODBC test) */
38 8 : if (CHKPrepare(T("SELECT XXNOTCOLUMN FROM sysobjects"), SQL_NTS, "SE") == SQL_SUCCESS)
39 6 : CHKExecute("E");
40 :
41 8 : CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, sqlstate, NULL, msg, TDS_VECTOR_SIZE(buf), NULL, "SI");
42 8 : printf("err=%s\n", C(msg));
43 :
44 :
45 8 : odbc_disconnect();
46 :
47 8 : printf("Done.\n");
48 8 : ODBC_FREE();
49 : return 0;
50 : }
|