Don't rely on isql anymore, as creating databases is now supported by the API

Changed tests to include ibase_query("SET TRANSACTION ...")
This commit is contained in:
Ard Biesheuvel 2004-04-01 16:25:51 +00:00
parent 6a6096ec11
commit 563e9dd664
4 changed files with 52 additions and 61 deletions

View File

@ -17,16 +17,19 @@ InterBase: connect, close and pconnect
$pcon1 = ibase_pconnect($test_base); $pcon1 = ibase_pconnect($test_base);
$pcon2 = ibase_pconnect($test_base); $pcon2 = ibase_pconnect($test_base);
ibase_close($con); ibase_close($con);
unset($con);
ibase_close($pcon1); ibase_close($pcon1);
unset($pcon1);
out_table("test1"); out_table("test1");
ibase_close($pcon2); ibase_close($pcon2);
unset($pcon2);
?> ?>
--EXPECT-- --EXPECT--
--- test1 --- --- test1 ---
1 test table created with isql 1 test table not created with isql
--- ---
--- test1 --- --- test1 ---
1 test table created with isql 1 test table not created with isql
--- ---

View File

@ -113,8 +113,8 @@ three transaction on default link
ibase_free_result($res); ibase_free_result($res);
$tr_1 = ibase_trans(); /* this default transaction also */ $tr_1 = ibase_query("SET TRANSACTION");
$tr_2 = ibase_trans(IBASE_READ); $tr_2 = ibase_query("SET TRANSACTION READ ONLY");
$tr_3 = ibase_trans(IBASE_READ+IBASE_COMMITTED+IBASE_REC_VERSION+IBASE_WAIT); $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); $tr_4 = ibase_trans(IBASE_READ+IBASE_COMMITTED+IBASE_REC_NO_VERSION+IBASE_NOWAIT);

View File

