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