Line data Source code
1 : /*
2 : * Purpose: Check dbcanquery throw away rows and we can continue after the call
3 : * Functions: dbcanquery
4 : */
5 :
6 : #include "common.h"
7 :
8 10 : TEST_MAIN()
9 : {
10 : LOGINREC *login;
11 : DBPROCESS *dbproc;
12 : DBINT data;
13 : RETCODE erc;
14 :
15 10 : set_malloc_options();
16 :
17 10 : read_login_info(argc, argv);
18 :
19 10 : printf("Starting %s\n", argv[0]);
20 :
21 10 : dbinit();
22 :
23 10 : dberrhandle(syb_err_handler);
24 10 : dbmsghandle(syb_msg_handler);
25 :
26 10 : printf("About to logon as \"%s\"\n", USER);
27 :
28 10 : login = dblogin();
29 10 : DBSETLPWD(login, PASSWORD);
30 10 : DBSETLUSER(login, USER);
31 10 : DBSETLAPP(login, "canquery");
32 :
33 10 : printf("About to open \"%s\"\n", SERVER);
34 :
35 10 : dbproc = dbopen(login, SERVER);
36 10 : if (!dbproc) {
37 0 : fprintf(stderr, "Unable to connect to %s\n", SERVER);
38 0 : return 1;
39 : }
40 10 : dbloginfree(login);
41 :
42 10 : printf("Using database \"%s\"\n", DATABASE);
43 10 : if (strlen(DATABASE)) {
44 10 : erc = dbuse(dbproc, DATABASE);
45 10 : assert(erc == SUCCEED);
46 : }
47 :
48 10 : sql_cmd(dbproc);
49 10 : dbsqlexec(dbproc);
50 :
51 10 : if (dbresults(dbproc) != SUCCEED) {
52 0 : fprintf(stderr, "error: expected a result set, none returned.\n");
53 0 : return 1;
54 : }
55 :
56 10 : if (dbcanquery(dbproc) != SUCCEED) {
57 0 : fprintf(stderr, "error: unexpected error from dbcanquery.\n");
58 0 : return 1;
59 : }
60 :
61 10 : if (dbresults(dbproc) != SUCCEED) {
62 0 : fprintf(stderr, "error: expected a result set, none returned.\n");
63 0 : return 1;
64 : }
65 :
66 10 : if (SUCCEED != dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & data)) {
67 0 : fprintf(stderr, "Had problem with bind\n");
68 0 : return 1;
69 : }
70 :
71 10 : if (REG_ROW != dbnextrow(dbproc)) {
72 0 : fprintf(stderr, "Failed. Expected a row\n");
73 0 : return 1;
74 : }
75 :
76 10 : if (data != 2) {
77 0 : fprintf(stderr, "Failed. Expected row data to be 2, was %d\n", data);
78 0 : return 1;
79 : }
80 :
81 10 : if (dbnextrow(dbproc) != NO_MORE_ROWS) {
82 0 : fprintf(stderr, "Was expecting no more rows\n");
83 0 : return 1;
84 : }
85 :
86 10 : dbclose(dbproc);
87 :
88 10 : dbexit();
89 10 : return 0;
90 : }
|