如何将文本绑定到SQL IN语句

时间:2019-04-18 06:16:23

标签: android c++ sql c java-native-interface

如何将文本绑定到' SQL IN `语句?

char *sql = "SELECT "
"ENTITY_GUID " \
"FROM ENTITY_TABLE WHERE "
"ENTITY_OWNER_GUID IN (?)";

int rc = sqlite3_prepare(db, sql, -1, &stmt, 0);

sqlite3_bind_text(stmt, 1, (const char *) char_sql_IN, -1, SQLITE_STATIC);  

char_sql_IN '26', '42', '43'打印到控制台

即:

char *sql = "SELECT "
"ENTITY_GUID " \
"FROM ENTITY_TABLE WHERE "
"ENTITY_OWNER_GUID IN (?)";

int rc = sqlite3_prepare(db, sql, -1, &stmt, 0);

sqlite3_bind_text(stmt, 1, (const char *) char_sql_IN, -1, SQLITE_STATIC);

if (rc != SQLITE_OK) {
    fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db));
}

rc = sqlite3_step(stmt);

while (rc == SQLITE_ROW) {
    long entityGUID = sqlite3_column_int(stmt, 0);
    rc = sqlite3_step(stmt);
}

谢谢大家。

0 个答案:

没有答案