@@ -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
}
@@ -2214,7 +2223,6 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, int
2214
2223
#endif
2215
2224
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
2216
2225
odbc_sql_error (link -> connection , SQL_NULL_HSTMT , "SQLConnect" );
2217
- SQLFreeConnect (link -> connection -> hdbc );
2218
2226
return false;
2219
2227
}
2220
2228
return true;
@@ -2282,7 +2290,7 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2282
2290
RETURN_FALSE ;
2283
2291
}
2284
2292
2285
- if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , 1 , hashed_details .s )) {
2293
+ if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , true , hashed_details .s )) {
2286
2294
smart_str_free (& hashed_details );
2287
2295
zval_ptr_dtor (return_value );
2288
2296
RETURN_FALSE ;
@@ -2357,8 +2365,9 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2357
2365
RETURN_FALSE ;
2358
2366
}
2359
2367
2360
- if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , 0 , hashed_details .s )) {
2368
+ if (!odbc_sqlconnect (return_value , db , uid , pwd , cur_opt , false , hashed_details .s )) {
2361
2369
smart_str_free (& hashed_details );
2370
+ zval_ptr_dtor (return_value );
2362
2371
RETURN_FALSE ;
2363
2372
}
2364
2373
ODBCG (num_links )++ ;
@@ -2824,6 +2833,8 @@ PHP_FUNCTION(odbc_tables)
2824
2833
}
2825
2834
result -> conn_ptr = conn ;
2826
2835
result -> fetched = 0 ;
2836
+
2837
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
2827
2838
}
2828
2839
/* }}} */
2829
2840
@@ -2893,6 +2904,8 @@ PHP_FUNCTION(odbc_columns)
2893
2904
}
2894
2905
result -> conn_ptr = conn ;
2895
2906
result -> fetched = 0 ;
2907
+
2908
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
2896
2909
}
2897
2910
/* }}} */
2898
2911
@@ -2956,6 +2969,8 @@ PHP_FUNCTION(odbc_columnprivileges)
2956
2969
}
2957
2970
result -> conn_ptr = conn ;
2958
2971
result -> fetched = 0 ;
2972
+
2973
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
2959
2974
}
2960
2975
/* }}} */
2961
2976
#endif /* HAVE_DBMAKER || HAVE_SOLID*/
@@ -3017,7 +3032,7 @@ PHP_FUNCTION(odbc_foreignkeys)
3017
3032
3018
3033
if (rc == SQL_ERROR ) {
3019
3034
odbc_sql_error (conn , result -> stmt , "SQLForeignKeys" );
3020
- efree ( result );
3035
+ zval_ptr_dtor ( return_value );
3021
3036
RETURN_FALSE ;
3022
3037
}
3023
3038
@@ -3034,16 +3049,15 @@ PHP_FUNCTION(odbc_foreignkeys)
3034
3049
}
3035
3050
result -> conn_ptr = conn ;
3036
3051
result -> fetched = 0 ;
3052
+
3053
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
3037
3054
}
3038
3055
/* }}} */
3039
3056
#endif /* HAVE_SOLID */
3040
3057
3041
3058
/* {{{ Returns a result identifier containing information about data types supported by the data source */
3042
3059
PHP_FUNCTION (odbc_gettypeinfo )
3043
3060
{
3044
- zend_value_error ("Nope" );
3045
- RETURN_THROWS ();
3046
-
3047
3061
zval * pv_conn ;
3048
3062
zend_long pv_data_type = SQL_ALL_TYPES ;
3049
3063
odbc_result * result = NULL ;
@@ -3055,8 +3069,6 @@ PHP_FUNCTION(odbc_gettypeinfo)
3055
3069
RETURN_THROWS ();
3056
3070
}
3057
3071
3058
- printf ("Hell noo" );
3059
-
3060
3072
data_type = (SQLSMALLINT ) pv_data_type ;
3061
3073
3062
3074
conn = Z_ODBC_CONNECTION_P (pv_conn );
@@ -3099,6 +3111,8 @@ PHP_FUNCTION(odbc_gettypeinfo)
3099
3111
}
3100
3112
result -> conn_ptr = conn ;
3101
3113
result -> fetched = 0 ;
3114
+
3115
+ zend_hash_next_index_insert_new (& ODBCG (results ), return_value );
3102
3116
}
3103
3117
/* }}} */
3104
3118
0 commit comments