iOS + sqlite issues (EXC_BAD_ACCESS)
I have a really strange one. I have a method that works perfectly fine, but I am trying to convert it to make the data more database driven vs the hardcoding that currently exists. When I add a call to my database method to pull the data, I'm getting an EXC_BAD_ACCESS long AFTER the database stuff is done. I've narrowed it down to the database stuff, since if I don't make the call at all, the crash doesn't happen.

So, the call to the method looks like this (this is where if I comment out, it doesn't crash):

    NSString *thisRoomNumber = [self readLocationsFromDatabaseBetweenPoints:fX YPoint:fY];

and the method itself looks like this:

        #pragma mark -
    #pragma mark SQL Operations
    - (NSString *)readLocationsFromDatabaseBetweenPoints:(float)tapPointX YPoint:(float)tapPointY{
        
        // Setup some globals
    	databaseName = @"db.sqlite";
        
    	// Get the path to the documents directory and append the databaseName
    	NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    	NSString *documentsDir = [documentPaths objectAtIndex:0];
    	databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
        
        // Setup the database object
    	sqlite3 *database;
            
        NSString *sqlStringBuilder = [NSString stringWithFormat:@"select * from floors where propertyid = ? and floorid = ? and %f between topleftxcoord and bottomrightxcoord and %f between topleftycoord and bottomrightycoord", tapPointX, tapPointY];
        
        NSString *roomNumber = @"0";
        
    	// Open the database from the users filessytem
    	if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    		// Setup the SQL Statement and compile it for faster access
    		const char *sqlStatement =  [sqlStringBuilder UTF8String];
            
            NSLog(@"%@", [NSString stringWithUTF8String:sqlStatement]);
            
    		sqlite3_stmt *compiledStatement;
    		if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
                sqlite3_bind_int(compiledStatement, 1, iPropertyId);
                sqlite3_bind_int(compiledStatement, 2, iFloorId);			
                
                // Loop through the results and add them to the feeds array
    			while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
    				// Read the data from the result row
                    NSInteger aLocId = sqlite3_column_int(compiledStatement, 0);
                    NSInteger aTLX = sqlite3_column_int(compiledStatement, 1);
                    NSInteger aTLY = sqlite3_column_int(compiledStatement, 2);
                    NSInteger aBRX = sqlite3_column_int(compiledStatement, 3);
                    NSInteger aBRY = sqlite3_column_int(compiledStatement, 4);
                    NSString *aRoomIdent = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)];
                    
                    roomNumber = aRoomIdent;
    
    			}
    		}else{
                NSLog(@"%d", sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL));
            }
    		// Release the compiled statement from memory
    		sqlite3_finalize(compiledStatement);
            
    	}
    	sqlite3_close(database);
        
        
        [documentsDir release];
        [documentPaths release];
        //[roomNumber release];
        [sqlStringBuilder release];
        
        return roomNumber;
    }

The call itself works fine. I get the results as expected, the "thisRoomNumber" comes back with what I expect it to be. Once the calling method kicks out to the next part it goes back to the delegate, at which point it crashes. I know it's tough to see whats going on without a lot of code to use, but the sheer amount of code would make this post MASSIVE.

Hopefully this will give us a starting point to fixing this. Also, the crash log dump gives absolutely nothing useful for this.


Thanks for any help you guys can provide! If you need more info, let me know, I'll do my best to add to this as needed.




iOS + sqlite issues (EXC_BAD_ACCESS)
===

I have a really strange one. I have a method that works perfectly fine, but I am trying to convert it to make the data more database driven vs the hardcoding that currently exists. When I add a call to my database method to pull the data, I'm getting an EXC_BAD_ACCESS long AFTER the database stuff is done. I've narrowed it down to the database stuff, since if I don't make the call at all, the crash doesn't happen.

So, the call to the method looks like this (this is where if I comment out, it doesn't crash):

    NSString *thisRoomNumber = [self readLocationsFromDatabaseBetweenPoints:fX YPoint:fY];

and the method itself looks like this:

        #pragma mark -
    #pragma mark SQL Operations
    - (NSString *)readLocationsFromDatabaseBetweenPoints:(float)tapPointX YPoint:(float)tapPointY{
        
        // Setup some globals
    	databaseName = @"db.sqlite";
        
    	// Get the path to the documents directory and append the databaseName
    	NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    	NSString *documentsDir = [documentPaths objectAtIndex:0];
    	databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
        
        // Setup the database object
    	sqlite3 *database;
            
        NSString *sqlStringBuilder = [NSString stringWithFormat:@"select * from floors where propertyid = ? and floorid = ? and %f between topleftxcoord and bottomrightxcoord and %f between topleftycoord and bottomrightycoord", tapPointX, tapPointY];
        
        NSString *roomNumber = @"0";
        
    	// Open the database from the users filessytem
    	if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
    		// Setup the SQL Statement and compile it for faster access
    		const char *sqlStatement =  [sqlStringBuilder UTF8String];
            
            NSLog(@"%@", [NSString stringWithUTF8String:sqlStatement]);
            
    		sqlite3_stmt *compiledStatement;
    		if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
                sqlite3_bind_int(compiledStatement, 1, iPropertyId);
                sqlite3_bind_int(compiledStatement, 2, iFloorId);			
                
                // Loop through the results and add them to the feeds array
    			while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
    				// Read the data from the result row
                    NSInteger aLocId = sqlite3_column_int(compiledStatement, 0);
                    NSInteger aTLX = sqlite3_column_int(compiledStatement, 1);
                    NSInteger aTLY = sqlite3_column_int(compiledStatement, 2);
                    NSInteger aBRX = sqlite3_column_int(compiledStatement, 3);
                    NSInteger aBRY = sqlite3_column_int(compiledStatement, 4);
                    NSString *aRoomIdent = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 5)];
                    
                    roomNumber = aRoomIdent;
    
    			}
    		}else{
                NSLog(@"%d", sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL));
            }
    		// Release the compiled statement from memory
    		sqlite3_finalize(compiledStatement);
            
    	}
    	sqlite3_close(database);
        
        
        [documentsDir release];
        [documentPaths release];
        //[roomNumber release];
        [sqlStringBuilder release];
        
        return roomNumber;
    }

The call itself works fine. I get the results as expected, the "thisRoomNumber" comes back with what I expect it to be. Once the calling method kicks out to the next part it goes back to the delegate, at which point it crashes. I know it's tough to see whats going on without a lot of code to use, but the sheer amount of code would make this post MASSIVE.

Hopefully this will give us a starting point to fixing this. Also, the crash log dump gives absolutely nothing useful for this.


Thanks for any help you guys can provide! If you need more info, let me know, I'll do my best to add to this as needed.



