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