Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ibase_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,10 @@ PHP_FUNCTION(ibase_free_result)
}

ib_result = (ibase_result *)zend_fetch_resource_ex(result_arg, LE_RESULT, le_result);

_php_ibase_free_xsqlda(ib_result->out_sqlda);
efree(ib_result);

zend_list_delete(Z_RES_P(result_arg));

/*
Expand Down
50 changes: 38 additions & 12 deletions ibase_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,34 +214,60 @@ PHP_FUNCTION(ibase_delete_user)
Connect to the service manager */
PHP_FUNCTION(ibase_service_attach)
{
size_t hlen, ulen, plen, spb_len;
size_t hlen = 0, ulen = 0, plen = 0;
ibase_service *svm;
char buf[128], *host, *user, *pass, *loc;
char buf[350], *host, *user, *pass;
char loc[128] = "service_mgr";
isc_svc_handle handle = 0;
unsigned short p = 0;

RESET_ERRMSG;

if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "sss",
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|sss",
&host, &hlen, &user, &ulen, &pass, &plen)) {

RETURN_FALSE;
}

/* construct the spb, hack the service name into it as well */
spb_len = slprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c%s" "%s:service_mgr",
isc_spb_version, isc_spb_current_version, isc_spb_user_name, (char)ulen,
user, isc_spb_password, (char)plen, pass, host);
if (ulen > 63) {
_php_ibase_module_error("Internal error: dba_username too long");
RETURN_FALSE;
}

if (spb_len > sizeof(buf) || spb_len == -1) {
_php_ibase_module_error("Internal error: insufficient buffer space for SPB (%zd)", spb_len);
if (plen > 255) {
_php_ibase_module_error("Internal error: dba_password too long");
RETURN_FALSE;
}

// 13 = strlen(":service_mgr") + \0;
if (hlen + 13 > sizeof(loc)) {
_php_ibase_module_error("Internal error: insufficient buffer space for name of the service (%zd)", hlen + 13);
RETURN_FALSE;
}

spb_len -= hlen + 12;
loc = buf + spb_len; /* points to %s:service_mgr part */
buf[p++] = isc_spb_version;
buf[p++] = isc_spb_current_version;

if(ulen > 0){
buf[p++] = isc_spb_user_name;
buf[p++] = (char)ulen;
memcpy(&buf[p], &user, ulen);
p += ulen;
}

if(plen > 0){
buf[p++] = isc_spb_password;
buf[p++] = (char)plen;
memcpy(&buf[p], &pass, plen);
p += plen;
}

if(hlen > 0){
slprintf(loc, sizeof(loc), "%s:service_mgr", host);
}

/* attach to the service manager */
if (isc_service_attach(IB_STATUS, 0, loc, &handle, (unsigned short)spb_len, buf)) {
if (isc_service_attach(IB_STATUS, 0, loc, &handle, p, buf)) {
_php_ibase_error();
RETURN_FALSE;
}
Expand Down
19 changes: 16 additions & 3 deletions interbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_delete_user, 0, 0, 3)
ZEND_ARG_INFO(0, last_name)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_service_attach, 0, 0, 3)
ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_service_attach, 0, 0, 0)
ZEND_ARG_INFO(0, host)
ZEND_ARG_INFO(0, dba_username)
ZEND_ARG_INFO(0, dba_password)
Expand Down Expand Up @@ -711,12 +711,12 @@ static PHP_INI_DISP(php_ibase_password_displayer_cb)
PUTS(" | "); \
} \
PUTS(str); \
has_puts = true; \
has_puts = 1; \
} while (0)

static PHP_INI_DISP(php_ibase_trans_displayer)
{
bool has_puts = false;
int has_puts = 0;
char *value;

if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
Expand Down Expand Up @@ -1589,6 +1589,19 @@ PHP_FUNCTION(ibase_gen_id)
RETURN_LONG((zend_long)result);
}

void fbp_dump_buffer(int len, const unsigned char *buffer){
int i;
for (i = 0; i < len; i++) {
if(buffer[i] < 31 || buffer[i] > 126)
php_printf("0x%02x ", buffer[i]);
else
php_printf("%c", buffer[i]);
}
if (i > 0) {
php_printf("\n");
}
}

/* }}} */

