Unable to run sql statements in perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vibhakhushi
    New Member
    • Mar 2010
    • 33

    Unable to run sql statements in perl

    Hi All,
    I am newbie in Perl Scripting. I have a requirement where I need to execute sql file on an Sqlite database.
    sqlite database has been set with password.
    I could connect to database. But when I try to execute sql statements its giving as "DBD::SQLite::d b prepare failed: file is encrypted or is not a database at <SQL> line 1." Here is my code

    Code:
    use DBI;
    
    my $dbfile = '../myData.db';      # your database file
    my $dbh = DBI->connect(          # connect to your database, create if needed
        "dbi:SQLite:dbname=$dbfile", # DSN: dbi, driver, database file
        "",                          # no user
        "xxxxxxxxxxxxxxxxxxxx",  #password
        { RaiseError => 1 },         # complain if something goes wrong
    ) or die $DBI::errstr;
    
    open SQL, "<../myDB.sql" or die $!;
    while(<SQL>)
    {
    	($dbh->prepare($_))->execute();
    }
    close SQL;
    I created that db in Lita(SqLite Administration Tool)and have set the password.
    I am running the perl scripts on Windows XP using ActivePerl version 5.12.2.
  • chorny
    Recognized Expert New Member
    • Jan 2008
    • 80

    #2
    Is every SQL statement on it's own line? I mean 1:1 relationship statement:line.

    Comment

    Working...