Can I use parameters for the table name in sqlite3?

前端 未结 2 1082
暖寄归人
暖寄归人 2020-12-03 17:26

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         


        
相关标签:
2条回答
  • 2020-12-03 17:40

    I know this is super old already but since your query is just a string you can always append the table name like this in C++:

    std::string queryString = "SELECT id FROM " + std::string(_db_name);
    

    or in objective-C:

    [@"SELECT id FROM " stringByAppendingString:_db_name];
    
    0 讨论(0)
  • 2020-12-03 17:59

    Ooookay, should have looked more thoroughly on SO.

    Answers:
    - SQLite Parameters - Not allowing tablename as parameter
    - Variable table name in sqlite

    They are meant for Python, but I guess the same applies for C++.

    tl;dr:

    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.

    0 讨论(0)
提交回复
热议问题