#endif /* HAVE_IBASE */
2 changes: 2 additions & 0 deletions php_ibase_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,6 @@ void php_ibase_service_minit(INIT_FUNC_ARGS);
#define max(a,b) ((a)>(b)?(a):(b))
#endif

void fbp_dump_buffer(int len, const unsigned char *buffer);

#endif /* PHP_IBASE_INCLUDES_H */
13 changes: 9 additions & 4 deletions tests/005.phpt
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
--TEST--
InterBase: transactions
--SKIPIF--
<?php die('skip: Broken test (Disabled until issue 41 is fixed)'); include("skipif.inc"); ?>
<?php
include("skipif.inc");
if(get_fb_version() >= 5.0)print 'skip: FB >= 5.0';
?>
--FILE--
<?php

// See https://github.com/FirebirdSQL/php-firebird/issues/41

require("interbase.inc");

ibase_connect($test_base);

@ibase_query("create table test5 (i integer)");
@ibase_query("delete from test5");
ibase_query("create table test5 (i integer)");
//ibase_query("delete from test5");
ibase_close();


Expand Down Expand Up @@ -264,7 +269,7 @@ three rows in fourth transaction with deadlock
2
3
4
errmsg [lock conflict on no wait transaction deadlock %a]
errmsg [%s]
---
three rows
--- test5 ---
Expand Down
32 changes: 14 additions & 18 deletions tests/bug45373.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@ Bug #45373 (php crash on query with errors in params)
include("skipif.inc");
// See GitHub issue 44
// https://github.com/FirebirdSQL/php-firebird/issues/44
include("skipif-php8-or-newer.inc");
?>
--FILE--
<?php

require("interbase.inc");
require("interbase.inc");

$db = ibase_connect($test_base);
$db = ibase_connect($test_base);

$q = ibase_prepare($db, "SELECT * FROM TEST1 WHERE I = ? AND C = ?");
$r = ibase_execute($q, 1, 'test table not created with isql');
var_dump(ibase_fetch_assoc($r));
ibase_free_result($r);

$sql = "select * from test1 where i = ? and c = ?";
// MUST run with error_reporting & E_NOTICE to generate Notice:
$r = ibase_execute($q, 1, 'test table not created with isql', 1);
var_dump(ibase_fetch_assoc($r));
ibase_free_result($r);

$q = ibase_prepare($db, $sql);
$r = ibase_execute($q, 1, 'test table not created with isql');
var_dump(ibase_fetch_assoc($r));
ibase_free_result($r);

$r = ibase_execute($q, 1, 'test table not created with isql', 1);
var_dump(ibase_fetch_assoc($r));
ibase_free_result($r);

$r = ibase_execute($q, 1);
var_dump(ibase_fetch_assoc($r));
// Enforcing function parameters became more stricter in latest versions of PHP
if($r = ibase_execute($q, 1)) {
var_dump(ibase_fetch_assoc($r));
}

?>
--EXPECTF--
Expand All @@ -47,6 +46,3 @@ array(2) {
}

Warning: ibase_execute(): Statement expects 2 arguments, 1 given in %s on line %d

Warning: ibase_fetch_assoc() expects parameter 1 to be resource, bool given in %s on line %d
NULL
17 changes: 9 additions & 8 deletions tests/datatype_int128.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@ Check for data type INT128 (Firebird 4.0 or above)
--SKIPIF--
<?php
include("skipif.inc");
if(get_fb_version() < 4.0)print "skip FB < 4.0";
?>
--FILE--
<?php

require("interbase.inc");
require("interbase.inc");

$db = ibase_connect($test_base);
$db = ibase_connect($test_base);

ibase_query(
"create table test_dt (
v_int128 int128 not null
"CREATE TABLE TEST_DT (
V_INT128 INT128 NOT NULL
)");
ibase_commit();

ibase_query("insert into test_dt (v_int128) values (1234)");
ibase_query("insert into test_dt (v_int128) values (-170141183460469231731687303715884105728)");
ibase_query("insert into test_dt (v_int128) values (170141183460469231731687303715884105727)");
ibase_query("INSERT INTO TEST_DT (V_INT128) VALUES (1234)");
ibase_query("INSERT INTO TEST_DT (V_INT128) VALUES (-170141183460469231731687303715884105728)");
ibase_query("INSERT INTO TEST_DT (V_INT128) VALUES (170141183460469231731687303715884105727)");

