Created
July 28, 2015 15:39
-
-
Save Grinnz/9d6284fe36ec7d40249c to your computer and use it in GitHub Desktop.
DBD::SQLite multiple query issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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