in reply to pp concatenate path

Hi,

Use forward slashes for filename? Esp on windows

'DBI:SQLite:C:/Users/DON/Desktop/data.db

I doubt your non-par version works at all

If does works as you say, it probably doesn't do what you think it does, it probably opens an ADStream and not the filename you wanted.

For \C:\Users\DON\Desktop\data.db

The filename is "\C"

and the stream is " users" ... but I've never seem a stream with slashes so that would fail also

  • Comment on Re: Can't connect to data source 'DBI:SQLite:\C:\Users\DON\Desktop\data.db
  • Download Code

Replies are listed 'Best First'.
Re^2: Can't connect to data source 'DBI:SQLite:\C:\Users\DON\Desktop\data.db
by IB2017 (Pilgrim) on Apr 21, 2018 at 06:52 UTC

    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

      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!

        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)

        will be marked as UTF characters rather than bytes

        There is just bytes or characters, and encoding gives characters

      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