简体   繁体   English

在iPhone中打开数据库时应用崩溃

[英]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 我正在使用FMDB APIS通过以下链接在我的项目中使用数据库:https://github.com/ccgus/fmdb

in the First Step i Create and object of FMDatabase and get the DB linked: 在第一步中,创建FMDatabase的对象,并获得链接的数据库:

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. 看来您似乎并没有保留dbObject The error message says that you're sending the open message to an instance of NSString . 错误消息表明您正在将open消息发送到NSString实例。 This means that the memory that used to contain your FMDatabase object is now ocupied by a string. 这意味着用于包含FMDatabase对象的内存现在已被字符串占用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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