$sql = 'select * from test_dt';
$sql = 'SELECT * FROM TEST_DT';
$query = ibase_query($sql);
while(($row = ibase_fetch_assoc($query))) {
var_dump($row);
Expand Down
2 changes: 1 addition & 1 deletion tests/ibase_drop_db_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ibase_drop_db(): Basic test

require("config.inc");

unlink($file = tempnam('/tmp',"php_ibase_test"));
unlink($file = tempnam(sys_get_temp_dir(),"php_ibase_test"));
if(!empty($host))$file = "$host:$file";

$db = ibase_query(IBASE_CREATE,
Expand Down
2 changes: 1 addition & 1 deletion tests/ibase_drop_db_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include("skipif-php8-or-newer.inc");

require("config.inc");

unlink($file = tempnam('/tmp',"php_ibase_test"));
unlink($file = tempnam(sys_get_temp_dir(),"php_ibase_test"));

$db = ibase_query(IBASE_CREATE,
sprintf("CREATE SCHEMA '%s' USER '%s' PASSWORD '%s' DEFAULT CHARACTER SET %s",$file,
Expand Down
2 changes: 1 addition & 1 deletion tests/ibase_drop_db_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include("skipif-php7-or-older.inc");

require("config.inc");

unlink($file = tempnam('/tmp',"php_ibase_test"));
unlink($file = tempnam(sys_get_temp_dir(),"php_ibase_test"));
if(!empty($host))$file = "$host:$file";

$db = ibase_query(IBASE_CREATE,
Expand Down
2 changes: 1 addition & 1 deletion tests/ibase_drop_db_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include("skipif-php7-or-older.inc");

require("config.inc");

unlink($file = tempnam('/tmp',"php_ibase_test"));
unlink($file = tempnam(sys_get_temp_dir(),"php_ibase_test"));
if(!empty($host))$file = "$host:$file";

$db = ibase_query(IBASE_CREATE,
Expand Down
17 changes: 17 additions & 0 deletions tests/interbase.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,22 @@ function cleanup_db()
ibase_drop_db($r);
}

function get_fb_version(): float
{
global $host, $user, $password, $fb_version, $fb_version_str;

if(isset($fb_version)) return $fb_version;

if($se = ibase_service_attach($host ? $host : "localhost", $user, $password)) {
$fb_version_str = ibase_server_info($se, IBASE_SVC_SERVER_VERSION);
if($fb_version_str === false)die("skip cannot ibase_server_info()");
$server_version = explode(" ", $fb_version_str);
$vers = (float)$server_version[count($server_version) - 1];
return $fb_version = $vers;
} else {
die("skip: cannot connect");
}
}

register_shutdown_function('cleanup_db');
init_db();
34 changes: 34 additions & 0 deletions tests/issue35_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Issue #35: ibase_prepare() fails to find table with SQL that has double quotes on table identifiers
--SKIPIF--
<?php
include("skipif.inc");
?>
--FILE--
<?php

require("interbase.inc");

$db = ibase_connect($test_base);

function test35() {
ibase_query('CREATE TABLE "test" (ID INTEGER, CLIENT_NAME VARCHAR(10))');
ibase_commit();
$p = ibase_prepare('INSERT INTO "test" (ID, CLIENT_NAME) VALUES (?, ?)');
ibase_execute($p, 1, "Some name");
$q = ibase_query('SELECT * FROM "test"');
while($r = ibase_fetch_object($q)){
var_dump($r);
}
}

test35();

?>
--EXPECTF--
object(stdClass)#1 (2) {
["ID"]=>
int(1)
["CLIENT_NAME"]=>
string(9) "Some name"
}
2 changes: 1 addition & 1 deletion tests/skipif-php8-or-newer.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

if (PHP_MAJOR_VERSION >= 8) {
die('skip: This test verifies behavior that can only be observed in PHP versions < 8.0');
}
?>
3 changes: 1 addition & 2 deletions tests/skipif.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
if (!extension_loaded("interbase")) print "skip interbase extension not available";
require("interbase.inc");
if(!@ibase_connect($test_base)){
die("skip cannot connect");
die("skip: cannot connect");
}
?>