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