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