@@ -146,12 +146,11 @@ static zend_function *odbc_result_get_constructor(zend_object *object) {
146
146
147
147
static void odbc_result_free (odbc_result * res )
148
148
{
149
- int i ;
150
-
151
149
if (res -> values ) {
152
- for ( i = 0 ; i < res -> numcols ; i ++ ) {
153
- if (res -> values [i ].value )
150
+ for ( int i = 0 ; i < res -> numcols ; i ++ ) {
151
+ if (res -> values [i ].value ) {
154
152
efree (res -> values [i ].value );
153
+ }
155
154
}
156
155
efree (res -> values );
157
156
res -> values = NULL ;
@@ -165,7 +164,6 @@ static void odbc_result_free(odbc_result *res)
165
164
SQLFreeStmt (res -> stmt ,SQL_DROP );
166
165
/* We don't want the connection to be closed after the last statement has been closed
167
166
* Connections will be closed on shutdown
168
- * zend_list_delete(res->conn_ptr->id);
169
167
*/
170
168
}
171
169
if (res -> param_info ) {
@@ -190,6 +188,7 @@ static void odbc_result_free_obj(zend_object *obj) {
190
188
191
189
PHP_ODBC_API ZEND_DECLARE_MODULE_GLOBALS (odbc )
192
190
static PHP_GINIT_FUNCTION (odbc );
191
+ static PHP_GSHUTDOWN_FUNCTION (odbc );
193
192
194
193
/* {{{ odbc_module_entry */
195
194
zend_module_entry odbc_module_entry = {
@@ -204,7 +203,7 @@ zend_module_entry odbc_module_entry = {
204
203
PHP_ODBC_VERSION ,
205
204
PHP_MODULE_GLOBALS (odbc ),
206
205
PHP_GINIT (odbc ),
207
- NULL ,
206
+ PHP_GSHUTDOWN ( odbc ) ,
208
207
NULL ,
209
208
STANDARD_MODULE_PROPERTIES_EX
210
209
};
@@ -218,12 +217,14 @@ ZEND_GET_MODULE(odbc)
218
217
#endif
219
218
220
219
static void close_results_with_connection (const odbc_connection * conn ) {
220
+ zend_ulong num_index ;
221
221
zval * p ;
222
222
223
- ZEND_HASH_FOREACH_VAL (& ODBCG (results ), p ) {
223
+ ZEND_HASH_FOREACH_NUM_KEY_VAL (& ODBCG (results ), num_index , p ) {
224
224
odbc_result * result = Z_ODBC_RESULT_P (p );
225
225
if (result -> conn_ptr == conn ) {
226
226
odbc_result_free ((odbc_result * ) p );
227
+ zend_hash_index_del (& ODBCG (results ), num_index );
227
228
}
228
229
} ZEND_HASH_FOREACH_END ();
229
230
}
@@ -443,6 +444,12 @@ static PHP_GINIT_FUNCTION(odbc)
443
444
zend_hash_init (& odbc_globals -> connections , 0 , NULL , NULL , 1 );
444
445
}
445
446
447
+ static PHP_GSHUTDOWN_FUNCTION (odbc )
448
+ {
449
+ zend_hash_destroy (& odbc_globals -> results );
450
+ zend_hash_destroy (& odbc_globals -> connections );
451
+ }
452
+
446
453
/* {{{ PHP_MINIT_FUNCTION */
447
454
PHP_MINIT_FUNCTION (odbc )
448
455
{
@@ -510,9 +517,6 @@ PHP_RSHUTDOWN_FUNCTION(odbc)
510
517
/* {{{ PHP_MSHUTDOWN_FUNCTION */
511
518
PHP_MSHUTDOWN_FUNCTION (odbc )
512
519
{
513
- zend_hash_destroy (& ODBCG (results ));
514
- zend_hash_destroy (& ODBCG (connections ));
515
-
516
520
UNREGISTER_INI_ENTRIES ();
517
521
return SUCCESS ;
518
522
}
@@ -819,6 +823,8 @@ PHP_FUNCTION(odbc_close_all)
819
823
odbc_result_free ((odbc_result * ) p );
820
824
} ZEND_HASH_FOREACH_END ();
821
825
826
+ zend_hash_clean (& ODBCG (results ));
827
+
822
828
/* Second loop through list, now close all non-persistent connections */
823
829
ZEND_HASH_FOREACH_VAL (& ODBCG (connections ), p ) {
824
830
odbc_link_free ((odbc_link * ) p );
@@ -912,7 +918,7 @@ PHP_FUNCTION(odbc_prepare)
912
918
break ;
913
919
default :
914
920
odbc_sql_error (conn , result -> stmt , "SQLPrepare" );
915
- efree ( result );
921
+ zval_ptr_dtor ( return_value );
916
922
RETURN_FALSE ;
917
923
}
918
924
@@ -940,6 +946,8 @@ PHP_FUNCTION(odbc_prepare)
940
946
RETURN_FALSE ;
941
947
}
942
948
}
949
+
950
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
943
951
}
944
952
/* }}} */
945
953
@@ -1314,6 +1322,8 @@ PHP_FUNCTION(odbc_exec)
1314
1322
Z_ADDREF_P (pv_conn );
1315
1323
result -> conn_ptr = conn ;
1316
1324
result -> fetched = 0 ;
1325
+
1326
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
1317
1327
}
1318
1328
/* }}} */
1319
1329
@@ -2072,7 +2082,7 @@ PHP_FUNCTION(odbc_pconnect)
2072
2082
/* }}} */
2073
2083
2074
2084
/* {{{ odbc_sqlconnect */
2075
- bool odbc_sqlconnect (zval * zv , char * db , char * uid , char * pwd , int cur_opt , int persistent , zend_string * hash )
2085
+ bool odbc_sqlconnect (zval * zv , char * db , char * uid , char * pwd , int cur_opt , bool persistent , zend_string * hash )
2076
2086
{
2077
2087
RETCODE rc ;
2078
2088
odbc_link * link ;
@@ -2103,7 +2113,6 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, int
2103
2113
rc = SQLSetConnectOption (link -> connection -> hdbc , SQL_ODBC_CURSORS , cur_opt );
2104
2114
if (rc != SQL_SUCCESS ) { /* && rc != SQL_SUCCESS_WITH_INFO ? */
2105
2115
odbc_sql_error (link -> connection , SQL_NULL_HSTMT , "SQLSetConnectOption" );
2106
- SQLFreeConnect (link -> connection -> hdbc );
2107
2116
return false;
2108
2117
}
2109
2118
}
@@ -2201,7 +2210,6 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, int
2201
2210
#endif
2202
2211
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
2203
2212
odbc_sql_error (link -> connection , SQL_NULL_HSTMT , "SQLConnect" );
2204
- SQLFreeConnect (link -> connection -> hdbc );
2205
2213
return false;
2206
2214
}
2207
2215
return true;
@@ -2269,7 +2277,7 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2269
2277
RETURN_FALSE ;
2270
2278
}
2271
2279
2272
- if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , 1 , hashed_details .s )) {
2280
+ if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , true , hashed_details .s )) {
2273
2281
smart_str_free (& hashed_details );
2274
2282
zval_ptr_dtor (return_value );
2275
2283
RETURN_FALSE ;
@@ -2344,8 +2352,9 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2344
2352
RETURN_FALSE ;
2345
2353
}
2346
2354
2347
- if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , 0 , hashed_details .s )) {
2355
+ if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , false , hashed_details .s )) {
2348
2356
smart_str_free (& hashed_details );
2357
+ zval_ptr_dtor (return_value );
2349
2358
RETURN_FALSE ;
2350
2359
}
2351
2360
ODBCG (num_links )++ ;
@@ -2805,6 +2814,8 @@ PHP_FUNCTION(odbc_tables)
2805
2814
}
2806
2815
result -> conn_ptr = conn ;
2807
2816
result -> fetched = 0 ;
2817
+
2818
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
2808
2819
}
2809
2820
/* }}} */
2810
2821
@@ -2871,6 +2882,8 @@ PHP_FUNCTION(odbc_columns)
2871
2882
}
2872
2883
result -> conn_ptr = conn ;
2873
2884
result -> fetched = 0 ;
2885
+
2886
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
2874
2887
}
2875
2888
/* }}} */
2876
2889
@@ -2931,6 +2944,8 @@ PHP_FUNCTION(odbc_columnprivileges)
2931
2944
}
2932
2945
result -> conn_ptr = conn ;
2933
2946
result -> fetched = 0 ;
2947
+
2948
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
2934
2949
}
2935
2950
/* }}} */
2936
2951
#endif /* HAVE_DBMAKER || HAVE_SOLID*/
@@ -2992,7 +3007,7 @@ PHP_FUNCTION(odbc_foreignkeys)
2992
3007
2993
3008
if (rc == SQL_ERROR ) {
2994
3009
odbc_sql_error (conn , result -> stmt , "SQLForeignKeys" );
2995
- efree ( result );
3010
+ zval_ptr_dtor ( return_value );
2996
3011
RETURN_FALSE ;
2997
3012
}
2998
3013
@@ -3006,16 +3021,15 @@ PHP_FUNCTION(odbc_foreignkeys)
3006
3021
}
3007
3022
result -> conn_ptr = conn ;
3008
3023
result -> fetched = 0 ;
3024
+
3025
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
3009
3026
}
3010
3027
/* }}} */
3011
3028
#endif /* HAVE_SOLID */
3012
3029
3013
3030
/* {{{ Returns a result identifier containing information about data types supported by the data source */
3014
3031
PHP_FUNCTION (odbc_gettypeinfo )
3015
3032
{
3016
- zend_value_error ("Nope" );
3017
- RETURN_THROWS ();
3018
-
3019
3033
zval * pv_conn ;
3020
3034
zend_long pv_data_type = SQL_ALL_TYPES ;
3021
3035
odbc_result * result = NULL ;
@@ -3027,8 +3041,6 @@ PHP_FUNCTION(odbc_gettypeinfo)
3027
3041
RETURN_THROWS ();
3028
3042
}
3029
3043
3030
- printf ("Hell noo" );
3031
-
3032
3044
data_type = (SQLSMALLINT ) pv_data_type ;
3033
3045
3034
3046
conn = Z_ODBC_CONNECTION_P (pv_conn );
@@ -3068,6 +3080,8 @@ PHP_FUNCTION(odbc_gettypeinfo)
3068
3080
}
3069
3081
result -> conn_ptr = conn ;
3070
3082
result -> fetched = 0 ;
3083
+
3084
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
3071
3085
}
3072
3086
/* }}} */
3073
3087
0 commit comments