如何使用C中的SQLite中的String中删除逗号?
我在删除SQLite数据库中的字符串数据中的所有逗号方面有问题。
该程序基于C,因此我将SQLite的C API用作SQLite3_Mprintf()。 我尝试将行与输入匹配,并且需要在没有逗号的情况下检查它(,)。
Sqlite的替换()用作替换(数据,',','')。
示例代码在下面。
sqlite3_stmt *main_stmt;
const char* comma = "','";
const char* removeComma = "''"
char *zSQL;
zSQL = sqlite3_mprintf(SELECT * FROM table WHERE (REPLACE(colA||colB, %w, %w) LIKE %%%q%%, comma, removeComma, input);
int result = sqlite3_prepare_v2(database, zSQL, -1, &main_stmt, 0);
我参考sqlite3参考。 https://www.sqlite.org/printf.html
我期望的是select *从表中select *(替换(cola || colb,',',''),例如%q
通过通过',''和'''作为 sqlite3_mprintf()的参数。
但是,结果被更改为select *从表中的选择 *(替换(Cola || colb,,,),例如%q
因此,逗号不会从数据,COLA || COLB中删除,结果与我的期望不同。
是否有任何想法将逗号作为替代()的第一个替代参数 用撇号作为第二个论点空白?
I have problem on removing all comma from string data in SQLite database.
The program is based on C so I use C API of SQLite as sqlite3_mprintf().
I try to get rows matched with input and it needs to be checked without comma(,).
REPLACE() of SQLite is used as REPLACE(data, ',', '').
Sample code is below.
sqlite3_stmt *main_stmt;
const char* comma = "','";
const char* removeComma = "''"
char *zSQL;
zSQL = sqlite3_mprintf(SELECT * FROM table WHERE (REPLACE(colA||colB, %w, %w) LIKE %%%q%%, comma, removeComma, input);
int result = sqlite3_prepare_v2(database, zSQL, -1, &main_stmt, 0);
I refer the sqlite3 reference.
https://www.sqlite.org/printf.html
Any Substitution Types of SQLite3 reference delete apostrophes from input data.
It makes REPLACE() functions different from what I think.
What I expect is SELECT * FROM table WHERE (REPLACE(colA||colB, ',', '') LIKE %q
by passing ',' and '' as argument of sqlite3_mprintf().
However, result is changed as SELECT * FROM table WHERE (REPLACE(colA||colB, ,, ) LIKE %q
so comma is not removed from data, colA||colB, and result is different from what I expect.
Are there any idea to input comma as first argument of REPLACE() with apostrophes
and blank with apostrophes as second argument?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论