Skip to content
Advertisement

sqlite variables

Greetings!

I am using SQLite. I want to declare variable, but it gives me a syntax error. Please help me to find a solution:

Select * from t2 where value= ?

This is my query. Now how can I pass values to ? ?

Thanks in advance, Jennie

Advertisement

Answer

As far as I know SQLite doesn’t support anything like that.

The syntax is standard for libraries that implement bound parameters (and prepared statements that use them), but you would need to do that in a programming language that queries the database, and not in the database itself.

The specifics, of course, depend on the programming language and the library.

In Perl, for example you could:

my $sth = $dbh->prepare("Select * from t2 where value=?");
foreach my $value (@values) {
    $sth->execute($value);
    $row = $sth->fetchrow_hashref;
    [...]
}

Bobby Tables has some more examples in a variety of languages.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement