From 6b3cda310a7deccc67cee73ec6cb84a43eb78e21 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Sat, 12 Jun 2004 18:56:07 +0000 Subject: [PATCH] Added client/server info attributes --- ext/pdo_firebird/firebird_driver.c | 68 +++++++++++++++++++++++-- ext/pdo_firebird/firebird_statement.c | 4 +- ext/pdo_firebird/php_pdo_firebird_int.h | 6 +++ ext/pdo_firebird/tests/execute.phpt | 6 +++ 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index c9a6c8e975..0fac01a87b 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -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; } diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index 4b7b3eb354..a3f9fe8b47 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -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); diff --git a/ext/pdo_firebird/php_pdo_firebird_int.h b/ext/pdo_firebird/php_pdo_firebird_int.h index b4f2260a22..8bb6a5cba2 100644 --- a/ext/pdo_firebird/php_pdo_firebird_int.h +++ b/ext/pdo_firebird/php_pdo_firebird_int.h @@ -49,6 +49,12 @@ /* 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 */ diff --git a/ext/pdo_firebird/tests/execute.phpt b/ext/pdo_firebird/tests/execute.phpt index 1ab33e20e2..d505156091 100644 --- a/ext/pdo_firebird/tests/execute.phpt +++ b/ext/pdo_firebird/tests/execute.phpt @@ -2,12 +2,17 @@ PDO_Firebird: prepare/execute/binding --SKIPIF-- +--INI-- +ibase.timestampformat=%Y-%m-%d %H:%M:%S --FILE-- 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"]=> -- 2.40.0