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

I have an app developed by another collegue, no longer with the company.I'm using the same code he had, but I'm getting database errors. Below is the DBI code. I have SQLitePro installed on my computer. I suspect the original code was developed with an earlier version of Sqlite. Below is the error, web app and code:

Error from website:

Content-type: text/html <h1>Software error:</h1> <pre>unable to open database file(1) at dbdimp.c line 94 </pre> <p> For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error. </p>

Code connecting to database:

#!c:\Perl\bin\Perl.exe # Created: 2006/03/28 use strict; use CGI qw {:cgi-lib :standard}; use CGI::Carp qw(fatalsToBrowser); use File::Copy; use DBI; my $form = Vars(); if ($$form{editnew} eq "edit") { print redirect("workplan.pl?workplan=$$form{createfrom}") } elsif ($$form{editnew} eq "new") { copy ("$$form{createfrom}.db","$$form{newname}.db"); my $database = DBI->connect("dbi:SQLite:dbname=$$form{newname}.db" +,"","") || die "$DBI::errstr\n"; $database->do("delete from edits"); $database->do("insert into edits values(0,0,0,0,'')"); $database->disconnect(); print redirect("workplan.pl?workplan=$$form{newname}") }

Web site code:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w +3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Page Title</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" + /> <link rel="stylesheet" type="text/css" href="css/main.css" /> <script src="javascript/index.js">function Submit1_onclick() { } </script> </head> <body> <h1>Work Tools</h1> <br /><br /><br /> <div> <h3>Create New Workplan</h3> <form method="post" name="Create New" action="workplan/createedit. +pl" onsubmit="javascript:return validate();"> <label for="createfrom">Create based on Workplan:</label> <select name="createfrom"> <option value="testplan">testplan</option> <option value="tiffany">tiffany</option> <option value="chris">chris</option> </select><br /> <label for name="newname">Name of Workplan:</label> <input type="text" name="newname" id="newname" /> <input type="hidden" name="editnew" value="new" /> <input type="submit" value="Create" id="Submit1" language="jav +ascript" onclick="return Submit1_onclick()" /> </form> <br /> <h3>Edit Existing Workplan</h3> <form method="post" name="Create New" action="createedit.pl"> <label for="createfrom">Workplan:</label> <select name="createfrom"> <option value="111Test">111Test</option> <option value="3-5k mix">3-5k mix</option> <option value="3-5k shuffle">3-5k shuffle</option> <option value="tiffany">tiffany</option> <option value="chris">chris</option> </select> <input type="hidden" name="editnew" value="edit" /> <input type="submit" value="Edit" /> </form> </body> </html>

20080915 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: Database problem - dbdimp.c
by zentara (Cardinal) on Sep 09, 2008 at 13:55 UTC
Re: Database problem - dbdimp.c
by Anonymous Monk on Sep 09, 2008 at 13:17 UTC
    That code is dangerous.
    First line should be
    #!/usr/bin/perl -T --
    You shouldn't use form data without validation, especially to modify the file system. Also you shouldn't use Vars().
      Improved example
      #!c:\Perl\bin\Perl.exe -T -- use strict; use warnings; use CGI qw{ :standard }; use CGI::Carp qw(fatalsToBrowser); use File::Copy; use DBI; my $editnew = param('editnew'); my $createfrom = param('createfrom'); if ($editnew eq "edit") { print redirect("workplan.pl?workplan=$createfrom"); } elsif ($editnew eq "new") { my $newname = param('newname'); # strip all non-word, doesn't untaint s/\W// for $createfrom, $newname; die "Missing parameters newname and createfrom" unless $createfrom + and $newname; # limit filename to \w, untaint, see perldoc perlsec #same as below /(\w+)/ and $_ = $1 for $createfrom, $newname; $createfrom = $1 if $createfrom =~ /(\w+)/; $newname = $1 if $newname =~ /(\w+)/; copy("$createfrom.db","$newname.db") or die qq~copy("$createfrom.d +b","$newname.db") failed : $!~; my $database = DBI->connect("dbi:SQLite:dbname=$newname.db","","") + or die "$DBI::errstr\n"; $database->do("delete from edits"); $database->do("insert into edits values(0,0,0,0,'')"); $database->disconnect(); print redirect("workplan.pl?workplan=$newname") } __END__
Re: Database problem - dbdimp.c
by psini (Deacon) on Sep 09, 2008 at 13:14 UTC

    Please edit your post adding <code> tags. As it is now it is absolutely unreadable.

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Re: Database problem - dbdimp.c
by Anonymous Monk on Sep 09, 2008 at 13:55 UTC
    It means it can't open
    $$form{newname}
    probably because $$form{newname} has a path to a nonexistent directory
Re: Database problem - dbdimp.c
by cdarke (Prior) on Nov 21, 2008 at 14:39 UTC
    I just had this very error message, and it was simply that the directory name used for the database was invalid. One possibility is that, since you are on Windows, you are providing a path like this: $dir\dbname instead of: $dir\\dbname. Just a thought.
Re: Database problem - dbdimp.c
by Franco_1 (Initiate) on Sep 09, 2008 at 18:15 UTC
    Oh you beings of wisdom. I will review all the recommendations and post an update. For somebody who has never written a line of Perl code, it's very intimidating inheriting legacy code.
      Unfortunately, the recommendations did not help. :-(