tomalan / sqlitepersistentobjects

Automatically exported from code.google.com/p/sqlitepersistentobjects
0 stars 0 forks source link

Problem loading NULL columns into NSString #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
NSArray *allMyModels = [myModel findByCriteria:@""];

When using code like this above, if any of the properties are NSStrings and are 
stored as NULL in 
the database, there is an error when loading them back in.

I know how to fix this, I just wanted a record of it. :)

Original issue reported on code.google.com by jeff.lam...@gmail.com on 2 Sep 2008 at 10:19

GoogleCodeExporter commented 9 years ago
For anyone running across this before the trunk is fixed, I did the following 
and it seems to have fixed the issue.

Replace the code at line 192 in SQLitePersistentObject.m with this (everything 
in that else statement):

const char *str = (const char *)sqlite3_column_text(statement, i);
NSString *sectionName;
if (str == NULL) {
    sectionName = [NSString string];
} else {
    sectionName = [NSString stringWithCString:str encoding:NSUTF8StringEncoding];
}
id colData = [propClass objectWithSqlColumnRepresentation:sectionName];
[oneItem setValue:colData forKey:propName];

Original comment by davidjc...@gmail.com on 7 Sep 2008 at 11:02

GoogleCodeExporter commented 9 years ago
ha, I just ran into this myself with NSDates, along with another problem. Patch:

diff --git a/SQLitePersistentObjects/NSDate-SQLitePersistence.m
b/SQLitePersistentObjects/NSDate-SQLitePersistence.m
index 621ec50..3d06c02 100644
--- a/SQLitePersistentObjects/NSDate-SQLitePersistence.m
+++ b/SQLitePersistentObjects/NSDate-SQLitePersistence.m
@@ -25,7 +25,7 @@
 {
        NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSSS"];
-       return [dateFormatter dateFromString:self];
+       return [dateFormatter dateFromString:columnData];
 }
 - (NSString *)sqlColumnRepresentationOfSelf
 {
diff --git a/SQLitePersistentObjects/SQLitePersistentObject.m
b/SQLitePersistentObjects/SQLitePersistentObject.m
index 4cf5d48..bfcb318 100644
--- a/SQLitePersistentObjects/SQLitePersistentObject.m
+++ b/SQLitePersistentObjects/SQLitePersistentObject.m
@@ -189,7 +189,11 @@ NSMutableDictionary *objectMap;
                                                }
                                                else
                                                {
-                                                       id colData = [propClass
objectWithSqlColumnRepresentation:[NSString stringWithUTF8String:(const char
*)sqlite3_column_text(statement, i)]];
+                                                       id colData = nil;
+                                                       const char *columnText =
(const char *)sqlite3_column_text(statement, i);
+                                                       if (NULL != columnText) 
{
+                                                               colData = 
[propClass
objectWithSqlColumnRepresentation:[NSString stringWithUTF8String:columnText]];
+                                                       }
                                                        [oneItem setValue:colData
forKey:propName];
                                                }
                                        }

Original comment by vicke...@gmail.com on 8 Oct 2008 at 3:48

GoogleCodeExporter commented 9 years ago
ugh, patch garbled in last post, fix attached

Original comment by vicke...@gmail.com on 8 Oct 2008 at 3:49

Attachments:

GoogleCodeExporter commented 9 years ago
To davidjcann:
Are you sure that's the right line ?

Original comment by mnemonic...@gmail.com on 3 Dec 2008 at 8:41

GoogleCodeExporter commented 9 years ago
I think the patch didn't solve the problem with the NSSTring.
Thanks

Original comment by geraudde...@gmail.com on 13 Dec 2008 at 12:10