Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aram063

macrumors newbie
Original poster
Dec 26, 2008
6
0
Hi

I making a program which can insert values into a sqlite database. It crashes everytime I press the button to insert the value. Following is method which I believe is causing the crash.

Code:
- (void) addValuetoDatabase {
	
	if(addStmt == nil) {
		const char *sql = "Insert into bPressure (value) Values(?)";
		printf("fsdgsfd");
		if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
			NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
		}
		printf("sfsdf");
	sqlite3_bind_int(addStmt, 1, value);
	
	if(SQLITE_DONE != sqlite3_step(addStmt))
		NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
	else
		//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
		valueID = sqlite3_last_insert_rowid(database);
	//Reset the add statement.
	sqlite3_reset(addStmt);
}

It crashes at sqlite3_prepare and Im not sure what's exactly wrong.

Does anyone know what's wrong. Please help me!

Following is part of the crash report.

Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000030
Crashed Thread: 0

Application Specific Information:
iPhone Simulator 1.0 (70), iPhone OS 2.0 (5A345)

Thread 0 Crashed:
0 libsqlite3.0.dylib 0x93d211f0 sqlite3Prepare + 48
1 HelloWorld 0x0000330c -BpValue addValuetoDatabase + 103 (BpValue.m:39)
2 HelloWorld 0x00002c5a -HelloWorldAppDelegate addValueToDatabase: + 84 (HelloWorldAppDelegate.m:78)
3 HelloWorld 0x00002fa8 -MyViewController changeGreeting: + 510 (MyViewController.m:54)
4 UIKit 0x30a5e25e -UIApplication sendAction:to:from:forEvent: + 116
5 UIKit 0x30abb022 -UIControl sendAction:to:forEvent: + 67
6 UIKit 0x30abb4ea -UIControl(Internal) _sendActionsForEvents:withEvent: + 478
7 UIKit 0x30aba830 -UIControl touchesEnded:withEvent: + 483
8 UIKit 0x30a75c0b -UIWindow sendEvent: + 454
9 UIKit 0x30a65e07 -UIApplication sendEvent: + 269
10 UIKit 0x30a6522a _UIApplicationHandleEvent + 4407
11 GraphicsServices 0x31699522 SendEvent + 35
12 GraphicsServices 0x3169b88c PurpleEventTimerCallBack + 276
13 com.apple.CoreFoundation 0x971be615 CFRunLoopRunSpecific + 3141
14 com.apple.CoreFoundation 0x971becf8 CFRunLoopRunInMode + 88
15 GraphicsServices 0x31699d38 GSEventRunModal + 217
16 GraphicsServices 0x31699dfd GSEventRun + 115
17 UIKit 0x30a5dadb -UIApplication _run + 440
18 UIKit 0x30a68ce4 UIApplicationMain + 1258
19 HelloWorld 0x000027fc main + 102 (main.m:14)
20 HelloWorld 0x0000276a start + 54

Thread 1:
0 libSystem.B.dylib 0x93b624a6 mach_msg_trap + 10
1 libSystem.B.dylib 0x93b69c9c mach_msg + 72
2 com.apple.CoreFoundation 0x971be0ce CFRunLoopRunSpecific + 1790
3 com.apple.CoreFoundation 0x971becf8 CFRunLoopRunInMode + 88
4 WebCore 0x32a8a450 RunWebThread + 384
5 libSystem.B.dylib 0x93b936f5 _pthread_start + 321
6 libSystem.B.dylib 0x93b935b2 thread_start + 34

Thread 2:
0 libSystem.B.dylib 0x93b624a6 mach_msg_trap + 10
1 libSystem.B.dylib 0x93b69c9c mach_msg + 72
2 GraphicsServices 0x3169ce0a EventReceiveThread + 467
3 libSystem.B.dylib 0x93b936f5 _pthread_start + 321
4 libSystem.B.dylib 0x93b935b2 thread_start + 34

Thread 3:
0 libSystem.B.dylib 0x93b624a6 mach_msg_trap + 10
1 libSystem.B.dylib 0x93b69c9c mach_msg + 72
2 com.apple.CoreFoundation 0x971be0ce CFRunLoopRunSpecific + 1790
3 com.apple.CoreFoundation 0x971becf8 CFRunLoopRunInMode + 88
4 com.apple.CFNetwork 0x95a59a32 CFURLCacheWorkerThread(void*) + 396
5 libSystem.B.dylib 0x93b936f5 _pthread_start + 321
6 libSystem.B.dylib 0x93b935b2 thread_start + 34

Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x000040c0 ebx: 0x000032b3 ecx: 0xffffffff edx: 0x00003e84
edi: 0x00000000 esi: 0x004124c0 ebp: 0xbfffe4d8 esp: 0xbfffe380
ss: 0x0000001f efl: 0x00010282 eip: 0x93d211f0 cs: 0x00000017
ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037
cr2: 0x00000030
 
Thanks for the reply!

I'm bit of a noob at C and Objective C...but as far as I can see all the variables are pointing to the intended values. Can you be a bit more specific. Sorry if this sounds really noob as I'm new to C and Objective C.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.