c - How do you escape strings for SQLite table names in c?
问题描述
How do you escape strings for SQLite table names in c?
I find a document, but it do not tell me the detail https://www.sqlite.org/lang_keywords.html
And this document says that sql is end with '\x00' https://www.sqlite.org/c3ref/prepare.html
Here is the similar question in python: How do you escape strings for SQLite table/column names in Python?
解决方案
Example:
example
to'example'
'a
to'''a'
Detail:
- Do not use the byte value 0 in the string.It will return an error like
unrecognized token: "'"
even if you pass the correct zSql len to sqlite3_prepare_v2(). - Replace
'
to''
in the string, add'
to the start and the end to the string.'
is single quote (byte 39). It is not recommend to use invalid utf8 string. The string do not need to be valid utf8 string according to the parse code in sqlite3 version 3.28.0 . I have tested that invalid utf8 string can use as table name, but the document of sqlite3_prepare_v2() says you need
SQL statement, UTF-8 encoded
I have write a program to confirm that any byte list with len 1,2 without byte value 0 in it, can use as the table name, and the program can read value from that table, can list the table from the
SQLITE_MASTER
table in sqlite3 version 3.28.0.
推荐阅读
- java - SpringBoot + Postman @RequestMapping value = "getImage/{imageName:.+}"
- cassandra - Cassandra 无法将列覆盖为旧值
- java - 如何以编程方式折叠primefaces手风琴面板中的所有面板?
- c++ - 处理时间差异
- google-cast - 使用 HLS 的 AC-3 和 E-AC-3 直通
- python - 在列表上的元组上使用函数在 Google Colab 中有效,但在本地机器上无效
- java - 如何在 Android Studio 中使用 Spinner 获取 RecyclerView 的结果
- tinymce - 为什么 TinyMCE 需要 API 密钥?
- php - 联系表格未发送消息
- python - Selenium webdriver 消息:没有这样的元素:无法找到元素 - iFrame