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

Hello friends... I am working on SunSO through putty..Now we have a script which uses DBI module to connect to the sqlite. the script is working fine...But when I am trying to directly (not through DBI but through command line) access the sqlite server( by giving sqlite dbname or sqlite3 dbname)...its giving the error "sqlite not found" or "sqlite3 not found"...when sqlite is not present here how come script is connecting to database?please help... this is how my script is successfully connecting to sqlite3

my $dbh = DBI->connect('DBI:SQLite:abc.db', $userid, $password, { Rais +eError => 1, AutoCommit => 0 }) or die $DBI::errstr;
<

Replies are listed 'Best First'.
Re: How to connect to SQLite database.
by Anonymous Monk on Jul 16, 2014 at 08:45 UTC

    As far as I know the Perl SQLite module does not require sqlite3 to be installed, so you'll have to install it separately, either through your system's package manager or manually.

Re: How to connect to SQLite database.
by Corion (Patriarch) on Jul 16, 2014 at 12:04 UTC

    If you only have DBI, there are command shells that allow you to connect to any DBI database and execute commands. For example DBI::Shell allows that.

    If you are content with just running commands from the command line, DBIx::RunSQL can be abused for that too:

    #!/opt/perl/perl-5.18/bin/perl -w use strict; use DBIx::RunSQL; my $options= DBIx::RunSQL->parse_command_line( 'sql_admin.pl' ); $options->{ user } ||= $ENV{ IQ_USER } || 'scott'; $options->{ password } ||= $ENV{ IQ_PASSWORD } || 'tiger'; if( ! $options->{ sql }) { $options->{ sql }= shift @ARGV; }; no warnings 'newline'; if( ! -f $options->{ sql }) { $options->{ sql }= \"$options->{sql}"; # in-memory file }; $options->{ dsn }||= $ENV{IQ_DSN} || 'dbi:SQLAnywhere:eng=q123;links=t +cpip'; DBIx::RunSQL->create( %$options );
Re: How to connect to SQLite database.
by Tux (Canon) on Jul 16, 2014 at 12:35 UTC

    Wow, I just learned that dbname= is optional in DBD::SQLite. I had to test that to believe it. And it is not even documented :)

    my $dbh = DBI->connect ("DBI:SQLite:dbname=abc.db", $userid, $password +, { RaiseError => 1, AutoCommit => 0, }) or die $DBI::errstr;

    would be the documented and preferred syntax. (Not that that would solve your problem though)


    Enjoy, Have FUN! H.Merijn