Line data Source code
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 : #include "common.h"
7 :
8 : int
9 10 : main(int argc, char **argv)
10 : {
11 : LOGINREC *login;
12 : DBPROCESS *dbproc;
13 : int i;
14 : char teststr[1024];
15 : DBINT testint;
16 :
17 10 : set_malloc_options();
18 :
19 10 : read_login_info(argc, argv);
20 :
21 10 : printf("Starting %s\n", argv[0]);
22 :
23 : /* Fortify_EnterScope(); */
24 10 : dbinit();
25 :
26 10 : dberrhandle(syb_err_handler);
27 10 : dbmsghandle(syb_msg_handler);
28 :
29 10 : printf("About to logon\n");
30 :
31 10 : login = dblogin();
32 10 : DBSETLPWD(login, PASSWORD);
33 10 : DBSETLUSER(login, USER);
34 10 : DBSETLAPP(login, "t0009");
35 10 : DBSETLHOST(login, "ntbox.dntis.ro");
36 :
37 10 : printf("About to open\n");
38 :
39 10 : dbproc = dbopen(login, SERVER);
40 10 : if (strlen(DATABASE))
41 10 : dbuse(dbproc, DATABASE);
42 10 : dbloginfree(login);
43 :
44 : #ifdef MICROSOFT_DBLIB
45 : dbsetopt(dbproc, DBBUFFER, "100");
46 : #else
47 10 : dbsetopt(dbproc, DBBUFFER, "100", 0);
48 : #endif
49 :
50 10 : printf("creating table\n");
51 10 : sql_cmd(dbproc);
52 10 : dbsqlexec(dbproc);
53 10 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
54 : /* nop */
55 : }
56 :
57 10 : printf("insert\n");
58 10 : sql_cmd(dbproc);
59 10 : dbsqlexec(dbproc);
60 10 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
61 : /* nop */
62 : }
63 10 : sql_cmd(dbproc);
64 10 : dbsqlexec(dbproc);
65 10 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
66 : /* nop */
67 : }
68 :
69 :
70 10 : printf("select\n");
71 10 : sql_cmd(dbproc);
72 10 : dbsqlexec(dbproc);
73 :
74 10 : if (dbresults(dbproc) != SUCCEED) {
75 0 : printf("Was expecting a result set.");
76 0 : exit(1);
77 : }
78 :
79 20 : for (i = 1; i <= dbnumcols(dbproc); i++)
80 20 : printf("col %d is %s\n", i, dbcolname(dbproc, i));
81 :
82 10 : dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & testint);
83 10 : dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
84 :
85 10 : if (REG_ROW != dbnextrow(dbproc)) {
86 0 : fprintf(stderr, "dblib failed for %s\n", __FILE__);
87 0 : exit(1);
88 : }
89 10 : if (0 != strcmp("abcdef ", teststr)) {
90 0 : fprintf(stderr, "Expected |%s|, found |%s|\n", "abcdef", teststr);
91 0 : fprintf(stderr, "dblib failed for %s\n", __FILE__);
92 0 : exit(1);
93 : }
94 :
95 10 : if (REG_ROW != dbnextrow(dbproc)) {
96 0 : fprintf(stderr, "dblib failed for %s\n", __FILE__);
97 0 : exit(1);
98 : }
99 10 : if (0 != strcmp("abc ", teststr)) {
100 0 : fprintf(stderr, "Expected |%s|, found |%s|\n", "abc", teststr);
101 0 : fprintf(stderr, "dblib failed for %s\n", __FILE__);
102 0 : exit(1);
103 : }
104 :
105 10 : dbexit();
106 :
107 10 : printf("dblib passed for %s\n", __FILE__);
108 : return 0;
109 : }
|