Line data Source code
1 : #include "common.h"
2 :
3 : /* first MARS test, test 2 concurrent recordset */
4 :
5 : #define SET_STMT(n) do { \
6 : if (pcur_stmt != &n) { \
7 : if (pcur_stmt) *pcur_stmt = odbc_stmt; \
8 : pcur_stmt = &n; \
9 : odbc_stmt = *pcur_stmt; \
10 : } \
11 : } while(0)
12 :
13 : static void
14 2 : AutoCommit(int onoff)
15 : {
16 2 : CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(onoff), 0, "S");
17 2 : }
18 :
19 : static void
20 2 : EndTransaction(SQLSMALLINT type)
21 : {
22 2 : CHKEndTran(SQL_HANDLE_DBC, odbc_conn, type, "S");
23 2 : }
24 :
25 :
26 : static void
27 10 : my_attrs(void)
28 : {
29 10 : SQLSetConnectAttr(odbc_conn, 1224 /*SQL_COPT_SS_MARS_ENABLED*/, (SQLPOINTER) 1 /*SQL_MARS_ENABLED_YES*/, SQL_IS_UINTEGER);
30 10 : }
31 :
32 10 : TEST_MAIN()
33 : {
34 : SQLINTEGER len, out;
35 : int i;
36 : SQLHSTMT stmt1, stmt2;
37 10 : SQLHSTMT *pcur_stmt = NULL;
38 :
39 10 : odbc_use_version3 = 1;
40 10 : odbc_set_conn_attr = my_attrs;
41 10 : odbc_connect();
42 :
43 10 : stmt1 = odbc_stmt;
44 :
45 10 : out = 0;
46 10 : len = sizeof(out);
47 10 : CHKGetConnectAttr(1224, (SQLPOINTER) &out, sizeof(out), &len, "SE");
48 :
49 : /* test we really support MARS on this connection */
50 : /* TODO should out be correct ?? */
51 10 : printf("Following row can contain an error due to MARS detection (is expected)\n");
52 10 : if (!out || odbc_command2("BEGIN TRANSACTION", "SNoE") != SQL_ERROR) {
53 8 : printf("MARS not supported for this connection\n");
54 8 : odbc_disconnect();
55 8 : odbc_test_skipped();
56 0 : return 0;
57 : }
58 2 : odbc_read_error();
59 2 : if (!strstr(odbc_err, "MARS")) {
60 0 : fprintf(stderr, "Error message invalid \"%s\"\n", odbc_err);
61 0 : return 1;
62 : }
63 :
64 : /* create a test table with some data */
65 2 : odbc_command("create table #mars1 (n int, v varchar(100))");
66 122 : for (i = 0; i < 60; ++i) {
67 : char cmd[120], buf[80];
68 120 : memset(buf, 'a' + (i % 26), sizeof(buf));
69 120 : buf[i * 7 % 73] = 0;
70 120 : sprintf(cmd, "insert into #mars1 values(%d, '%s')", i, buf);
71 120 : odbc_command(cmd);
72 : }
73 :
74 : /* and another to avid locking problems */
75 2 : odbc_command("create table #mars2 (n int, v varchar(100))");
76 :
77 2 : AutoCommit(SQL_AUTOCOMMIT_OFF);
78 :
79 : /* try to do a select which return a lot of data (to test server didn't cache everything) */
80 2 : odbc_command("select a.n, b.n, a.v from #mars1 a, #mars1 b order by a.n, b.n");
81 2 : CHKFetch("S");
82 :
83 : /* try to do other commands */
84 2 : CHKAllocStmt(&stmt2, "S");
85 2 : SET_STMT(stmt2);
86 2 : odbc_command("insert into #mars2 values(1, 'foo')");
87 2 : SET_STMT(stmt1);
88 :
89 2 : CHKFetch("S");
90 :
91 : /* reset statements */
92 2 : odbc_reset_statement();
93 2 : SET_STMT(stmt2);
94 2 : odbc_reset_statement();
95 :
96 : /* now to 2 select with prepare/execute */
97 2 : CHKPrepare(T("select a.n, b.n, a.v from #mars1 a, #mars1 b order by a.n, b.n"), SQL_NTS, "S");
98 2 : SET_STMT(stmt1);
99 2 : CHKPrepare(T("select a.n, b.n, a.v from #mars1 a, #mars1 b order by a.n desc, b.n"), SQL_NTS, "S");
100 2 : SET_STMT(stmt2);
101 2 : CHKExecute("S");
102 2 : SET_STMT(stmt1);
103 2 : CHKExecute("S");
104 2 : SET_STMT(stmt2);
105 2 : CHKFetch("S");
106 2 : SET_STMT(stmt1);
107 2 : CHKFetch("S");
108 2 : SET_STMT(stmt2);
109 2 : CHKFetch("S");
110 2 : odbc_reset_statement();
111 2 : SET_STMT(stmt1);
112 2 : CHKFetch("S");
113 2 : odbc_reset_statement();
114 :
115 2 : EndTransaction(SQL_COMMIT);
116 :
117 : /* TODO test receiving large data should not take much memory */
118 :
119 2 : odbc_disconnect();
120 2 : return 0;
121 : }
122 :
|