@@ -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
}
@@ -820,6 +824,8 @@ PHP_FUNCTION(odbc_close_all)
820
824
odbc_result_free ((odbc_result * ) p );
821
825
} ZEND_HASH_FOREACH_END ();
822
826
827
+ zend_hash_clean (& ODBCG (results ));
828
+
823
829
/* Second loop through list, now close all non-persistent connections */
824
830
ZEND_HASH_FOREACH_VAL (& ODBCG (connections ), p ) {
825
831
odbc_link_free ((odbc_link * ) p );
@@ -913,7 +919,7 @@ PHP_FUNCTION(odbc_prepare)
913
919
break ;
914
920
default :
915
921
odbc_sql_error (conn , result -> stmt , "SQLPrepare" );
916
- efree ( result );
922
+ zval_ptr_dtor ( return_value );
917
923
RETURN_FALSE ;
918
924
}
919
925
@@ -944,6 +950,8 @@ PHP_FUNCTION(odbc_prepare)
944
950
RETURN_FALSE ;
945
951
}
946
952
}
953
+
954
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
947
955
}
948
956
/* }}} */
949
957
@@ -1324,6 +1332,8 @@ PHP_FUNCTION(odbc_exec)
1324
1332
Z_ADDREF_P (pv_conn );
1325
1333
result -> conn_ptr = conn ;
1326
1334
result -> fetched = 0 ;
1335
+
1336
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
1327
1337
}
1328
1338
/* }}} */
1329
1339
@@ -2085,7 +2095,7 @@ PHP_FUNCTION(odbc_pconnect)
2085
2095
/* }}} */
2086
2096
2087
2097
/* {{{ odbc_sqlconnect */
2088
- bool odbc_sqlconnect (zval * zv , char * db , char * uid , char * pwd , int cur_opt , int persistent , zend_string * hash )
2098
+ bool odbc_sqlconnect (zval * zv , char * db , char * uid , char * pwd , int cur_opt , bool persistent , zend_string * hash )
2089
2099
{
2090
2100
RETCODE rc ;
2091
2101
odbc_link * link ;
@@ -2116,7 +2126,6 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, int
2116
2126
rc = SQLSetConnectOption (link -> connection -> hdbc , SQL_ODBC_CURSORS , cur_opt );
2117
2127
if (rc != SQL_SUCCESS ) { /* && rc != SQL_SUCCESS_WITH_INFO ? */
2118
2128
odbc_sql_error (link -> connection , SQL_NULL_HSTMT , "SQLSetConnectOption" );
2119
- SQLFreeConnect (link -> connection -> hdbc );
2120
2129
return false;
2121
2130
}
2122
2131
}
@@ -2190,7 +2199,6 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, int
2190
2199
#endif
2191
2200
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
2192
2201
odbc_sql_error (link -> connection , SQL_NULL_HSTMT , "SQLConnect" );
2193
- SQLFreeConnect (link -> connection -> hdbc );
2194
2202
return false;
2195
2203
}
2196
2204
return true;
@@ -2257,7 +2265,7 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2257
2265
RETURN_FALSE ;
2258
2266
}
2259
2267
2260
- if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , 1 , hashed_details .s )) {
2268
+ if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , true , hashed_details .s )) {
2261
2269
smart_str_free (& hashed_details );
2262
2270
zval_ptr_dtor (return_value );
2263
2271
RETURN_FALSE ;
@@ -2332,8 +2340,9 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2332
2340
RETURN_FALSE ;
2333
2341
}
2334
2342
2335
- if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , 0 , hashed_details .s )) {
2343
+ if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , false , hashed_details .s )) {
2336
2344
smart_str_free (& hashed_details );
2345
+ zval_ptr_dtor (return_value );
2337
2346
RETURN_FALSE ;
2338
2347
}
2339
2348
ODBCG (num_links )++ ;
@@ -2799,6 +2808,8 @@ PHP_FUNCTION(odbc_tables)
2799
2808
}
2800
2809
result -> conn_ptr = conn ;
2801
2810
result -> fetched = 0 ;
2811
+
2812
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
2802
2813
}
2803
2814
/* }}} */
2804
2815
@@ -2868,6 +2879,8 @@ PHP_FUNCTION(odbc_columns)
2868
2879
}
2869
2880
result -> conn_ptr = conn ;
2870
2881
result -> fetched = 0 ;
2882
+
2883
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
2871
2884
}
2872
2885
/* }}} */
2873
2886
@@ -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
@@ -3009,16 +3024,15 @@ PHP_FUNCTION(odbc_foreignkeys)
3009
3024
}
3010
3025
result -> conn_ptr = conn ;
3011
3026
result -> fetched = 0 ;
3027
+
3028
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
3012
3029
}
3013
3030
/* }}} */
3014
3031
#endif /* HAVE_SOLID */
3015
3032
3016
3033
/* {{{ Returns a result identifier containing information about data types supported by the data source */
3017
3034
PHP_FUNCTION (odbc_gettypeinfo )
3018
3035
{
3019
- zend_value_error ("Nope" );
3020
- RETURN_THROWS ();
3021
-
3022
3036
zval * pv_conn ;
3023
3037
zend_long pv_data_type = SQL_ALL_TYPES ;
3024
3038
odbc_result * result = NULL ;
@@ -3030,8 +3044,6 @@ PHP_FUNCTION(odbc_gettypeinfo)
3030
3044
RETURN_THROWS ();
3031
3045
}
3032
3046
3033
- printf ("Hell noo" );
3034
-
3035
3047
data_type = (SQLSMALLINT ) pv_data_type ;
3036
3048
3037
3049
conn = Z_ODBC_CONNECTION_P (pv_conn );
@@ -3074,6 +3086,8 @@ PHP_FUNCTION(odbc_gettypeinfo)
3074
3086
}
3075
3087
result -> conn_ptr = conn ;
3076
3088
result -> fetched = 0 ;
3089
+
3090
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
3077
3091
}
3078
3092
/* }}} */
3079
3093
0 commit comments