Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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 ( [id://1213306]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^4: Can't connect to data source 'DBI:SQLite:\C:\Users\DON\Desktop\data.db
by Anonymous Monk on Apr 21, 2018 at 08:25 UTC

    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

        if you suspect then you don't know

        It is silly to suspect DBI has a problem with unicode, if DBI did, it would manifest for OP without PAR

        DBI does not have a problem with unicode in a dsn, it simply doesn't care,

        As previously stated, the problem as reported by OP is unreproducible

        This is where the error comes from

        # 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 s +tyle. $driver = $old_driver || $1 || $ENV{DBI_DRIVER} or Carp::croak("Can't connect to data source '$dsn' " ."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 set)");

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

    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 ] );
Re^4: Can't connect to data source 'DBI:SQLite:\C:\Users\DON\Desktop\data.db
by Anonymous Monk on Apr 21, 2018 at 07:25 UTC

    will be marked as UTF characters rather than bytes

    There is just bytes or characters, and encoding gives characters

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1213306]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-03-29 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found