NCBI C++ ToolKit
dbmorecmds.c
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  * Purpose: Test behaviour of dbmorecmds()
3  * Functions: dbmorecmds
4  */
5 
6 #include "common.h"
7 
8 #include <common/test_assert.h>
9 
10 int failed = 0;
11 
12 int
13 main(int argc, char **argv)
14 {
15  const int rows_to_add = 10;
16  LOGINREC *login;
18  int i, nresults;
19 
21 
22  read_login_info(argc, argv);
23  fprintf(stdout, "Starting %s\n", argv[0]);
24 
25  /* Fortify_EnterScope(); */
26  dbinit();
27 
30 
31  fprintf(stdout, "About to logon\n");
32 
33  login = dblogin();
34  fprintf(stdout, "after dblogin\n");
37  DBSETLAPP(login, "t0024");
38 
39  fprintf(stdout, "About to open [%s]\n", USER);
40 
42  fprintf(stdout, "After dbopen [%s]\n", SERVER);
43 
44  if (strlen(DATABASE)) {
45  fprintf(stdout, "About to dbuse [%s]\n", DATABASE);
47  }
49 
50  fprintf(stdout, "After dbuse [%s]\n", DATABASE);
51 
52  fprintf(stdout, "creating table\n");
53  sql_cmd(dbproc);
55  while (dbresults(dbproc) != NO_MORE_RESULTS) {
56  /* nop */
57  }
58 
59  fprintf(stdout, "insert\n");
60  for (i = 0; i < rows_to_add; i++) {
61  sql_cmd(dbproc);
63  while (dbresults(dbproc) != NO_MORE_RESULTS) {
64  /* nop */
65  }
66  }
67 
68  fprintf(stdout, "select one resultset\n");
69  sql_cmd(dbproc);
71 
72  nresults = 0;
73 
74  if (dbresults(dbproc) == SUCCEED) {
75  do {
76  while (dbnextrow(dbproc) != NO_MORE_ROWS)
77  continue;
78  nresults++;
79  } while (dbmorecmds(dbproc) == SUCCEED);
80  }
81 
82  /* dbmorecmds should return success 0 times for select 1 */
83  if (nresults != 1) {
84  failed = 1;
85  fprintf(stdout, "Was expecting nresults == 1.\n");
86  exit(1);
87  }
88 
90 
91  fprintf(stdout, "select two resultsets\n");
92  sql_cmd(dbproc);
94 
95  nresults = 0;
96 
97  do {
98  if (dbresults(dbproc) == SUCCEED) {
99  while (dbnextrow(dbproc) != NO_MORE_ROWS)
100  continue;
101  nresults++;
102  }
103  } while (dbmorecmds(dbproc) == SUCCEED);
104 
105 
106  /* dbmorecmds should return success 2 times for select 2 */
107  if (nresults != 2) { /* two results sets plus a return code */
108  failed = 1;
109  fprintf(stdout, "nresults was %d; was expecting nresults = 2.\n", nresults);
110  exit(1);
111  }
112 
113  /* end of test processing */
114  dbexit();
115 
116  fprintf(stdout, "%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
117  return failed ? 1 : 0;
118 }
#define USER
Definition: fastme_common.h:43
char PASSWORD[512]
Definition: common.c:31
char DATABASE[512]
Definition: common.c:32
CS_RETCODE read_login_info(void)
Definition: common.c:71
char SERVER[512]
Definition: common.c:30
int syb_err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
Definition: common.c:404
RETCODE sql_cmd(DBPROCESS *dbproc)
Definition: common.c:280
int syb_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line)
Definition: common.c:334
void set_malloc_options(void)
Definition: common.c:47
int main(int argc, char **argv)
Definition: dbmorecmds.c:13
int failed
Definition: dbmorecmds.c:10
static DBPROCESS * dbproc
Definition: done_handling.c:29
#define dbopen(x, y)
Definition: sybdb.h:855
#define NO_MORE_ROWS
Definition: sybdb.h:582
#define SUCCEED
Definition: sybdb.h:585
#define NO_MORE_RESULTS
Definition: sybdb.h:584
static TDSLOGIN * login
Definition: dataread.c:31
#define dbnextrow
#define DBSETLPWD(x, y)
Set the password in the login packet.
Definition: sybdb.h:1259
#define DBSETLAPP(x, y)
Set the (client) application name in the login packet.
Definition: sybdb.h:1266
#define DBSETLUSER(x, y)
Set the username in the login packet.
Definition: sybdb.h:1256
LOGINREC * dblogin(void)
Allocate a LOGINREC structure.
Definition: dblib.c:719
RETCODE dbresults(DBPROCESS *dbproc)
Set up query results.
Definition: dblib.c:1706
RETCODE dbinit(void)
Initialize db-lib.
Definition: dblib.c:674
RETCODE dbcancel(DBPROCESS *dbproc)
Cancel the current command batch.
Definition: dblib.c:3279
RETCODE dbuse(DBPROCESS *dbproc, const char *name)
Change current database.
Definition: dblib.c:1449
RETCODE dbsqlexec(DBPROCESS *dbproc)
send the SQL command to the server and wait for an answer.
Definition: dblib.c:1423
EHANDLEFUNC dberrhandle(EHANDLEFUNC handler)
Set an error handler, for messages from db-lib.
Definition: dblib.c:5030
void dbloginfree(LOGINREC *login)
free the LOGINREC
Definition: dblib.c:751
RETCODE dbmorecmds(DBPROCESS *dbproc)
See if more commands are to be processed.
Definition: dblib.c:6150
void dbexit()
Close server connections and free all related structures.
Definition: dblib.c:1559
MHANDLEFUNC dbmsghandle(MHANDLEFUNC handler)
Set a message handler, for messages from the server.
Definition: dblib.c:5049
exit(2)
int i
Modified on Tue May 07 08:16:35 2024 by modify_doxy.py rev. 669887