在下面的例子中使用了一個單一的數據庫表(動物),其中包含三列(名稱,描述,照片)。查詢sqlite3數據庫多表
如果我的數據庫包含兩個表(1.animals,2.Cities),每個表都有它的列(名稱,描述,照片),我該如何要求例如。 「名稱城市」定位在第1列表2中,並結合表1第2列中的「動物描述」,用這些「值」來製作對象。
referncing這.....(字符*)sqlite3_column_text(compiledStatement,1)....
謝謝。
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from animals";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
// Create a new animal object with the data from the database
Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];
在你的問題旁邊,使用fmdb,一個很棒的SQLite3 Objective-C包裝器。 https://github.com/ccgus/fmdb – 2011-03-30 00:29:02
@ Cesar A. Rivas謝謝 – Xzolo32 2011-03-30 16:05:36