Line data Source code
1 : /*
2 : * Purpose: Test for proper return code from dbsqlexec()
3 : * Functions: db_name dbcmd dberrhandle dbmsghandle dbnextrow dbopen dbresults dbsqlexec
4 : */
5 :
6 : #include "common.h"
7 :
8 : int failed = 0;
9 :
10 : int err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr);
11 :
12 : /*
13 : * The bad column name message has severity 16, causing db-lib to call the error handler after calling the message handler.
14 : * This wrapper anticipates that behavior, and again sets the userdata, telling the handler this error is expected.
15 : */
16 : int
17 8 : err_handler(DBPROCESS * dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
18 : {
19 8 : int expected_error = 207;
20 8 : dbsetuserdata(dbproc, (BYTE*) &expected_error);
21 8 : return syb_err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr);
22 : }
23 :
24 : int
25 8 : main(int argc, char **argv)
26 : {
27 : LOGINREC *login;
28 : DBPROCESS *dbproc;
29 : RETCODE ret;
30 : int expected_error;
31 :
32 8 : set_malloc_options();
33 :
34 8 : read_login_info(argc, argv);
35 :
36 8 : printf("Starting %s\n", argv[0]);
37 :
38 : /* Fortify_EnterScope(); */
39 8 : dbinit();
40 :
41 8 : dberrhandle(err_handler);
42 8 : dbmsghandle(syb_msg_handler);
43 :
44 8 : printf("About to logon\n");
45 :
46 8 : login = dblogin();
47 8 : DBSETLPWD(login, PASSWORD);
48 8 : DBSETLUSER(login, USER);
49 8 : DBSETLAPP(login, "t0020");
50 :
51 8 : printf("About to open\n");
52 :
53 8 : dbproc = dbopen(login, SERVER);
54 8 : if (strlen(DATABASE))
55 8 : dbuse(dbproc, DATABASE);
56 8 : dbloginfree(login);
57 :
58 8 : sql_cmd(dbproc);
59 8 : fprintf(stderr, "The following invalid column error is normal.\n");
60 :
61 8 : expected_error = 207;
62 8 : dbsetuserdata(dbproc, (BYTE*) &expected_error);
63 :
64 8 : ret = dbsqlexec(dbproc);
65 8 : if (ret != FAIL) {
66 0 : failed = 1;
67 0 : fprintf(stderr, "Failed. Expected FAIL to be returned.\n");
68 0 : exit(1);
69 : }
70 :
71 8 : sql_cmd(dbproc);
72 8 : ret = dbsqlexec(dbproc);
73 8 : if (ret != SUCCEED) {
74 0 : failed = 1;
75 0 : fprintf(stderr, "Failed. Expected SUCCEED to be returned.\n");
76 0 : exit(1);
77 : }
78 :
79 16 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
80 16 : while (dbnextrow(dbproc) != NO_MORE_ROWS)
81 8 : continue;
82 : }
83 :
84 8 : dbexit();
85 :
86 8 : printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
87 8 : return failed ? 1 : 0;
88 : }
|