Skip to content

Commit b8d02fe

Browse files
committed
Merge pull request #135
Fix fetching rows after calling $sth->execute() second time
2 parents 7eba1f3 + 4bdf27b commit b8d02fe

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

dbdimp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4594,6 +4594,8 @@ IV mariadb_st_execute_iv(SV* sth, imp_sth_t* imp_sth)
45944594
if (!mariadb_st_free_result_sets(sth, imp_sth, TRUE))
45954595
return -2;
45964596

4597+
imp_sth->currow = 0;
4598+
45974599
if (use_server_side_prepare)
45984600
{
45994601
if (imp_sth->use_mysql_use_result)

t/35prepare.t

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ use vars qw($test_dsn $test_user $test_password);
1313
$dbh = DbiTestConnect($test_dsn, $test_user, $test_password,
1414
{ RaiseError => 1, PrintError => 0 });
1515

16-
plan tests => 47;
16+
plan tests => 5+2*63;
1717

18-
ok(defined $dbh, "Connected to database");
18+
for my $mariadb_server_prepare (0, 1) {
19+
20+
$dbh->{mariadb_server_prepare} = $mariadb_server_prepare;
1921

2022
ok($dbh->do("DROP TABLE IF EXISTS dbd_mysql_t35prepare"), "Making slate clean");
2123

@@ -79,11 +81,41 @@ ok($ret_ref = $sth->fetchall_arrayref(),
7981
note "RETREF " . scalar @$ret_ref . "\n";
8082
ok(@{$ret_ref} == 4 , "\$ret_ref should contain four rows in result set");
8183

84+
# Check that repeated $sth->execute + $sth->fetchall_arrayref work as expected
85+
ok($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t35prepare LIMIT 2"));
86+
ok($sth->execute());
87+
is_deeply($sth->fetchall_arrayref(), [ [ 1, '1st first value' ], [ 2, '2nd second value' ] ]);
88+
ok($sth->execute());
89+
is_deeply($sth->fetchall_arrayref(), [ [ 1, '1st first value' ], [ 2, '2nd second value' ] ]);
90+
ok($sth->execute());
91+
is_deeply($sth->fetchall_arrayref(), [ [ 1, '1st first value' ], [ 2, '2nd second value' ] ]);
92+
93+
# Check that repeated $sth->execute + $sth->fetchrow_arrayref work as expected
94+
ok($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t35prepare LIMIT 3"));
95+
ok($sth->execute());
96+
is_deeply($sth->fetchrow_arrayref(), [ 1, '1st first value' ]);
97+
is_deeply($sth->fetchrow_arrayref(), [ 2, '2nd second value' ]);
98+
ok($sth->finish());
99+
ok($sth->execute());
100+
is_deeply($sth->fetchrow_arrayref(), [ 1, '1st first value' ]);
101+
is_deeply($sth->fetchrow_arrayref(), [ 2, '2nd second value' ]);
102+
ok($sth->finish());
103+
104+
# Check that repeated calls of $dbh->selectcol_arrayref, $dbh->prepare and $dbh->prepare_cached work as expected
105+
is_deeply($dbh->selectcol_arrayref("SELECT id FROM dbd_mysql_t35prepare LIMIT 2"), [ 1, 2 ]);
106+
is_deeply($dbh->selectcol_arrayref("SELECT id FROM dbd_mysql_t35prepare LIMIT 2"), [ 1, 2 ]);
107+
is_deeply($dbh->selectcol_arrayref($dbh->prepare("SELECT id FROM dbd_mysql_t35prepare LIMIT 2")), [ 1, 2 ]);
108+
is_deeply($dbh->selectcol_arrayref($dbh->prepare("SELECT id FROM dbd_mysql_t35prepare LIMIT 2")), [ 1, 2 ]);
109+
is_deeply($dbh->selectcol_arrayref($dbh->prepare_cached("SELECT id FROM dbd_mysql_t35prepare LIMIT 2")), [ 1, 2 ]);
110+
is_deeply($dbh->selectcol_arrayref($dbh->prepare_cached("SELECT id FROM dbd_mysql_t35prepare LIMIT 2")), [ 1, 2 ]);
111+
82112
ok($sth= $dbh->prepare("DROP TABLE IF EXISTS dbd_mysql_t35prepare"),
83113
"Testing prepare of dropping table");
84114

85115
ok($sth->execute(), "Executing drop table");
86116

117+
}
118+
87119
# Bug #20153: Fetching all data from a statement handle does not mark it
88120
# as finished
89121
ok($sth= $dbh->prepare("SELECT 1"), "Prepare - Testing bug #20153");

0 commit comments

Comments
 (0)