执行 SQL 查询

数据库操作

//SQLite 随系统提供:来自 libsqlite3 的 C API
#import <sqlite3.h>

sqlite3 *db;
sqlite3_open("data.db", &db);

sqlite3_stmt *stmt;
sqlite3_prepare_v2(db,
    "select id, name from lines",
    -1, &stmt, NULL);

while (sqlite3_step(stmt) == SQLITE_ROW) {
    int rowId = sqlite3_column_int(stmt, 0);
    const char *name = (const char *)
        sqlite3_column_text(stmt, 1);
    NSLog(@"%d: %s", rowId, name);
}

sqlite3_finalize(stmt);
sqlite3_close(db);