]> granicus.if.org Git - php/commitdiff
Added client/server info attributes
authorArd Biesheuvel <abies@php.net>
Sat, 12 Jun 2004 18:56:07 +0000 (18:56 +0000)
committerArd Biesheuvel <abies@php.net>
Sat, 12 Jun 2004 18:56:07 +0000 (18:56 +0000)
ext/pdo_firebird/firebird_driver.c
ext/pdo_firebird/firebird_statement.c
ext/pdo_firebird/php_pdo_firebird_int.h
ext/pdo_firebird/tests/execute.phpt

index c9a6c8e975cb7af811ed110f20dd9df37e917ff9..0fac01a87b942831f7f91acdd703b41215679655 100644 (file)
@@ -30,6 +30,8 @@
 #include "php_pdo_firebird.h"
 #include "php_pdo_firebird_int.h"
 
+#define _GNU_SOURCE
+
 /* map driver specific error message to PDO error */
 void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, long line TSRMLS_DC) /* {{{ */
 {
@@ -353,7 +355,6 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TS
        pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
 
        switch (attr) {
-
                case PDO_ATTR_AUTOCOMMIT:
 
                        convert_to_long(val);
@@ -382,16 +383,73 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TS
 }
 /* }}} */
 
+/* callback to used to report database server info */
+static void firebird_info_cb(void *arg, char const *s) /* {{{ */
+{
+       if (arg) {
+               if (*(char*)arg) { /* second call */
+                       strcat(arg, " ");
+               }
+               strcat(arg, s);
+       }
+}
+/* }}} */
+
 /* called by PDO to get a driver-specific dbh attribute */
 static int firebird_handle_get_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC) /* {{{ */
 {
+       pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
+
+       switch (attr) {
+               char tmp[200] = "Firebird 1.0/Interbase 6";
+               info_func_t info_func;
+               
+               case PDO_ATTR_AUTOCOMMIT:
+                       ZVAL_LONG(val,dbh->auto_commit);
+                       return 1;
+
+               case PDO_ATTR_CONNECTION_STATUS:
+                       ZVAL_BOOL(val, !isc_version(&H->db, firebird_info_cb, NULL));
+                       return 1;
+
+               case PDO_ATTR_CLIENT_VERSION: {
+#if defined(__GNUC__) || defined(PHP_WIN32)
+#ifdef __GNUC__
+                       info_func_t info_func = (info_func_t)dlsym(RTLD_DEFAULT, "isc_get_client_version");
+#else
+                       HMODULE l = GetModuleHandle("fbclient");
+
+                       if (!l && !(l = GetModuleHandle("gds32"))) {
+                               return 0;
+                       }
+                       info_func = (info_func_t)GetProcAddress(l, "isc_get_client_version");
+#endif
+                       if (info_func) {
+                               info_func(tmp);
+                       }
+                       ZVAL_STRING(val,tmp,1);
+#else
+                       ZVAL_NULL(val);
+#endif
+                       }
+                       return 1;
+                       
+               case PDO_ATTR_SERVER_VERSION:
+               case PDO_ATTR_SERVER_INFO:
+                       *tmp = 0;
+                       
+                       if (!isc_version(&H->db, firebird_info_cb, (void*)tmp)) {
+                               ZVAL_STRING(val,tmp,1);
+                               return 1;
+                       }
+       }
        return 0;
-}
+}       
 /* }}} */
-
+        
 /* called by PDO to retrieve driver-specific information about an error that has occurred */
 static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC) /* {{{ */
-{
+{       
        pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
        ISC_STATUS *s = H->isc_status;
        char buf[400];
@@ -407,7 +465,7 @@ static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval
                add_next_index_string(info, buf, 1);
        } else {
                add_next_index_long(info, -999);
-               add_next_index_string(info, H->last_app_error,1);
+               add_next_index_string(info, const_cast(H->last_app_error),1);
        }
        return 1;
 }
index 4b7b3eb3545a6a15896162538a7bd8eaf54d364f..a3f9fe8b47ec40fa595ffdd704938ef769f55241 100644 (file)
@@ -277,7 +277,6 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr,  /* {{
                                        *len = sprintf(*ptr, "%" LL_MASK "d", *(ISC_INT64*)var->sqldata);
 #endif
                                        break;
-                       
                                case SQL_FLOAT:
                                        *ptr = FETCH_BUF(S->fetch_buf[colno], double, *len);
                                        *(double*)*ptr = *(float*)var->sqldata;
@@ -298,9 +297,8 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr,  /* {{
                                                isc_decode_timestamp((ISC_TIMESTAMP*)var->sqldata, &t);
                                                fmt = INI_STR("ibase.timestampformat");
                                        }
-                                       
+
                                        /* convert the timestamp into a string */
-                                       
                                        *len = 80;      /* TODO enough ? */
                                        *ptr = FETCH_BUF(S->fetch_buf[colno], char, *len);
                                        *len = strftime(*ptr, *len, fmt, &t);
index b4f2260a224b4ac924ba7e59ec268c770d60b9f4..8bb6a5cba2c2ea01cfa8a428150b7e92b9cc8677 100644 (file)
 /* Firebird API has a couple of missing const decls in its API */
 #define const_cast(s) ((char*)(s))
 
+#ifdef PHP_WIN32
+typedef void (__stdcall *info_func_t)(char*);
+#else
+typedef void (*info_func_t)(char*);
+#endif
+
 typedef struct {
 
        /* the result of the last API call */
index 1ab33e20e20aee35eb78b11b3e0c7997cdb65fbb..d505156091e2eec5e263003b8331668c2cacb81a 100644 (file)
@@ -2,12 +2,17 @@
 PDO_Firebird: prepare/execute/binding
 --SKIPIF--
 <?php include("skipif.inc"); ?>
+--INI--
+ibase.timestampformat=%Y-%m-%d %H:%M:%S
 --FILE--
 <?php /* $Id$ */
 
        require("testdb.inc");
     
        $db = new PDO("firebird:dbname=$test_base",$user,$password) or die;
+
+       var_dump($db->getAttribute(PDO_ATTR_CONNECTION_STATUS));
+
        $db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_WARNING);
 
        $db->exec("CREATE TABLE ddl (id SMALLINT NOT NULL PRIMARY KEY, text VARCHAR(32),
@@ -38,6 +43,7 @@ PDO_Firebird: prepare/execute/binding
        
 ?>
 --EXPECT--
+bool(true)
 int(1)
 array(6) {
   ["ID"]=>