~percona-dev/percona-server/release-5.5.11-20.2-fix-bug-764138

« back to all changes in this revision

Viewing changes to HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test13.pl

  • Committer: Ignacio Nin
  • Date: 2011-03-13 17:18:23 UTC
  • mfrom: (33.3.17 release-5.5.8-20)
  • Revision ID: ignacio.nin@percona.com-20110313171823-m06xs104nekulywb
Merge changes from release-5.5.8-20 to 5.5.9

Merge changes from the release branch of 5.5.8 to 5.5.9. These include
the HandlerSocket and UDF directories and the building scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# vim:sw=2:ai
 
4
 
 
5
# test for auto_increment
 
6
 
 
7
BEGIN {
 
8
        push @INC, "../common/";
 
9
};
 
10
 
 
11
use strict;
 
12
use warnings;
 
13
use hstest;
 
14
 
 
15
my $dbh = hstest::init_testdb();
 
16
my $table = 'hstesttbl';
 
17
my $tablesize = 10;
 
18
$dbh->do(
 
19
  "create table $table (" .
 
20
  "k int primary key auto_increment, " .
 
21
  "v1 varchar(30), " .
 
22
  "v2 varchar(30)) " .
 
23
  "engine = myisam default charset = binary");
 
24
srand(999);
 
25
 
 
26
my $sth = $dbh->prepare("insert into $table values (?,?,?)");
 
27
for (my $i = 0; $i < $tablesize; ++$i) {
 
28
  my $k = 0;
 
29
  my $v1 = "v1sql_" . $i;
 
30
  my $v2 = "v2sql_" . $i;
 
31
  $sth->execute($k, $v1, $v2);
 
32
}
 
33
 
 
34
my %valmap = ();
 
35
 
 
36
print "HSINSERT\n";
 
37
my $hs = hstest::get_hs_connection(undef, 9999);
 
38
my $dbname = $hstest::conf{dbname};
 
39
$hs->open_index(1, $dbname, $table, '', 'k,v1,v2');
 
40
# inserts with auto_increment
 
41
for (my $i = 0; $i < $tablesize; ++$i) {
 
42
  my $k = 0;
 
43
  my $v1 = "v1hs_" . $i;
 
44
  my $v2 = "v2hs_" . $i;
 
45
  my $r = $hs->execute_insert(1, [ $k, $v1, $v2 ]);
 
46
  my $err = $r->[0];
 
47
  if ($err != 0) {
 
48
    my $err_str = $r->[1];
 
49
    print "$err $err_str\n";
 
50
  }
 
51
}
 
52
# make sure that it works even when inserts are pipelined. these requests
 
53
# are possibly executed in a single transaction.
 
54
for (my $i = 0; $i < $tablesize; ++$i) {
 
55
  my $k = 0;
 
56
  my $v1 = "v1hs3_" . $i;
 
57
  my $v2 = "v2hs3_" . $i;
 
58
  my $r = $hs->execute_multi([
 
59
        [ 1, '+', [$k, $v1, $v2] ],
 
60
        [ 1, '+', [$k, $v1, $v2] ],
 
61
        [ 1, '+', [$k, $v1, $v2] ],
 
62
        ]);
 
63
  for (my $i = 0; $i < 3; ++$i) {
 
64
    my $err = $r->[$i]->[0];
 
65
    if ($err != 0) {
 
66
      my $err_str = $r->[1];
 
67
      print "$err $err_str\n";
 
68
    }
 
69
  }
 
70
}
 
71
undef $hs;
 
72
 
 
73
dump_table();
 
74
 
 
75
sub dump_table {
 
76
  print "DUMP_TABLE\n";
 
77
  my $aref = $dbh->selectall_arrayref("select k,v1,v2 from $table order by k");
 
78
  for my $row (@$aref) {
 
79
    my ($k, $v1, $v2) = @$row;
 
80
    $v1 = "[null]" if !defined($v1);
 
81
    $v2 = "[null]" if !defined($v2);
 
82
    print "$k $v1 $v2\n";
 
83
    # print "MISMATCH\n" if ($valmap{$k} ne $v);
 
84
  }
 
85
}
 
86