@@ -62,7 +62,7 @@ static struct {
62
62
63
63
64
64
RETCODE SQL_API SQLAllocStmt (HDBC hdbc ,
65
- HSTMT FAR * phstmt )
65
+ HSTMT FAR * phstmt )
66
66
{
67
67
static char * func = "SQLAllocStmt" ;
68
68
ConnectionClass * conn = (ConnectionClass * ) hdbc ;
@@ -88,12 +88,12 @@ StatementClass *stmt;
88
88
}
89
89
90
90
if ( ! CC_add_statement (conn , stmt )) {
91
- conn -> errormsg = "Maximum number of connections exceeded." ;
92
- conn -> errornumber = CONN_STMT_ALLOC_ERROR ;
91
+ conn -> errormsg = "Maximum number of connections exceeded." ;
92
+ conn -> errornumber = CONN_STMT_ALLOC_ERROR ;
93
93
CC_log_error (func , "" , conn );
94
- SC_Destructor (stmt );
94
+ SC_Destructor (stmt );
95
95
* phstmt = SQL_NULL_HSTMT ;
96
- return SQL_ERROR ;
96
+ return SQL_ERROR ;
97
97
}
98
98
99
99
* phstmt = (HSTMT ) stmt ;
@@ -111,7 +111,7 @@ StatementClass *stmt;
111
111
112
112
113
113
RETCODE SQL_API SQLFreeStmt (HSTMT hstmt ,
114
- UWORD fOption )
114
+ UWORD fOption )
115
115
{
116
116
static char * func = "SQLFreeStmt" ;
117
117
StatementClass * stmt = (StatementClass * ) hstmt ;
@@ -151,22 +151,22 @@ StatementClass *stmt = (StatementClass *) hstmt;
151
151
} else if (fOption == SQL_CLOSE ) {
152
152
/* this should discard all the results, but leave the statement */
153
153
/* itself in place (it can be executed again) */
154
- if (!SC_recycle_statement (stmt )) {
154
+ if (!SC_recycle_statement (stmt )) {
155
155
// errormsg passed in above
156
156
SC_log_error (func , "" , stmt );
157
- return SQL_ERROR ;
157
+ return SQL_ERROR ;
158
158
}
159
159
160
160
} else if (fOption == SQL_RESET_PARAMS ) {
161
161
SC_free_params (stmt , STMT_FREE_PARAMS_ALL );
162
162
163
163
} else {
164
- stmt -> errormsg = "Invalid option passed to SQLFreeStmt." ;
165
- stmt -> errornumber = STMT_OPTION_OUT_OF_RANGE_ERROR ;
164
+ stmt -> errormsg = "Invalid option passed to SQLFreeStmt." ;
165
+ stmt -> errornumber = STMT_OPTION_OUT_OF_RANGE_ERROR ;
166
166
SC_log_error (func , "" , stmt );
167
- return SQL_ERROR ;
167
+ return SQL_ERROR ;
168
168
}
169
-
169
+
170
170
return SQL_SUCCESS ;
171
171
}
172
172
@@ -306,7 +306,7 @@ SC_Destructor(StatementClass *self)
306
306
return TRUE;
307
307
}
308
308
309
- /* Free parameters and free the memory from the
309
+ /* Free parameters and free the memory from the
310
310
data-at-execution parameters that was allocated in SQLPutData.
311
311
*/
312
312
void
@@ -348,7 +348,7 @@ int i;
348
348
}
349
349
350
350
351
- int
351
+ int
352
352
statement_type (char * statement )
353
353
{
354
354
int i ;
@@ -365,14 +365,14 @@ int i;
365
365
from SQLExecute if STMT_FINISHED, or
366
366
from SQLFreeStmt(SQL_CLOSE)
367
367
*/
368
- char
368
+ char
369
369
SC_recycle_statement (StatementClass * self )
370
370
{
371
371
ConnectionClass * conn ;
372
372
373
373
mylog ("recycle statement: self= %u\n" , self );
374
374
375
- /* This would not happen */
375
+ /* This would not happen */
376
376
if (self -> status == STMT_EXECUTING ) {
377
377
self -> errornumber = STMT_SEQUENCE_ERROR ;
378
378
self -> errormsg = "Statement is currently executing a transaction." ;
@@ -396,7 +396,7 @@ mylog("recycle statement: self= %u\n", self);
396
396
If so, we have to rollback that transaction.
397
397
*/
398
398
conn = SC_get_conn (self );
399
- if ( ! CC_is_in_autocommit (conn ) && CC_is_in_trans (conn )) {
399
+ if ( ! CC_is_in_autocommit (conn ) && CC_is_in_trans (conn )) {
400
400
401
401
CC_send_query (conn , "ABORT" , NULL );
402
402
CC_set_no_trans (conn );
@@ -470,7 +470,7 @@ mylog("recycle statement: self= %u\n", self);
470
470
}
471
471
472
472
/* Pre-execute a statement (SQLPrepare/SQLDescribeCol) */
473
- void
473
+ void
474
474
SC_pre_execute (StatementClass * self )
475
475
{
476
476
@@ -485,11 +485,11 @@ SC_pre_execute(StatementClass *self)
485
485
mylog (" preprocess: after status = FINISHED, so set PREMATURE\n" );
486
486
self -> status = STMT_PREMATURE ;
487
487
}
488
- }
488
+ }
489
489
}
490
490
491
491
/* This is only called from SQLFreeStmt(SQL_UNBIND) */
492
- char
492
+ char
493
493
SC_unbind_cols (StatementClass * self )
494
494
{
495
495
Int2 lf ;
@@ -508,7 +508,7 @@ Int2 lf;
508
508
return 1 ;
509
509
}
510
510
511
- void
511
+ void
512
512
SC_clear_error (StatementClass * self )
513
513
{
514
514
self -> errornumber = 0 ;
@@ -552,7 +552,7 @@ static char msg[4096];
552
552
return msg ;
553
553
}
554
554
555
- char
555
+ char
556
556
SC_get_error (StatementClass * self , int * number , char * * message )
557
557
{
558
558
char rv ;
@@ -576,13 +576,13 @@ char rv;
576
576
}
577
577
578
578
/* Currently, the driver offers very simple bookmark support -- it is
579
- just the current row number. But it could be more sophisticated
579
+ just the current row number. But it could be more sophisticated
580
580
someday, such as mapping a key to a 32 bit value
581
581
*/
582
582
unsigned long
583
583
SC_get_bookmark (StatementClass * self )
584
584
{
585
- return (self -> currTuple + 1 );
585
+ return (self -> currTuple + 1 );
586
586
}
587
587
588
588
RETCODE
@@ -601,19 +601,19 @@ ColumnInfoClass *ci;
601
601
ci = QR_get_fields (res ); /* the column info */
602
602
603
603
mylog ("manual_result = %d, use_declarefetch = %d\n" , self -> manual_result , globals .use_declarefetch );
604
-
604
+
605
605
if ( self -> manual_result || ! globals .use_declarefetch ) {
606
606
607
- if (self -> currTuple >= QR_get_num_tuples (res ) - 1 ||
607
+ if (self -> currTuple >= QR_get_num_tuples (res ) - 1 ||
608
608
(self -> options .maxRows > 0 && self -> currTuple == self -> options .maxRows - 1 )) {
609
609
610
- /* if at the end of the tuples, return "no data found"
611
- and set the cursor past the end of the result set
610
+ /* if at the end of the tuples, return "no data found"
611
+ and set the cursor past the end of the result set
612
612
*/
613
- self -> currTuple = QR_get_num_tuples (res );
613
+ self -> currTuple = QR_get_num_tuples (res );
614
614
return SQL_NO_DATA_FOUND ;
615
615
}
616
-
616
+
617
617
mylog ("**** SQLFetch: manual_result\n" );
618
618
(self -> currTuple )++ ;
619
619
}
@@ -643,15 +643,15 @@ ColumnInfoClass *ci;
643
643
self -> last_fetch_count = 1 ;
644
644
645
645
/* If the bookmark column was bound then return a bookmark.
646
- Since this is used with SQLExtendedFetch, and the rowset size
646
+ Since this is used with SQLExtendedFetch, and the rowset size
647
647
may be greater than 1, and an application can use row or column wise
648
648
binding, use the code in copy_and_convert_field() to handle that.
649
649
*/
650
650
if (self -> bookmark .buffer ) {
651
651
char buf [32 ];
652
652
653
653
sprintf (buf , "%ld" , SC_get_bookmark (self ));
654
- result = copy_and_convert_field (self , 0 , buf ,
654
+ result = copy_and_convert_field (self , 0 , buf ,
655
655
SQL_C_ULONG , self -> bookmark .buffer , 0 , self -> bookmark .used );
656
656
}
657
657
@@ -663,9 +663,9 @@ ColumnInfoClass *ci;
663
663
self -> bindings [lf ].data_left = -1 ;
664
664
665
665
if (self -> bindings [lf ].buffer != NULL ) {
666
- // this column has a binding
666
+ // this column has a binding
667
667
668
- // type = QR_get_field_type(res, lf);
668
+ // type = QR_get_field_type(res, lf);
669
669
type = CI_get_oid (ci , lf ); /* speed things up */
670
670
671
671
mylog ("type = %d\n" , type );
@@ -759,13 +759,13 @@ QueryInfo qi;
759
759
SC_log_error (func , "" , self );
760
760
return SQL_ERROR ;
761
761
}
762
-
763
- ok = QR_command_successful (res );
764
-
762
+
763
+ ok = QR_command_successful (res );
764
+
765
765
mylog ("SQLExecute: ok = %d, status = %d\n" , ok , QR_get_status (res ));
766
-
766
+
767
767
QR_Destructor (res );
768
-
768
+
769
769
if (!ok ) {
770
770
self -> errormsg = "Could not begin a transaction" ;
771
771
self -> errornumber = STMT_EXEC_ERROR ;
@@ -805,32 +805,33 @@ QueryInfo qi;
805
805
qi .cursor = self -> cursor_name ;
806
806
qi .row_size = globals .fetch_max ;
807
807
808
- /* Most likely the rowset size will not be set by the application until
809
- after the statement is executed, so might as well use the cache size.
810
- The qr_next_tuple() function will correct for any discrepancies in
808
+ /* Most likely the rowset size will not be set by the application until
809
+ after the statement is executed, so might as well use the cache size.
810
+ The qr_next_tuple() function will correct for any discrepancies in
811
811
sizes and adjust the cache accordingly.
812
812
*/
813
813
814
814
sprintf (fetch , "fetch %d in %s" , qi .row_size , self -> cursor_name );
815
-
815
+
816
816
self -> result = CC_send_query ( conn , fetch , & qi );
817
817
}
818
818
819
819
mylog (" done sending the query:\n" );
820
820
821
821
822
-
822
+
823
823
}
824
- else { // not a SELECT statement so don't use a cursor
824
+ else { // not a SELECT statement so don't use a cursor
825
825
mylog (" it's NOT a select statement: stmt=%u\n" , self );
826
826
self -> result = CC_send_query (conn , self -> stmt_with_params , NULL );
827
-
827
+
828
828
// If we are in autocommit, we must send the commit.
829
829
if ( ! self -> internal && CC_is_in_autocommit (conn ) && STMT_UPDATE (self )) {
830
- CC_send_query (conn , "COMMIT" , NULL );
831
- CC_set_no_trans (conn );
830
+ res = CC_send_query (conn , "COMMIT" , NULL );
831
+ QR_Destructor (res );
832
+ CC_set_no_trans (conn );
832
833
}
833
-
834
+
834
835
}
835
836
836
837
conn -> status = oldstatus ;
@@ -841,19 +842,19 @@ QueryInfo qi;
841
842
842
843
was_ok = QR_command_successful (self -> result );
843
844
was_nonfatal = QR_command_nonfatal (self -> result );
844
-
845
+
845
846
if ( was_ok )
846
847
self -> errornumber = STMT_OK ;
847
848
else
848
849
self -> errornumber = was_nonfatal ? STMT_INFO_ONLY : STMT_ERROR_TAKEN_FROM_BACKEND ;
849
-
850
+
850
851
self -> currTuple = -1 ; /* set cursor before the first tuple in the list */
851
852
self -> current_col = -1 ;
852
853
self -> rowset_start = -1 ;
853
-
854
+
854
855
/* see if the query did return any result columns */
855
856
numcols = QR_NumResultCols (self -> result );
856
-
857
+
857
858
/* now allocate the array to hold the binding info */
858
859
if (numcols > 0 ) {
859
860
extend_bindings (self , numcols );
@@ -864,7 +865,7 @@ QueryInfo qi;
864
865
return SQL_ERROR ;
865
866
}
866
867
}
867
-
868
+
868
869
} else { /* Bad Error -- The error message will be in the Connection */
869
870
870
871
if (self -> statement_type == STMT_TYPE_CREATE ) {
@@ -927,7 +928,7 @@ SC_log_error(char *func, char *desc, StatementClass *self)
927
928
qlog (" message='%s', command='%s', notice='%s'\n" , nullcheck (res -> message ), nullcheck (res -> command ), nullcheck (res -> notice ));
928
929
qlog (" status=%d, inTuples=%d\n" , res -> status , res -> inTuples );
929
930
}
930
-
931
+
931
932
// Log the connection error if there is one
932
933
CC_log_error (func , desc , self -> hdbc );
933
934
}
0 commit comments