Line data Source code
1 : /*
2 : * Purpose: Retrieve the connection SPID.
3 : * Functions: dbspid
4 : */
5 :
6 : #include "common.h"
7 :
8 10 : TEST_MAIN()
9 : {
10 : LOGINREC *login;
11 : DBPROCESS *dbproc;
12 : DBINT expected_spid, actual_spid;
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, "spid");
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 : #ifdef DBQUOTEDIDENT
49 10 : printf("QUOTED_IDENTIFIER is %s\n", (dbisopt(dbproc, DBQUOTEDIDENT, NULL))? "ON":"OFF");
50 : #endif
51 10 : sql_cmd(dbproc);
52 10 : dbsqlexec(dbproc);
53 :
54 10 : if (dbresults(dbproc) != SUCCEED) {
55 0 : fprintf(stderr, "error: expected a result set, none returned.\n");
56 0 : return 1;
57 : }
58 :
59 10 : if (SUCCEED != dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & expected_spid)) {
60 0 : fprintf(stderr, "Had problem with bind\n");
61 0 : return 1;
62 : }
63 10 : if (REG_ROW != dbnextrow(dbproc)) {
64 0 : fprintf(stderr, "Failed. Expected a row\n");
65 0 : return 1;
66 : }
67 10 : assert(expected_spid > 0);
68 :
69 10 : actual_spid = dbspid(dbproc);
70 10 : if (expected_spid != actual_spid) {
71 0 : fprintf(stderr, "Failed. Expected spid to be %d, was %d\n", expected_spid, actual_spid);
72 0 : return 1;
73 : }
74 :
75 10 : if (dbnextrow(dbproc) != NO_MORE_ROWS) {
76 0 : fprintf(stderr, "Was expecting no more rows\n");
77 0 : return 1;
78 : }
79 :
80 10 : dbclose(dbproc);
81 :
82 10 : dbexit();
83 10 : return 0;
84 : }
|