在Iphone中打开数据库时App崩溃

时间:2012-01-17 13:13:27

标签: iphone sqlite

我正在使用FMDB APIS使用以下链接在我的项目中使用数据库:https://github.com/ccgus/fmdb

在第一步我创建FMDatabase的对象并获取数据库链接:

FMDatabase *dbObject = [FMDatabase databaseWithPath:dbPath];

现在我使用以下代码打开数据库:

 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];
}   

现在我想从字段中写入Clik of button按钮的数据。我写下面的代码:

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];
}

现在我在这里重新打开数据库。在同一视图控制器中。它给了我以下错误。 请注意第一次打开数据库,下次不打开数据库。我不知道这个问题是什么。请指导。

我得到的错误是:

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

1 个答案:

答案 0 :(得分:1)

看起来好像你在某个时候没有保留dbObject。错误消息表明您正在向open的实例发送NSString消息。这意味着以前用于包含FMDatabase对象的内存现在被字符串占用。

相关问题