/*
IBTEST
Copyright (C) 2006 Milan Babuskov (mbabuskov@yahoo.com)
This program is free software; you can redistribute it and/or modify
it under the terms of 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.
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 the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
You can also find the license here:
http://www.gnu.org/licenses/gpl.txt
*/
// we'll handle our own errors
error_reporting(0);
// if register globals is set, we need to convert stuff
if (isset($_POST['database']))
{
$database = $_POST['database'];
$username = $_POST['username'];
$password = $_POST['password'];
}
if (empty($database))
{?>
exit();
}
echo "Connecting...";
$link = ibase_connect($database, $username, $password);
if (!$link)
{
echo "Error while connecting: ".ibase_errmsg();
exit();
}
echo "OK.
\nRunning tests...
\n";
?>
Test name |
SQL |
Result |
Expected |
Commit |
$tests = array(
'Check database' => array('Select rdb$relation_id, rdb$character_set_name from rdb$database', '*')
,'Bad query' => array('this one should fail', '*')
,'Create table' => array('create table PHP_TEST ( x integer, c char(10), v varchar(10) )', '*')
,'Add field Y' => array('alter table PHP_TEST add y integer not null', '*')
,'Insert1' => array('insert into PHP_TEST (x,y) values (1,2)', '*')
,'Select1 (check)' => array('select x+y, x, y from PHP_TEST', array(3,1,2))
,'Update2 X' => array('update PHP_TEST set x = x + 10', '*')
,'Select2 (check)' => array('select x, y from PHP_TEST', array(11, 2))
,'Add field Z' => array('alter table PHP_TEST add Z decimal(16,2) not null', '*')
,'Update3 Z' => array('update PHP_TEST set z = 1', '*')
,'Select3 (check)' => array('select z, z+1, z*11, z/12.50 from PHP_TEST', array(1, 2, 11, 0.08))
,'Update4 Z' => array('update PHP_TEST set z = -1', '*')
,'Select4 (check)' => array('select z, z+1, z*11, z/12.50 from PHP_TEST', array(-1, 0, -11, -0.08))
,'Update5 Z' => array('update PHP_TEST set z = 0.48', '*')
,'Select5 (check)' => array('select z, z+1, z*11, z/12.50 from PHP_TEST',
array(0.48, 1.48, 5.28, 0.0384))
,'Update6 Z' => array('update PHP_TEST set z = -0.52', '*')
,'Select6 (check)' => array('select z, z+1, z*11, z/12.50 from PHP_TEST',
array(-0.52, 0.48, -5.72,-0.0416))
,'Update7 Z' => array('update PHP_TEST set z = 1.18', '*')
,'Select7 (check)' => array('select z, z+1, z*11, z/12.50 from PHP_TEST',
array(1.18, 2.18, 12.98, 0.0944))
,'Update8 Z' => array('update PHP_TEST set z = -1.38', '*')
,'Select8 (check)' => array('select z, z+1, z*11, z/12.50 from PHP_TEST',
array(-1.38, -0.38, -15.18, -0.1104))
,'Update C' => array('update PHP_TEST set c = \'PHP test\'', '*')
,'Check char padding' => array('select c from PHP_TEST', 'PHP test ') // check CHAR padding
,'Update V' => array('update PHP_TEST set v = \'PHP test\'', '*')
,'Check varchar padding' => array('select v from PHP_TEST', 'PHP test')
,'Add decimal fields' => array('alter table PHP_TEST
add d1 decimal(4,2),
add d2 decimal(6,3),
add d3 decimal(8,4),
add d4 decimal(10,5),
add d5 decimal(14,7),
add d6 decimal(16,8),
add dd double precision,
add df float', '*')
,'Update decimals' => array('update PHP_TEST set
d1 = 12.52, d2 = 918.812, d3 = 1234.8765, d4 = 54321.06789,
d5 = 6543210.1234567, d6 = 87654321.01234567, dd = 1234.5678,
df = 1234.56', '*')
,'Check types1' => array('select d1,d2,d3,dd,df from PHP_TEST',
array(12.52, 918.812, 1234.8765))
,'Check types2' => array('select d4,d5,d6 from PHP_TEST',
array(54321.06789, 6543210.1234567))
,'Create SP' => array('create procedure php_test_sp returns (
x integer, c char(10), v varchar(10),
d1 decimal(4,2), d2 decimal(6,3),
d3 decimal(8,4), d4 decimal(10,5),
d5 decimal(14,7), d6 decimal(16,8),
dd double precision, df float) as BEGIN
for select x, c, v, d1, d2, d3, d4, d5, d6, dd, df from php_test
into :x, :c, :v, :d1, :d2, :d3, :d4, :d5, :d6, :dd, :df
do suspend; END', '*')
,'Select SP1' => array('select c, v, x from php_test_sp', 'PHP test ')
,'Select SP2' => array('select d1,d2,d3,dd,df from php_test_sp',
array(12.52, 918.812, 1234.8765))
,'Select SP3' => array('select d4, d5, d6 from php_test_sp',
array(54321.06789, 6543210.1234567))
,'Drop SP' => array('drop procedure PHP_TEST_SP', '*')
,'Drop table' => array('drop table PHP_TEST', '*')
//,'' => array('', '*')
);
foreach($tests as $t => $p)
{
echo "\n" . htmlspecialchars($t) . " | "
. htmlspecialchars($p[0]) . " | ";
$res = ibase_query($p[0]);
if (!$res)
{
echo "".htmlspecialchars(ibase_errmsg()).
"";
}
else
{
print_results($res, $row);
if (!$row)
echo "Executed Ok. No resultset.";
}
echo " | ";
if (is_array($p[1]) || $p[1] != '*')
{
$a = array();
if (!is_array($p[1]))
$a[0] = $p[1];
else
$a = $p[1];
for ($i = 0; $i < sizeof($a); $i++)
{
if ($i > 0)
echo ", ";
if ($a[$i] == $row[$i])
echo ''.$a[$i].'';
else
echo ''.$a[$i].'';
}
}
echo " | ";
if (ibase_commit())
echo "OK.";
else
{
echo "Error while commiting: "
. htmlspecialchars(ibase_errmsg()) . "";
}
echo " |
\n";
}
?>
Testing complete.
function print_results($res, &$first_row)
{
$first_row = ibase_fetch_row($res);
if (!$first_row)
return false;
$row = $first_row;
$coln = ibase_num_fields($res);
echo "\n";
echo "";
for ($i=0; $i < $coln; $i++)
{
$col_info = ibase_field_info($res, $i);
echo "\n ".$col_info['alias']
." ".$col_info['type']." | ";
}
echo "
\n";
do
{
echo "\n";
for ($i=0; $i < $coln; $i++)
{
echo "\t".htmlspecialchars($row[$i])." | \n";
}
echo "
\n";
}
while ($row = ibase_fetch_row($res));
echo "
\n";
return $first_row;
}
?>