Line data Source code
1 : /*
2 : * Purpose: Test fetching 50 rows in two result sets with a 5000-row buffer.
3 : * Functions: dbbind dbcmd dbnextrow dbnumcols dbresults dbsetopt dbsqlexec
4 : */
5 :
6 : #include "common.h"
7 :
8 : static char teststr[1024];
9 : static DBINT testint;
10 :
11 : static int failed = 0;
12 :
13 :
14 : static void
15 20 : get_results(DBPROCESS * dbproc, int start)
16 : {
17 20 : int current = start - 1;
18 :
19 780 : while (REG_ROW == dbnextrow(dbproc)) {
20 : char expected[1024];
21 :
22 740 : current++;
23 740 : sprintf(expected, "row %04d", current);
24 :
25 740 : if (testint != current) {
26 0 : fprintf(stderr, "Failed. Expected i to be %d, was %d\n", current, (int) testint);
27 0 : abort();
28 : }
29 740 : if (0 != strncmp(teststr, expected, strlen(expected))) {
30 0 : printf("Failed. Expected s to be |%s|, was |%s|\n", expected, teststr);
31 0 : abort();
32 : }
33 740 : printf("Read a row of data -> %d %s\n", (int) testint, teststr);
34 : }
35 20 : }
36 :
37 :
38 : int
39 10 : main(int argc, char **argv)
40 : {
41 : RETCODE rc;
42 10 : const int rows_to_add = 50;
43 : LOGINREC *login;
44 : DBPROCESS *dbproc;
45 : int i;
46 :
47 10 : set_malloc_options();
48 :
49 10 : read_login_info(argc, argv);
50 10 : printf("Starting %s\n", argv[0]);
51 :
52 : /* Fortify_EnterScope(); */
53 10 : dbinit();
54 :
55 10 : dberrhandle(syb_err_handler);
56 10 : dbmsghandle(syb_msg_handler);
57 :
58 10 : printf("About to logon\n");
59 :
60 10 : login = dblogin();
61 10 : DBSETLPWD(login, PASSWORD);
62 10 : DBSETLUSER(login, USER);
63 10 : DBSETLAPP(login, "t0006");
64 10 : DBSETLHOST(login, "ntbox.dntis.ro");
65 :
66 10 : printf("About to open\n");
67 :
68 10 : dbproc = dbopen(login, SERVER);
69 10 : if (strlen(DATABASE))
70 10 : dbuse(dbproc, DATABASE);
71 10 : dbloginfree(login);
72 :
73 : #ifdef MICROSOFT_DBLIB
74 : dbsetopt(dbproc, DBBUFFER, "5000");
75 : #else
76 10 : dbsetopt(dbproc, DBBUFFER, "5000", 0);
77 : #endif
78 :
79 10 : printf("creating table\n");
80 10 : sql_cmd(dbproc);
81 10 : dbsqlexec(dbproc);
82 10 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
83 : /* nop */
84 : }
85 :
86 10 : printf("insert\n");
87 500 : for (i = 1; i < rows_to_add; i++) {
88 490 : sql_cmd(dbproc);
89 490 : dbsqlexec(dbproc);
90 490 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
91 : /* nop */
92 : }
93 : }
94 :
95 10 : printf("first select\n");
96 10 : if (SUCCEED != sql_cmd(dbproc)) {
97 0 : fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__);
98 0 : failed = 1;
99 : }
100 10 : if (SUCCEED != dbsqlexec(dbproc)) {
101 0 : fprintf(stderr, "%s:%d: dbsqlexec failed\n", __FILE__, __LINE__);
102 0 : failed = 1;
103 : }
104 :
105 :
106 10 : if (dbresults(dbproc) != SUCCEED) {
107 0 : printf("%s:%d: Was expecting a result set.", __FILE__, __LINE__);
108 0 : failed = 1;
109 0 : exit(1);
110 : }
111 :
112 20 : for (i = 1; i <= dbnumcols(dbproc); i++)
113 20 : printf("col %d is %s\n", i, dbcolname(dbproc, i));
114 :
115 10 : dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
116 10 : dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
117 :
118 10 : get_results(dbproc, 1);
119 :
120 10 : testint = -1;
121 10 : strcpy(teststr, "bogus");
122 10 : printf("second select\n");
123 10 : sql_cmd(dbproc);
124 10 : dbsqlexec(dbproc);
125 :
126 10 : if ((rc = dbresults(dbproc)) != SUCCEED) {
127 0 : printf("%s:%d: Was expecting a result set. (rc=%d)\n", __FILE__, __LINE__, rc);
128 0 : failed = 1;
129 : }
130 :
131 10 : if (!failed) {
132 10 : dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
133 10 : dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
134 :
135 10 : get_results(dbproc, 25);
136 : }
137 10 : dbexit();
138 :
139 10 : printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
140 10 : return failed ? 1 : 0;
141 : }
|