@@ -124,13 +124,14 @@ static void free_cols(pdo_stmt_t *stmt, pdo_odbc_stmt *S)
124
124
if (S -> cols ) {
125
125
int i ;
126
126
127
- for (i = 0 ; i < stmt -> column_count ; i ++ ) {
127
+ for (i = 0 ; i < S -> col_count ; i ++ ) {
128
128
if (S -> cols [i ].data ) {
129
129
efree (S -> cols [i ].data );
130
130
}
131
131
}
132
132
efree (S -> cols );
133
133
S -> cols = NULL ;
134
+ S -> col_count = 0 ;
134
135
}
135
136
}
136
137
@@ -260,14 +261,14 @@ static int odbc_stmt_execute(pdo_stmt_t *stmt)
260
261
SQLRowCount (S -> stmt , & row_count );
261
262
stmt -> row_count = row_count ;
262
263
263
- if (! stmt -> executed ) {
264
+ if (S -> cols == NULL ) {
264
265
/* do first-time-only definition of bind/mapping stuff */
265
266
SQLSMALLINT colcount ;
266
267
267
268
/* how many columns do we have ? */
268
269
SQLNumResultCols (S -> stmt , & colcount );
269
270
270
- stmt -> column_count = (int )colcount ;
271
+ stmt -> column_count = S -> col_count = (int )colcount ;
271
272
S -> cols = ecalloc (colcount , sizeof (pdo_odbc_column ));
272
273
S -> going_long = 0 ;
273
274
}
@@ -845,13 +846,25 @@ static int odbc_stmt_next_rowset(pdo_stmt_t *stmt)
845
846
free_cols (stmt , S );
846
847
/* how many columns do we have ? */
847
848
SQLNumResultCols (S -> stmt , & colcount );
848
- stmt -> column_count = (int )colcount ;
849
+ stmt -> column_count = S -> col_count = (int )colcount ;
849
850
S -> cols = ecalloc (colcount , sizeof (pdo_odbc_column ));
850
851
S -> going_long = 0 ;
851
852
852
853
return 1 ;
853
854
}
854
855
856
+ static int odbc_stmt_close_cursor (pdo_stmt_t * stmt )
857
+ {
858
+ SQLRETURN rc ;
859
+ pdo_odbc_stmt * S = (pdo_odbc_stmt * )stmt -> driver_data ;
860
+
861
+ rc = SQLCloseCursor (S -> stmt );
862
+ if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
863
+ return 0 ;
864
+ }
865
+ return 1 ;
866
+ }
867
+
855
868
const struct pdo_stmt_methods odbc_stmt_methods = {
856
869
odbc_stmt_dtor ,
857
870
odbc_stmt_execute ,
@@ -862,5 +875,6 @@ const struct pdo_stmt_methods odbc_stmt_methods = {
862
875
odbc_stmt_set_param ,
863
876
odbc_stmt_get_attr , /* get attr */
864
877
NULL , /* get column meta */
865
- odbc_stmt_next_rowset
878
+ odbc_stmt_next_rowset ,
879
+ odbc_stmt_close_cursor
866
880
};
0 commit comments