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