BugsBiteBugs / sqlitepersistentobjects

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

nil collection classes cause off-by-one insertion on - [SQLitePersistentObject save] #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an SQLitePersistentObject subclass with a collection class ivar, 
another supported ivar type 
and the associated @property declarations.
2. Set the collection class instance to nil
3. Instantiate an instance and save it

What is the expected output? What do you see instead?
It's expected that the object will be properly saved.

The problem occurs in SQLitePersistentObject.m:568-571 - the code that checks 
if the property is 
nil doesn't take into account that the property type might be a collection type.

    id theProperty = [self valueForKey:propName];
    if (theProperty == nil)
    {
        sqlite3_bind_null(stmt, colIndex++);
    }

Since null is bound regardless of whether or not the property was intended to 
be be bound (as 
determined in lines 540:552), an extra null bound and the colIndex is 
incorrectly incremented.

The workaround is to make sure your collection properties aren't null when you 
save, 

Original issue reported on code.google.com by eric.s.blair on 4 Dec 2008 at 8:33

GoogleCodeExporter commented 9 years ago
I checked in a change tonight that should fix this - it adds a check to make 
sure that the nil property isn't a 
collection before binding null.

Original comment by jeff.lam...@gmail.com on 19 Feb 2009 at 1:06