RedJeep has asked for the wisdom of the Perl Monks concerning the following question:
Hello folks. I have two Windows 10 computers. Running IIS. Both configured identically... well, as best as I can tell. I am trying to create a very basic CGI web site that registers users to a SQLite database. On one server, it works fine. On my desktop system the CGI page with database INSERT does not kick off any errors (that I can see) but it does not INSERT the new record. But, what is really odd, is that if I try and submit the same data again, I get a Unique Constraint error. The database has only three columns (fname, lname and email). "email" has a constraint.
Following is a snippet of the code used to create the databasemy $sql = <<'END_SQL'; CREATE TABLE people ( id INTEGER PRIMARY KEY, fname VARCHAR(100), lname VARCHAR(100), email VARCHAR(100) UNIQUE NOT NULL,
But, again I have this running fine on another system. Following is my test code. I have stripped out passing params and hard-coded the variables of fname, lname and email. The database currently only has one record so there are no obvious constraints.
What seems really odd to me is that the new record is not being written. No error kicked off (that I can see). But if I try to resubmit the same data (the same email) then I get the error of.
Output on first try submitting a new record from browser. But it does not actually write to the database
Test 103Output on second try submitting that same record from browser. But, again, it does not actually write to the database.
Software error:
DBD::SQLite::db do failed: UNIQUE constraint failed: people.email at C:\inetpub\wwwroot\cgi_test_sqlite.pl line 31.
For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.
And I copy the same script to my other Windows 10 IIS server and it works fine. Or, I run from the command line and it INSERTs successfully.I know I should move on from CGI, but this is a small site and typically this sort of thing is super easy to do.
Following is output from SQLite query:
C:\inetpub\wwwroot\data>sqlite3 cgi_test1.dbI appreciate any insight that you could provide. I don't think I have a Perl script problem. Maybe one of you has seen this. I just don't know.
#!/usr/local/bin/perl ### Setup environment use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI::Session; use CGI::Session qw/-ip-match/; use DBI; my $q = CGI->new; ### People my $dbfile = "/inetpub/wwwroot/data/cgi_test1.db"; my $dsn = "dbi:SQLite:dbname=$dbfile"; my $user_a = ""; my $password_a = ""; my $dbh = DBI->connect($dsn, $user_a, $password_a, { PrintError => 0, RaiseError => 1, AutoCommit => 0, FetchHashKeyName => 'NAME_lc', },) or die $dbh::errstr; my $fname = 'Joe'; my $lname = 'Smith'; my $email = 'red.jeep2334@gmail.com'; $dbh->do('INSERT INTO people (fname, lname, email) VALUES (?, ?, ? +)', undef, $fname, $lname, $email); $dbh->commit(); $dbh->disconnect(); print "Content-Type: text/html\n\n"; print "<html> <head>\n"; print "<title>Test</title>"; print "</head>\n"; print "<body>\n"; print "<h3>Test 103</h3>\n"; print "dbfile: $dbfile <br>\n"; print "lg_name: $email <br>\n"; print "</body> </html>\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble writing to SQLite from CGI on Windows
by hippo (Archbishop) on May 21, 2019 at 08:01 UTC | |
|
Re: Trouble writing to SQLite from CGI on Windows
by poj (Abbot) on May 21, 2019 at 08:34 UTC | |
|
Re: Trouble writing to SQLite from CGI on Windows
by RedJeep (Sexton) on May 22, 2019 at 05:32 UTC | |
by marto (Cardinal) on May 22, 2019 at 06:11 UTC | |
by RedJeep (Sexton) on May 23, 2019 at 00:24 UTC |