Skip to content

Commit 27265a5

Browse files
committed
Introduce ibase_get_client_version()
1 parent 58a74b8 commit 27265a5

File tree

7 files changed

+60
-15
lines changed

7 files changed

+60
-15
lines changed

interbase.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ ZEND_END_ARG_INFO()
317317
ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_free_event_handler, 0, 0, 1)
318318
ZEND_ARG_INFO(0, event)
319319
ZEND_END_ARG_INFO()
320+
321+
ZEND_BEGIN_ARG_INFO(arginfo_ibase_get_client_version, 0)
322+
ZEND_END_ARG_INFO()
320323
/* }}} */
321324

322325
/* {{{ extension definition structures */
@@ -378,6 +381,8 @@ static const zend_function_entry ibase_functions[] = {
378381
PHP_FE(ibase_set_event_handler, arginfo_ibase_set_event_handler)
379382
PHP_FE(ibase_free_event_handler, arginfo_ibase_free_event_handler)
380383

384+
PHP_FE(ibase_get_client_version, arginfo_ibase_get_client_version)
385+
381386
/**
382387
* These aliases are provided in order to maintain forward compatibility. As Firebird
383388
* and InterBase are developed independently, functionality might be different between
@@ -441,6 +446,8 @@ static const zend_function_entry ibase_functions[] = {
441446
PHP_FALIAS(fbird_wait_event, ibase_wait_event, arginfo_ibase_wait_event)
442447
PHP_FALIAS(fbird_set_event_handler, ibase_set_event_handler, arginfo_ibase_set_event_handler)
443448
PHP_FALIAS(fbird_free_event_handler, ibase_free_event_handler, arginfo_ibase_free_event_handler)
449+
450+
PHP_FALIAS(fbird_get_client_version, ibase_get_client_version, arginfo_ibase_get_client_version)
444451
PHP_FE_END
445452
};
446453

@@ -491,6 +498,18 @@ PHP_FUNCTION(ibase_errmsg)
491498
}
492499
/* }}} */
493500

501+
/* {{{ proto float ibase_get_client_version(void)
502+
Return client version in form major.minor */
503+
PHP_FUNCTION(ibase_get_client_version)
504+
{
505+
if (zend_parse_parameters_none() == FAILURE) {
506+
return;
507+
}
508+
509+
RETURN_DOUBLE((double)IBG(client_major_version) + (double)IBG(client_minor_version) / 10);
510+
}
511+
/* }}} */
512+
494513
/* {{{ proto int ibase_errcode(void)
495514
Return error code */
496515
PHP_FUNCTION(ibase_errcode)
@@ -811,8 +830,20 @@ static PHP_GINIT_FUNCTION(ibase)
811830
ibase_globals->num_persistent = ibase_globals->num_links = 0;
812831
ibase_globals->sql_code = *ibase_globals->errmsg = 0;
813832
ibase_globals->default_link = NULL;
814-
ibase_globals->fb_get_master_interface = _php_ibase_get_fbclient_symbol("fb_get_master_interface");
815-
ibase_globals->fb_get_statement_interface = _php_ibase_get_fbclient_symbol("fb_get_statement_interface");
833+
ibase_globals->get_master_interface = _php_ibase_get_fbclient_symbol("fb_get_master_interface");
834+
ibase_globals->get_statement_interface = _php_ibase_get_fbclient_symbol("fb_get_statement_interface");
835+
836+
if (ibase_globals->get_master_interface) {
837+
ibase_globals->master_instance = ((fb_get_master_interface_t)(ibase_globals->get_master_interface))();
838+
ibase_globals->client_version = fb_get_client_version(ibase_globals->master_instance);
839+
ibase_globals->client_major_version = ibase_globals->client_version >> 8;
840+
ibase_globals->client_minor_version = ibase_globals->client_version & 0xFF;
841+
} else {
842+
ibase_globals->master_instance = NULL;
843+
ibase_globals->client_version = -1;
844+
ibase_globals->client_major_version = -1;
845+
ibase_globals->client_minor_version = -1;
846+
}
816847
}
817848

818849
PHP_MINIT_FUNCTION(ibase)

pdo_firebird_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
#include "php_ibase_includes.h"
2626

