1 : /*
2 : * Purpose: Test if dbbind can handle a varlen of 0 with a column bound as STRINGBIND and a database column of CHAR.
3 : * Functions: dbbind dbcmd dbnextrow dbnumcols dbopen dbresults dbsqlexec
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: t0009.c,v 1.13 2005/05/23 08:06:25 freddy77 Exp $";
28 : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
29 :
30 :
31 :
32 : int
33 : main(int argc, char **argv)
34 2 : {
35 : LOGINREC *login;
36 : DBPROCESS *dbproc;
37 : int i;
38 : char teststr[1024];
39 : DBINT testint;
40 :
41 2 : set_malloc_options();
42 :
43 2 : read_login_info(argc, argv);
44 :
45 2 : fprintf(stdout, "Start\n");
46 2 : add_bread_crumb();
47 :
48 : /* Fortify_EnterScope(); */
49 2 : dbinit();
50 :
51 2 : add_bread_crumb();
52 2 : dberrhandle(syb_err_handler);
53 2 : dbmsghandle(syb_msg_handler);
54 :
55 2 : fprintf(stdout, "About to logon\n");
56 :
57 2 : add_bread_crumb();
58 2 : login = dblogin();
59 2 : DBSETLPWD(login, PASSWORD);
60 2 : DBSETLUSER(login, USER);
61 2 : DBSETLAPP(login, "t0009");
62 2 : DBSETLHOST(login, "ntbox.dntis.ro");
63 :
64 2 : fprintf(stdout, "About to open\n");
65 :
66 2 : add_bread_crumb();
67 2 : dbproc = dbopen(login, SERVER);
68 2 : if (strlen(DATABASE))
69 2 : dbuse(dbproc, DATABASE);
70 2 : add_bread_crumb();
71 2 : dbloginfree(login);
72 2 : add_bread_crumb();
73 :
74 : #ifdef MICROSOFT_DBLIB
75 : dbsetopt(dbproc, DBBUFFER, "100");
76 : #else
77 2 : dbsetopt(dbproc, DBBUFFER, "100", 0);
78 : #endif
79 2 : add_bread_crumb();
80 :
81 2 : fprintf(stdout, "creating table\n");
82 2 : dbcmd(dbproc, "create table #dblib0009 (i int not null, s char(10) not null)");
83 2 : dbsqlexec(dbproc);
84 4 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
85 : /* nop */
86 : }
87 :
88 2 : fprintf(stdout, "insert\n");
89 2 : dbcmd(dbproc, "insert into #dblib0009 values (1, 'abcdef')");
90 2 : dbsqlexec(dbproc);
91 4 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
92 : /* nop */
93 : }
94 2 : dbcmd(dbproc, "insert into #dblib0009 values (2, 'abc')");
95 2 : dbsqlexec(dbproc);
96 4 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
97 : /* nop */
98 : }
99 :
100 :
101 2 : fprintf(stdout, "select\n");
102 2 : dbcmd(dbproc, "select * from #dblib0009 order by i");
103 2 : dbsqlexec(dbproc);
104 2 : add_bread_crumb();
105 :
106 :
107 2 : if (dbresults(dbproc) != SUCCEED) {
108 0 : add_bread_crumb();
109 0 : fprintf(stdout, "Was expecting a result set.");
110 0 : exit(1);
111 : }
112 2 : add_bread_crumb();
113 :
114 6 : for (i = 1; i <= dbnumcols(dbproc); i++) {
115 4 : add_bread_crumb();
116 4 : printf("col %d is %s\n", i, dbcolname(dbproc, i));
117 4 : add_bread_crumb();
118 : }
119 :
120 2 : add_bread_crumb();
121 2 : dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & testint);
122 2 : add_bread_crumb();
123 2 : dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
124 2 : add_bread_crumb();
125 :
126 2 : add_bread_crumb();
127 :
128 :
129 2 : if (REG_ROW != dbnextrow(dbproc)) {
130 0 : fprintf(stderr, "dblib failed for %s\n", __FILE__);
131 0 : exit(1);
132 : }
133 2 : if (0 != strcmp("abcdef ", teststr)) {
134 0 : fprintf(stderr, "Expected |%s|, found |%s|\n", "abcdef", teststr);
135 0 : fprintf(stderr, "dblib failed for %s\n", __FILE__);
136 0 : exit(1);
137 : }
138 :
139 2 : if (REG_ROW != dbnextrow(dbproc)) {
140 0 : fprintf(stderr, "dblib failed for %s\n", __FILE__);
141 0 : exit(1);
142 : }
143 2 : if (0 != strcmp("abc ", teststr)) {
144 0 : fprintf(stderr, "Expected |%s|, found |%s|\n", "abc", teststr);
145 0 : fprintf(stderr, "dblib failed for %s\n", __FILE__);
146 0 : exit(1);
147 : }
148 :
149 2 : add_bread_crumb();
150 2 : dbexit();
151 2 : add_bread_crumb();
152 :
153 2 : printf("dblib passed for %s\n", __FILE__);
154 2 : free_bread_crumb();
155 2 : return 0;
156 : }
|