0
我使用FMDB APIS使用下面的鏈接繼續用在我的項目數據庫:在第一步的創建和對象//github.com/ccgus/fmdb崩潰
:HTTPS FMDatabase並獲得DB鏈接:
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。我寫下面的代碼:
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
好的,我應該保留它的財產嗎? – Shah 2012-01-17 13:30:35
如果你有一個屬性的值(你不在上面的代碼中),那麼它應該被設置爲'retain',並且你應該用'self.dbObject = ...'表示賦值給它。 – 2012-01-17 13:54:18