Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mysql: Fix MYSQL_BIND struct
Add a missing field, uncovered by testing in on 32bits machine.
Xliff_++ for spot the NH::Blob problem.
  • Loading branch information
salortiz committed Mar 30, 2016
1 parent b4ebdac commit e01c873
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 6 additions & 4 deletions lib/DBDish/mysql/Native.pm6
Expand Up @@ -70,7 +70,8 @@ class MYSQL_RES is repr('CPointer') { ... }

# Current rakudo don't allow set a Pointer in a CStruct based class.
# so we use an 'intprt'
constant intptr = nativesizeof(Pointer) == 8 ?? uint64 !! uint32;
constant intptr is export = nativesizeof(Pointer) == 8 ?? uint64 !! uint32;
constant ptrsize_t is export = nativesizeof(intptr);
class MYSQL_BIND is repr('CStruct') is export {
#has Pointer[ulong] $!length is rw;
has intptr $.length is rw;
Expand All @@ -85,8 +86,9 @@ class MYSQL_BIND is repr('CStruct') is export {
has Pointer $.skip_result;
has ulong $.buffer_length is rw;
has ulong $.offset;
has size_t $.param_number is rw;
has size_t $.pack_length;
has ulong $.lenght_value;
has uint32 $.param_number is rw;
has uint32 $.pack_length;
has uint32 $.buffer_type is rw;
has my_bool $.error_value;
has my_bool $.is_unsigned;
Expand Down Expand Up @@ -172,7 +174,7 @@ class MYSQL is export is repr('CPointer') {
}

# Native methods
method mysql_affected_rows(MYSQL:D: --> int32) is native(LIB) { * }
method mysql_affected_rows(MYSQL:D: --> int64) is native(LIB) { * }
method mysql_close(MYSQL:D: ) is native(LIB) { * }
method mysql_errno(MYSQL:D: --> int32) is native(LIB) { * }
method mysql_error(MYSQL:D: --> Str) is native(LIB) { * }
Expand Down
15 changes: 8 additions & 7 deletions lib/DBDish/mysql/StatementHandle.pm6
Expand Up @@ -30,7 +30,7 @@ method !handle-errors {
}

method !get-meta(MYSQL_RES $res) {
my $lengths = blob-allocate(Buf[int64], $!field_count);
my $lengths = blob-allocate(Buf[intptr], $!field_count);
loop (my $i = 0; $i < $!field_count; $i++) {
with $res.mysql_fetch_field {
@!column-name.push: .name;
Expand All @@ -53,22 +53,22 @@ submethod BUILD(:$!mysql_client!, :$!parent!, :$!stmt = MYSQL_STMT,
if $!param-count = .mysql_stmt_param_count -> $pc {
$!par-binds = LinearArray[MYSQL_BIND].new($pc);
my $lb = BPointer(
$!in-lengths = blob-allocate(Buf[int64], $pc)
$!in-lengths = blob-allocate(Buf[intptr], $pc)
).Int;
$!par-binds[$_].length = $lb + $_ * 8 for ^$pc;
$!par-binds[$_].length = $lb + $_ * ptrsize_t for ^$pc;
}
if ($!field_count = .mysql_stmt_field_count) && .mysql_stmt_result_metadata -> $res {
$!binds = LinearArray[MYSQL_BIND].new($!field_count);
my $lb = BPointer($!out-lengths = self!get-meta($res)).Int;
$!isnull = blob-allocate(Buf[int64], $!field_count);
$!isnull = blob-allocate(Buf[intptr], $!field_count);
my $nb = BPointer($!isnull).Int;
for ^$!field_count -> $col {
given $!binds[$col] {
if .buffer_length = $!out-lengths[$col] {
@!out-bufs[$col] = blob-allocate(Buf, $!out-lengths[$col]);
.buffer = BPointer(@!out-bufs[$col]).Int;
.length = $lb + $col * 8;
.is_null = $nb + $col * 8;
.length = $lb + $col * ptrsize_t;
.is_null = $nb + $col * ptrsize_t;
.buffer_type = @!column-type[$col] ~~ Blob
?? MYSQL_TYPE_BLOB !! MYSQL_TYPE_STRING;
} else {
Expand Down Expand Up @@ -110,7 +110,8 @@ method execute(*@params) {
$!par-binds[$k].buffer_type = MYSQL_TYPE_NULL;
}
}
$!stmt.mysql_stmt_bind_param($!par-binds.typed-pointer)
$!stmt.mysql_stmt_bind_param($!par-binds.typed-pointer);
without self!handle-errors { .fail }
}
$!stmt.mysql_stmt_execute
or $!Prefetch
Expand Down

0 comments on commit e01c873

Please sign in to comment.