如何使用C中的SQLite中的String中删除逗号?

发布于 2025-02-11 05:07:35 字数 993 浏览 0 评论 0原文

我在删除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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文