Added client/server info attributes

This commit is contained in:
Ard Biesheuvel 2004-06-12 18:56:07 +00:00
parent 8a3975191e
commit 6b3cda310a
4 changed files with 77 additions and 9 deletions

View 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
}
/* }}} */
/* 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) /* {{{ */
/* callback to used to report database server info */
static void firebird_info_cb(void *arg, char const *s) /* {{{ */
{
return 0;
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;
}

View 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);

View file

@ -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 */

View 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"]=>