Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix undef error

  • Loading branch information...
commit 179fc9a678bacf7095546b13d214aec5d7c99731 1 parent 9199c70
@nobuo-danjou nobuo-danjou authored
Showing with 54 additions and 4 deletions.
  1. +13 −4 lib/MiniDBD/mysql.pm6
  2. +41 −0 t/05.t
View
17 lib/MiniDBD/mysql.pm6
@@ -72,6 +72,11 @@ sub mysql_options( OpaquePointer $mysql_client, Int $option, Str $arg)
is native('libmysqlclient')
{ ... }
+sub mysql_thread_id( OpaquePointer $mysql_client )
+ returns Int
+ is native('libmysqlclient')
+ { ... }
+
#-----------------------------------------------------------------------
class MiniDBD::mysql::StatementHandle does MiniDBD::StatementHandle {
@@ -172,14 +177,14 @@ class MiniDBD::mysql::Result {
return @row;
} else {
$!connection.finish;
- }
+ }
}
return;
}
method fetchrow_hashref {
my %result;
- my @row = self.fetchrow_array;
+ my @row = self.fetchrow_array or return;
for 0 ..^ $!field_count -> $i {
%result{@!column_names[$i]} = @row[$i];
}
@@ -187,8 +192,10 @@ class MiniDBD::mysql::Result {
}
method free {
- mysql_free_result($!result_set);
- $!connection.check_mysql_error;
+ if defined($!result_set) {
+ mysql_free_result($!result_set);
+ $!connection.check_mysql_error;
+ }
}
}
@@ -202,6 +209,7 @@ class MiniDBD::mysql::Connection does MiniDBD::Connection {
method mysql_client {
if (defined $!mysql_client) {
+ self.finish;
my $status = mysql_ping($!mysql_client);
if ($status != 0) {
self.connect;
@@ -282,6 +290,7 @@ class MiniDBD::mysql::Connection does MiniDBD::Connection {
method disconnect () {
self.finish;
mysql_close($!mysql_client);
+ $!mysql_client = Mu;
return Bool::True;
}
View
41 t/05.t
@@ -0,0 +1,41 @@
+use v6;
+use Test;
+use t::lib;
+
+ok my $dbh = t::lib::dbh, 'got dbh';
+
+{
+ ok $dbh.do('drop table if exists minidbd_mysql_test'), 'drop table if exists';
+}
+{
+ ok my $sth = $dbh.prepare(q{
+ create table minidbd_mysql_test(
+ id int not null primary key auto_increment,
+ data text
+ ) default charset utf8
+ }), 'create table prepare';
+ ok $sth.execute, 'create table execute';
+}
+{
+ ok my $sth1 = $dbh.prepare('select * from minidbd_mysql_test where id = ?');
+ ok my $sth2 = $dbh.prepare('insert into minidbd_mysql_test (data) values (?)');
+
+ for <ほげ ふが> -> $data {
+ ok $sth2.execute($data), 'insert execute';
+ ok my $id = $dbh.mysql_insertid;
+ ok $sth1.execute($id), 'select execute';
+ ok my $row = $sth1.fetchrow_hashref;
+ is_deeply $row, {
+ id => "$id",
+ data => "$data",
+ };
+ }
+}
+
+{
+ ok $dbh.do('drop table minidbd_mysql_test');
+}
+
+done;
+
+# vim: ft=perl6 :
Please sign in to comment.
Something went wrong with that request. Please try again.