1use strict;
2use warnings;
3
4use Test::More;
5use DBI;
6
7use vars qw($test_dsn $test_user $test_password);
8require "t/lib.pl";
9
10my $dbh = eval { DBI->connect($test_dsn, $test_user, $test_password, { PrintError => 1, RaiseError => 1, AutoCommit => 0, mysql_server_prepare => 1, mysql_server_prepare_disable_fallback => 1 }) };
11plan skip_all => "no database connection" if $@ or not $dbh;
12plan skip_all => "You must have MySQL version 4.1.3 and greater for this test to run" if $dbh->{mysql_clientversion} < 40103 or $dbh->{mysql_serverversion} < 40103;
13
14plan tests => 39;
15
16my $sth;
17
18ok $dbh->do("CREATE TEMPORARY TABLE t (i INTEGER NOT NULL, n LONGBLOB)");
19
20ok $sth = $dbh->prepare("INSERT INTO t(i, n) VALUES(?, ?)");
21ok $sth->execute(1, "x" x 10);
22ok $sth->execute(2, "x" x 100);
23ok $sth->execute(3, "x" x 1000);
24ok $sth->execute(4, "x" x 10000);
25ok $sth->execute(5, "x" x 100000);
26ok $sth->execute(6, "x" x 1000000);
27ok $sth->finish();
28
29ok $sth = $dbh->prepare("SELECT * FROM t WHERE i=? AND n=?");
30
31ok $sth->bind_param(2, "x" x 1000000);
32ok $sth->bind_param(1, "abcx", 12);
33ok $sth->execute();
34
35ok $sth->bind_param(2, "a" x 1000000);
36ok $sth->bind_param(1, 1, 3);
37ok $sth->execute();
38
39ok $sth->finish();
40
41ok $sth = $dbh->prepare("SELECT * FROM t WHERE i=? AND n=?");
42ok $sth->execute();
43ok $sth->finish();
44
45ok $sth = $dbh->prepare("SELECT 1 FROM t WHERE i = ?" . (" OR i = ?" x 10000));
46ok $sth->execute((1) x (10001));
47ok $sth->finish();
48
49my $test;
50ok $sth = $dbh->prepare("SELECT i,n FROM t WHERE i = ?");
51
52ok $sth->execute(1);
53ok $sth->fetchrow_arrayref();
54
55ok $sth->execute(2);
56$test = map { $_ } 'a';
57ok $sth->fetchrow_arrayref();
58
59ok $sth->execute(3);
60$test = map { $_ } 'b' x 10000000; # try to reuse released memory
61ok $sth->fetchrow_arrayref();
62
63ok $sth->execute(4);
64$test = map { $_ } 'cd' x 10000000; # try to reuse of released memory
65ok $sth->fetchrow_arrayref();
66
67ok $sth->execute(5);
68$test = map { $_ } 'efg' x 10000000; # try to reuse of released memory
69ok $sth->fetchrow_arrayref();
70
71ok $sth->execute(6);
72$test = map { $_ } 'hijk' x 10000000; # try to reuse of released memory
73ok $sth->fetchrow_arrayref();
74
75ok $sth->finish();
76
77ok $dbh->do("SELECT 1 FROM t WHERE i = ?" . (" OR i = ?" x 10000), {}, (1) x (10001));
78
79ok $dbh->disconnect();
80