@ -1,46 +1,40 @@
<?php <?php /* $Id$ */
/* $Id$ */
/* used in tests */
srand((double)microtime()*1000000); srand((double)microtime()*1000000);
$test_base = dirname(__FILE__)."/ibase_test.tmp"; /* we need just the generated name, not the file itself */
@unlink($test_base); unlink($test_base = tempnam('/tmp',"php_ibase_test"));
$name = tempnam(dirname(__FILE__), "CREATEDB"); function init_db()
$ftmp = fopen($name,"w"); {
fwrite($ftmp, global $test_base;
"
create database \"$test_base\";
create table test1 (i integer, c varchar(100));
commit;
insert into test1(i, c) values(1, 'test table created with isql');
exit;
"
);
fclose($ftmp);
/* set the correct binary */ $test_db = ibase_query("CREATE DATABASE \"$test_base\"");
if (is_executable('isql')) { $tr = ibase_trans($test_db);
$cmd = 'isql'; ibase_query($tr,"create table test1 (i integer, c varchar(100))");
} else { ibase_commit_ret($tr);
$cmd = '/opt/interbase/bin/isql'; ibase_query($tr,"insert into test1(i, c) values(1, 'test table not created with isql')");
ibase_commit($tr);
ibase_close($test_db);
} }
exec("$cmd -i $name 2>&1"); function cleanup_db()
@unlink($name); {
global $test_base;
$r = ibase_connect($test_base);
ibase_drop_db($r);
}
register_shutdown_function('cleanup_db');
init_db();
function out_table($table_name) function out_table($table_name)
{ {
echo "--- $table_name ---\n"; echo "--- $table_name ---\n";
$res = ibase_query("select * from $table_name"); $res = ibase_query("select * from $table_name");
$f = ibase_num_fields($res); while ($r = ibase_fetch_row($res)) {
while ($r = ibase_fetch_row($res)){ echo join("\t",$r)."\t\n";
for($i = 0; $i < $f; $i++)
echo "$r[$i]\t";
echo "\n";
} }
ibase_free_result($res); ibase_free_result($res);
echo "---\n"; echo "---\n";
@ -49,34 +43,28 @@ function out_table($table_name)
function out_result($result, $table_name = "") function out_result($result, $table_name = "")
{ {
echo "--- $table_name ---\n"; echo "--- $table_name ---\n";
$f = ibase_num_fields($result); while ($r = ibase_fetch_row($result)) {
while ($r = ibase_fetch_row($result)){ echo join("\t",$r)."\t\n";
for($i = 0; $i < $f; $i++)
echo "$r[$i]\t";
echo "\n";
} }
echo "---\n"; echo "---\n";
} }
function out_result_trap_error($result, $table_name = "") function out_result_trap_error($result, $table_name = "")
{ {
echo "--- $table_name ---\n"; echo "--- $table_name ---\n";
while ($r = @ibase_fetch_assoc($result)){ while ($r = ibase_fetch_row($result)) {
while (list($k, $v) = each($r) ){ echo join("\t",$r)."\t\n";
echo "$r[$k]\t";
}
echo "\n";
} }
echo "errmsg [" . ibase_errmsg() . "]\t\n"; echo "errmsg [" . ibase_errmsg() . "]\t\n";
echo "---\n"; echo "---\n";
} }
/* M/D/Y H:M:S */ /* M/D/Y H:M:S */
function rand_datetime() function rand_datetime()
{ {
return sprintf("%02d/%02d/%4d %02d:%02d:%02d", return sprintf("%02d/%02d/%4d %02d:%02d:%02d",
rand()%12+1, rand()%28+1, rand()%100+1910, rand()%12+1, rand()%28+1, rand()%100+1910,
rand()%24, rand()%60, rand()%60); rand()%24, rand()%60, rand()%60);
} }
/* random binary string */ /* random binary string */
@ -84,8 +72,9 @@ function rand_binstr($max_len)
{ {
$len = rand() % $max_len; $len = rand() % $max_len;
$s = ""; $s = "";
while($len--) while($len--) {
$s .= sprintf("%c", rand() % 256); $s .= sprintf("%c", rand() % 256);
}
return $s; return $s;
} }
@ -93,25 +82,28 @@ function rand_str($max_len)
{ {
$len = rand() % $max_len; $len = rand() % $max_len;
$s = ""; $s = "";
while($len--) while ($len--) {
$s .= sprintf("%c", rand() % 26 + 65);; $s .= sprintf("%c", rand() % 26 + 65);
}
return $s; return $s;
} }
function rand_number($len , $prec = -1, $sign = 1) function rand_number($len , $prec = -1, $sign = 1)
{ {
if($prec == -1){ if ($prec == -1) {
$n = substr(rand() . rand(), 0, rand() % $len + 1); $n = substr(rand() . rand(), 0, rand() % $len + 1);
if(strlen($n) < $len) if (strlen($n) < $len) {
$n .= "." . substr(rand(), 0, rand() % ($len - strlen($n)) + 1); $n .= "." . substr(rand(), 0, rand() % ($len - strlen($n)) + 1);
}elseif ($prec == 0){ }
} else if ($prec == 0) {
$n = substr(rand() . rand(), 0, rand() % $len + 1); $n = substr(rand() . rand(), 0, rand() % $len + 1);
}else{ } else {
$n = substr(rand() . rand(), 0, rand() % ($len - $prec) + 1); $n = substr(rand() . rand(), 0, rand() % ($len - $prec) + 1);
$n .= "." . substr(rand(), 0, $prec); $n .= "." . substr(rand(), 0, $prec);
} }
if($sign && (rand() % 3 == 0)) if ($sign && (rand() % 3 == 0)) {
$n = "-" .$n; $n = "-" .$n;
}
return $n; return $n;
} }

View File

@ -1,9 +1,5 @@
<?php <?php /* $Id$ */
/* $Id$ */
/* used in tests */
if (!extension_loaded("interbase")) print "skip"; if (!extension_loaded("interbase")) print "skip";
if (!is_executable("isql") && !is_executable("/opt/interbase/bin/isql")) print "skip";
?> ?>