使用Sqlite3在Xcode,Objective-C中查找表名

时间:2012-04-04 15:54:00

标签: objective-c xcode sqlite compilation

我必须从compiledStatement中找到一个表名(由sqlite3库的sqlite3_prepare_v2方法返回)。

我无法使用方法const char *sqlite3_column_table_name(sqlite3_stmt*,int);,因为此方法需要使用选项[SQLITE_ENABLE_COLUMN_METADATA]编译dylib。

我想知道如何使用该选项重新编译dylib(我可以在哪里找到要编译的代码以及如何使用哪个命令和标志?)或者是否存在另一种方法来细化表名。

1 个答案:

答案 0 :(得分:0)

如果您知道可能构建语句的查询类型,则可以使用此方法

/*
** CAPI3REF: Retrieving Statement SQL
**
** ^This interface can be used to retrieve a saved copy of the original
** SQL text used to create a [prepared statement] if that statement was
** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
*/
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);

检索用于构建语句的Query。获得查询后,您可以解析查询以获取表名。

例如,如果您的陈述是插入,那么您将获得

INSERT INTO TABLE_NAME...

现在第三个单词是你的表名。你可以用,

componentSeperatedByString

但我更喜欢使用正则表达式。