Skip to content

Instantly share code, notes, and snippets.

@Grinnz
Created July 28, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grinnz/9d6284fe36ec7d40249c to your computer and use it in GitHub Desktop.
Save Grinnz/9d6284fe36ec7d40249c to your computer and use it in GitHub Desktop.
DBD::SQLite multiple query issue
use strict;
use warnings;
use DBI;
use Test::More;
sub run {
my ($sql, $query) = @_;
my $sth;
while ($query) {
$sth = $sql->prepare_cached($query);
$sth->execute;
$query = $sth->{sqlite_unprepared_statements};
}
return $sth;
}
my %attrs = (AutoInactiveDestroy => 1, AutoCommit => 1, RaiseError => 1, PrintError => 0, sqlite_unicode => 1);
my $sql = DBI->connect('dbi:SQLite:dbname=:memory:','','',\%attrs);
my ($query, $sth, $result);
$query = "select exists(
select 1 from sqlite_master
where type = 'table' and name = 'mojo_migrations'
)";
$sth = run($sql, $query);
$result = $sth->fetchall_arrayref;
ok(!$result->[0][0], "Table does not exist");
$query = 'create table if not exists mojo_migrations (
name text unique not null,
version integer not null check (version >= 0)
)';
$sth = run($sql, $query);
$query = "select exists(
select 1 from sqlite_master
where type = 'table' and name = 'mojo_migrations'
)";
$sth = run($sql, $query);
$result = $sth->fetchall_arrayref;
ok($result->[0][0], "Table exists");
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment