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