开发者

sqlite variables

Greetings!

I am using SQLite. I wan开发者_运维技巧t 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


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.


You can support variables in sqlite using an in-memory temp table. See my answer at https://stackoverflow.com/a/14574227/1435110


The only way to use variables like that is by using the binding functions. In many cases, constructing a query string in the language you are using is easier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