我在iOS项目中使用FMDB。但是当我用FMDB读取ROWID时,Xcode日志"警告:我找不到名为' rowid'的列。"
...
//Create database
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *dbPath = [documentsPath stringByAppendingPathComponent:@"bookmarksDatabase.sqlite"];
BOOL needCreateTable = ![[NSFileManager defaultManager] fileExistsAtPath:dbPath];
FMDatabase *db = [FMDatabase databaseWithPath:dbPath];
[db open];
if (needCreateTable) {
[db executeUpdate:@"CREATE TABLE bookmarks (title TEXT ,url TEXT ,folderID INTEGER ,locationIndex INTEGER)"];
}
else
{
[self reloadBookmarkDatabase:db];
}
[db close];
...
//Read database. Only "ROWID" column can't find.
FMResultSet *results = [db executeQuery:@"SELECT * FROM bookmarks ORDER BY locationIndex"];
while([results next]) {
BookmarkData *temp = [[BookmarkData alloc] initWithID:[results intForColumn:@"ROWID"] title:[results stringForColumn:@"title"] url:[results stringForColumn:@"url"] folderID:[results intForColumn:@"folderID"] locationIndex:[results intForColumn:@"locationIndex"]];
[self.bookmarkArray addObject:temp];
NSLog(@"bookmark id:%d, title:%@, url:%@, folderID:%d, locationIndex:%d",temp.ID,temp.title,temp.url,temp.folderID,temp.locationIndex);
}
答案 0 :(得分:5)
SELECT *
仅返回表定义中的列。
如果您想获取rowid
列,则必须明确列出:
SELECT *, rowid FROM ...
如果您确实需要使用此列,那么最好将其作为表定义的一部分:
CREATE TABLE bookmarks (
ID INTEGER PRIMARY KEY, -- same as rowid
title TEXT,
...
)