Line data Source code
1 : /* Tests 2 active statements */
2 : #include "common.h"
3 :
4 : int
5 10 : main(void)
6 : {
7 10 : SQLHSTMT stmt1 = SQL_NULL_HSTMT;
8 10 : SQLHSTMT stmt2 = SQL_NULL_HSTMT;
9 : SQLHSTMT old_odbc_stmt;
10 : char buff[64];
11 : SQLLEN ind;
12 :
13 10 : odbc_use_version3 = 1;
14 10 : odbc_connect();
15 :
16 10 : odbc_check_cursor();
17 :
18 8 : odbc_command("CREATE TABLE #t1 ( k INT, c VARCHAR(20))");
19 8 : odbc_command("INSERT INTO #t1 VALUES (1, 'aaa')");
20 8 : odbc_command("INSERT INTO #t1 VALUES (2, 'bbbbb')");
21 8 : odbc_command("INSERT INTO #t1 VALUES (3, 'ccccccccc')");
22 8 : odbc_command("INSERT INTO #t1 VALUES (4, 'dd')");
23 :
24 8 : old_odbc_stmt = odbc_stmt;
25 :
26 8 : CHKAllocHandle(SQL_HANDLE_STMT, odbc_conn, &stmt1, "S");
27 8 : CHKAllocHandle(SQL_HANDLE_STMT, odbc_conn, &stmt2, "S");
28 :
29 :
30 8 : odbc_stmt = stmt1;
31 : /* CHKSetStmtAttr(SQL_ATTR_CURSOR_SCROLLABLE, (SQLPOINTER) SQL_NONSCROLLABLE, SQL_IS_UINTEGER, "S"); */
32 8 : CHKSetStmtAttr(SQL_ATTR_CURSOR_SENSITIVITY, (SQLPOINTER) SQL_SENSITIVE, SQL_IS_UINTEGER, "S");
33 : /* CHKSetStmtAttr(SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_LOCK, SQL_IS_UINTEGER, "S"); */
34 :
35 :
36 8 : odbc_stmt = stmt2;
37 : /* CHKSetStmtAttr(SQL_ATTR_CURSOR_SCROLLABLE, (SQLPOINTER) SQL_NONSCROLLABLE, SQL_IS_UINTEGER, "S"); */
38 8 : CHKSetStmtAttr(SQL_ATTR_CURSOR_SENSITIVITY, (SQLPOINTER) SQL_SENSITIVE, SQL_IS_UINTEGER, "S");
39 : /* CHKSetStmtAttr(SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_LOCK, SQL_IS_UINTEGER, "S"); */
40 :
41 8 : odbc_stmt = stmt1;
42 8 : CHKSetCursorName(T("c1"), SQL_NTS, "S");
43 :
44 8 : odbc_stmt = stmt2;
45 8 : CHKSetCursorName(T("c2"), SQL_NTS, "S");
46 :
47 8 : odbc_stmt = stmt1;
48 8 : CHKPrepare(T("SELECT * FROM #t1 ORDER BY k"), SQL_NTS, "S");
49 :
50 8 : odbc_stmt = stmt2;
51 8 : CHKPrepare(T("SELECT * FROM #t1 ORDER BY k DESC"), SQL_NTS, "S");
52 :
53 8 : odbc_stmt = stmt1;
54 8 : CHKExecute("S");
55 :
56 8 : odbc_stmt = stmt2;
57 8 : CHKExecute("S");
58 :
59 8 : odbc_stmt = stmt1;
60 8 : CHKFetch("S");
61 :
62 8 : CHKGetData(2, SQL_C_CHAR, (SQLPOINTER) buff, sizeof(buff), &ind, "S");
63 8 : printf(">> Fetch from 1: [%s]\n", buff);
64 :
65 8 : odbc_stmt = stmt2;
66 8 : CHKFetch("S");
67 :
68 8 : CHKGetData(2, SQL_C_CHAR, (SQLPOINTER) buff, sizeof(buff), &ind, "S");
69 8 : printf(">> Fetch from 2: [%s]\n", buff);
70 :
71 : /*
72 : * this should check a problem with SQLGetData
73 : * fetch a data on stmt2 than fetch on stmt1 and try to get data on first one
74 : */
75 8 : CHKFetch("S"); /* "ccccccccc" */
76 8 : odbc_stmt = stmt1;
77 8 : CHKFetch("S"); /* "bbbbb" */
78 8 : odbc_stmt = stmt2;
79 8 : CHKGetData(2, SQL_C_CHAR, (SQLPOINTER) buff, sizeof(buff), &ind, "S");
80 8 : printf(">> Fetch from 2: [%s]\n", buff);
81 8 : if (strcmp(buff, "ccccccccc") != 0)
82 0 : ODBC_REPORT_ERROR("Invalid results from SQLGetData");
83 8 : odbc_stmt = stmt1;
84 8 : CHKGetData(2, SQL_C_CHAR, (SQLPOINTER) buff, sizeof(buff), &ind, "S");
85 8 : printf(">> Fetch from 1: [%s]\n", buff);
86 8 : if (strcmp(buff, "bbbbb") != 0)
87 0 : ODBC_REPORT_ERROR("Invalid results from SQLGetData");
88 :
89 8 : odbc_stmt = stmt1;
90 8 : CHKCloseCursor("SI");
91 8 : odbc_stmt = stmt2;
92 8 : CHKCloseCursor("SI");
93 :
94 8 : odbc_stmt = stmt1;
95 8 : CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) stmt1, "S");
96 8 : odbc_stmt = stmt2;
97 8 : CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) stmt2, "S");
98 :
99 8 : odbc_stmt = old_odbc_stmt;
100 8 : odbc_disconnect();
101 :
102 : return 0;
103 : }
104 :
|