Skip to content

Commit

Permalink
Remove use of deprecated spatialite functions
Browse files Browse the repository at this point in the history
Use *_ex threadsafe functions instead.
  • Loading branch information
jagregory committed Aug 21, 2014
1 parent 2ef9a0d commit 12eb132
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions SpatialDBKit/SpatialDatabase.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ void Swizzle(Class c, SEL orig, SEL new)
method_exchangeImplementations(origMethod, newMethod);
}

@implementation SpatialDatabase
@implementation SpatialDatabase {
void *spatialite_conn;
}

+ (NSString*)spatialiteLibVersion
{
Expand All @@ -56,22 +58,51 @@ - (id)initWithPath:(NSString *)inPath
SpatialDatabaseInstances++;
if (SpatialDatabaseInstances==1)
{
NSLog(@"Spatialite initialization");
spatialite_init(TRUE);
Swizzle([FMResultSet class], @selector(objectForColumnIndex:), @selector(_swizzleObjectForColumnIndex:));
}
}
return self;
}

- (BOOL)open
{
BOOL opened = [super open];

if (opened)
{
[self initSpatialite];
}

return opened;
}

- (BOOL)openWithFlags:(int)flags
{
BOOL opened = [super openWithFlags:flags];

if (opened)
{
[self initSpatialite];
}

return opened;
}

- (void)initSpatialite
{
NSLog(@"Spatialite initialization");
spatialite_conn = spatialite_alloc_connection();
spatialite_init_ex(_db, spatialite_conn, 1);
}

-(void)dealloc
{
// remove reference to dummyObject
SpatialDatabaseInstances--;
if (SpatialDatabaseInstances == 0)
{
NSLog(@"Terminating spatialite");
spatialite_cleanup();
spatialite_cleanup_ex(spatialite_conn);
}
}

Expand Down

0 comments on commit 12eb132

Please sign in to comment.