gpt4 book ai didi

ios - 警告 : I could not find the column named 'rowid'

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:27:06 26 4
gpt4 key购买 nike

我在我的 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);
}

最佳答案

SELECT * 仅返回表定义中的列。

如果要获取rowid列,则必须显式列出:

SELECT *, rowid FROM ...

如果您确实需要使用此列,最好将其作为表定义的一部分:

CREATE TABLE bookmarks (
ID INTEGER PRIMARY KEY, -- same as rowid
title TEXT,
...
)

关于ios - 警告 : I could not find the column named 'rowid' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26826074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com