1 #include "common.h"
2
3 /* Test SQLFetchScroll with no bound columns */
4
5 static int bind_all = 0;
6 static int normal_fetch = 0;
7 static int use_cursors = 1;
8
Test(void)9 static void Test(void)
10 {
11 #define ROWS 5
12 struct data_t {
13 SQLINTEGER i;
14 SQLLEN ind_i;
15 char c[20];
16 SQLLEN ind_c;
17 } data[ROWS];
18 SQLUSMALLINT statuses[ROWS];
19 SQLLEN num_row;
20
21 odbc_reset_statement();
22
23 /* this should not fail or return warnings */
24 if (use_cursors) {
25 CHKSetStmtAttr(SQL_ATTR_CONCURRENCY, TDS_INT2PTR(SQL_CONCUR_READ_ONLY), 0, "S");
26 CHKSetStmtAttr(SQL_ATTR_CURSOR_TYPE, TDS_INT2PTR(SQL_CURSOR_STATIC), 0, "S");
27 }
28 CHKPrepare(T("SELECT c, i FROM #cursor6_test"), SQL_NTS, "S");
29 CHKExecute("S");
30 CHKSetStmtAttr(SQL_ATTR_ROW_BIND_TYPE, TDS_INT2PTR(sizeof(data[0])), 0, "S");
31 CHKSetStmtAttr(SQL_ATTR_ROW_ARRAY_SIZE, TDS_INT2PTR(ROWS), 0, "S");
32 CHKSetStmtAttr(SQL_ATTR_ROW_STATUS_PTR, statuses, 0, "S");
33 CHKSetStmtAttr(SQL_ATTR_ROWS_FETCHED_PTR, &num_row, 0, "S");
34 if (bind_all)
35 CHKBindCol(1, SQL_C_CHAR, &data[0].c, sizeof(data[0].c), &data[0].ind_c, "S");
36 CHKBindCol(2, SQL_C_LONG, &data[0].i, sizeof(data[0].i), &data[0].ind_i, "S");
37
38 #define FILL(s, n) do { \
39 int _n; for (_n = 0; _n < TDS_VECTOR_SIZE(s); ++_n) s[_n] = n; \
40 } while(0)
41 FILL(statuses, 9876);
42 num_row = -3;
43 data[0].i = (SQLINTEGER) 0xdeadbeef;
44 data[1].i = (SQLINTEGER) 0xdeadbeef;
45 if (normal_fetch)
46 CHKFetch("S");
47 else
48 CHKFetchScroll(SQL_FETCH_NEXT, 0, "S");
49
50 /* now check row numbers */
51 printf("num_row %ld statuses[0] %d statuses[1] %d odbc3 %d\n", (long int) num_row,
52 (int) statuses[0], (int) statuses[1], odbc_use_version3);
53
54 if (odbc_use_version3 || !normal_fetch) {
55 if (num_row != ROWS || statuses[0] != SQL_ROW_SUCCESS || statuses[1] != SQL_ROW_SUCCESS) {
56 fprintf(stderr, "result error 1\n");
57 exit(1);
58 }
59 } else {
60 if (data[0].i != 1 || data[1].i != 0xdeadbeef) {
61 fprintf(stderr, "result error 2\n");
62 exit(1);
63 }
64 }
65
66 FILL(statuses, 8765);
67 num_row = -3;
68 if (normal_fetch)
69 CHKFetch("S");
70 else
71 CHKFetchScroll(SQL_FETCH_NEXT, 0, "S");
72 }
73
Init(void)74 static void Init(void)
75 {
76 int i;
77 char sql[128];
78
79 odbc_command("CREATE TABLE #cursor6_test (i INT, c VARCHAR(20))");
80 for (i = 1; i <= 10; ++i) {
81 sprintf(sql, "INSERT INTO #cursor6_test(i,c) VALUES(%d, 'a%db%dc%d')", i, i, i, i);
82 odbc_command(sql);
83 }
84
85 }
86
87 int
main(int argc,char * argv[])88 main(int argc, char *argv[])
89 {
90 odbc_use_version3 = 1;
91 odbc_connect();
92
93 odbc_check_cursor();
94
95 Init();
96
97 #define ALL(n) for (n = 0; n < 2; ++n)
98 ALL(use_cursors)
99 ALL(bind_all)
100 ALL(normal_fetch)
101 Test();
102
103 odbc_disconnect();
104
105 odbc_use_version3 = 0;
106
107 odbc_connect();
108 Init();
109
110 ALL(use_cursors)
111 ALL(bind_all)
112 ALL(normal_fetch)
113 Test();
114
115 odbc_disconnect();
116
117 return 0;
118 }
119