0

Ladies and Gents,

I'm using FMDB in an iOS application. I have some text in columns which exceeds 255 bytes. I use BASE and browse the database file, and I can query the length of the data in the columns... So I know my data is there and that it is longer than 255...

YET, when trying to pull out data from these columns, I always get a C string of exactly 255 bytes, and I have no clue whatsoever why.

Here's some piece of code (basically from - (NSString*)stringForColumnIndex:(int)columnIdx { of FMDB FMResultSet.m, and I can trap the error already there.

- (NSString*)stringForColumnIndex:(int)columnIdx {

if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
    return nil;
}

const char *c = (const char *)sqlite3_column_text([_statement statement], columnIdx);

int xx = strlen(c); //added by me, already here it is only 255 bytes


if (!c) {
    // null row.
    return nil;
}
return [NSString stringWithUTF8String:c];
}

What am I missing? I'm using the standard supplied libsqlite3.dylib, FMDB includes sqlite.h. I tried to google similar problems to no avail for hours now.

4

1 回答 1

0

这既不是 FMDB 也不是 SQLite 限制。我一直使用 FMDB 从我的 SQLite 数据库中返回超过 255 个字符的字符串。我刚刚检查过:

    FMResultSet *rs = [fmdb executeQuery:@"select personnel_description from personnel where personnel_id=297"];
    [rs next];
    NSString *test2 = [rs stringForColumnIndex:0];
    NSLog(@"%s len=%d string=%@", __FUNCTION__, [test2 length], test2);
    [rs close];

我得到了我的 8429 字符串,与 BASE 告诉我的长度相同。

这让我想知道您的数据是否有些奇怪(例如二进制数据而不是字符、DBCS 等)。您是否尝试过作为对象而不是字符串返回并检查它?也许确认它是一个 NSString 而不是一个 NSData 结果集,例如:

    id test3 = [rs objectForColumnIndex:0];
    if ([test3 isKindOfClass:[NSString class]])
        NSLog(@"It's a string");
    else
        NSLog(@"It's not");

如果您真的认为这是 FMDB 问题,您可以尝试在FMDB 讨论中发布此问题。另外,我会确保您拥有最新的 FMDB 代码,您可以从同一站点检索该代码。

于 2012-04-30T21:32:48.473 回答