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