30
30
#include "php_pdo_firebird.h"
31
31
#include "php_pdo_firebird_int.h"
32
32
33
+ #define _GNU_SOURCE
34
+
33
35
/* map driver specific error message to PDO error */
34
36
void _firebird_error (pdo_dbh_t * dbh , pdo_stmt_t * stmt , char const * file , long line TSRMLS_DC ) /* {{{ */
35
37
{
@@ -353,7 +355,6 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TS
353
355
pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
354
356
355
357
switch (attr ) {
356
-
357
358
case PDO_ATTR_AUTOCOMMIT :
358
359
359
360
convert_to_long (val );
@@ -382,16 +383,73 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TS
382
383
}
383
384
/* }}} */
384
385
386
+ /* callback to used to report database server info */
387
+ static void firebird_info_cb (void * arg , char const * s ) /* {{{ */
388
+ {
389
+ if (arg ) {
390
+ if (* (char * )arg ) { /* second call */
391
+ strcat (arg , " " );
392
+ }
393
+ strcat (arg , s );
394
+ }
395
+ }
396
+ /* }}} */
397
+
385
398
/* called by PDO to get a driver-specific dbh attribute */
386
399
static int firebird_handle_get_attribute (pdo_dbh_t * dbh , long attr , zval * val TSRMLS_DC ) /* {{{ */
387
400
{
401
+ pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
402
+
403
+ switch (attr ) {
404
+ char tmp [200 ] = "Firebird 1.0/Interbase 6" ;
405
+ info_func_t info_func ;
406
+
407
+ case PDO_ATTR_AUTOCOMMIT :
408
+ ZVAL_LONG (val ,dbh -> auto_commit );
409
+ return 1 ;
410
+
411
+ case PDO_ATTR_CONNECTION_STATUS :
412
+ ZVAL_BOOL (val , !isc_version (& H -> db , firebird_info_cb , NULL ));
413
+ return 1 ;
414
+
415
+ case PDO_ATTR_CLIENT_VERSION : {
416
+ #if defined(__GNUC__ ) || defined(PHP_WIN32 )
417
+ #ifdef __GNUC__
418
+ info_func_t info_func = (info_func_t )dlsym (RTLD_DEFAULT , "isc_get_client_version" );
419
+ #else
420
+ HMODULE l = GetModuleHandle ("fbclient" );
421
+
422
+ if (!l && !(l = GetModuleHandle ("gds32" ))) {
423
+ return 0 ;
424
+ }
425
+ info_func = (info_func_t )GetProcAddress (l , "isc_get_client_version" );
426
+ #endif
427
+ if (info_func ) {
428
+ info_func (tmp );
429
+ }
430
+ ZVAL_STRING (val ,tmp ,1 );
431
+ #else
432
+ ZVAL_NULL (val );
433
+ #endif
434
+ }
435
+ return 1 ;
436
+
437
+ case PDO_ATTR_SERVER_VERSION :
438
+ case PDO_ATTR_SERVER_INFO :
439
+ * tmp = 0 ;
440
+
441
+ if (!isc_version (& H -> db , firebird_info_cb , (void * )tmp )) {
442
+ ZVAL_STRING (val ,tmp ,1 );
443
+ return 1 ;
444
+ }
445
+ }
388
446
return 0 ;
389
- }
447
+ }
390
448
/* }}} */
391
-
449
+
392
450
/* called by PDO to retrieve driver-specific information about an error that has occurred */
393
451
static int pdo_firebird_fetch_error_func (pdo_dbh_t * dbh , pdo_stmt_t * stmt , zval * info TSRMLS_DC ) /* {{{ */
394
- {
452
+ {
395
453
pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
396
454
ISC_STATUS * s = H -> isc_status ;
397
455
char buf [400 ];
@@ -407,7 +465,7 @@ static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval
407
465
add_next_index_string (info , buf , 1 );
408
466
} else {
409
467
add_next_index_long (info , -999 );
410
- add_next_index_string (info , H -> last_app_error ,1 );
468
+ add_next_index_string (info , const_cast ( H -> last_app_error ) ,1 );
411
469
}
412
470
return 1 ;
413
471
}
0 commit comments