Hi,
I would love if someone helped me with this DBIx::Recordset problem:
My CGI/DBI program shall
1) Connect to a db and list the 'temp_' tables there.
2) If user wants to upload new data, the data will be created in a new
'temp_' table.
3) Operations will be performed on the new and old 'temp_' tables together.
Somehow DBIx::Recordset::AllNames() doesn't recognise the newly created
table, even though I re-create the $db connection. I get this error
message:
Unknown table temp_tab3 in dbi:Pg:dbname=marcus_test at
/usr/local/lib/perl5/site_perl/5.6.1/DBIx/Database.pm line 57
DBIx::Database::Base::savecroak('DBIx::Database=HASH(0x84e50f4)',
'Unknown table temp_tab3 in dbi:Pg:dbname=marcus_test') called at
/usr/local/lib/perl5/site_perl/5.6.1/DBIx/Database.pm line 848
DBIx::Database::AllNames('DBIx::Database=HASH(0x84e50f4)',
'temp_tab3') called at /var/www/cgi-bin/marcus/ma_merge6.pl line 98
Also, do I really need to call the DBIx::Database->new() method every
time I want to get a fresh list to the new tables in the same session?
Bits of the code:
use strict;
use CGI qw(:standard);
use DBIx::Recordset;
....
$db = DBIx::Database->new({'!DataSource' => 'dbi:Pg:dbname=$database',
'!Username'=> $user,
'!KeepOpen' => 1}) or die
"Couldn't connect to database";
....
$available_tables = $db->AllTables;
foreach (keys %$available_tables) {
if (/^temp/) {
push @temp_tables,$_;
}
}
if (param('file')) { ###If user chooses to upload data
into a new table
$table = "temp_tab";
my $fh = $q->upload('file');
while (<$fh>) {
if (/^ID/i) {
s/([a-zA-Z_0-9.-]+)[\s]/$1 TEXT,/gi;
$db->do("CREATE TABLE $table ($_ PRIMARY KEY(ID))");
} else {
s/([a-zA-Z_0-9.,-]+)[\s]/\'$1\'/gi;
s/\'\'/\',\'/gi;
$db->do("INSERT INTO $table VALUES ($_)");
}
}
$db->do("GRANT ALL ON $table TO PUBLIC");
if ($table) {
$db = DBIx::Database->new({'!DataSource' => 'dbi:Pg:dbname=$database',
'!Username'=> $user,
'!KeepOpen' => 1}) or
die "Couldn't connect to database";
$columns = $db->AllNames($table);
foreach (@$columns) {
push @new_temp_tables,$_;
}
....
/Marcus