tomalan / sqlitepersistentobjects

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

Error trying delete transient collection property #68

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Declare a collection property in a class
2. Set it like a transient field
3. Delete object that constains the transient field

What is the expected output? What do you see instead?

It was expected that didn't tried delete the transient fields, but a error
was reported.
See below:
Error deleting foreign key rows in table [tableName]_[propertyName].

Please provide any additional information below.

Bugfix at SQLitePersistentObject.m at deleteCascade:

-(void)deleteObjectCascade:(BOOL)cascade
{
    if(pk < 0)
        return;

    if(alreadyDeleting)
        return;
    alreadyDeleting = TRUE;
    //Primary key set implies object already saved and table checked
    //[self tableCheck];

    [[self class] unregisterObject:self];

    NSString *deleteQuery = [NSString stringWithFormat:@"DELETE FROM %@ WHERE
pk = %d", [[self class] tableName], pk];
    sqlite3 *database = [[SQLiteInstanceManager sharedManager] database];
    char *errmsg = NULL;
    if (sqlite3_exec (database, [deleteQuery UTF8String], NULL, NULL, &errmsg)
!= SQLITE_OK)
        NSLog(@"Error deleting row in table: %s", errmsg);
    sqlite3_free(errmsg);

    NSDictionary *theProps = [[self class] propertiesWithEncodedTypes];
-   // Bugfix to do not delete transient fields
-   NSArray *theTransients = [[self class] transients];

    for (NSString *prop in [theProps allKeys])
    {
-       // Bugfix to do not delete transient fields
-       if ([theTransients containsObject:prop]) continue;
....

Regards,

Paulo R. Schwertner

Original issue reported on code.google.com by paulo.sc...@gmail.com on 4 May 2009 at 2:15