SQLite Parameters - Not allowing tablename as parameter

前端 未结 2 1102
盖世英雄少女心
盖世英雄少女心 2020-11-29 09:18

I\'m developing an application in AIR via Flex, but I\'m not seeing where I\'m going wrong with SQLite (I\'m used to MySQL). Parameters work, but only in certain instances.

2条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 10:04

    Generally one cannot use SQL parameters/placeholders for database identifiers (tables, columns, views, schemas, etc.) or database functions (e.g., CURRENT_DATE), but instead only for binding literal values.

    With server-side support for parameterized (a.k.a. prepared) statements, the DB engine parses your query once, remembering out the peculiars of any parameters -- their types, max lengths, precisions, etc. -- that you will bind in subsequent executions of the already-parsed query. But the query cannot be properly parsed into its syntactic elements if critical bits, like database objects, are unknown.

    So, one generally has to substitute table names oneself, in a stored procedure or in client code which dynamically concats/interpolates/whatevers the SQL statement to be properly executed. In any case, please remember to use your SQL API's function for quoting database identifiers, since the API won't do it for you.

提交回复
热议问题