fionbarr has asked for the wisdom of the Perl Monks concerning the following question:
#! perl use strict; use warnings; use DBI; my $dbh; &do_connect(\$dbh); &create_tables($dbh); exit; sub do_connect { # my $dbh = shift or die "code_review:do_connect: must pass in +handle...$!\n"; my $driver = "SQLite"; my $database = "/home/user/bmcclintock/code_review.db"; my $username = undef; my $password = undef; my $dsn = "DBI:$driver:database=$database"; $dbh = DBI->connect( $dsn, $username, $password ); } sub create_tables { my $dbh = shift; # Delete the table if it already exists. eval { local $dbh->{PrintError} = 1; $dbh->do("DROP TABLE review") and print "review dropped\n"; $dbh->do("DROP TABLE depot") and print "depot dropped\n"; $dbh->do("DROP TABLE reviewer") and print "reviewer dropped\n"; die "error in dropping tables\n" if $@; }; my $table = "review"; $dbh->do("CREATE TABLE $table (key INTEGER PRIMARY KEY, submitter VARCHAR(50), director VARCHAR(50), change_num INTEGER, action VARCHAR(20), time DATE )") or die "code_review::create_table: + could not create <$table>...$!\n"; print "\n$table created\n"; $table = "depot"; $dbh->do("CREATE TABLE $table (change_num INTEGER PRIMARY KEY, depot VARCHAR(50) )") or die "code_review::create_table: + could not create <$table>...$!\n"; print "$table created\n"; $table = "reviewer"; $dbh->do("CREATE TABLE $table (change_num INTEGER PRIMARY KEY, reviewed_by VARCHAR(50) )") or die "code_review::create_table: + could not create <$table>...$!\n"; print "$table created\n"; $dbh->do("CREATE TRIGGER INS_TIMEENTER AFTER INSERT ON REVIEW BEGIN UPDATE REVIEW SET TIME = DATETIME('NOW','LOCALTIME') WHERE ROWID = NEW.ROWID; END"); print "\ntables created\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: create SQLite database problems
by chilledham (Friar) on Mar 06, 2012 at 19:47 UTC | |
by fionbarr (Friar) on Mar 06, 2012 at 19:51 UTC | |
by chilledham (Friar) on Mar 06, 2012 at 19:55 UTC | |
by fionbarr (Friar) on Mar 06, 2012 at 20:03 UTC | |
by chilledham (Friar) on Mar 06, 2012 at 20:10 UTC | |
Re: create SQLite database problems
by Riales (Hermit) on Mar 06, 2012 at 23:24 UTC | |
by chilledham (Friar) on Mar 06, 2012 at 23:40 UTC | |
by Riales (Hermit) on Mar 07, 2012 at 18:30 UTC |