我可以使用参数在sqlite3的表名? [英] Can I use parameters for the table name in sqlite3?
问题描述
我有一些异样的感觉华南简介sqlite3的参数的,我想暴露给你。
I'm having some strange feeling abour sqlite3 parameters that I would like to expose to you.
这是我的查询和故障消息:
This is my query and the fail message :
#query
'SELECT id FROM ? WHERE key = ? AND (userid = '0' OR userid = ?) ORDER BY userid DESC LIMIT 1;'
#error message, fails when calling sqlite3_prepare()
error: 'near "?": syntax error'
在我的code,它看起来像:
In my code it looks like:
// Query is a helper class, at creation it does an sqlite3_preprare()
Query q("SELECT id FROM ? WHERE key = ? AND (userid = 0 OR userid = ?) ORDER BY userid DESC LIMIT 1;");
// bind arguments
q.bindString(1, _db_name.c_str() ); // class member, the table name
q.bindString(2, key.c_str()); // function argument (std::string)
q.bindInt (3, currentID); // function argument (int)
q.execute();
我有,我不能对表名使用SQLite的参数的感觉,但我找不到在的 SQLITE3 C API 。
I have the feeling that I can't use sqlite parameters for the table name, but I can't find the confirmation in the Sqlite3 C API.
你知道什么是错我的查询?结果
我一定要pre-过程中我的SQL语句包含表名的前的preparing查询?
Do you know what's wrong with my query?
Do I have to pre-process my SQL statement to include the table name before preparing the query?
推荐答案
Ooookay,本来应该看起来更彻底的SO。
Ooookay, should have looked more thoroughly on SO.
回答:结果
- <一个href=\"http://stackoverflow.com/questions/1274432/sqlite-parameters-not-allowing-tablename-as-parameter\">SQLite参数 - 不使表名作为参数结果
- SQLite中 变量表名称
Answers:
- SQLite Parameters - Not allowing tablename as parameter
- variable table name in sqlite
这意味着它们是Python的,但我想这同样适用于C ++。
They are meant for Python, but I guess the same applies for C++.
TL;博士
您无法通过表名作为参数。结果
如果任何人有SQLite的文档中的一个链接,我有这个确认,我会很乐意接受的答案。
You can't pass the table name as a parameter.
If anyone have a link in the SQLite documentation where I have the confirmation of this, I'll gladly accept the answer.
这篇关于我可以使用参数在sqlite3的表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!