in reply to DBI execute .sql file
Your specific DBD driver might have a method to do it for you. Barring that, you could try:
my $sql_file = '/path/to/file.sql'; my $dbh; # DBI connection initilized elsewhere local $/ = ';'; open(SQL, '<', $sql_file) or die "Can't open $sql_file: $!\n"; while(my $line = <SQL>) { $dbh->do($line) or warn "Can't execute statement in $sql_file, line $.: " . $d +bh->errstr; } close(SQL);
Though there might be some special cases where the above will fail.
----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
Note: All code is untested, unless otherwise stated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: DBI execute .sql file
by arthas (Hermit) on Jul 08, 2003 at 15:53 UTC | |
|
Re: Re: DBI execute .sql file
by Mago (Parson) on Jul 08, 2003 at 20:07 UTC |