Skip to content

Commit aa8e9d5

Browse files
committed
Add client major / minor version PHP functions
1 parent edda6d4 commit aa8e9d5

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

interbase.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ ZEND_END_ARG_INFO()
310310

311311
ZEND_BEGIN_ARG_INFO(arginfo_ibase_get_client_version, 0)
312312
ZEND_END_ARG_INFO()
313+
314+
ZEND_BEGIN_ARG_INFO(arginfo_ibase_get_client_major_version, 0)
315+
ZEND_END_ARG_INFO()
316+
317+
ZEND_BEGIN_ARG_INFO(arginfo_ibase_get_client_minor_version, 0)
318+
ZEND_END_ARG_INFO()
313319
/* }}} */
314320

315321
/* {{{ extension definition structures */
@@ -369,6 +375,8 @@ static const zend_function_entry ibase_functions[] = {
369375
PHP_FE(ibase_free_event_handler, arginfo_ibase_free_event_handler)
370376

371377
PHP_FE(ibase_get_client_version, arginfo_ibase_get_client_version)
378+
PHP_FE(ibase_get_client_major_version, arginfo_ibase_get_client_major_version)
379+
PHP_FE(ibase_get_client_minor_version, arginfo_ibase_get_client_minor_version)
372380

373381
/**
374382
* These aliases are provided in order to maintain forward compatibility. As Firebird
@@ -432,6 +440,8 @@ static const zend_function_entry ibase_functions[] = {
432440
PHP_FALIAS(fbird_free_event_handler, ibase_free_event_handler, arginfo_ibase_free_event_handler)
433441

434442
PHP_FALIAS(fbird_get_client_version, ibase_get_client_version, arginfo_ibase_get_client_version)
443+
PHP_FALIAS(fbird_get_client_major_version, ibase_get_client_major_version, arginfo_ibase_get_client_major_version)
444+
PHP_FALIAS(fbird_get_client_minor_version, ibase_get_client_minor_version, arginfo_ibase_get_client_minor_version)
435445
PHP_FE_END
436446
};
437447

@@ -486,14 +496,26 @@ PHP_FUNCTION(ibase_errmsg)
486496
Return client version in form major.minor */
487497
PHP_FUNCTION(ibase_get_client_version)
488498
{
489-
if (zend_parse_parameters_none() == FAILURE) {
490-
return;
491-
}
492-
493499
RETURN_DOUBLE((double)IBG(client_major_version) + (double)IBG(client_minor_version) / 10);
494500
}
495501
/* }}} */
496502

503+
/* {{{ proto int ibase_get_client_major_version(void)
504+
Return client major version */
505+
PHP_FUNCTION(ibase_get_client_major_version)
506+
{
507+
RETURN_LONG(IBG(client_major_version));
508+
}
509+
/* }}} */
510+
511+
/* {{{ proto int ibase_get_client_minor_version(void)
512+
Return client minor version */
513+
PHP_FUNCTION(ibase_get_client_minor_version)
514+
{
515+
RETURN_LONG(IBG(client_minor_version));
516+
}
517+
/* }}} */
518+
497519
/* {{{ proto int ibase_errcode(void)
498520
Return error code */
499521
PHP_FUNCTION(ibase_errcode)
@@ -820,7 +842,7 @@ static PHP_GINIT_FUNCTION(ibase)
820842
if (ibase_globals->get_master_interface) {
821843
ibase_globals->master_instance = ((fb_get_master_interface_t)(ibase_globals->get_master_interface))();
822844
ibase_globals->client_version = fb_get_client_version(ibase_globals->master_instance);
823-
ibase_globals->client_major_version = ibase_globals->client_version >> 8;
845+
ibase_globals->client_major_version = (ibase_globals->client_version >> 8) & 0xFF;
824846
ibase_globals->client_minor_version = ibase_globals->client_version & 0xFF;
825847
} else {
826848
ibase_globals->master_instance = NULL;

php_interbase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ PHP_FUNCTION(ibase_set_event_handler);
117117
PHP_FUNCTION(ibase_free_event_handler);
118118

119119
PHP_FUNCTION(ibase_get_client_version);
120+
PHP_FUNCTION(ibase_get_client_major_version);
121+
PHP_FUNCTION(ibase_get_client_minor_version);
120122

121123
#else
122124

tests/fbclient_vers_001.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Get fbclient version
3+
--SKIPIF--
4+
<?php
5+
include("skipif.inc");
6+
skip_if_ext_lt(61);
7+
?>
8+
--FILE--
9+
<?php
10+
11+
var_dump(
12+
ibase_get_client_version() === (float)ibase_get_client_major_version() + ibase_get_client_minor_version() / 10
13+
);
14+
15+
?>
16+
--EXPECT--
17+
bool(true)

0 commit comments

Comments
 (0)