@@ -2167,15 +2167,7 @@ int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd, int
2167
2167
/* Persistent connections: two list-types le_pconn, le_conn and a plist
2168
2168
* where hashed connection info is stored together with index pointer to
2169
2169
* the actual link of type le_pconn in the list. Only persistent
2170
- * connections get hashed up. Normal connections use existing pconnections.
2171
- * Maybe this has to change with regard to transactions on pconnections?
2172
- * Possibly set autocommit to on on request shutdown.
2173
- *
2174
- * We do have to hash non-persistent connections, and reuse connections.
2175
- * In the case where two connects were being made, without closing the first
2176
- * connect, access violations were occurring. This is because some of the
2177
- * "globals" in this module should actually be per-connection variables. I
2178
- * simply fixed things to get them working for now. Shane
2170
+ * connections get hashed up.
2179
2171
*/
2180
2172
/* {{{ odbc_do_connect */
2181
2173
void odbc_do_connect (INTERNAL_FUNCTION_PARAMETERS , int persistent )
@@ -2184,8 +2176,7 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2184
2176
size_t db_len , uid_len , pwd_len ;
2185
2177
zend_long pv_opt = SQL_CUR_DEFAULT ;
2186
2178
odbc_connection * db_conn ;
2187
- char * hashed_details ;
2188
- int hashed_len , cur_opt ;
2179
+ int cur_opt ;
2189
2180
2190
2181
/* Now an optional 4th parameter specifying the cursor type
2191
2182
* defaulting to the cursors default
@@ -2212,20 +2203,15 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2212
2203
persistent = 0 ;
2213
2204
}
2214
2205
2215
- hashed_len = spprintf (& hashed_details , 0 , "%s_%s_%s_%s_%d" , ODBC_TYPE , db , uid , pwd , cur_opt );
2216
-
2217
- /* FIXME the idea of checking to see if our connection is already persistent
2218
- is good, but it adds a lot of overhead to non-persistent connections. We
2219
- should look and see if we can fix that somehow */
2220
- /* try to find if we already have this link in our persistent list,
2221
- * no matter if it is to be persistent or not
2222
- */
2223
-
2224
2206
try_and_get_another_connection :
2225
2207
2226
2208
if (persistent ) {
2209
+ char * hashed_details ;
2210
+ int hashed_len ;
2227
2211
zend_resource * le ;
2228
2212
2213
+ hashed_len = spprintf (& hashed_details , 0 , "%s_%s_%s_%s_%d" , ODBC_TYPE , db , uid , pwd , cur_opt );
2214
+
2229
2215
/* the link is not in the persistent list */
2230
2216
if ((le = zend_hash_str_find_ptr (& EG (persistent_list ), hashed_details , hashed_len )) == NULL ) {
2231
2217
if (ODBCG (max_links ) != -1 && ODBCG (num_links ) >= ODBCG (max_links )) {
@@ -2254,9 +2240,8 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2254
2240
db_conn -> res = zend_register_resource (db_conn , le_pconn );
2255
2241
RETVAL_RES (db_conn -> res );
2256
2242
} else { /* found connection */
2257
- if (le -> type != le_pconn ) {
2258
- RETURN_FALSE ;
2259
- }
2243
+ ZEND_ASSERT (le -> type == le_pconn );
2244
+
2260
2245
/*
2261
2246
* check to see if the connection is still valid
2262
2247
*/
@@ -2287,50 +2272,27 @@ void odbc_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
2287
2272
}
2288
2273
}
2289
2274
}
2275
+ efree (hashed_details );
2290
2276
db_conn -> res = zend_register_resource (db_conn , le_pconn );
2291
2277
RETVAL_RES (db_conn -> res );
2292
2278
} else { /* non persistent */
2293
- zend_resource * index_ptr , new_index_ptr ;
2294
-
2295
- if ((index_ptr = zend_hash_str_find_ptr (& EG (regular_list ), hashed_details , hashed_len )) != NULL ) {
2296
- zend_ulong conn_id ;
2297
- zend_resource * p ;
2279
+ zend_resource new_index_ptr ;
2298
2280
2299
- if (index_ptr -> type != le_index_ptr ) {
2300
- RETURN_FALSE ;
2301
- }
2302
- conn_id = (zend_ulong )index_ptr -> ptr ;
2303
- p = zend_hash_index_find_ptr (& EG (regular_list ), conn_id ); /* check if the connection is still there */
2304
-
2305
- if (p && p -> ptr && (p -> type == le_conn || p -> type == le_pconn )) {
2306
- GC_ADDREF (p );
2307
- RETVAL_RES (p );
2308
- efree (hashed_details );
2309
- return ;
2310
- } else {
2311
- zend_hash_str_del (& EG (regular_list ), hashed_details , hashed_len );
2312
- }
2313
- }
2314
2281
if (ODBCG (max_links ) != -1 && ODBCG (num_links ) >= ODBCG (max_links )) {
2315
2282
php_error_docref (NULL , E_WARNING ,"Too many open connections (%ld)" ,ODBCG (num_links ));
2316
- efree (hashed_details );
2317
2283
RETURN_FALSE ;
2318
2284
}
2319
2285
2320
2286
if (!odbc_sqlconnect (& db_conn , db , uid , pwd , cur_opt , 0 )) {
2321
- efree (hashed_details );
2322
2287
RETURN_FALSE ;
2323
2288
}
2324
2289
db_conn -> res = zend_register_resource (db_conn , le_conn );
2325
2290
RETVAL_RES (db_conn -> res );
2326
2291
new_index_ptr .ptr = (void * )(zend_uintptr_t )Z_RES_HANDLE_P (return_value );
2327
2292
new_index_ptr .type = le_index_ptr ;
2328
2293
2329
- zend_hash_str_update_mem (& EG (regular_list ), hashed_details , hashed_len , (void * ) & new_index_ptr ,
2330
- sizeof (zend_resource ));
2331
2294
ODBCG (num_links )++ ;
2332
2295
}
2333
- efree (hashed_details );
2334
2296
}
2335
2297
/* }}} */
2336
2298
0 commit comments