Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reloading a database from a file 2

Status
Not open for further replies.
Dec 17, 2002
41
US
I'm havin a helluva day. I'm trying to access a txt file that has records from my db. The user selects the date (which is also the folder name) and the table (which is also the file name) then I want it to reload those records back into an empty table. Right now, It says it can't even open the file. What am I doing wrong?

my $foldername = param('folder_name');
my $tablename = param('table_name');

open(DAT,&quot;<../../Backup Data Files/$foldername/$tablename.txt&quot;) || die(&quot;Cannot Open File&quot;);

my @line=<DAT>;

foreach $line (@line)
{

my $sql = qq{INSERT INTO $tablename VALUES ($line) };

my $sth = $dbh->prepare( $sql );
$sth->execute();

$sql = qq{ COMMIT };

$sth = $dbh->prepare( $sql );
$sth->execute();

};

close(DAT);
 
Try this:

$file = &quot;../../Backup Data Files/$foldername/$tablename.txt&quot;;

open(DAT,&quot;$file&quot;) || die(&quot;Cannot Open File\n$file\n$!\n&quot;);

That way you can see what file the script is trying to open, and the $! will tell you why it's failing (hopefully).
Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Mike - Corrected the path. Now getting this...

DBD::Oracle::st execute failed: ORA-00001: unique constraint (TESTDB.SYS_C006567) violated (DBD ERROR: OCIStmtExecute) at Directory names I can't show you\Web Page\CGI-BIN\reload.pl line 42, line 8.

Line 42 is the prepare for the insert statement. Line 8 assigns the db name into a variable to be used in the log in process. I've used line 8 before to do the same process it is doing now and I know line 42 should be ok. Any ideas about what's going on?

 
You're violating a unique constraint, like it says. You're almost certainly inserting a value into the database that already exists, and the table has a constraint that will not allow you to do that.
 
Good news, It's up and running. Mike, thanks for helping me see my problems. Rosenk, someone went in and reloaded the db on me while I was on another project, hence the error, but thanks for the help. And wouldn't you know it, right when I get all my programs up and running they put me on a new contract. I guess now I'll have to change my name to Primaveratard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top