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