http://qs321.pair.com?node_id=559653

waltw has asked for the wisdom of the Perl Monks concerning the following question:

Dear Perl Monks:

I am using CGI::App and have as one of my run-modes the following short and simple update routine against a data schema implemented using SQLite.

The objective is to take the edited media type code description returned from an HTML form and update the existing record in the database.

The Problem

The database does not update with the new data, and continues to show the old data. SQLite does not throw an error. I can't figure out my sin of commission or omission and hope for a quick head slapping experience.

Other notes

  1. I can verify the data is returned and delivered to my routine with the edits intact
  2. I can verify that SQLite dutifully throws an error if I mal-form the SQL>
  3. I can stub out the routine to print the SQL statement, post interpolation -- it is correct
  4. I can verify that SQL statement operates as intended when applied to the SQLite command line
  5. Single table referenced, Media:

    CREATE TABLE Media (media_code TEXT, media_desc TEXT, PRIMARY KEY (media_code));

Question

After $sth->execute(); the database remains non-UPDATEd nor does it throw any errors -- why??!!

I'm pulling my hair and beard over this one -- read through Programming the Perl DBI, searched on this site, read through CPAN's docs on CGI and CGI:App.

Thank you,

Walt

Short Routine Follows

sub updateMedia { my $self=shift; my $q = $self->query(); my $dbh = $self->param('mydbh'); my $scripturl = $q->url(); my $scripthome = $q->script_name(); # From HTML form my $media_desc = $q->param('txtMediaDesc'); my $media_code = $q->param('media_code'); # SQL Update my $media_desc_quoted = $dbh->quote( $media_desc ); my $media_code_quoted = $dbh->quote( $media_code ); my $sql = qq{UPDATE Media SET media_desc=$media_desc_quoted WHERE media_code=$media_code_quoted}; my $sth = $dbh->prepare($sql); $sth->execute(); # Redirect back to start $self->header_type('redirect'); $self->header_props(-url=>$scripthome."?rm=editMedia&media_cod +e=".$media_code); return;