I am playing with SQLite and can't get the trigger to work...any pointers?
#!/usr/bin/perl # Copyright GPL (c) 2004 Mike Chirico mchirico@users.sourceforge.net m +chirico@comcast.net # You will need the following to work with # SQLite3 # # $ perl -MCPAN -e shell # cpan> install DBI # cpan> install DBD::SQLite # Reference # http://www.perl.com/pub/a/2004/09/12/embedded.html use strict; use warnings; use DBI; my $database = "test_database"; my $dbh = DBI->connect( "dbi:SQLite:$database" ) || die "Cannot connec +t: $DBI::errstr"; $dbh->do("DROP TABLE user"); $dbh->do("DROP TABLE profile"); $dbh->do("DROP TABLE demographic"); $dbh->do( "CREATE TABLE user ( email VARCHAR(25), user_id VARCHAR(15), perm VARCHAR(30))"); $dbh->do( "CREATE TABLE profile ( user_id VARCHAR(15), pref VARCHAR(30), ic_ind INTEGER)"); $dbh->do( "CREATE TABLE demographic ( user_id VARCHAR(15), fname VARCHAR(15), lname VARCHAR(20), interest INTEGER)"); $dbh->do("DROP TRIGGER update_profile"); $dbh->do("CREATE TRIGGER update_profile AFTER INSERT ON user BEGIN INSERT INTO profile user_id values (new.user_id); END;"); $dbh->do( "INSERT INTO user (email, user_id, perm) values ('abc\@test.net','a12345','perm_data_1' +)"); $dbh->do( "INSERT INTO user (email, user_id, perm) values ('nancy\@optonline.net','a131313','perm +_data_2')"); $dbh->do( "INSERT INTO user (email, user_id, perm) values ('naomi\@gmail.com','b515515','perm_dat +a_3')"); $dbh->do( "INSERT INTO profile (user_id, pref,ic_ind) values ('b515515','sex','whatever')"); $dbh->do ("INSERT INTO profile (user_id, pref, ic_ind) values ('a12345', 'talking', 'whatever')"); $dbh->do ("INSERT INTO demographic (user_id, fname, lname, interest) values ('a12345', 'Nancy', 'McGrath','whatever +')"); print "LAST insert id: ",$dbh->func('last_insert_rowid'),"\n\n\n"; my $i; print "dumping profile\n"; my $res = $dbh->selectall_arrayref( q( SELECT * FROM profile )); foreach( @$res ) { foreach $i (0..$#$_) { print "$_->[$i] " } print "\n"; } print "\ndumping user\n"; $res = $dbh->selectall_arrayref( q( SELECT email, user_id, perm FROM u +ser )); foreach( @$res ) { foreach $i (0..$#$_) { print "$_->[$i] " } print "\n"; } print "\ndumping demographic\n"; $res = $dbh->selectall_arrayref( q( SELECT * FROM user )); foreach( @$res ) { foreach $i (0..$#$_) { print "$_->[0] " } print "\n"; } $dbh->disconnect;

In reply to sqlite triggers by fionbarr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.