Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl6 API with Slang::SQL

Tags:

raku

bailador

Hi im trying to do an API in Perl6 using Bailador, DBIish and Slang::SQL but when I try to use

sql select * from user where nom='"$name"'; do -> $row {
        "$row".say;
}

instead of

sql select * from user where nom="try"; do -> $row {
        "$row".say;
}

it dont tell me anything :c (obviously $name == "try") I search for hour on the internet but with no answer. I already try to use only DBIish synthaxe but it end with the same result. Can someone help me :) ?

like image 372
Mudada Avatar asked Apr 13 '16 15:04

Mudada


2 Answers

You should be using place holders is the main reason why. The slang doesn't do quoting of that kind, and even if it did you'd be introducing a point of entry for a SQL injection exploit in your code - unless you escaped quotes in the variable.

Instead try:

sql select * from user where nom = ?; with ($name) do -> $row {
    $row.say;
}

Good luck with your app. BTW there's a subreddit that'd be interested in your progress https://www.reddit.com/r/perl6

like image 173
Matt Oates Avatar answered Oct 20 '22 23:10

Matt Oates


So I tried Matt Oates's answer but it didn't give me anything back (like if it didn't find anything in the DB). But I finally found the syntax that did the job:

my $email = request.params<email>;
my $db = 'SELECT * FROM user WHERE email=?';
my $do = $*DB.prepare($db);
$do.execute($email);
my %row = $do.fetchrow_hashref;
return (%row);
like image 1
Mudada Avatar answered Oct 20 '22 23:10

Mudada