-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb2topasutil.c
748 lines (622 loc) · 28.2 KB
/
db2topasutil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/param.h>
#include <sqlcli1.h>
#include <sqlutil.h>
#include <db2ApiDf.h>
#include <sqlenv.h>
#include <pthread.h>
#include "db2topasutil.h"
/* private functions */
void HandleLocationPrint(db2AdminMsgWriteStruct *msg, SQLRETURN cliRC) ;
void HandleDiagnosticsPrint(db2AdminMsgWriteStruct *msg, SQLSMALLINT htype, SQLHANDLE hndl) ;
void SqlInfoPrint(char *appMsg, struct sqlca *pSqlca, int line, char *file)
{
int rc = 0;
char sqlInfo[1024];
char sqlInfoToken[1024];
char sqlstateMsg[1024];
char errorMsg[1024];
db2AdminMsgWriteStruct msg;
struct sqlca msg_sqlca;
if (pSqlca->sqlcode != 0 && pSqlca->sqlcode != 100) {
sprintf(sqlInfo, "");
sprintf(sqlInfoToken, "application message = %s\n", appMsg);
strcat(sqlInfo, sqlInfoToken);
sprintf(sqlInfoToken, "line= %d ", line);
strcat(sqlInfo, sqlInfoToken);
sprintf(sqlInfoToken, "file= %s ", file);
strcat(sqlInfo, sqlInfoToken);
sprintf(sqlInfoToken, "SQLCODE= %d\n", pSqlca->sqlcode);
strcat(sqlInfo, sqlInfoToken);
/* get error message */
rc = sqlaintp(errorMsg, 1024, 80, pSqlca);
if (rc > 0) /* return code is the length of the errorMsg string */ {
sprintf(sqlInfoToken, "%s", errorMsg);
strcat(sqlInfo, sqlInfoToken);
}
/* get SQLSTATE message */
rc = sqlogstt(sqlstateMsg, 1024, 80, pSqlca->sqlstate);
if (rc > 0) {
sprintf(sqlInfoToken, "%s\n", sqlstateMsg);
strcat(sqlInfo, sqlInfoToken);
}
if (pSqlca->sqlcode < 0) {
msg.iError_type = DB2LOG_ERROR;
} else
{
msg.iError_type = DB2LOG_WARNING;
strcat(sqlInfo, sqlInfoToken);
} /* endif */
msg.iMsgType = STRING_MSG ;
msg.iComponent = 0;
msg.iFunction = 0;
msg.iProbeID = line;
msg.piData_title = file;
msg.piData = sqlInfo;
db2AdminMsgWrite(SQLM_CURRENT_VERSION, &msg, &msg_sqlca);
} /* endif */
return;
} /* SqlInfoPrint */
/*****************************************************************************/
int HandleInfoPrint(SQLSMALLINT htype, /* handle type identifier */
SQLHANDLE hndl, /* handle used by the CLI function */
SQLRETURN cliRC, /* return code of the CLI function */
int line,
char *file)
{
int rc = 0;
char buffer[1024];
db2AdminMsgWriteStruct msg;
msg.iMsgType = STRING_MSG ;
msg.iComponent = 0;
msg.iFunction = 0;
msg.iProbeID = line;
switch (cliRC)
{
case SQL_SUCCESS:
rc = 0;
break;
case SQL_INVALID_HANDLE:
sprintf(buffer, "CLI Invalid Handle, file %s, line %d", file, line);
msg.piData_title = buffer;
msg.iError_type = DB2LOG_ERROR;
HandleLocationPrint(&msg, cliRC);
rc = 1;
break;
case SQL_ERROR:
sprintf(buffer, "CLI SQL Error, file %s, line %d", file, line);
msg.piData_title = buffer;
msg.iError_type = DB2LOG_ERROR;
HandleLocationPrint(&msg, cliRC);
HandleDiagnosticsPrint(&msg, htype, hndl);
rc = 2;
break;
case SQL_SUCCESS_WITH_INFO:
rc = 0;
break;
case SQL_STILL_EXECUTING:
rc = 0;
break;
case SQL_NEED_DATA:
rc = 0;
break;
case SQL_NO_DATA_FOUND:
rc = 0;
break;
default:
sprintf(buffer, "CLI Default, file %s, line %d", file, line);
msg.piData_title = buffer;
msg.iError_type = DB2LOG_ERROR;
HandleLocationPrint(&msg, cliRC);
rc = 3;
break;
}
return rc;
} /* HandleInfoPrint */
/*****************************************************************************/
void HandleLocationPrint(db2AdminMsgWriteStruct *msg, SQLRETURN cliRC)
{
char buffer[1024];
struct sqlca msg_sqlca;
sprintf(buffer, "cliRC = %d", cliRC);
msg->piData = buffer;
db2AdminMsgWrite(SQLM_CURRENT_VERSION, msg, &msg_sqlca);
return;
} /* HandleLocationPrint */
/*****************************************************************************/
void HandleDiagnosticsPrint(db2AdminMsgWriteStruct *msg, SQLSMALLINT htype, SQLHANDLE hndl)
{
SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1];
SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
SQLINTEGER sqlcode;
SQLSMALLINT length, i;
struct sqlca msg_sqlca;
char buffer [ SQL_MAX_MESSAGE_LENGTH + SQL_SQLSTATE_SIZE + 512];
i = 1;
/* get multiple field settings of diagnostic record */
while (SQLGetDiagRec(htype,
hndl,
i,
sqlstate,
&sqlcode,
message,
SQL_MAX_MESSAGE_LENGTH + 1,
&length) == SQL_SUCCESS)
{
sprintf(buffer, "sqlstate = %s, sqlcode = %d\nmessage = %s", sqlstate,sqlcode,message);
msg->piData = buffer;
db2AdminMsgWrite(SQLM_CURRENT_VERSION, msg, &msg_sqlca);
i++;
}
return;
} /* HandleDiagnosticsPrint */
/*****************************************************************************/
int InstanceAttach(char nodeName[],
char user[],
char pswd[])
{
struct sqlca sqlca;
char *pSpace;
char mesg[1024];
if (strlen(nodeName) > 0) {
sprintf(mesg, "############## ATTACH TO THE INSTANCE: %s #######",
nodeName);
INFO_MSG(mesg);
/* attach to instance */
if (strlen(pswd) > 0)
sqleatin(nodeName, user, pswd, &sqlca);
else
sqleatin(nodeName, '\0', '\0', &sqlca);
sprintf(mesg, "instance attach to %s", nodeName);
DB2_API_CHECK(mesg);
} else {
/* attach to default instance DB2INSTANCE */
sqlegins(nodeName, &sqlca);
DB2_API_CHECK("instance -- get");
/* Trim spaces from instance name if present */
strrtrim(nodeName);
sqleatin(nodeName, '\0', '\0', &sqlca);
sprintf(mesg, "instance attach to %s", nodeName);
DB2_API_CHECK(mesg);
}
return 0;
} /* InstanceAttach */
/*****************************************************************************/
int InstanceDetach(char *nodeName)
{
char mesg[1024];
struct sqlca sqlca;
if (strlen(nodeName) > 0) {
/* detach from an instance */
sqledtin(&sqlca);
sprintf(mesg, "instance detach from %s", nodeName);
DB2_API_CHECK(mesg);
}
return 0;
} /* InstanceDetach */
/*****************************************************************************/
char *strtrim(char *str)
{
return strltrim(strrtrim(str));
}
/*****************************************************************************/
char *strrtrim(char *str)
{
char *end;
if (!str)
return '\0';
/* point right before NULL char */
end = str + strlen(str) - 1;
while (end >= str) {
if (isspace(*end))
*end-- = '\0';
else
return str;
}
return str;
}
/***********************************************************/
char *strltrim(char *str)
{
if (!str)
return '\0';
while (*str) {
if (isspace(*str))
str++;
else
return str;
}
return str;
}
/***********************************************************/
char *strrev(char *str)
{
char *p1, *p2;
if (! str || ! *str)
return str;
for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
{
*p1 ^= *p2;
*p2 ^= *p1;
*p1 ^= *p2;
}
return str;
}
/*********************************************************************/
char *basename (const char *name)
{
const char *base = name;
while (*name) {
if (*name++ == '/') {
base = name;
}
}
return (char *) base;
}
/**********************************************************************/
Header *init_header()
{
int rc = 0;
SnapReq snapReq;
Header * header = malloc(sizeof(Header));
if (header == NULL) {
WARN_MSG("Failed to allocate memory for header");
return header;
}
/* initialize stack and add snapshot req for all appls*/
stack_init(&(header->snap_req_stack), free);
snapReq.type = appls;
snapReq.agent_id = 0;
snapReq.util_id = 0;
snapReq.tbspace_id = 1000000000;
snapReq.tbspace_pg_sz = 0;
strcpy(snapReq.auth_id, "");
strcpy(snapReq.exec_id, "");
strcpy(snapReq.prog_nm, "");
strcpy(snapReq.client_nm, "");
strcpy(snapReq.dbname, "");
strcpy(snapReq.tbspace, "");
strcpy(snapReq.stmt_text, "");
snapReq.stmt_node_number = 1000;
snapReq.stmt_section_number = 999999;
snapReq.node = -1;
snapReq.order_by_col = cpu;
snapReq.order = desc;
rc = push_snapReq(header, &snapReq);
if (rc < 0) {
WARN_MSG("Couldn't add snapshot req to stack");
stack_destroy(&(header->snap_req_stack));
free(header);
return NULL;
}
header->show_dbase_list = TRUE;
header->show_appl_list = TRUE;
header->show_lock_list = TRUE;
header->show_stmt_list = TRUE;
header->snapScr = wstmt_list;
strcpy(header->myname, "N/A");
header->spin = 0;
strcpy(header->pswd, "");
if (gethostname(header->hostname, MAXHOSTNAMELEN) != 0)
strcpy(header->hostname, "unknown");
strcpy(header->db2node, "000");
if (getenv("DB2NODE") != NULL)
strncpy(header->db2node, getenv("DB2NODE"), 4);
strcpy(header->user_id, "unknown");
if (getlogin() != NULL)
strncpy(header->user_id, getlogin(), USERID_SZ);
header->interval = 2;
/* these options are set based on the assumption
that appls snapshot will be taken
*/
header->col1_opt = appl_handle;
header->col3_opt = auth_id;
header->col4_opt = appl_status;
header->col8_opt = bp;
header->col12_opt = log_usg;
header->reinit_DB2SnapReq = TRUE;
header->appls_connected = 0;
header->appls_executing = 0;
header->db_assoc_agents = 0;
header->db_memusg = 0;
header->db_genheap = 0;
header->db_sortheap = 0;
header->db_lockheap =0;
header->db_utilheap =0;
(header->t1_snapshot_timestamp).seconds = 0;
(header->t2_snapshot_timestamp).seconds = 0;
(header->t1_snapshot_timestamp).microsec = 0;
(header->t2_snapshot_timestamp).microsec = 0;
header->db_ucpu_used_delta = 0;
header->db_scpu_used_delta = 0;
header->t1_db_bpr_tm = 0;
header->t1_db_bpw_tm = 0;
header->t2_db_bpr_tm = header->t1_db_bpr_tm;
header->t2_db_bpw_tm = header->t1_db_bpw_tm;
header->t2_db_buffered_rio = 0;
header->t2_db_buffered_wio = 0;
header->t1_db_buffered_rio = header->t2_db_buffered_rio;
header->t1_db_buffered_wio = header->t2_db_buffered_wio;
header->t2_db_direct_io = 0;
header->t1_db_direct_io = header->t2_db_direct_io;
header->t2_db_direct_io_reqs = 0;
header->t1_db_direct_io_reqs = header->t2_db_direct_io_reqs;
header->t1_db_io_type_read = 0;
header->t2_db_io_type_read = 0;
header->t1_db_io_type_write = 0;
header->t2_db_io_type_write = 0;
header->t1_db_io_type_data = 0;
header->t2_db_io_type_data = 0;
header->t1_db_io_type_idx = 0;
header->t2_db_io_type_idx = 0;
header->t1_db_io_type_temp = 0;
header->t2_db_io_type_temp = 0;
header->t1_db_io_type_xml = 0;
header->t2_db_io_type_xml = 0;
header->t1_db_io_type_dio = 0;
header->t2_db_io_type_dio = 0;
header->t2_db_log_reads = 0;
header->t2_db_log_writes = 0;
header->t1_db_log_reads = 0;
header->t1_db_log_writes = 0;
header->db_log_avail = 0;
header->db_log_used = 0;
header->smallest_log_avail_node = 1000;
header->agent_id_oldest_xact = 0;
header->mark = FALSE;
header->dump = FALSE;
header->dbase_scrn_row = 4;
return header;
} /* init_header */
/********************************************************************************/
void free_header(Header *header)
{
if (header != NULL) {
stack_destroy(&(header->snap_req_stack));
free(header);
}
} /*free_header*/
/********************************************************************************/
const SnapReq *peek_snapReq(Header *header)
{
const SnapReq * snapReq;
snapReq = stack_peek(&(header->snap_req_stack));
if (snapReq == NULL)
return NULL;
return snapReq;
} /*peek_snapReq */
/********************************************************************************/
int num_snapReq(Header *header) {
return stack_size(&(header->snap_req_stack));
}
/********************************************************************************/
int pop_snapReq(Header *header)
{
SnapReq * snapReq;
int rc = 0;
if ( num_snapReq(header) > 1) {
rc = stack_pop(&(header->snap_req_stack), (void * *) &snapReq) ;
if (rc == 0)
free(snapReq);
return rc;
}
return - 1;
} /*pop_snapReq*/
/**********************************************************************************/
int push_snapReq(Header *header, const SnapReq *snapReq)
{
const SnapReq * oldSnapReq = peek_snapReq(header);
if (snapReq == NULL)
return -1;
/* don't add snapReq if it is the same as what's on the stack */
if (oldSnapReq != NULL
&& oldSnapReq->type == snapReq->type
&& oldSnapReq->agent_id == snapReq->agent_id
&& oldSnapReq->util_id == snapReq->util_id
&& strncasecmp(oldSnapReq->exec_id,snapReq->exec_id,USERID_SZ) == 0
&& strncasecmp(oldSnapReq->auth_id,snapReq->auth_id,USERID_SZ) == 0
&& strncasecmp(oldSnapReq->prog_nm,snapReq->prog_nm,USERID_SZ) == 0
&& strncasecmp(oldSnapReq->client_nm,snapReq->client_nm,USERID_SZ) == 0
&& strncasecmp(oldSnapReq->dbname,snapReq->dbname,SQL_DBNAME_SZ) == 0
&& oldSnapReq->node == snapReq->node)
return 1;
SnapReq * pSnapReq = malloc(sizeof(SnapReq));
if (pSnapReq == NULL) {
return - 1;
}
*pSnapReq = *snapReq;
return stack_push(&(header->snap_req_stack), (void *) pSnapReq);
} /*push_snapReq */
/******************************************************************************************/
char *time_STRING ( sqlm_timestamp timestamp, char *timeString)
{ /* Event Monitor returns GMT time, adjust it to local time*/
sqluint64 seconds = (sqluint64) timestamp.seconds;
sqluint32 microsec = timestamp.microsec;
struct tm *pstTm;
pstTm = localtime((time_t * ) & seconds);
if (seconds == 0)
strcpy(timeString, "");
else {
if (microsec < 0) {
sprintf(timeString, "%02d/%02d/%04d %02d:%02d",
pstTm->tm_mon + 1, pstTm->tm_mday, pstTm->tm_year + 1900,
pstTm->tm_hour, pstTm->tm_min);
} else {
sprintf(timeString, "%02d/%02d/%04d %02d:%02d",
pstTm->tm_mon + 1, pstTm->tm_mday, pstTm->tm_year + 1900,
pstTm->tm_hour, pstTm->tm_min);
}
}
return timeString;
} /* end of time_STRING*/
/******************************************************************************************/
/* initialize a CLI application by:
o allocating an environment handle
o allocating a connection handle
o setting AUTOCOMMIT
o connecting to the database */
int CLIAppInit(char dbAlias[],
char user[],
char pswd[],
SQLHANDLE *pHenv,
SQLHANDLE *pHdbc,
SQLPOINTER autocommitValue)
{
SQLRETURN cliRC = SQL_SUCCESS;
char buffer[1024];
int rc = 0;
db2AdminMsgWriteStruct msg;
struct sqlca msg_sqlca;
msg.iMsgType = STRING_MSG ;
msg.iComponent = 0;
msg.iFunction = 0;
/* allocate an environment handle */
cliRC = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, pHenv);
if (cliRC != SQL_SUCCESS)
{
msg.iProbeID = __LINE__;
msg.iError_type = DB2LOG_ERROR;
msg.piData_title = "ERROR while allocating the environment handle ";
sprintf(buffer, " cliRC = %d, line = %d, file = %d ", cliRC, __LINE__, __FILE__);
msg.piData = buffer;
db2AdminMsgWrite(SQLM_CURRENT_VERSION, &msg, &msg_sqlca);
return 1;
}
/* set attribute to enable application to run as ODBC 3.0 application */
cliRC = SQLSetEnvAttr(*pHenv,
SQL_ATTR_ODBC_VERSION,
(void *)SQL_OV_ODBC3,
0);
ENV_HANDLE_CHECK(*pHenv, cliRC);
/* allocate a database connection handle */
cliRC = SQLAllocHandle(SQL_HANDLE_DBC, *pHenv, pHdbc);
ENV_HANDLE_CHECK(*pHenv, cliRC);
/* set AUTOCOMMIT off or on */
cliRC = SQLSetConnectAttr(*pHdbc,
SQL_ATTR_AUTOCOMMIT,
autocommitValue,
SQL_NTS);
DBC_HANDLE_CHECK(*pHdbc, cliRC);
/* connect to the database */
cliRC = SQLConnect(*pHdbc,
(SQLCHAR *)dbAlias,
SQL_NTS,
(SQLCHAR *)user,
SQL_NTS,
(SQLCHAR *)pswd,
SQL_NTS);
if (cliRC != SQL_SUCCESS) {
sprintf(buffer, " Can't connect to dbase %s using id %s", dbAlias, user);
msg.iProbeID = __LINE__;
msg.piData_title = "ERROR while connecting to database ";
msg.iError_type = DB2LOG_WARNING;
msg.piData = buffer;
db2AdminMsgWrite(SQLM_CURRENT_VERSION, &msg, &msg_sqlca);
}
DBC_HANDLE_CHECK(*pHdbc, cliRC);
sprintf(buffer, " Connected to %s. ", dbAlias);
msg.piData_title = "Success";
msg.iProbeID = __LINE__;
msg.iError_type = DB2LOG_INFORMATION;
msg.piData = buffer;
db2AdminMsgWrite(SQLM_CURRENT_VERSION, &msg, &msg_sqlca);
return 0;
} /* CLIAppInit */
/******************************************************************************************/
/* terminate a CLI application by:
o disconnecting from the database
o freeing the connection handle
o freeing the environment handle */
int CLIAppTerm(SQLHANDLE * pHenv, SQLHANDLE * pHdbc, char dbAlias[])
{
SQLRETURN cliRC = SQL_SUCCESS;
int rc = 0;
char buffer[1024];
db2AdminMsgWriteStruct msg;
struct sqlca msg_sqlca;
/* disconnect from the database */
cliRC = SQLDisconnect(*pHdbc);
DBC_HANDLE_CHECK(*pHdbc, cliRC);
sprintf(buffer, " Disconnected from dbAlias %s ", dbAlias);
msg.iMsgType = STRING_MSG ;
msg.iComponent = 0;
msg.iFunction = 0;
msg.iProbeID = __LINE__;
msg.piData_title = __FILE__;
msg.piData = buffer;
msg.iError_type = DB2LOG_INFORMATION;
db2AdminMsgWrite(SQLM_CURRENT_VERSION, &msg, &msg_sqlca);
/* free connection handle */
cliRC = SQLFreeHandle(SQL_HANDLE_DBC, *pHdbc);
DBC_HANDLE_CHECK(*pHdbc, cliRC);
/* free environment handle */
cliRC = SQLFreeHandle(SQL_HANDLE_ENV, *pHenv);
ENV_HANDLE_CHECK(*pHenv, cliRC);
return 0;
} /* CLIAppTerm */
/******************************************************************************************/
int StmtResourcesFree(SQLHANDLE hstmt)
{
SQLRETURN cliRC = SQL_SUCCESS;
int rc = 0;
/* free the statement handle */
cliRC = SQLFreeStmt(hstmt, SQL_UNBIND);
rc = HandleInfoPrint(SQL_HANDLE_STMT, hstmt, cliRC, __LINE__, __FILE__);
if (rc != 0)
{
return 1;
}
/* free the statement handle */
cliRC = SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
rc = HandleInfoPrint(SQL_HANDLE_STMT, hstmt, cliRC, __LINE__, __FILE__);
if (rc != 0)
{
return 1;
}
/* free the statement handle */
cliRC = SQLFreeStmt(hstmt, SQL_CLOSE);
rc = HandleInfoPrint(SQL_HANDLE_STMT, hstmt, cliRC, __LINE__, __FILE__);
if (rc != 0)
{
return 1;
}
return 0;
} /* StmtResourcesFree */
/******************************************************************************************/
void TransRollback(SQLHANDLE hdbc)
{
SQLRETURN cliRC = SQL_SUCCESS;
int rc = 0;
/* end transactions on the connection */
cliRC = SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_ROLLBACK);
rc = HandleInfoPrint(SQL_HANDLE_DBC, hdbc, cliRC, __LINE__, __FILE__);
} /* TransRollback */
/******************************************************************************************/
void chomp(char *s) {
while(*s && *s != '\n' && *s != '\r') s++;
*s = 0;
}
/******************************************************************************************/
sqluint32 timediff(sqlm_time T2, sqlm_time T1)
{
if ( ((T2.seconds * 1000000) + T2.microsec) >
((T1.seconds * 1000000) + T1.microsec))
return ((T2.seconds * 1000000) + T2.microsec) -
((T1.seconds * 1000000) + T1.microsec);
else
return 0;
}
/******************************************************************************************/
sqluint32 timestampdiff(sqlm_timestamp T2, sqlm_timestamp T1)
{
if ( ((T2.seconds * 1000000) + T2.microsec) >
((T1.seconds * 1000000) + T1.microsec))
return ((T2.seconds * 1000000) + T2.microsec) -
((T1.seconds * 1000000) + T1.microsec);
else
return 0;
}