2727
/* Returns the client version. 0 bytes are minor version, 1 bytes are major version. */
28-
extern "C" unsigned fb_get_client_version(void)
28+
extern "C" unsigned fb_get_client_version(void *master_ptr)
2929
{
30-
Firebird::IMaster* master = Firebird::fb_get_master_interface();
30+
Firebird::IMaster* master = (Firebird::IMaster*)master_ptr;
3131
Firebird::IUtil* util = master->getUtilInterface();
3232
return util->getClientVersion();
3333
}

pdo_firebird_utils.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
extern "C" {
2727
#endif
2828

29-
unsigned fb_get_client_version(void);
30-
31-
ISC_TIME fb_encode_time(unsigned hours, unsigned minutes, unsigned seconds, unsigned fractions);
32-
33-
ISC_DATE fb_encode_date(unsigned year, unsigned month, unsigned day);
29+
unsigned fb_get_client_version(void *master_ptr);
3430

3531
void fb_decode_time_tz(const ISC_TIME_TZ* timeTz, unsigned* hours, unsigned* minutes, unsigned* seconds, unsigned* fractions,
3632
unsigned timeZoneBufferLength, char* timeZoneBuffer);

php_ibase_includes.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ ZEND_BEGIN_MODULE_GLOBALS(ibase)
7575
zend_long sql_code;
7676
zend_long default_trans_params;
7777
zend_long default_lock_timeout; // only used togetger with trans_param IBASE_LOCK_TIMEOUT
78-
void *fb_get_master_interface;
79-
void *fb_get_statement_interface;
78+
void *get_master_interface;
79+
void *master_instance;
80+
void *get_statement_interface;
81+
int client_version;
82+
int client_major_version;
83+
int client_minor_version;
8084
ZEND_END_MODULE_GLOBALS(ibase)
8185

8286
ZEND_EXTERN_MODULE_GLOBALS(ibase)
@@ -288,4 +292,10 @@ void fbp_error_ex(long level, const char *, ...)
288292
#define fbp_notice(msg, ...) fbp_error_ex(E_NOTICE, msg " (%s:%d)\n" __VA_OPT__(,) __VA_ARGS__, __FILE__, __LINE__)
289293
#endif
290294

295+
typedef ISC_STATUS (ISC_EXPORT *fb_get_statement_interface_t)(
296+
ISC_STATUS* status_vector, void* db_handle, isc_stmt_handle* stmt_handle
297+
);
298+
299+
typedef void* (ISC_EXPORT *fb_get_master_interface_t)(void);
300+
291301
#endif /* PHP_IBASE_INCLUDES_H */

php_interbase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ PHP_FUNCTION(ibase_wait_event);
119119
PHP_FUNCTION(ibase_set_event_handler);
120120
PHP_FUNCTION(ibase_free_event_handler);
121121

122+
PHP_FUNCTION(ibase_get_client_version);
123+
122124
#else
123125

124126
#define phpext_interbase_ptr NULL

tests/functions.inc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,23 @@ function insert_into($table, $data, $tr = null) {
118118

119119
/** @var float $v */
120120
function skip_if_fb_lt($v) {
121-
if(($cv = get_fb_version()) < $v)die("skip: Firebird version $cv < $v");
121+
if(($cv = get_fb_version()) < $v)die("skip Firebird server version $cv < $v");
122122
}
123123

124124
/** @var float $v */
125125
function skip_if_fb_gt($v) {
126-
if(($cv = get_fb_version()) > $v)die("skip: Firebird version $cv > $v");
126+
if(($cv = get_fb_version()) > $v)die("skip Firebird server version $cv > $v");
127127
}
128128

129129
/** @var float $v */
130130
function skip_if_fb_gte($v) {
131-
if(($cv = get_fb_version()) >= $v)die("skip: Firebird version $cv >= $v");
131+
if(($cv = get_fb_version()) >= $v)die("skip Firebird server version $cv >= $v");
132+
}
133+
134+
/** @var float $v */
135+
function skip_if_fbclient_lt($v) {
136+
if(!function_exists("ibase_get_client_version"))die("skip Unable to determine Firebird client library version");
137+
if(($cv = ibase_get_client_version()) < $v)die("skip Firebird client library version $cv < $v");
132138
}
133139

134140
function ibase_query_bulk(array $queries, $tr = null) {

tests/long_names_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Long names: Firebird 4.0 or newer
33
--SKIPIF--
44
<?php
55
require_once("skipif.inc");
6-
skip_if_fb_lt(4.0);
6+
skip_if_fb_lt(4.0) || skip_if_fbclient_lt(4.0);
77
?>
88
--FILE--
99
<?php

0 commit comments

Comments
 (0)