#!/usr/local/bin/perl
#
# $Id$
#
# This tests multiquery results
#
$^W = 1;
use Data::Dumper;
#
# Include lib.pl
#
use DBI ();
$mdriver = "";
foreach $file ("lib.pl", "t/lib.pl") {
do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
exit 10;
}
if ($mdriver ne '') {
last;
}
}
if ($mdriver eq 'whatever') {
print "1..0\n";
exit 0;
}
sub Version () {
my $dbh = DBI->connect($test_dsn, $test_user, $test_password)
or ErrMsgF("Cannot connect: Error %s.\n\n"
. "Make sure, your database server is up and running.\n"
. "Check that '$test_dsn' references a valid database"
. " name.\nDBI error message: %s\n",
$DBI::err, $DBI::errstr);
my $version = $dbh->{'mysql_serverinfo'};
$version =~ /(\d+)/;
return int $1;
}
#
# Main loop; leave this untouched, put tests after creating
# the new table.
#
while (Testing()) {
#
# Test the version. if < 5.x these can all be skipped
#
my $version = Version();
if ($version < 5) {
Skip("Skipping all multi_transaction tests - mysql version $version < 5.x");
} else {
Test($state or ($dbh = DBI->connect($test_dsn, $test_user,
$test_password, { mysql_multi_statements => 1 })),
undef, undef)
or ErrMsgF("Cannot connect: Error %s.\n\n"
. "Make sure, your database server is up and running.\n"
. "Check that '$test_dsn' references a valid database"
. " name.\nDBI error message: %s\n",
$DBI::err, $DBI::errstr);
#
# Find a possible new table name
#
Test($state or $table = FindNewTable($dbh))
or DbiError($dbh->err, $dbh->errstr);
#
# Create a new table; EDIT THIS!
#
Test($state or ($def = TableDefinition($table,
["id", "INTEGER", 4, 0],
["name", "CHAR", 64, 0]),
$dbh->do($def)))
or DbiError($dbh->err, $dbh->errstr);
#
# Insert test data into the test table.......
#
Test($state or $dbh->do("INSERT INTO $table"
. " VALUES(1, 'Alligator Descartes');"
. "INSERT INTO $table"
. " VALUES(2, 'Foo Bar')"))
or DbiError($dbh->err, $dbh->errstr);
#
# Create a new stored procedure
#
Test($state or $dbh->do(" CREATE PROCEDURE test() "
. "begin "
. "SELECT * from $table; "
. "end ;"))
or DbiError($dbh->err, $dbh->errstr);
#
# Disconnect
#
Test($state or $dbh->disconnect)
or ErrMsgF("Failed to disconnect: err %s, errstr %s.\n",
$dbh->err, $dbh->errstr);
#
# Reconnect with multi_results capability
#
Test($state or ($dbh = DBI->connect($test_dsn, $test_user,
$test_password, { mysql_multi_results => 1 })),
undef, undef)
or ErrMsgF("Cannot connect: Error %s.\n\n"
. "Make sure, your database server is up and running.\n"
. "Check that '$test_dsn' references a valid database"
. " name.\nDBI error message: %s\n",
$DBI::err, $DBI::errstr);
#
# Prepare a handle for calling the procedure
#
Test($state or $sth = $dbh->prepare("call test()"))
or DbiError($dbh->err, $dbh->errstr);
#
# Call the procedure
#
Test($state or $sth->execute())
or DbiError($dbh->err, $dbh->errstr);
#
# Check that we got two rows back
#
Test($state or ($rv = $sth->rows()) == 2)
or ErrMsgF("Expected 2 rows, got %s.\n", $rv);
#
# finish the handle
#
Test($state or $sth->finish())
or DbiError($dbh->err, $dbh->errstr);
#
# Finally drop the test table.
#
Test($state or $dbh->do("DROP TABLE $table"))
or DbiError($dbh->err, $dbh->errstr);
#
# Drop the procedure
#
Test($state or $dbh->do("DROP PROCEDURE test"))
or DbiError($dbh->err, $dbh->errstr);
#
# Disconnect
#
Test($state or $dbh->disconnect)
or ErrMsgF("Failed to disconnect: err %s, errstr %s.\n",
$dbh->err, $dbh->errstr);
}
}