Skip to content

Commit 6b3cda3

Browse files
author
Ard Biesheuvel
committed
Added client/server info attributes
1 parent 8a39751 commit 6b3cda3

File tree

4 files changed

+76
-8
lines changed

4 files changed

+76
-8
lines changed

Diff for: ext/pdo_firebird/firebird_driver.c

+63-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "php_pdo_firebird.h"
3131
#include "php_pdo_firebird_int.h"
3232

33+
#define _GNU_SOURCE
34+
3335
/* map driver specific error message to PDO error */
3436
void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, long line TSRMLS_DC) /* {{{ */
3537
{
@@ -353,7 +355,6 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TS
353355
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
354356

355357
switch (attr) {
356-
357358
case PDO_ATTR_AUTOCOMMIT:
358359

359360
convert_to_long(val);
@@ -382,16 +383,73 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TS
382383
}
383384
/* }}} */
384385

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+
385398
/* called by PDO to get a driver-specific dbh attribute */
386399
static int firebird_handle_get_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC) /* {{{ */
387400
{
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+
}
388446
return 0;
389-
}
447+
}
390448
/* }}} */
391-
449+
392450
/* called by PDO to retrieve driver-specific information about an error that has occurred */
393451
static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info TSRMLS_DC) /* {{{ */
394-
{
452+
{
395453
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
396454
ISC_STATUS *s = H->isc_status;
397455
char buf[400];
@@ -407,7 +465,7 @@ static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval
407465
add_next_index_string(info, buf, 1);
408466
} else {
409467
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);
411469
}
412470
return 1;
413471
}

Diff for: ext/pdo_firebird/firebird_statement.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{
277277
*len = sprintf(*ptr, "%" LL_MASK "d", *(ISC_INT64*)var->sqldata);
278278
#endif
279279
break;
280-
281280
case SQL_FLOAT:
282281
*ptr = FETCH_BUF(S->fetch_buf[colno], double, *len);
283282
*(double*)*ptr = *(float*)var->sqldata;
@@ -298,9 +297,8 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{
298297
isc_decode_timestamp((ISC_TIMESTAMP*)var->sqldata, &t);
299298
fmt = INI_STR("ibase.timestampformat");
300299
}
301-
300+
302301
/* convert the timestamp into a string */
303-
304302
*len = 80; /* TODO enough ? */
305303
*ptr = FETCH_BUF(S->fetch_buf[colno], char, *len);
306304
*len = strftime(*ptr, *len, fmt, &t);

Diff for: ext/pdo_firebird/php_pdo_firebird_int.h

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
/* Firebird API has a couple of missing const decls in its API */
5050
#define const_cast(s) ((char*)(s))
5151

52+
#ifdef PHP_WIN32
53+
typedef void (__stdcall *info_func_t)(char*);
54+
#else
55+
typedef void (*info_func_t)(char*);
56+
#endif
57+
5258
typedef struct {
5359

5460
/* the result of the last API call */

Diff for: ext/pdo_firebird/tests/execute.phpt

+6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
PDO_Firebird: prepare/execute/binding
33
--SKIPIF--
44
<?php include("skipif.inc"); ?>
5+
--INI--
6+
ibase.timestampformat=%Y-%m-%d %H:%M:%S
57
--FILE--
68
<?php /* $Id$ */
79

810
require("testdb.inc");
911

1012
$db = new PDO("firebird:dbname=$test_base",$user,$password) or die;
13+
14+
var_dump($db->getAttribute(PDO_ATTR_CONNECTION_STATUS));
15+
1116
$db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_WARNING);
1217

1318
$db->exec("CREATE TABLE ddl (id SMALLINT NOT NULL PRIMARY KEY, text VARCHAR(32),
@@ -38,6 +43,7 @@ PDO_Firebird: prepare/execute/binding
3843

3944
?>
4045
--EXPECT--
46+
bool(true)
4147
int(1)
4248
array(6) {
4349
["ID"]=>

0 commit comments

Comments
 (0)