Skip to content

Test::MockFile & DBD::SQLite #91

@atoomic

Description

@atoomic

Would be nice to be able to use DBI with a mocked sqlite file.

The following sample is failing on ping and does not see the file as created.
Not sure how easy it would be to fix it.

note that it seems that we can write/read to it, probably because it fall back to in memory

#!perl

use Test::More;
use Test::MockFile;

use DBI;

my $f = q[/tmp/mydb.sqlite];

unlink $f;

# Comment me to run unmocked
my $mocked = Test::MockFile->file( $f );

my $dbh = DBI->connect("dbi:SQLite:dbname=$f","","", {
  AutoCommit => 1,
  RaiseError => 1,
});

ok $dbh->ping, 'ping';

ok $dbh->do( <<EOS ), 'create table';
CREATE TABLE groups (
   id INTEGER PRIMARY KEY,
   name TEXT NOT NULL
)
EOS


my $sth = $dbh->prepare("INSERT INTO groups VALUES (?, ?)");
ok $sth->execute(1 => q[group one] );

note explain [ $dbh->selectall_array("select * from groups") ];

ok -f $f, 'sqlite file created';

output

╰─> perl test.pl
not ok 1 - ping
#   Failed test 'ping'
#   at test.pl line 21.
ok 2 - create table
ok 3
# [
#   [
#     1,
#     'group one'
#   ]
# ]
not ok 4 - sqlite file created

note: consider running DBI_TRACE=2 perl test.pl

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions