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 10 : TEST_MAIN()
39 : {
40 : RETCODE rc;
41 10 : const int rows_to_add = 50;
42 : LOGINREC *login;
43 : DBPROCESS *dbproc;
44 : int i;
45 :
46 10 : set_malloc_options();
47 :
48 10 : read_login_info(argc, argv);
49 10 : printf("Starting %s\n", argv[0]);
50 :
51 : /* Fortify_EnterScope(); */
52 10 : dbinit();
53 :
54 10 : dberrhandle(syb_err_handler);
55 10 : dbmsghandle(syb_msg_handler);
56 :
57 10 : printf("About to logon\n");
58 :
59 10 : login = dblogin();
60 10 : DBSETLPWD(login, PASSWORD);
61 10 : DBSETLUSER(login, USER);
62 10 : DBSETLAPP(login, "t0006");
63 10 : DBSETLHOST(login, "ntbox.dntis.ro");
64 :
65 10 : printf("About to open\n");
66 :
67 10 : dbproc = dbopen(login, SERVER);
68 10 : if (strlen(DATABASE))
69 10 : dbuse(dbproc, DATABASE);
70 10 : dbloginfree(login);
71 :
72 : #ifdef MICROSOFT_DBLIB
73 : dbsetopt(dbproc, DBBUFFER, "5000");
74 : #else
75 10 : dbsetopt(dbproc, DBBUFFER, "5000", 0);
76 : #endif
77 :
78 10 : printf("creating table\n");
79 10 : sql_cmd(dbproc);
80 10 : dbsqlexec(dbproc);
81 10 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
82 : /* nop */
83 : }
84 :
85 10 : printf("insert\n");
86 500 : for (i = 1; i < rows_to_add; i++) {
87 490 : sql_cmd(dbproc);
88 490 : dbsqlexec(dbproc);
89 490 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
90 : /* nop */
91 : }
92 : }
93 :
94 10 : printf("first select\n");
95 10 : if (SUCCEED != sql_cmd(dbproc)) {
96 0 : fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__);
97 0 : failed = 1;
98 : }
99 10 : if (SUCCEED != dbsqlexec(dbproc)) {
100 0 : fprintf(stderr, "%s:%d: dbsqlexec failed\n", __FILE__, __LINE__);
101 0 : failed = 1;
102 : }
103 :
104 :
105 10 : if (dbresults(dbproc) != SUCCEED) {
106 0 : printf("%s:%d: Was expecting a result set.", __FILE__, __LINE__);
107 0 : failed = 1;
108 0 : exit(1);
109 : }
110 :
111 20 : for (i = 1; i <= dbnumcols(dbproc); i++)
112 20 : printf("col %d is %s\n", i, dbcolname(dbproc, i));
113 :
114 10 : dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
115 10 : dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
116 :
117 10 : get_results(dbproc, 1);
118 :
119 10 : testint = -1;
120 10 : strcpy(teststr, "bogus");
121 10 : printf("second select\n");
122 10 : sql_cmd(dbproc);
123 10 : dbsqlexec(dbproc);
124 :
125 10 : if ((rc = dbresults(dbproc)) != SUCCEED) {
126 0 : printf("%s:%d: Was expecting a result set. (rc=%d)\n", __FILE__, __LINE__, rc);
127 0 : failed = 1;
128 : }
129 :
130 10 : if (!failed) {
131 10 : dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
132 10 : dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
133 :
134 10 : get_results(dbproc, 25);
135 : }
136 10 : dbexit();
137 :
138 10 : printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
139 10 : return failed ? 1 : 0;
140 : }
|