PLSqliteDatabase *db = [[PLSqliteDatabase alloc] initWithPath: @"/path/to/database"];
if (![db open])
NSLog(@"Could not open database");
更新操作(即没有返回记录集)
更新操作可以使用 -[PLDatabase executeUpdate:]
if (![db executeUpdate: @"CREATE TABLE example (id INTEGER)"])
NSLog(@"Table creation failed");
if (![db executeUpdate: @"INSERT INTO example (id) VALUES (?)", [NSNumber numberWithInteger: 42]])
NSLog(@"Data insert failed");
id<PLResultSet> results = [db executeQuery: @"SELECT id FROM example WHERE id = ?", [NSNumber numberWithInteger: 42]];
while ([results next]) {
NSLog(@"Value of column id is %d", [results intForColumn: @"id"]);
}
// 如果没有关闭结果集不会导致内存泄漏, 但会结果集会被保留直到下一次的查询
[results close];