Line data Source code
1 : #include "common.h"
2 :
3 : /* some tests on error reporting */
4 :
5 10 : TEST_MAIN()
6 : {
7 : SQLRETURN RetCode;
8 : HSTMT stmt;
9 :
10 10 : odbc_connect();
11 :
12 : /* create a test table */
13 10 : odbc_command("create table #tmp (i int)");
14 10 : odbc_command("insert into #tmp values(3)");
15 10 : odbc_command("insert into #tmp values(4)");
16 10 : odbc_command("insert into #tmp values(5)");
17 10 : odbc_command("insert into #tmp values(6)");
18 10 : odbc_command("insert into #tmp values(7)");
19 :
20 : /* issue our command */
21 10 : RetCode = odbc_command2("select 100 / (i - 5) from #tmp order by i", "SE");
22 :
23 : /* special case, early Sybase detect error early */
24 10 : if (RetCode != SQL_ERROR) {
25 :
26 : /* TODO when multiple row fetch available test for error on some columns */
27 10 : CHKFetch("S");
28 10 : CHKFetch("S");
29 10 : CHKFetch("E");
30 : }
31 :
32 10 : odbc_read_error();
33 10 : if (!strstr(odbc_err, "zero")) {
34 0 : fprintf(stderr, "Message invalid\n");
35 0 : return 1;
36 : }
37 :
38 10 : SQLFetch(odbc_stmt);
39 10 : SQLFetch(odbc_stmt);
40 10 : SQLFetch(odbc_stmt);
41 10 : SQLMoreResults(odbc_stmt);
42 :
43 10 : CHKAllocStmt(&stmt, "S");
44 :
45 10 : odbc_command("SELECT * FROM sysobjects");
46 :
47 10 : odbc_stmt = stmt;
48 :
49 : /* a statement is already active so you get error... */
50 10 : if (odbc_command2("SELECT * FROM sysobjects", "SE") == SQL_SUCCESS) {
51 2 : SQLMoreResults(odbc_stmt);
52 : /* ...or we are using MARS! */
53 2 : odbc_command2("BEGIN TRANSACTION", "E");
54 : }
55 :
56 10 : odbc_read_error();
57 :
58 10 : odbc_disconnect();
59 :
60 10 : printf("Done.\n");
61 10 : return 0;
62 : }
|