1 : /*
2 : * Purpose: Test to see if row buffering and blobs works correctly.
3 : * Functions: dbbind dbnextrow dbopen dbresults dbsqlexec dbgetrow
4 : */
5 :
6 : #if HAVE_CONFIG_H
7 : #include <config.h>
8 : #endif /* HAVE_CONFIG_H */
9 :
10 : #include <stdio.h>
11 :
12 : #if HAVE_STDLIB_H
13 : #include <stdlib.h>
14 : #endif /* HAVE_STDLIB_H */
15 :
16 : #if HAVE_STRING_H
17 : #include <string.h>
18 : #endif /* HAVE_STRING_H */
19 :
20 : #include <sqlfront.h>
21 : #include <sqldb.h>
22 :
23 : #include "common.h"
24 :
25 :
26 :
27 : static char software_version[] = "$Id: text_buffer.c,v 1.1 2005/08/16 15:04:03 freddy77 Exp $";
28 : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
29 :
30 :
31 : int
32 : main(int argc, char **argv)
33 2 : {
34 : LOGINREC *login;
35 : DBPROCESS *dbproc;
36 : int i;
37 : char teststr[1024];
38 : DBINT testint;
39 :
40 2 : set_malloc_options();
41 :
42 2 : read_login_info(argc, argv);
43 :
44 2 : fprintf(stdout, "Start\n");
45 2 : add_bread_crumb();
46 :
47 : /* Fortify_EnterScope(); */
48 2 : dbinit();
49 :
50 2 : add_bread_crumb();
51 2 : dberrhandle(syb_err_handler);
52 2 : dbmsghandle(syb_msg_handler);
53 :
54 2 : fprintf(stdout, "About to logon\n");
55 :
56 2 : add_bread_crumb();
57 2 : login = dblogin();
58 2 : DBSETLPWD(login, PASSWORD);
59 2 : DBSETLUSER(login, USER);
60 2 : DBSETLAPP(login, "text_buffer");
61 2 : DBSETLHOST(login, "ntbox.dntis.ro");
62 :
63 2 : fprintf(stdout, "About to open\n");
64 :
65 2 : add_bread_crumb();
66 2 : dbproc = dbopen(login, SERVER);
67 2 : if (strlen(DATABASE))
68 2 : dbuse(dbproc, DATABASE);
69 2 : add_bread_crumb();
70 2 : dbloginfree(login);
71 2 : add_bread_crumb();
72 :
73 : #ifdef MICROSOFT_DBLIB
74 : dbsetopt(dbproc, DBBUFFER, "100");
75 : #else
76 2 : dbsetopt(dbproc, DBBUFFER, "100", 0);
77 : #endif
78 2 : add_bread_crumb();
79 :
80 2 : fprintf(stdout, "creating table\n");
81 2 : dbcmd(dbproc, "create table #dblib (i int not null, s text)");
82 2 : dbsqlexec(dbproc);
83 4 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
84 : /* nop */
85 : }
86 :
87 2 : fprintf(stdout, "insert\n");
88 2 : dbcmd(dbproc, "insert into #dblib values (1, 'ABCDEF')");
89 2 : dbsqlexec(dbproc);
90 4 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
91 : /* nop */
92 : }
93 2 : dbcmd(dbproc, "insert into #dblib values (2, 'abc')");
94 2 : dbsqlexec(dbproc);
95 4 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
96 : /* nop */
97 : }
98 :
99 :
100 2 : fprintf(stdout, "select\n");
101 2 : dbcmd(dbproc, "select * from #dblib order by i");
102 2 : dbsqlexec(dbproc);
103 2 : add_bread_crumb();
104 :
105 :
106 2 : if (dbresults(dbproc) != SUCCEED) {
107 0 : add_bread_crumb();
108 0 : fprintf(stdout, "Was expecting a result set.");
109 0 : return 1;
110 : }
111 2 : add_bread_crumb();
112 :
113 6 : for (i = 1; i <= dbnumcols(dbproc); i++) {
114 4 : add_bread_crumb();
115 4 : printf("col %d is %s\n", i, dbcolname(dbproc, i));
116 4 : add_bread_crumb();
117 : }
118 :
119 2 : add_bread_crumb();
120 2 : dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & testint);
121 2 : add_bread_crumb();
122 2 : dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
123 2 : add_bread_crumb();
124 :
125 2 : add_bread_crumb();
126 :
127 :
128 2 : if (REG_ROW != dbnextrow(dbproc)) {
129 0 : fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__);
130 0 : return 1;
131 : }
132 2 : if (dbdatlen(dbproc, 2) != 6 || 0 != strcmp("ABCDEF", teststr)) {
133 0 : fprintf(stderr, "Expected |%s|, found |%s|\n", "ABCDEF", teststr);
134 0 : fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__);
135 0 : return 1;
136 : }
137 :
138 2 : if (REG_ROW != dbnextrow(dbproc)) {
139 0 : fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__);
140 0 : return 1;
141 : }
142 2 : if (dbdatlen(dbproc, 2) != 3 || 0 != strcmp("abc", teststr)) {
143 0 : fprintf(stderr, "Expected |%s|, found |%s|\n", "abc", teststr);
144 0 : fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__);
145 0 : return 1;
146 : }
147 :
148 : /* get again row 1 */
149 2 : dbgetrow(dbproc, 1);
150 :
151 : /* here length and string should be ok */
152 2 : if (dbdatlen(dbproc, 2) != 6 || 0 != strcmp("ABCDEF", teststr)) {
153 0 : fprintf(stderr, "Expected |%s|, found |%s|\n", "ABCDEF", teststr);
154 0 : fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__);
155 0 : return 1;
156 : }
157 :
158 2 : dbgetrow(dbproc, 2);
159 2 : if (dbdatlen(dbproc, 2) != 3 || 0 != strcmp("abc", teststr)) {
160 0 : fprintf(stderr, "Expected |%s|, found |%s|\n", "abc", teststr);
161 0 : fprintf(stderr, "dblib failed for %s:%d\n", __FILE__, __LINE__);
162 0 : return 1;
163 : }
164 :
165 2 : add_bread_crumb();
166 2 : dbexit();
167 2 : add_bread_crumb();
168 :
169 2 : printf("dblib passed for %s\n", __FILE__);
170 2 : free_bread_crumb();
171 2 : return 0;
172 : }
|