Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySql prepared statements #58

Merged
merged 8 commits into from Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't depend on Buf.allocate, stay 6.c compatible
  • Loading branch information
salortiz committed Mar 24, 2016
commit 540cfbd06d8d1e3881147a903a83cd8b6e3893d4
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