Subject Re: Problem creating tables
Author sc_odo
Thanks Alan,
OK, to make it simple, here is the part of my script that creates the
tables. The data is inserted by another function after that.

function create_tables($conn_arr, $tab_arr, $drvs){
include(_MMODDIR_."/lang/main.".DLANG.".php");
include(_LANGDIR_."/install.".DLANG.".php");
$db = @ADONewConnection("firebird");
$db->debug = true;

$msg = "";
if(!is_object($db))
return array(-1, "<h5 style='color:
#FF3300;'>".str_replace("###DBMS###", $drvs[$conn_arr["dbms"]],
$inst_err[23])."</h5>");

$msg .= "<h5 style='color: #006600;'>".str_replace("###DBMS###",
$drvs[$conn_arr["dbms"]], $inst_msg[10])."</h5>";
if(empty($conn_arr["db_user"])){
$msg .= "<h5 style='color: #FF3300;'>".$inst_err[24]."</h5>";
return array(-1, $msg);
}
$msg = str_replace(array("###DBUSER###", "###DBNAME###"),
array($conn_arr["db_user"], $conn_arr["db_name"]), $inst_msg[11]);
$msg .= "<h5>$msg</h5>";
$conn = @$db->NConnect("localhost".$conn_arr["cn_port"],
$conn_arr["db_user"], $conn_arr["db_pass"], $conn_arr["db_name"]);
if($conn != 1){
$msg .= "<h5 style='color: #FF3300;'>".$inst_err[25]."</h5>";
$e = get_error($db);
if(!empty($e))
$msg .= "<div style='max-width:500px; background-color:
#FF3300; color: #FFEB0C;'>$e</div>";
if(@$db->IsConnected())
@$db->Close();
return array(-1, $msg);
}

if(!is_array($tab_arr) || empty($tab_arr)){
$msg .= "<h5 style='color: #FF3300;'>".$inst_err[26]."</h5>";
if(@$db->IsConnected())
@$db->Close();
return array(-1, $msg);
}

$dict = @NewDataDictionary($db, "firebird");
if(!$dict)
return array(-1, "<h5 style='color:
#FF3300;'>".$inst_err[27]."</h5>");

foreach($tab_arr as $c => $tab){
$r_tabs = array();
$r_tabs = @$dict->CreateTableSQL($tab["tab_name"], $tab["cols"],
$tab["tab_opts"]);

if(!is_array($r_tabs) || empty($r_tabs)){
$msg .= "<h5 style='color:
#FF3300;'>".str_replace("###TABNAME###", $tab["tab_name"],
$inst_err[28])."</h5>";
$e = get_error($db);
if(!empty($e))
$msg .= "<div style='max-width:500px; background-color:
#FF3300; color: #FFEB0C;'>$e</div>";
if(@$db->IsConnected())
@$db->Close();
return array(-1, $msg);
}

$res = @$dict->ExecuteSQLArray($r_tabs, false);
if($res != 2){
$msg .= "<h5 style='color:
#FF3300;'>".str_replace("###TABNAME###", $tab["tab_name"],
$inst_err[28])."</h5>";
$e = get_error($db);
if(!empty($e))
$msg .= "<div style='max-width:500px; background-color:
#FF3300; color: #FFEB0C;'>$e</div>";
if(@$db->IsConnected())
@$db->Close();
return array(-1, $msg);
}

}
$msg .= "<h5 style='color: #006600;'>".$inst_mag[12]."</h5>";
if(@$db->IsConnected())
@$db->Close();
return array(1, $msg);
}

OK, this ist it. The function recieves an array of table definitions
in ADODBs specific format. CreateTableSQL() converts the definitions
to regular SQL statements and ExecuteSQLArray() executes the statements.

Thanks in advance

Best regards

Ralf

--- In firebird-php@yahoogroups.com, "Alan McDonald" <alan@...> wrote:
>
> >
> > Hello all,
> > I have a problem creating tables from a php script. I'm using FB SS
> > 1.5.3 on Suse 9.1.
> > The script should create a database with around 30 tables. To do that
> > I use ADODB datadict. In case something goes wrong, the database
> > should be deleted.
> > Creation of the database works fine. The creation of the tables fails.
> > It just creates around 5 tables but the script returns success code on
> > the creation of all tables. After the creation of the tables some
> > grants and some data should be inserted, and this fails. Because of
> > this failure the script now should drop the database, which doesn't
> > work any more, isql returns -901 -object <database> is in use. This
> > even remains after minutes or hours of waiting. The only way to get
> > dropping to work is restarting the firebird server. There are no other
> > clients connected to the server.
> > It seems that the server is still caught in the process of creating
> > the tables.
> >
> > Any ideas where the problem could come from?
> >
> > Best regards
> >
> > Ralf
>
> are you specifically committing the transaction(s)?
> do you commit the transaction after table creation and before data
> insertion? then start another transaction?
> do you use connect() or pconnect()?
> do you specifically close the connection?
> maybe we should see the script
> Alan
>