CurtTilmes / raku-dbsqlite

SQLite access for Raku
10 stars 4 forks source link

DB::SQLite doesn't like IntStr placeholders #2

Closed mscha closed 5 years ago

mscha commented 5 years ago

DB::SQLite dies when passing an IntStr value as a placeholder. Most likely scenario is when passing a parameter on the command line via sub MAIN.

Example:

#!/usr/bin/env perl6
use v6.c;

use DB::SQLite;

my $db = DB::SQLite.new;

sub MAIN(Int $foo)
{
    say $db.query('SELECT 1 WHERE ? = ?', $foo, $foo).value;
}

This dies with:

Ambiguous call to 'AUTOGEN(DB::SQLite::Native::Statement: Int, IntStr)'; these signatures all match:
:(DB::SQLite::Native::Statement: Int $n, Int:D $v, *%_ --> Nil)
:(DB::SQLite::Native::Statement: Int $n, Str:D $v, *%_ --> Nil)
  in method execute at /opt/perl6-2018.10/share/perl6/site/sources/F735A230CF27D032781E817AC2AB5AC529C14695 (DB::SQLite::Statement) line 25
  in method query at /opt/perl6-2018.10/share/perl6/site/sources/F1B43C2361FC6DB5F165CBD906DB9F08A144DB8A (DB::Connection) line 48
  in method query at /opt/perl6-2018.10/share/perl6/site/sources/51223C7606846125E36A7A53A8884E0090F594CE (DB) line 21
  in sub MAIN at ./sqlite-test line 8
  in block <unit> at ./sqlite-test line 8

A workaround, of course, is to make sure all values are Ints:

    say $db.query('SELECT 1 WHERE ? = ?', +$foo, +$foo).value;

But it would be good if it wasn't necessary to work around this. I think it's safe to assume that an IntStr holds a number.

CurtTilmes commented 5 years ago

Patched via commit https://github.com/CurtTilmes/perl6-dbsqlite/commit/753bdf02cb3e7bc2b37729b9c9ce69c36c1a3cc2

I'll release a new version in a bit.

CurtTilmes commented 5 years ago

Pushed version 0.3 with the fix to CPAN. It should show up there in a bit.