Skip to content

Commit

Permalink
Set auto_increment_offset explicitly in tests.
Browse files Browse the repository at this point in the history
Fixes [RT83487](https://rt.cpan.org/Ticket/Display.html?id=83487)

Also I switched to use temporary tables which is recommended in the
DBI guidelines and which saves 'drop table' and 'drop table if exists'
  • Loading branch information
mbeijen committed Oct 10, 2013
1 parent 6e9f3b5 commit 3c50975
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
1 change: 1 addition & 0 deletions ChangeLog
@@ -1,4 +1,5 @@
2013-??-?? Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.025)
* set auto_increment_offset explicitly to make tests pass if they are set on server - RT83487, reported by Ian Barton.
* Assume 'localhost' when testport is set but no testhost in Makefile.PL - RT83496, reported by Philip Stoev.
* Corrected documentation for mysql_init_command option - Alexey Molchanov <alexey.molchanov@portaone.com>
* Skip stored procedure tests if user is unpriviliged - RT83348 - Chris Weyl <cweyl@alumni.drew.edu>
Expand Down
18 changes: 9 additions & 9 deletions t/31insertid.t
@@ -1,5 +1,7 @@
#!perl -w
# vim: ft=perl
#!/usr/bin/perl

use strict;
use warnings;

use strict;
use DBI ();
Expand All @@ -15,15 +17,16 @@ eval{$dbh = DBI->connect($test_dsn, $test_user, $test_password,
{RaiseError => 1});};

if ($@) {
plan skip_all =>
plan skip_all =>
"ERROR: $DBI::errstr. Can't continue test";
}
plan tests => 18;
plan tests => 18;

ok $dbh->do("DROP TABLE IF EXISTS $table");
ok $dbh->do('SET @@auto_increment_offset = 1');
ok $dbh->do('SET @@auto_increment_increment = 1');

my $create = <<EOT;
CREATE TABLE $table (
CREATE TEMPORARY TABLE $table (
id INT(3) PRIMARY KEY AUTO_INCREMENT NOT NULL,
name VARCHAR(64))
EOT
Expand Down Expand Up @@ -58,11 +61,8 @@ cmp_ok $sth->{'mysql_insertid'}, '==', $max_id->[0], "sth insert id $sth->{'mysq

cmp_ok $dbh->{'mysql_insertid'}, '==', $max_id->[0], "dbh insert id $dbh->{'mysql_insertid'} == max(id) $max_id->[0] in $table";


ok $sth->finish();

ok $sth2->finish();

ok $dbh->do("DROP TABLE $table");

ok $dbh->disconnect();
27 changes: 10 additions & 17 deletions t/40bindparam2.t
@@ -1,13 +1,7 @@
#!perl -w
# vim: ft=perl

#
# $Id: 40bindparam.t 6304 2006-05-17 21:23:10Z capttofu $
#
# This is a skeleton test. For writing new tests, take this file
# and modify/extend it.
#
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use DBI ();
Expand All @@ -21,13 +15,14 @@ eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,

if ($@) {
plan skip_all => "ERROR: $DBI::errstr. Can't continue test";
}
}
plan tests => 13;

ok $dbh->do("DROP TABLE IF EXISTS $table"), "drop table $table";
ok $dbh->do('SET @@auto_increment_offset = 1');
ok $dbh->do('SET @@auto_increment_increment = 1');

my $create= <<EOT;
CREATE TABLE $table (
my $create= <<EOT;
CREATE TEMPORARY TABLE $table (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
num INT(3))
EOT
Expand All @@ -41,10 +36,10 @@ ok ($rows= $dbh->selectall_arrayref("SELECT * FROM $table"));

is $rows->[0][1], 1, "\$rows->[0][1] == 1";

ok ($sth = $dbh->prepare("UPDATE $table SET num = ? WHERE id = ?"));
ok (my $sth = $dbh->prepare("UPDATE $table SET num = ? WHERE id = ?"));

ok ($sth->bind_param(2, 1, SQL_INTEGER()));

ok ($sth->execute());

ok ($sth->finish());
Expand All @@ -53,6 +48,4 @@ ok ($rows = $dbh->selectall_arrayref("SELECT * FROM $table"));

ok !defined($rows->[0][1]);

ok ($dbh->do("DROP TABLE $table"));

ok ($dbh->disconnect());

0 comments on commit 3c50975

Please sign in to comment.