Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't depend on Buf.allocate, stay 6.c compatible
  • Loading branch information
salortiz committed Mar 24, 2016
1 parent 9ce7f9f commit 540cfbd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/DBDish/mysql/Native.pm6
Expand Up @@ -174,9 +174,9 @@ class MYSQL is export is repr('CPointer') {
if $bin { # HACK: mysql_real_scape assumes latin1 :(
$b.list.fmt('%02x','');
} else {
my $r = Blob.allocate($b.bytes * 2 + 1);
my $res = mysql_real_escape_string(self, $r, $b, $b.bytes);
$r.subbuf(0, $res).decode.Str;
my \r = Blob.new; nqp::setelems(r, $b.bytes * 2 + 1);
my $res = mysql_real_escape_string(self, r, $b, $b.bytes);
r.subbuf(0, $res).decode.Str;
}
}
multi method escape(Str $s --> Str) {
Expand Down
10 changes: 5 additions & 5 deletions lib/DBDish/mysql/StatementHandle.pm6
Expand Up @@ -33,7 +33,7 @@ submethod BUILD(:$!mysql_client!, :$!parent!, :$!stmt = MYSQL_STMT, :$!param-cou
) { }

method !get-meta(MYSQL_RES $res) {
my $lengths = Buf[int64].allocate($!field_count);
my $lengths = blob-allocate(Buf[int64], $!field_count);
loop (my $i = 0; $i < $!field_count; $i++) {
with $res.mysql_fetch_field {
@!column-name.push: .name;
Expand All @@ -60,7 +60,7 @@ method execute(*@params) {
if $!param-count {
my @Bufs;
my $par = LinearArray[MYSQL_BIND].new($!param-count);
my $lengths = Buf[int64].allocate($!param-count);
my $lengths = blob-allocate(Buf[int64], $!param-count);
my $lb = BPointer($lengths).Int;
LEAVE { $par.dispose if $par }
for @params.kv -> $k, $v { # The binding dance
Expand All @@ -87,16 +87,16 @@ method execute(*@params) {
&& $!stmt.mysql_stmt_result_metadata -> $res
{ # Need to bind outputs, reuse params structs.
$lengths = self!get-meta($res);
$!isnull = Buf[int64].allocate($!field_count);
$!isnull = blob-allocate(Buf[int64], $!field_count);
my $nb = BPointer($!isnull).Int;
my $stmt_buf = LinearArray[MYSQL_BIND].new($!field_count);
$lb = BPointer($lengths).Int;
@Bufs = ();
for ^$!field_count -> $col {
given $stmt_buf[$col] {
.buffer = BPointer(
@Bufs[$col] = Buf.allocate(
.buffer_length = $lengths[$col]
@Bufs[$col] = blob-allocate(
Buf, .buffer_length = $lengths[$col]
)
).Int;
.length = $lb + $col * 8;
Expand Down

0 comments on commit 540cfbd

Please sign in to comment.