AnyEvent-DBI-MySQL
view release on metacpan or search on metacpan
$res = shift;
is($res, 1, 'execute');
is_deeply($sth2->fetchrow_hashref(), {id=>4,s=>'two'}, 'prepare_cached');
is_deeply($sth2->fetchrow_hashref(), undef, '⦠no more records');
is($sth1, $sth2, 'sth really was cached');
NEXT();
});
},
sub {
$sth = $dbh->prepare('SELECT * FROM Async WHERE id=?');
$sth->bind_param(1, 5);
$sth->execute(sub {
$res = shift;
is($res, 1, 'execute');
is_deeply($sth->fetchrow_hashref(), {id=>5,s=>'three'}, 'bind_param');
NEXT();
});
},
sub {
$sth = $dbh->prepare('INSERT INTO Async (id,s) VALUES (?,?)', {async=>0});
my $tuples = $sth->execute_array(
{ ArrayTupleStatus => \my @tuple_status },
[ 10, 20 ],
[ 'ten', 'twenty' ],
);
t/async_cv.t view on Meta::CPAN
is_deeply($sth1->fetchrow_hashref(), {id=>5,s=>'three'}, 'prepare_cached');
is_deeply($sth1->fetchrow_hashref(), undef, '⦠no more records');
($sth2 = $dbh->prepare_cached('SELECT * FROM Async WHERE id=?'))->execute(4, $cv=AE::cv);
is($cv->recv, 1, 'execute');
is_deeply($sth2->fetchrow_hashref(), {id=>4,s=>'two'}, 'prepare_cached');
is_deeply($sth2->fetchrow_hashref(), undef, '⦠no more records');
is($sth1, $sth2, 'sth really was cached');
$sth = $dbh->prepare('SELECT * FROM Async WHERE id=?');
$sth->bind_param(1, 5);
$sth->execute($cv=AE::cv);
is($cv->recv, 1, 'execute');
is_deeply($sth->fetchrow_hashref(), {id=>5,s=>'three'}, 'bind_param');
$sth = $dbh->prepare('INSERT INTO Async (id,s) VALUES (?,?)', {async=>0});
my $tuples = $sth->execute_array(
{ ArrayTupleStatus => \my @tuple_status },
[ 10, 20 ],
[ 'ten', 'twenty' ],
);
is($tuples, 2, '[SYNC] execute_array');
is_deeply(\@tuple_status, [1,1], '⦠ArrayTupleStatus');
my ($rv, $sth) = @_;
is($rv, undef, 'INSERT failed');
like($sth->errstr, qr/Duplicate/, 'got error');
});
$dbh->prepare('INSERT INTO Async SET id=?,s=?',
{async=>0})->execute(1,'one',2,'two',
sub {
my ($rv, $sth) = @_;
is($rv, undef, 'INSERT failed');
like($sth->errstr, qr/bind variables/, 'got error from execute()');
});
$dbh->selectrow_array('SELECT * FROM Async',
{async=>0},
sub {
my (@res) = @_;
is_deeply \@res, [1,'one'], 'selectrow_array';
is($dbh->errstr, undef, 'no error');
});
my ($res) = @_;
is_deeply $res, undef, 'selectcol_arrayref failed';
like($dbh->errstr, qr/Unknown column/, 'got error');
});
$dbh->selectcol_arrayref('SELECT bad1 FROM Async',
{async=>0}, 1,
sub {
my ($res) = @_;
is_deeply $res, undef, 'selectcol_arrayref failed';
like($dbh->errstr, qr/bind variables/, 'got error from execute()');
});
push my @tests,
sub {
$dbh->do('CREATE TABLE IF NOT EXISTS Async
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, s VARCHAR(255) NOT NULL)',
sub {
my ($rv, $dbh) = @_;
is($rv, '0E0', 'CREATE TABLE');
is($dbh->errstr, undef, 'no error');
like($sth->errstr, qr/Duplicate/, 'got error');
NEXT();
});
},
sub {
$dbh->prepare('INSERT INTO Async SET id=?,s=?',
)->execute(1,'one',2,'two',
sub {
my ($rv, $sth) = @_;
is($rv, undef, 'INSERT failed');
like($sth->errstr, qr/bind variables/, 'got error from execute()');
NEXT();
});
},
sub {
$dbh->selectrow_array('SELECT * FROM Async',
sub {
my (@res) = @_;
is_deeply \@res, [1,'one'], 'selectrow_array';
is($dbh->errstr, undef, 'no error');
NEXT();
is_deeply $res, undef, 'selectcol_arrayref failed';
like($dbh->errstr, qr/Unknown column/, 'got error');
NEXT();
});
},
sub {
$dbh->selectcol_arrayref('SELECT bad1 FROM Async', {}, 1,
sub {
my ($res) = @_;
is_deeply $res, undef, 'selectcol_arrayref failed';
like($dbh->errstr, qr/bind variables/, 'got error from execute()');
NEXT();
});
},
sub {
$dbh->do('DROP TABLE Async');
done_testing();
exit;
};
},
sub {
$res = ($sth2 = $dbh->prepare_cached('SELECT * FROM Async WHERE id=?', {async=>0}))->execute(4);
is($res, 1, 'execute');
is_deeply($sth2->fetchrow_hashref(), {id=>4,s=>'two'}, 'prepare_cached');
is_deeply($sth2->fetchrow_hashref(), undef, '⦠no more records');
is($sth1, $sth2, 'sth really was cached');
},
sub {
$sth = $dbh->prepare('SELECT * FROM Async WHERE id=?', {async=>0});
$sth->bind_param(1, 5);
$res = $sth->execute();
is($res, 1, 'execute');
is_deeply($sth->fetchrow_hashref(), {id=>5,s=>'three'}, 'bind_param');
},
sub {
$sth = $dbh->prepare('INSERT INTO Async (id,s) VALUES (?,?)', {async=>0});
my $tuples = $sth->execute_array(
{ ArrayTupleStatus => \my @tuple_status },
[ 10, 20 ],
[ 'ten', 'twenty' ],
);
is($tuples, 2, '[SYNC] execute_array');
is_deeply(\@tuple_status, [1,1], '⦠ArrayTupleStatus');
( run in 1.039 second using v1.01-cache-2.11-cpan-2398b32b56e )