在下面的例子中使用了一个单一的数据库表(动物),其中包含三列(名称,描述,照片)。查询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