diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/interbase/tests | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/interbase/tests')
24 files changed, 1826 insertions, 0 deletions
diff --git a/ext/interbase/tests/002.phpt b/ext/interbase/tests/002.phpt new file mode 100644 index 0000000..070a6f0 --- /dev/null +++ b/ext/interbase/tests/002.phpt @@ -0,0 +1,33 @@ +--TEST-- +InterBase: connect, close and pconnect +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php /* $Id$ */ + + require("interbase.inc"); + + ibase_connect($test_base); + out_table("test1"); + ibase_close(); + + $con = ibase_connect($test_base); + $pcon1 = ibase_pconnect($test_base); + $pcon2 = ibase_pconnect($test_base); + ibase_close($con); + unset($con); + ibase_close($pcon1); + unset($pcon1); + + out_table("test1"); + + ibase_close($pcon2); + unset($pcon2); +?> +--EXPECT-- +--- test1 --- +1 test table not created with isql +--- +--- test1 --- +1 test table not created with isql +--- diff --git a/ext/interbase/tests/003.phpt b/ext/interbase/tests/003.phpt new file mode 100644 index 0000000..652e3bd --- /dev/null +++ b/ext/interbase/tests/003.phpt @@ -0,0 +1,183 @@ +--TEST-- +InterBase: misc sql types (may take a while) +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php /* $Id$ */ + + require("interbase.inc"); + ibase_connect($test_base); + + ibase_query( + "create table test3 ( + iter integer not null, + v_char char(1000), + v_date timestamp, + v_decimal4_2 decimal(4,2), + v_decimal4_0 decimal(4,0), + v_decimal7_2 decimal(7,2), + v_decimal7_0 decimal(7,0), + v_numeric15_15 numeric(15,15), + v_numeric15_0 numeric(15,0), + v_double double precision, + v_float float, + v_integer integer, + v_smallint smallint, + v_varchar varchar(10000) + )"); + ibase_commit(); + + /* should fail, but gracefully */ + @ibase_query("insert into test3 (iter) values (?)", null); + + /* if timefmt is not supported, suppress error here */ + ini_set('ibase.timestampformat',"%m/%d/%Y %H:%M:%S"); + + for($iter = 0; $iter < 10; $iter++){ + /* prepare data */ + $v_char = rand_str(1000); + $v_date = rand_datetime(); + $v_decimal4_2 = rand_number(4,2); + $v_decimal4_0 = rand_number(4,0); + $v_decimal7_2 = rand_number(7,2); + $v_decimal7_0 = rand_number(7,0); + $v_numeric15_15 = rand_number(15,15); + $v_numeric15_0 = $iter ? rand_number(15,0) : 0; + $v_double = rand_number(18); + $v_float = rand_number(7); + $v_integer = rand_number(9,0); + $v_smallint = rand_number(5) % 32767; + $v_varchar = rand_str(10000); + + ibase_query( + "insert into test3 (iter, v_char,v_date,v_decimal4_2, v_decimal4_0, v_decimal7_2, v_decimal7_0,v_numeric15_15, v_numeric15_0,v_double,v_float,v_integer,v_smallint,v_varchar) + values ($iter, '$v_char','$v_date',$v_decimal4_2, $v_decimal4_0, $v_decimal7_2, $v_decimal7_0,$v_numeric15_15, $v_numeric15_0,$v_double,$v_float,$v_integer,$v_smallint,'$v_varchar')"); + $sel = ibase_query("select * from test3 where iter = $iter"); + $row = ibase_fetch_object($sel); + if(substr($row->V_CHAR,0,strlen($v_char)) != $v_char){ + echo " CHAR fail:\n"; + echo " in: $v_char\n"; + echo " out: $row->V_CHAR\n"; + } + if($row->V_DATE != $v_date){ + echo " DATE fail\n"; + echo " in: $v_date\n"; + echo " out: $row->V_DATE\n"; + } + if($row->V_DECIMAL4_2 != $v_decimal4_2){ + echo " DECIMAL4_2 fail\n"; + echo " in: $v_decimal4_2\n"; + echo " out: $row->V_DECIMAL4_2\n"; + } + if($row->V_DECIMAL4_0 != $v_decimal4_0){ + echo " DECIMAL4_0 fail\n"; + echo " in: $v_decimal4_0\n"; + echo " out: $row->V_DECIMAL4_0\n"; + } + if($row->V_DECIMAL7_2 != $v_decimal7_2){ + echo " DECIMAL7_2 fail\n"; + echo " in: $v_decimal7_2\n"; + echo " out: $row->V_DECIMAL7_2\n"; + } + if($row->V_DECIMAL7_0 != $v_decimal7_0){ + echo " DECIMAL7_0 fail\n"; + echo " in: $v_decimal7_0\n"; + echo " out: $row->V_DECIMAL7_0\n"; + } + if($row->V_NUMERIC15_15 != $v_numeric15_15){ + echo " NUMERIC15_15 fail\n"; + echo " in: $v_numeric15_15\n"; + echo " out: $row->V_NUMERIC15_15\n"; + } + if($row->V_NUMERIC15_0 != (string)$v_numeric15_0){ + echo " NUMERIC15_0 fail\n"; + echo " in: $v_numeric15_0\n"; + echo " out: $row->V_NUMERIC15_0\n"; + } + + if(abs($row->V_DOUBLE - $v_double) > abs($v_double / 1E15)){ + echo " DOUBLE fail\n"; + echo " in: $v_double\n"; + echo " out: $row->V_DOUBLE\n"; + } + if(abs($row->V_FLOAT - $v_float) > abs($v_float / 1E7)){ + echo " FLOAT fail\n"; + echo " in: $v_float\n"; + echo " out: $row->V_FLOAT\n"; + } + if($row->V_INTEGER != $v_integer){ + echo " INTEGER fail\n"; + echo " in: $v_integer\n"; + echo " out: $row->V_INTEGER\n"; + } + if($row->V_SMALLINT != $v_smallint){ + echo " SMALLINT fail\n"; + echo " in: $v_smallint\n"; + echo " out: $row->V_SMALLINT\n"; + } + + if(substr($row->V_VARCHAR,0,strlen($v_varchar)) != $v_varchar){ + echo " VARCHAR fail:\n"; + echo " in: $v_varchar\n"; + echo " out: $row->V_VARCHAR\n"; + } + + ibase_free_result($sel); + } /* for($iter) */ + + /* check for correct handling of duplicate field names */ + $q = ibase_query('SELECT 1 AS id, 2 AS id, 3 AS id, 4 AS id, 5 AS id, 6 AS id, 7 AS id, 8 AS id, 9 AS id, + 10 AS id, 11 AS id, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 FROM rdb$database'); + var_dump(ibase_fetch_assoc($q)); + + ibase_close(); + echo "end of test\n"; +?> +--EXPECT-- +array(22) { + ["ID"]=> + int(1) + ["ID_01"]=> + int(2) + ["ID_02"]=> + int(3) + ["ID_03"]=> + int(4) + ["ID_04"]=> + int(5) + ["ID_05"]=> + int(6) + ["ID_06"]=> + int(7) + ["ID_07"]=> + int(8) + ["ID_08"]=> + int(9) + ["ID_09"]=> + int(10) + ["ID_10"]=> + int(11) + ["CONSTANT"]=> + int(12) + ["CONSTANT_01"]=> + int(13) + ["CONSTANT_02"]=> + int(14) + ["CONSTANT_03"]=> + int(15) + ["CONSTANT_04"]=> + int(16) + ["CONSTANT_05"]=> + int(17) + ["CONSTANT_06"]=> + int(18) + ["CONSTANT_07"]=> + int(19) + ["CONSTANT_08"]=> + int(20) + ["CONSTANT_09"]=> + int(21) + ["CONSTANT_10"]=> + int(22) +} +end of test diff --git a/ext/interbase/tests/004.phpt b/ext/interbase/tests/004.phpt new file mode 100644 index 0000000..579445d --- /dev/null +++ b/ext/interbase/tests/004.phpt @@ -0,0 +1,182 @@ +--TEST-- +InterBase: BLOB test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php /* $Id$ */ + + require("interbase.inc"); + + $link = ibase_connect($test_base); + + ibase_query( + "CREATE TABLE test4 ( + v_integer integer, + v_blob blob)"); + ibase_commit(); + + /* create 100k blob file */ + $blob_str = rand_binstr(100*1024); + + $name = tempnam(dirname(__FILE__),"blob.tmp"); + $ftmp = fopen($name,"w"); + fwrite($ftmp,$blob_str); + fclose($ftmp); + + echo "import blob 1\n"; + $ftmp = fopen($name,"r"); + $bl_s = ibase_blob_import($ftmp); + ibase_query("INSERT INTO test4 (v_integer, v_blob) VALUES (1, ?)", $bl_s); + + $bl_s = ibase_blob_import($link,$ftmp); + ibase_query($link, "INSERT INTO test4 (v_integer, v_blob) VALUES (1, ?)", $bl_s); + fclose($ftmp); + + echo "test blob 1\n"; + $q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 1"); + + $row = ibase_fetch_object($q); + $bl_h = ibase_blob_open($row->V_BLOB); + + $blob = ''; + while($piece = ibase_blob_get($bl_h, 1 + rand() % 1024)) + $blob .= $piece; + if($blob != $blob_str) + echo " BLOB 1 fail (1)\n"; + ibase_blob_close($bl_h); + + $bl_h = ibase_blob_open($link,$row->V_BLOB); + + $blob = ''; + while($piece = ibase_blob_get($bl_h, 100 * 1024)) + $blob .= $piece; + if($blob != $blob_str) + echo " BLOB 1 fail (2)\n"; + ibase_blob_close($bl_h); + ibase_free_result($q); + unset($blob); + + echo "create blob 2\n"; + + ibase_query("INSERT INTO test4 (v_integer, v_blob) VALUES (2, ?)", $blob_str); + + echo "test blob 2\n"; + + $q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 2"); + $row = ibase_fetch_object($q,IBASE_TEXT); + + if($row->V_BLOB != $blob_str) + echo " BLOB 2 fail\n"; + ibase_free_result($q); + unset($blob); + + + echo "create blob 3\n"; + + $bl_h = ibase_blob_create($link); + + ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n"); + ibase_blob_add($bl_h, "| PHP HTML Embedded Scripting Language Version 3.0 |\n"); + ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n"); + ibase_blob_add($bl_h, "| Copyright (c) 1997-2000 PHP Development Team (See Credits file) |\n"); + ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n"); + ibase_blob_add($bl_h, "| This program is free software; you can redistribute it and/or modify |\n"); + ibase_blob_add($bl_h, "| it under the terms of one of the following licenses: |\n"); + ibase_blob_add($bl_h, "| |\n"); + ibase_blob_add($bl_h, "| A) the GNU General Public License as published by the Free Software |\n"); + ibase_blob_add($bl_h, "| Foundation; either version 2 of the License, or (at your option) |\n"); + ibase_blob_add($bl_h, "| any later version. |\n"); + ibase_blob_add($bl_h, "| |\n"); + ibase_blob_add($bl_h, "| B) the PHP License as published by the PHP Development Team and |\n"); + ibase_blob_add($bl_h, "| included in the distribution in the file: LICENSE |\n"); + ibase_blob_add($bl_h, "| |\n"); + ibase_blob_add($bl_h, "| This program is distributed in the hope that it will be useful, |\n"); + ibase_blob_add($bl_h, "| but WITHOUT ANY WARRANTY; without even the implied warranty of |\n"); + ibase_blob_add($bl_h, "| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |\n"); + ibase_blob_add($bl_h, "| GNU General Public License for more details. |\n"); + ibase_blob_add($bl_h, "| |\n"); + ibase_blob_add($bl_h, "| You should have received a copy of both licenses referred to here. |\n"); + ibase_blob_add($bl_h, "| If you did not, or have any questions about PHP licensing, please |\n"); + ibase_blob_add($bl_h, "| contact core@php.net. |\n"); + ibase_blob_add($bl_h, "+----------------------------------------------------------------------+\n"); + $bl_s = ibase_blob_close($bl_h); + ibase_query("INSERT INTO test4 (v_integer, v_blob) VALUES (3, ?)", $bl_s); + ibase_commit(); + echo "echo blob 3\n"; + + $q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 3"); + $row = ibase_fetch_object($q); + ibase_commit(); + ibase_close(); + + ibase_connect($test_base); + ibase_blob_echo($link, $row->V_BLOB); + ibase_free_result($q); + + echo "fetch blob 3\n"; + $q = ibase_query("SELECT v_blob FROM test4 WHERE v_integer = 3"); + $row = ibase_fetch_object($q,IBASE_TEXT); + echo $row->V_BLOB; + ibase_free_result($q); + + ibase_close(); + unlink($name); + echo "end of test\n"; +?> +--EXPECT-- +import blob 1 +test blob 1 +create blob 2 +test blob 2 +create blob 3 +echo blob 3 ++----------------------------------------------------------------------+ +| PHP HTML Embedded Scripting Language Version 3.0 | ++----------------------------------------------------------------------+ +| Copyright (c) 1997-2000 PHP Development Team (See Credits file) | ++----------------------------------------------------------------------+ +| This program is free software; you can redistribute it and/or modify | +| it under the terms of one of the following licenses: | +| | +| A) the GNU General Public License as published by the Free Software | +| Foundation; either version 2 of the License, or (at your option) | +| any later version. | +| | +| B) the PHP License as published by the PHP Development Team and | +| included in the distribution in the file: LICENSE | +| | +| This program is distributed in the hope that it will be useful, | +| but WITHOUT ANY WARRANTY; without even the implied warranty of | +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | +| GNU General Public License for more details. | +| | +| You should have received a copy of both licenses referred to here. | +| If you did not, or have any questions about PHP licensing, please | +| contact core@php.net. | ++----------------------------------------------------------------------+ +fetch blob 3 ++----------------------------------------------------------------------+ +| PHP HTML Embedded Scripting Language Version 3.0 | ++----------------------------------------------------------------------+ +| Copyright (c) 1997-2000 PHP Development Team (See Credits file) | ++----------------------------------------------------------------------+ +| This program is free software; you can redistribute it and/or modify | +| it under the terms of one of the following licenses: | +| | +| A) the GNU General Public License as published by the Free Software | +| Foundation; either version 2 of the License, or (at your option) | +| any later version. | +| | +| B) the PHP License as published by the PHP Development Team and | +| included in the distribution in the file: LICENSE | +| | +| This program is distributed in the hope that it will be useful, | +| but WITHOUT ANY WARRANTY; without even the implied warranty of | +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | +| GNU General Public License for more details. | +| | +| You should have received a copy of both licenses referred to here. | +| If you did not, or have any questions about PHP licensing, please | +| contact core@php.net. | ++----------------------------------------------------------------------+ +end of test diff --git a/ext/interbase/tests/005.phpt b/ext/interbase/tests/005.phpt new file mode 100644 index 0000000..5b16ac2 --- /dev/null +++ b/ext/interbase/tests/005.phpt @@ -0,0 +1,290 @@ +--TEST-- +InterBase: transactions +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php /* $Id$ */ + + require("interbase.inc"); + + ibase_connect($test_base); + + @ibase_query("create table test5 (i integer)"); + @ibase_query("delete from test5"); + ibase_close(); + + + echo "default transaction:\n"; + +/* +Difference between default and other transactions: +default commited when you call ibase_close(). +Other transaction doing rollback. + +If you not open default transaction with +ibase_trans, default transaction open +when you call ibase_query(), ibase_prepare(), +ibase_blob_create(), ibase_blob_import() first time. +*/ + +/* +simple default transaction test without ibase_trans() +*/ + + ibase_connect($test_base); + + echo "empty table\n"; + + /* out_table call ibase_query() + and ibase_query() start default transaction */ + out_table("test5"); + + /* in default transaction context */ + ibase_query("insert into test5 (i) values (1)"); + + echo "one row\n"; + out_table("test5"); + + ibase_rollback(); /* default rolled */ + + echo "after rollback table empty again\n"; + out_table("test5"); /* started new default transaction */ + + ibase_query("insert into test5 (i) values (2)"); + + ibase_close(); /* commit here! */ + + ibase_connect($test_base); + + echo "one row\n"; + out_table("test5"); + ibase_close(); + +/* +default transaction on default link +First open transaction on link will be default. +$tr_def_l1 may be ommited. All queryes without link and trans +parameters run in this context +*/ + + $link_def = ibase_connect($test_base); + + $tr_def_l1 = ibase_trans(IBASE_READ); /* here transaction start */ + + /* all default */ + $res = ibase_query("select * from test5"); + + echo "one row\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + /* specify transaction context... */ + $res = ibase_query($tr_def_l1, "select * from test5"); + + echo "one row... again.\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + /* specify default transaction on link */ + $res = ibase_query($link_def, "select * from test5"); + + echo "one row.\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + ibase_rollback($link_def); /* just for example */ + + ibase_close(); + +/* +three transaction on default link +*/ + ibase_connect($test_base); + + $res = ibase_query("select * from test5"); + + echo "one row\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + $tr_1 = ibase_query("SET TRANSACTION"); + $tr_2 = ibase_query("SET TRANSACTION READ ONLY"); + $tr_3 = ibase_trans(IBASE_READ+IBASE_COMMITTED+IBASE_REC_VERSION+IBASE_WAIT); + $tr_4 = ibase_trans(IBASE_READ+IBASE_COMMITTED+IBASE_REC_NO_VERSION+IBASE_NOWAIT); + + /* insert in first transaction context... */ + /* as default */ + ibase_query("insert into test5 (i) values (3)"); + /* specify context */ + ibase_query($tr_1, "insert into test5 (i) values (4)"); + + $res = ibase_query("select * from test5"); + + echo "two rows\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + $res = ibase_query($tr_1, "select * from test5"); + + echo "two rows again\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + ibase_commit(); + ibase_commit($tr_1); + + $tr_1 = ibase_trans(); + ibase_query($tr_1, "insert into test5 (i) values (5)"); + + /* tr_2 is IBASE_READ + IBASE_CONCURRENCY + IBASE_WAIT */ + $res = ibase_query($tr_2, "select * from test5"); + + echo "one row in second transaction\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + /* tr_3 is IBASE_COMMITTED + IBASE_REC_VERSION + IBASE_WAIT */ + $res = ibase_query($tr_3, "select * from test5"); + + echo "three rows in third transaction\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + /* tr_4 IBASE_COMMITED + IBASE_REC_NO_VERSION + IBASE_NOWAIT */ + $res = ibase_query($tr_4, "select * from test5"); + + echo "three rows in fourth transaction with deadlock\n"; + out_result_trap_error($res,"test5"); + + ibase_free_result($res); + + ibase_rollback($tr_1); + ibase_close(); +/* +transactions on second link +*/ + $link_1 = ibase_pconnect($test_base); + $link_2 = ibase_pconnect($test_base); + + $tr_1 = ibase_trans(IBASE_DEFAULT, $link_2); /* this default transaction also */ + $tr_2 = ibase_trans(IBASE_COMMITTED, $link_2); + + $res = ibase_query($tr_1, "select * from test5"); + + echo "three rows\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + ibase_query($tr_1, "insert into test5 (i) values (5)"); + + $res = ibase_query($tr_1, "select * from test5"); + + echo "four rows\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + ibase_commit($tr_1); + + $res = ibase_query($tr_2, "select * from test5"); + + echo "four rows again\n"; + out_result($res,"test5"); + + ibase_free_result($res); + + ibase_close($link_1); + ibase_close($link_2); + + echo "end of test\n"; +?> +--EXPECT-- +default transaction: +empty table +--- test5 --- +--- +one row +--- test5 --- +1 +--- +after rollback table empty again +--- test5 --- +--- +one row +--- test5 --- +2 +--- +one row +--- test5 --- +2 +--- +one row... again. +--- test5 --- +2 +--- +one row. +--- test5 --- +2 +--- +one row +--- test5 --- +2 +--- +two rows +--- test5 --- +2 +3 +--- +two rows again +--- test5 --- +2 +4 +--- +one row in second transaction +--- test5 --- +2 +--- +three rows in third transaction +--- test5 --- +2 +3 +4 +--- +three rows in fourth transaction with deadlock +--- test5 --- +2 +3 +4 +errmsg [lock conflict on no wait transaction deadlock ] +--- +three rows +--- test5 --- +2 +3 +4 +--- +four rows +--- test5 --- +2 +3 +4 +5 +--- +four rows again +--- test5 --- +2 +3 +4 +5 +--- +end of test + diff --git a/ext/interbase/tests/006.phpt b/ext/interbase/tests/006.phpt new file mode 100644 index 0000000..ad6120f --- /dev/null +++ b/ext/interbase/tests/006.phpt @@ -0,0 +1,301 @@ +--TEST-- +InterBase: binding (may take a while) +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php /* $Id$ */ + + require("interbase.inc"); + + ibase_connect($test_base); + + ibase_query( + "create table test6 ( + iter integer, + v_char char(1000), + v_date timestamp, + v_decimal decimal(12,3), + v_double double precision, + v_float float, + v_integer integer, + v_numeric numeric(4,2), + v_smallint smallint, + v_varchar varchar(10000) + )"); + ibase_query( + "create procedure add1 (arg integer) + returns (result integer) + as + begin + result = arg +1; + end"); + ibase_commit(); + + /* if timefmt not supported, hide error */ + ini_set('ibase.timestampformat',"%m/%d/%Y %H:%M:%S"); + + echo "insert\n"; + + for($iter = 0; $iter < 3; $iter++) { + /* prepare data */ + $v_char = rand_str(1000); + $v_date = rand_datetime(); + $v_decimal = rand_number(12,3); + $v_double = rand_number(20); + $v_float = rand_number(7); + $v_integer = rand_number(9,0); + $v_numeric = rand_number(4,2); + $v_smallint = rand_number(5) % 32767; + $v_varchar = rand_str(10000); + + ibase_query("insert into test6 + (iter,v_char,v_date,v_decimal,v_double,v_float, + v_integer,v_numeric,v_smallint,v_varchar) + values (?,?,?,?,?,?,?,?,?,?)", + $iter, $v_char, $v_date, $v_decimal, $v_double, $v_float, + $v_integer, $v_numeric, $v_smallint, $v_varchar); + $sel = ibase_query("select * from test6 where iter = ?", $iter); + + $row = ibase_fetch_object($sel); + if(substr($row->V_CHAR,0,strlen($v_char)) != $v_char) { + echo " CHAR fail:\n"; + echo " in: $v_char\n"; + echo " out: $row->V_CHAR\n"; + } + if($row->V_DATE != $v_date) { + echo " DATE fail\n"; + echo " in: $v_date\n"; + echo " out: $row->V_DATE\n"; + } + if($row->V_DECIMAL != $v_decimal) { + echo " DECIMAL fail\n"; + echo " in: $v_decimal\n"; + echo " out: $row->V_DECIMAL\n"; + } + if(abs($row->V_DOUBLE - $v_double) > abs($v_double / 1E15)) { + echo " DOUBLE fail\n"; + echo " in: $v_double\n"; + echo " out: $row->V_DOUBLE\n"; + } + if(abs($row->V_FLOAT - $v_float) > abs($v_float / 1E7)) { + echo " FLOAT fail\n"; + echo " in: $v_float\n"; + echo " out: $row->V_FLOAT\n"; + } + if($row->V_INTEGER != $v_integer) { + echo " INTEGER fail\n"; + echo " in: $v_integer\n"; + echo " out: $row->V_INTEGER\n"; + } + if ($row->V_NUMERIC != $v_numeric) { + echo " NUMERIC fail\n"; + echo " in: $v_numeric\n"; + echo " out: $row->V_NUMERIC\n"; + } + if ($row->V_SMALLINT != $v_smallint) { + echo " SMALLINT fail\n"; + echo " in: $v_smallint\n"; + echo " out: $row->V_SMALLINT\n"; + } + if ($row->V_VARCHAR != $v_varchar) { + echo " VARCHAR fail:\n"; + echo " in: $v_varchar\n"; + echo " out: $row->V_VARCHAR\n"; + } + ibase_free_result($sel); + }/* for($iter)*/ + + echo "select\n"; + for($iter = 0; $iter < 3; $iter++) { + /* prepare data */ + $v_char = rand_str(1000); + $v_date = (int)rand_number(10,0,0); + $v_decimal = rand_number(12,3); + $v_double = rand_number(20); + $v_float = rand_number(7); + $v_integer = rand_number(9,0); + $v_numeric = rand_number(4,2); + $v_smallint = rand_number(5) % 32767; + $v_varchar = rand_str(10000); + + /* clear table*/ + ibase_query("delete from test6"); + + /* make one record */ + ibase_query("insert into test6 + (iter, v_char,v_date,v_decimal, + v_integer,v_numeric,v_smallint,v_varchar) + values (666, '$v_char',?,$v_decimal, $v_integer, + $v_numeric, $v_smallint, '$v_varchar')",$v_date); + + /* test all types */ + if(!($sel = ibase_query( + "select iter from test6 where v_char = ?", $v_char)) || + !ibase_fetch_row($sel)) { + echo "CHAR fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test6 where v_date = ?", $v_date)) || + !ibase_fetch_row($sel)) { + echo "DATE fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test6 where v_decimal = ?", $v_decimal)) || + !ibase_fetch_row($sel)) { + echo "DECIMAL fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test6 where v_integer = ?", $v_integer)) || + !ibase_fetch_row($sel)) { + echo "INTEGER fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test6 where v_numeric = ?", $v_numeric)) || + !ibase_fetch_row($sel)) { + echo "NUMERIC fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test6 where v_smallint = ?", $v_smallint)) || + !ibase_fetch_row($sel)) { + echo "SMALLINT fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test6 where v_varchar = ?", $v_varchar)) || + !ibase_fetch_row($sel)) { + echo "VARCHAR fail\n"; + } + ibase_free_result($sel); + + } /*for iter*/ + + echo "prepare and exec insert\n"; + + /* prepare table */ + ibase_query("delete from test6"); + + /* prepare query */ + $query = ibase_prepare( + "insert into test6 (v_integer) values (?)"); + + for($i = 0; $i < 10; $i++) { + ibase_execute($query, $i); + } + + out_table("test6"); + + ibase_free_query($query); + + echo "prepare and exec select\n"; + + /* prepare query */ + $query = ibase_prepare("select * from test6 + where v_integer between ? and ?"); + + $low_border = 2; + $high_border = 6; + + $res = ibase_execute($query, $low_border, $high_border); + out_result($res, "test6"); + ibase_free_result($res); + + $low_border = 0; + $high_border = 4; + $res = ibase_execute($query, $low_border, $high_border); + out_result($res, "test6"); + ibase_free_result($res); + + $res = ibase_execute($query, "5", 7.499); + out_result($res, "test6"); + ibase_free_result($res); + + ibase_free_query($query); + + /* test execute procedure */ + $query = ibase_prepare("execute procedure add1(?)"); + $res = array(); + for ($i = 0; $i < 10; $i++) { + $res[] = ibase_execute($query,$i); + } + ibase_free_query($query); + foreach ($res as $r) { + out_result($r, "proc add1"); + ibase_free_result($r); + } + + ibase_close(); + echo "end of test\n"; +?> +--EXPECT-- +insert +select +prepare and exec insert +--- test6 --- + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +--- +prepare and exec select +--- test6 --- + 2 + 3 + 4 + 5 + 6 +--- +--- test6 --- + 0 + 1 + 2 + 3 + 4 +--- +--- test6 --- + 5 + 6 + 7 +--- +--- proc add1 --- +1 +--- +--- proc add1 --- +2 +--- +--- proc add1 --- +3 +--- +--- proc add1 --- +4 +--- +--- proc add1 --- +5 +--- +--- proc add1 --- +6 +--- +--- proc add1 --- +7 +--- +--- proc add1 --- +8 +--- +--- proc add1 --- +9 +--- +--- proc add1 --- +10 +--- +end of test + diff --git a/ext/interbase/tests/007.phpt b/ext/interbase/tests/007.phpt new file mode 100644 index 0000000..069b7ed --- /dev/null +++ b/ext/interbase/tests/007.phpt @@ -0,0 +1,183 @@ +--TEST-- +InterBase: array handling +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php /* $Id$ */ + + require("interbase.inc"); + + ibase_connect($test_base); + + ibase_query( + "create table test7 ( + iter integer, + v_multi integer[10,10,10], + v_char char(100)[10], + v_date timestamp[10], + v_decimal decimal(18,3)[10], + v_double double precision[10], + v_float float[10], + v_integer integer[10], + v_numeric numeric(9,2)[10], + v_smallint smallint[10], + v_varchar varchar(1000)[10] + )"); + ibase_commit(); + + /* if timefmt not supported, hide error */ + ini_set('ibase.timestampformat',"%m/%d/%Y %H:%M:%S"); + + echo "insert\n"; + + for ($i = 1; $i <= 10; ++$i) { + for ($j = 1; $j <= 10; ++$j) { + for ($k = 1; $k <= 10; ++$k) { + $v_multi[$i][$j][$k] = $i * $j * $k; + } + } + } + + for($iter = 0; $iter < 3; $iter++) { + + /* prepare data */ + $v_char = array(); + $v_date = array(); + $v_decimal = array(); + $v_double = array(); + $v_float = array(); + $v_integer = array(); + $v_numeric = array(); + $v_smallint = array(); + $v_varchar = array(); + + for ($i = 1; $i <= 10; ++$i) { + $v_char[$i] = rand_str(100); + $v_date[$i] = rand_datetime(); + $v_decimal[$i] = rand_number(18,3); + $v_double[$i] = rand_number(20); + $v_float[$i] = rand_number(7); + $v_integer[$i] = rand_number(9,0); + $v_numeric[$i] = rand_number(9,2); + $v_smallint[$i] = rand_number(5) % 32767; + $v_varchar[$i] = rand_str(1000); + } + + ibase_query("insert into test7 + (iter,v_multi,v_char,v_date,v_decimal,v_double,v_float, + v_integer,v_numeric,v_smallint,v_varchar) + values (?,?,?,?,?,?,?,?,?,?,?)", + $iter, $v_multi, $v_char, $v_date, $v_decimal, $v_double, $v_float, + $v_integer, $v_numeric, $v_smallint, $v_varchar); + $sel = ibase_query("select * from test7 where iter = $iter"); + + $row = ibase_fetch_object($sel,IBASE_FETCH_ARRAYS); + for ($i = 1; $i <= 10; ++$i) { + + if(strncmp($row->V_CHAR[$i],$v_char[$i],strlen($v_char[$i])) != 0) { + echo " CHAR[$i] fail:\n"; + echo " in: ".$v_char[$i]."\n"; + echo " out: ".$row->V_CHAR[$i]."\n"; + } + if($row->V_DATE[$i] != $v_date[$i]) { + echo " DATE[$i] fail\n"; + echo " in: ".$v_date[$i]."\n"; + echo " out: ".$row->V_DATE[$i]."\n"; + } + if($row->V_DECIMAL[$i] != $v_decimal[$i]) { + echo " DECIMAL[$i] fail\n"; + echo " in: ".$v_decimal[$i]."\n"; + echo " out: ".$row->V_DECIMAL[$i]."\n"; + } + if(abs($row->V_DOUBLE[$i] - $v_double[$i]) > abs($v_double[$i] / 1E15)) { + echo " DOUBLE[$i] fail\n"; + echo " in: ".$v_double[$i]."\n"; + echo " out: ".$row->V_DOUBLE[$i]."\n"; + } + if(abs($row->V_FLOAT[$i] - $v_float[$i]) > abs($v_float[$i] / 1E7)) { + echo " FLOAT[$i] fail\n"; + echo " in: ".$v_float[$i]."\n"; + echo " out: ".$row->V_FLOAT[$i]."\n"; + } + if($row->V_INTEGER[$i] != $v_integer[$i]) { + echo " INTEGER[$i] fail\n"; + echo " in: ".$v_integer[$i]."\n"; + echo " out: ".$row->V_INTEGER[$i]."\n"; + } + if ($row->V_NUMERIC[$i] != $v_numeric[$i]) { + echo " NUMERIC[$i] fail\n"; + echo " in: ".$v_numeric[$i]."\n"; + echo " out: ".$row->V_NUMERIC[$i]."\n"; + } + if ($row->V_SMALLINT[$i] != $v_smallint[$i]) { + echo " SMALLINT[$i] fail\n"; + echo " in: ".$v_smallint[$i]."\n"; + echo " out: ".$row->V_SMALLINT[$i]."\n"; + } + if ($row->V_VARCHAR[$i] != $v_varchar[$i]) { + echo " VARCHAR[$i] fail:\n"; + echo " in: ".$v_varchar[$i]."\n"; + echo " out: ".$row->V_VARCHAR[$i]."\n"; + } + } + ibase_free_result($sel); + }/* for($iter) */ + + echo "select\n"; + + $sel = ibase_query("SELECT v_multi[5,5,5],v_multi[10,10,10] FROM test7 WHERE iter = 0"); + print_r(ibase_fetch_row($sel)); + ibase_free_result($sel); + + for($iter = 1; $iter <= 3; $iter++) { + + if(!($sel = ibase_query( + "select iter from test7 where v_char[$iter] LIKE ?", $v_char[$iter]."%")) || + !ibase_fetch_row($sel)) { + echo "CHAR fail\n"; + } + ibase_free_result($sel); + + if(!($sel = ibase_query( + "select iter from test7 where v_date[$iter] = ?", $v_date[$iter])) || + !ibase_fetch_row($sel)) { + echo "DATE fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test7 where v_decimal[$iter] = ?", $v_decimal[$iter])) || + !ibase_fetch_row($sel)) { + echo "DECIMAL fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test7 where v_integer[$iter] = ?", $v_integer[$iter])) || + !ibase_fetch_row($sel)) { + echo "INTEGER fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test7 where v_numeric[$iter] = ?", $v_numeric[$iter])) || + !ibase_fetch_row($sel)) { + echo "NUMERIC fail\n"; + } + ibase_free_result($sel); + if(!($sel = ibase_query( + "select iter from test7 where v_smallint[$iter] = ?", $v_smallint[$iter])) || + !ibase_fetch_row($sel)) { + echo "SMALLINT fail\n"; + } + ibase_free_result($sel); + } + ibase_close(); + echo "end of test\n"; +?> +--EXPECT-- +insert +select +Array +( + [0] => 125 + [1] => 1000 +) +end of test diff --git a/ext/interbase/tests/008.phpt b/ext/interbase/tests/008.phpt new file mode 100644 index 0000000..8292fc3 --- /dev/null +++ b/ext/interbase/tests/008.phpt @@ -0,0 +1,48 @@ +--TEST-- +InterBase: event handling +--SKIPIF-- +<?php +if (PHP_OS == "WINNT") echo "skip"; +include("skipif.inc"); +?> +--FILE-- +<?php /* $Id$ */ + +require("interbase.inc"); + +$count = 0; + +function event_callback($event) +{ + global $count; + if ($event == 'TEST1') echo "FAIL TEST1\n"; + return (++$count < 5); /* cancel event */ +} + +$link = ibase_connect($test_base); + +ibase_query("CREATE PROCEDURE pevent AS BEGIN POST_EVENT 'TEST1'; POST_EVENT 'TEST2'; END"); +ibase_commit(); + +$e = ibase_set_event_handler('event_callback','TEST1'); +ibase_free_event_handler($e); + +ibase_set_event_handler('event_callback','TEST2'); + +usleep(5E+5); + +for ($i = 0; $i < 8; ++$i) { + ibase_query("EXECUTE PROCEDURE pevent"); + ibase_commit(); + + usleep(3E+5); +} + +usleep(5E+5); + +if (!$count || $count > 5) echo "FAIL ($count)\n"; +echo "end of test\n"; + +?> +--EXPECT-- +end of test diff --git a/ext/interbase/tests/bug45373.phpt b/ext/interbase/tests/bug45373.phpt new file mode 100644 index 0000000..8b16ef0 --- /dev/null +++ b/ext/interbase/tests/bug45373.phpt @@ -0,0 +1,47 @@ +--TEST-- +Bug #45373 (php crash on query with errors in params) +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + + require("interbase.inc"); + + $db = ibase_connect($test_base); + + + $sql = "select * from test1 where i = ? and c = ?"; + + $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)); + +?> +--EXPECTF-- +array(2) { + ["I"]=> + int(1) + ["C"]=> + string(32) "test table not created with isql" +} + +Notice: ibase_execute(): Statement expects 2 arguments, 3 given in %s on line %d +array(2) { + ["I"]=> + int(1) + ["C"]=> + string(32) "test table not created with isql" +} + +Warning: ibase_execute(): Statement expects 2 arguments, 1 given in %s on line %d + +Warning: ibase_fetch_assoc() expects parameter 1 to be resource, boolean given in %s on line %d +NULL diff --git a/ext/interbase/tests/bug45575.phpt b/ext/interbase/tests/bug45575.phpt new file mode 100644 index 0000000..ca0fa83 --- /dev/null +++ b/ext/interbase/tests/bug45575.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #45575 (Segfault with invalid non-string as event handler callback) +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$db = ibase_connect($test_base); + +function foobar($var) { var_dump($var); return true; } + +ibase_set_event_handler($db, null, 'TEST1'); +ibase_set_event_handler($db, 1, 'TEST1'); +ibase_set_event_handler('foobar', 'TEST1'); + +?> +--EXPECTF-- +Warning: ibase_set_event_handler(): Callback argument is not a callable function in %s on line %d + +Warning: ibase_set_event_handler(): Callback argument 1 is not a callable function in %s on line %d diff --git a/ext/interbase/tests/bug46247.phpt b/ext/interbase/tests/bug46247.phpt new file mode 100644 index 0000000..ffd153b --- /dev/null +++ b/ext/interbase/tests/bug46247.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #46247 (ibase_set_event_handler() is allowing to pass callback without event) +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$db = ibase_connect($test_base); + +function test() { } + +ibase_set_event_handler(); + +ibase_set_event_handler('test', 1); +ibase_set_event_handler($db, 'test', 1); +ibase_set_event_handler(NULL, 'test', 1); + + +ibase_set_event_handler('foo', 1); +ibase_set_event_handler($db, 'foo', 1); +ibase_set_event_handler(NULL, 'foo', 1); + +?> +--EXPECTF-- + +Warning: Wrong parameter count for ibase_set_event_handler() in %s on line %d + +Warning: ibase_set_event_handler(): supplied argument is not a valid InterBase link resource in %s on line %d + +Warning: ibase_set_event_handler(): Callback argument foo is not a callable function in %s on line %d + +Warning: ibase_set_event_handler(): Callback argument foo is not a callable function in %s on line %d + +Warning: ibase_set_event_handler(): supplied argument is not a valid InterBase link resource in %s on line %d diff --git a/ext/interbase/tests/bug46543.phpt b/ext/interbase/tests/bug46543.phpt new file mode 100644 index 0000000..59e088c --- /dev/null +++ b/ext/interbase/tests/bug46543.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #46543 (ibase_trans() memory leaks when using wrong parameters) +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +@ibase_close(); + +ibase_trans(1); +ibase_trans(); +ibase_trans('foo'); +ibase_trans(fopen(__FILE__, 'r')); + +$x = ibase_connect($test_base); +ibase_trans(1, 2, $x, $x, 3); + +?> +--EXPECTF-- +Warning: ibase_trans(): no Firebird/InterBase link resource supplied in %s on line %d + +Warning: ibase_trans(): no Firebird/InterBase link resource supplied in %s on line %d + +Warning: ibase_trans(): no Firebird/InterBase link resource supplied in %s on line %d + +Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %s on line %d diff --git a/ext/interbase/tests/ibase_affected_rows_001.phpt b/ext/interbase/tests/ibase_affected_rows_001.phpt new file mode 100644 index 0000000..398a84c --- /dev/null +++ b/ext/interbase/tests/ibase_affected_rows_001.phpt @@ -0,0 +1,32 @@ +--TEST-- +ibase_affected_rows(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); + +ibase_query($x, 'INSERT INTO test1 VALUES (1, 100)'); +ibase_query($x, 'INSERT INTO test1 VALUES (10000, 100)'); + +ibase_query($x, 'UPDATE test1 SET i = 10000'); +var_dump(ibase_affected_rows($x)); + + +ibase_query($x, 'UPDATE test1 SET i = 10000 WHERE i = 2.0'); +var_dump(ibase_affected_rows($x)); + +ibase_query($x, 'UPDATE test1 SET i ='); +var_dump(ibase_affected_rows($x)); + + +?> +--EXPECTF-- +int(3) +int(0) + +Warning: ibase_query(): Dynamic SQL Error SQL error code = -104 %s on line %d +int(0) diff --git a/ext/interbase/tests/ibase_close_001.phpt b/ext/interbase/tests/ibase_close_001.phpt new file mode 100644 index 0000000..6e31916 --- /dev/null +++ b/ext/interbase/tests/ibase_close_001.phpt @@ -0,0 +1,25 @@ +--TEST-- +ibase_close(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); +var_dump(ibase_close($x)); +var_dump(ibase_close($x)); +var_dump(ibase_close()); +var_dump(ibase_close('foo')); + +?> +--EXPECTF-- +bool(true) +bool(true) + +Warning: ibase_close(): %d is not a valid Firebird/InterBase link resource in %s on line %d +bool(false) + +Warning: ibase_close() expects parameter 1 to be resource,%string given in %s on line %d +NULL diff --git a/ext/interbase/tests/ibase_drop_db_001.phpt b/ext/interbase/tests/ibase_drop_db_001.phpt new file mode 100644 index 0000000..7526e13 --- /dev/null +++ b/ext/interbase/tests/ibase_drop_db_001.phpt @@ -0,0 +1,31 @@ +--TEST-- +ibase_drop_db(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +unlink($file = tempnam('/tmp',"php_ibase_test")); + + +$db = ibase_query(IBASE_CREATE, + sprintf("CREATE SCHEMA '%s' USER '%s' PASSWORD '%s' DEFAULT CHARACTER SET %s",$file, + $user, $password, ($charset = ini_get('ibase.default_charset')) ? $charset : 'NONE')); + +var_dump($db); +var_dump(ibase_drop_db($db)); +var_dump(ibase_drop_db(1)); +var_dump(ibase_drop_db(NULL)); + +?> +--EXPECTF-- +resource(%d) of type (Firebird/InterBase link) +bool(true) + +Warning: ibase_drop_db() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +Warning: ibase_drop_db() expects parameter 1 to be resource, null given in %s on line %d +NULL diff --git a/ext/interbase/tests/ibase_errmsg_001.phpt b/ext/interbase/tests/ibase_errmsg_001.phpt new file mode 100644 index 0000000..ad0e827 --- /dev/null +++ b/ext/interbase/tests/ibase_errmsg_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +ibase_errmsg(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); + +ibase_query('SELECT Foobar'); +var_dump(ibase_errmsg()); + +ibase_close($x); +var_dump(ibase_errmsg()); + +?> +--EXPECTF-- +Warning: ibase_query(): Dynamic SQL Error SQL error code = -104 %s on line %d +string(%d) "Dynamic SQL Error SQL error code = -104 %s" +bool(false) diff --git a/ext/interbase/tests/ibase_free_query_001.phpt b/ext/interbase/tests/ibase_free_query_001.phpt new file mode 100644 index 0000000..bedec71 --- /dev/null +++ b/ext/interbase/tests/ibase_free_query_001.phpt @@ -0,0 +1,28 @@ +--TEST-- +ibase_free_query(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); + +$q =ibase_prepare($x, 'SELECT 1 FROM test1 WHERE i = ?'); +$q =ibase_prepare($x, 'SELECT 1 FROM test1 WHERE i = ?'); +$q = ibase_prepare($x, 'SELECT 1 FROM test1 WHERE i = ?'); + +var_dump(ibase_free_query($q)); +var_dump(ibase_free_query($q)); +var_dump(ibase_free_query($x)); + +?> +--EXPECTF-- +bool(true) + +Warning: ibase_free_query(): 11 is not a valid Firebird/InterBase query resource in %s on line %d +bool(false) + +Warning: ibase_free_query(): supplied resource is not a valid Firebird/InterBase query resource in %s on line %d +bool(false) diff --git a/ext/interbase/tests/ibase_num_fields_001.phpt b/ext/interbase/tests/ibase_num_fields_001.phpt new file mode 100644 index 0000000..f1e0e4a --- /dev/null +++ b/ext/interbase/tests/ibase_num_fields_001.phpt @@ -0,0 +1,25 @@ +--TEST-- +ibase_num_fields(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); + +var_dump(ibase_num_fields(ibase_query('SELECT * FROM test1'))); + +var_dump(ibase_num_fields(1)); +var_dump(ibase_num_fields()); + +?> +--EXPECTF-- +int(2) + +Warning: ibase_num_fields() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +Warning: ibase_num_fields() expects exactly 1 parameter, 0 given in %s on line %d +NULL diff --git a/ext/interbase/tests/ibase_num_params_001.phpt b/ext/interbase/tests/ibase_num_params_001.phpt new file mode 100644 index 0000000..655cae1 --- /dev/null +++ b/ext/interbase/tests/ibase_num_params_001.phpt @@ -0,0 +1,32 @@ +--TEST-- +ibase_num_params(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); + +$rs = ibase_prepare('SELECT * FROM test1 WHERE 1 = ? AND 2 = ?'); +var_dump(ibase_num_params($rs)); + +$rs = ibase_prepare('SELECT * FROM test1 WHERE 1 = ? AND 2 = ?'); +var_dump(ibase_num_params()); + +$rs = ibase_prepare('SELECT * FROM test1 WHERE 1 = ? AND 2 = ? AND 3 = :x'); +var_dump(ibase_num_params($rs)); + + +?> +--EXPECTF-- +int(2) + +Warning: ibase_num_params() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: ibase_prepare(): Dynamic SQL Error SQL error code = -206 %s in %s on line %d + +Warning: ibase_num_params() expects parameter 1 to be resource, boolean given in %s on line %d +NULL diff --git a/ext/interbase/tests/ibase_param_info_001.phpt b/ext/interbase/tests/ibase_param_info_001.phpt new file mode 100644 index 0000000..31fe196 --- /dev/null +++ b/ext/interbase/tests/ibase_param_info_001.phpt @@ -0,0 +1,53 @@ +--TEST-- +ibase_param_info(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); + +$rs = ibase_prepare('SELECT * FROM test1 WHERE 1 = ? AND 2 = ?'); +var_dump(ibase_param_info($rs, 1)); + +print "---\n"; + +var_dump(ibase_param_info($rs, 100)); + +print "---\n"; + +var_dump(ibase_param_info(100)); + + +?> +--EXPECTF-- +array(10) { + [0]=> + string(0) "" + ["name"]=> + string(0) "" + [1]=> + string(0) "" + ["alias"]=> + string(0) "" + [2]=> + string(0) "" + ["relation"]=> + string(0) "" + [3]=> + string(1) "4" + ["length"]=> + string(1) "4" + [4]=> + string(7) "INTEGER" + ["type"]=> + string(7) "INTEGER" +} +--- +bool(false) +--- + +Warning: ibase_param_info() expects exactly 2 parameters, 1 given in %s on line %d +NULL diff --git a/ext/interbase/tests/ibase_rollback_001.phpt b/ext/interbase/tests/ibase_rollback_001.phpt new file mode 100644 index 0000000..3cde5e9 --- /dev/null +++ b/ext/interbase/tests/ibase_rollback_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +ibase_rollback(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); + +ibase_query('INSERT INTO test1 VALUES (100, 2)'); +ibase_query('INSERT INTO test1 VALUES (100, 2)'); +ibase_query('INSERT INTO test1 VALUES (100, 2)'); + +$rs = ibase_query('SELECT COUNT(*) FROM test1 WHERE i = 100'); +var_dump(ibase_fetch_row($rs)); + +var_dump(ibase_rollback($x)); + +$rs = ibase_query('SELECT COUNT(*) FROM test1 WHERE i = 100'); +var_dump(ibase_fetch_row($rs)); + +var_dump(ibase_rollback($x)); +var_dump(ibase_rollback()); + +?> +--EXPECTF-- +array(1) { + [0]=> + int(3) +} +bool(true) +array(1) { + [0]=> + int(0) +} +bool(true) + +Warning: ibase_rollback(): invalid transaction handle (expecting explicit transaction start) in %s on line %d +bool(false) diff --git a/ext/interbase/tests/ibase_trans_001.phpt b/ext/interbase/tests/ibase_trans_001.phpt new file mode 100644 index 0000000..cceb60e --- /dev/null +++ b/ext/interbase/tests/ibase_trans_001.phpt @@ -0,0 +1,21 @@ +--TEST-- +ibase_trans(): Basic test +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); +var_dump(ibase_trans($x)); +var_dump(ibase_trans(1)); +var_dump(ibase_close()); +var_dump(ibase_close($x)); + +?> +--EXPECTF-- +resource(%d) of type (Firebird/InterBase transaction) +resource(%d) of type (Firebird/InterBase transaction) +bool(true) +bool(true) diff --git a/ext/interbase/tests/ibase_trans_002.phpt b/ext/interbase/tests/ibase_trans_002.phpt new file mode 100644 index 0000000..be7c073 --- /dev/null +++ b/ext/interbase/tests/ibase_trans_002.phpt @@ -0,0 +1,34 @@ +--TEST-- +ibase_trans(): Basic operations +--SKIPIF-- +<?php include("skipif.inc"); ?> +--FILE-- +<?php + +require("interbase.inc"); + +$x = ibase_connect($test_base); + +$trans = ibase_trans(IBASE_DEFAULT, $x); +$sth = ibase_prepare($trans, 'INSERT INTO test1 VALUES (?, ?)'); + +$res = ibase_execute($sth, 100, 100); +var_dump($res); + +ibase_commit($trans); + +$rs = ibase_query($x, 'SELECT * FROM test1 WHERE i = 100'); +var_dump(ibase_fetch_assoc($rs)); + +ibase_free_query($sth); +unset($res); + +?> +--EXPECT-- +int(1) +array(2) { + ["I"]=> + int(100) + ["C"]=> + string(3) "100" +} diff --git a/ext/interbase/tests/interbase.inc b/ext/interbase/tests/interbase.inc new file mode 100644 index 0000000..42eb6e5 --- /dev/null +++ b/ext/interbase/tests/interbase.inc @@ -0,0 +1,120 @@ +<?php /* $Id$ */ + +srand((double)microtime()*1000000); + +$user = 'SYSDBA'; +$password = 'masterkey'; +ini_set('ibase.default_user',$user); +ini_set('ibase.default_password',$password); + +/* we need just the generated name, not the file itself */ +unlink($test_base = tempnam('/tmp',"php_ibase_test")); + +function init_db() +{ + global $test_base, $user, $password; + + $test_db = ibase_query(IBASE_CREATE, + sprintf("CREATE SCHEMA '%s' USER '%s' PASSWORD '%s' DEFAULT CHARACTER SET %s",$test_base, + $user, $password, ($charset = ini_get('ibase.default_charset')) ? $charset : 'NONE')); + $tr = ibase_trans($test_db); + ibase_query($tr,"create table test1 (i integer, c varchar(100))"); + ibase_commit_ret($tr); + ibase_query($tr,"insert into test1(i, c) values(1, 'test table not created with isql')"); + ibase_commit($tr); + ibase_close($test_db); +} + +function cleanup_db() +{ + global $test_base; + + $r = ibase_connect($test_base); + ibase_drop_db($r); +} + +register_shutdown_function('cleanup_db'); +init_db(); + +function out_table($table_name) +{ + echo "--- $table_name ---\n"; + $res = ibase_query("select * from $table_name"); + while ($r = ibase_fetch_row($res)) { + echo join("\t",$r)."\t\n"; + } + ibase_free_result($res); + echo "---\n"; +} + +function out_result($result, $table_name = "") +{ + echo "--- $table_name ---\n"; + while ($r = ibase_fetch_row($result)) { + echo join("\t",$r)."\t\n"; + } + echo "---\n"; +} + +function out_result_trap_error($result, $table_name = "") +{ + echo "--- $table_name ---\n"; + while ($r = @ibase_fetch_row($result)) { + echo join("\t",$r)."\t\n"; + } + echo "errmsg [" . ibase_errmsg() . "]\t\n"; + echo "---\n"; +} + +/* M/D/Y H:M:S */ +function rand_datetime() +{ + return sprintf("%02d/%02d/%4d %02d:%02d:%02d", + rand()%12+1, rand()%28+1, rand()%100+1910, + rand()%24, rand()%60, rand()%60); +} + +/* random binary string */ +function rand_binstr($max_len) +{ + $len = rand() % $max_len; + $s = ""; + while($len--) { + $s .= sprintf("%c", rand() % 256); + } + return $s; +} + +function rand_str($max_len) +{ + $len = rand() % $max_len; + $s = ""; + while ($len--) { + $s .= sprintf("%c", rand() % 26 + 65); + } + return $s; +} + +function rand_number($len , $prec = -1, $sign = 1) +{ + if ($prec == -1) { + $n = substr(rand() . rand(), 0, rand() % $len + 1); + if (strlen($n) < $len) { + $n .= "." . substr(rand(), 0, rand() % ($len - strlen($n)) + 1); + } + } else if ($prec == 0) { + $n = substr(rand() . rand(), 0, rand() % $len + 1); + } else if (($prec - $len) == 0) { + $n = substr(rand() . rand(), 0, 1); + $n .= "." . substr(rand(), 0, $prec); + } else { + $n = substr(rand() . rand(), 0, rand() % ($len - $prec) + 1); + $n .= "." . substr(rand(), 0, $prec); + } + if ($sign && (rand() % 3 == 0)) { + $n = "-" .$n; + } + return $n; +} + +?> diff --git a/ext/interbase/tests/skipif.inc b/ext/interbase/tests/skipif.inc new file mode 100644 index 0000000..79813f6 --- /dev/null +++ b/ext/interbase/tests/skipif.inc @@ -0,0 +1,9 @@ +<?php /* $Id$ */ + +if (!extension_loaded("interbase")) print "skip interbase extension not available"; +require("interbase.inc"); +if(!@ibase_connect($test_base)){ + die("skip cannot connnect"); +} + +?> |