in reply to Re: Can't connect to data source 'DBI:SQLite:\C:\Users\DON\Desktop\data.db
in thread pp concatenate path

Thank you monks. I have tried any possible solution (cleaning the path for Windows, setting ENV etc.), but NO solution works in the packed versions (pp). And I really do not understand why! Here is a better script that reproduces the problem (the first part works, the second no).

use warnings; use strict; use DBI; use DBD::SQLite; #Working part with hard coded path my $dbfile1="C:/users/DON/Desktop/data.db"; print "\nFIRST Connection to dbfile path read from script ($dbfile1) . +.. "; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile1","","") || die $DBI +::errstr; print "done!\n\n"; #NOT working part with path from file my $dbfile2; print "Reading dbfile path from configuration file... "; my $FileInput="config.txt";#simple txt file containing this: C:/users/ +DON/Desktop/data.db open my $FH, "<:encoding(UTF-8)", $FileInput || die (print "can't open + file $dbfile2"); while (my $line = <$FH>) { $dbfile2 = $line; chomp $dbfile2; } print "$dbfile2\n"; print "SECOND Connection with dbfile read from file $dbfile2 ... "; $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile2","","")|| die $DBI::er +rstr; print "done!\n";

Again, from the command line the script works correctly. The by pp compiled version behaves like this:

FIRST Connection to dbfile path read from script (C:/users/DON/Desktop +/data.db) ... done! Reading dbfile path from configuration file... C:/users/DON/Desktop/da +ta.db Can't connect to data source 'dbi:SQLite:dbname=C:/users/DON/Desktop/d +ata.db' because I can't work out what driver to use (it doesn't seem +to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not s +et) at script/myscript.pl line 22. SECOND Connection with dbfile read from file C:/users/DON/Desktop/data +.db ...
I

I've been stuck for days on this problem. So any help is very much appreciated

Replies are listed 'Best First'.
Re^3: Can't connect to data source 'DBI:SQLite:\C:\Users\DON\Desktop\data.db
by huck (Prior) on Apr 21, 2018 at 07:12 UTC

    Besides noticing that open my $FH, "<:encoding(UTF-8)", $FileInput || die (print "can't open file $dbfile2"); should probably be open my $FH, "<:encoding(UTF-8)", $FileInput || die (print "can't open file $FileInput");

    i wonder what adding

    if ($dbfile1 eq $dbfile2){ print "same\n";} else {print "different\n";}
    would output. seeing "<:encoding(UTF-8)" makes me wonder even more as dbfile2 will be marked as UTF characters rather than bytes

    Edit: and that means the first parm to the second connect will be marked as UTF as well to doesnt it? Maybe you should try creating both "dbi:SQLite:dbname=$..." strings outside the connect call and compare them as well.

      PS: your comparison (with "<:encoding(UTF-8)")

      if ($dbfile1 eq $dbfile2){ print "same\n";} else {print "different\n";}

      returns always same, both in the version compiled with pp and in the script version! So I do not really understand where the problem lies!

        I suspect it means that DBI has problems dealing with connect strings marked as UTF

      THANK YOU!

      eliminating the "<:encoding(UTF-8)" solves the problem, even if I am not quite sure why. As my file is encoded in UTF8, how am I supposed to open it correctly and read it?

      Just to complete the picture

      This is perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x +86-multi-thread PAR Packager, version 1.043 (PAR version 1.015) DBD::SQLite is up to date (1.58)

        even if I am not quite sure why. As my file is encoded in UTF8, how am I supposed to open it correctly and read it?

        What output does this program produce for you? After being packed with pp?

        #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; open my($fh),'<:encoding(UTF-8)', 'deleteme.txt' or die $!; my $file = <$fh>; close $fh; my $dsn = "dbi:SQLite:dbname=$file"; # extract dbi:driver prefix from $dsn into $1 $dsn =~ s/^dbi:(\w*?)(?:\((.*?)\))?://i or '' =~ /()/; # ensure $1 etc are empty if match fails my $driver_attrib_spec = $2 || ''; # Set $driver. Old style driver, if specified, overrides new dsn style +. my $driver = $1 or die pp( $file, $dsn, [ $1, $2 ] ); dd( $file, $dsn, [ $1, $2 ] );

      will be marked as UTF characters rather than bytes

      There is just bytes or characters, and encoding gives characters

Re^3: Can't connect to data source 'DBI:SQLite:\C:\Users\DON\Desktop\data.db
by Anonymous Monk on Apr 21, 2018 at 07:21 UTC

    I've been stuck for days on this problem. So any help is very much appreciated

    What is your  perl -V ?

    First line from  pp --version ?

    You par packer command line  pp .... ?

    Additional output if you add  DBI->trace(1); ?

    DBI/DBD::SQLite version?

    I cannot reproduce this error on v5.16.1 with PAR Packager, version 1.036 (PAR version 1.015) and DBI 1.636 DBD::SQLite 1.48 and old windows

      Additional output

      Reading dbfile path from configuration file... C:/users/DON/Desktop/da +ta.db same DBI 1.641-ithread default trace level set to 0x0/1 (pid 12552 pi 2 +6e26a4) at myscript.pl line 20 via PAR.pm line 645 -> DBI->connect(dbi:SQLite:dbname=C:/users/DON/Desktop/data.db, , +****) sqlite trace: Closing DB at dbdimp.c line 640 sqlite trace: rc = 0 at dbdimp.c line 642 <- DESTROY(DBI::db=HASH(0x554f094))= ( undef ) [1 items] at PAR.pm + line 645 Can't connect to data source 'dbi:SQLite:dbname=C:/users/DON/Desktop/d +ata.db' because I can't work out what driver to use (it doesn't seem +to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not s +et) at script/myscript.pl line 22. <- disconnect_all= ( '' ) [1 items] at DBI.pm line 756 SECOND Connection with dbfile read from file C:/users/DON/Desktop/data +.db ... ! <- DESTROY(DBI::dr=HASH(0x554eb84))= ( undef ) [1 items] +during global destruction
        What about the other questions?