简体   繁体   中英

App Crash when opening Database in Iphone

I am using FMDB APIS to use database in my project using the following link:https://github.com/ccgus/fmdb

in the First Step i Create and object of FMDatabase and get the DB linked:

FMDatabase *dbObject = [FMDatabase databaseWithPath:dbPath];

Now I open the Database using the following code:

 if (![dbObject open]) {
    NSLog(@"Could not Open Database");
}else {
    NSLog(@"Database Opened!");
    [dbObject executeUpdate:@"create table user(id integer primary key autoincrement, f_name text, l_name text, session_id text)"];
    [dbObject close];
}   

Now i want to write the data On Clik of button from fields. i Write the following code:

if (![dbObject open]) {
    NSLog(@"Could not Open Database");
}else {
    NSLog(@"Database Opened!");
    [dbObject executeUpdate:@"insert into user(f_name, l_name, session_id) values(?,?,?)",loginObject.fName, loginObject.lName, loginObject.sessionId,nil];
    [dbObject close];
}

Now when i reopen the DB here. in the same view controller. it gives me the following error. please note First time its opening the Database and next times its not. I dont know whats the problem. Please guide.

the Error i got is:

[NSCFString open]: unrecognized selector sent to instance 0x4e21630

It looks as though you're not retaining dbObject at some point. The error message says that you're sending the open message to an instance of NSString . This means that the memory that used to contain your FMDatabase object is now ocupied by a string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM