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