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.
This is neither a FMDB nor SQLite limitation. I use FMDB to return strings longer than 255 characters from my SQLite database all the time. I just checked:
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];
and I got my 8429 character string, same length that BASE told me it was going to be.
This makes me wonder if there's something strange about your data (e.g. binary data instead of characters, DBCS, etc.). Have you tried returning as an object rather than a string and examining that? Perhaps confirm that it is a NSString and not a NSData result set, e.g.:
id test3 = [rs objectForColumnIndex:0];
if ([test3 isKindOfClass:[NSString class]])
NSLog(@"It's a string");
else
NSLog(@"It's not");
If you really think this is a FMDB issue, you could try posting this question at the FMDB discussion. Also, I'd make sure you have the latest FMDB code, which you can retrieve from that same site.