2
我想插入數據到sqlite..hhile插入即時通訊獲得重複在我的代碼..我看到與它有關的問題和即時通訊瞭解有關..所有隻是幫助我這個代碼來檢查數據插入到數據庫之前存在...檢查數據是否存在之前插入到iPhone的SQLite數據庫
- (IBAction)AddtoFavourites:(id)sender {
sqlite3 *database;
[email protected]"dataTable.sqlite";
NSArray *documentpath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentdir=[documentpath objectAtIndex:0];
dbPath=[documentdir stringByAppendingPathComponent:dbName];
if(sqlite3_open([dbPath UTF8String], &database)==SQLITE_OK){
//I want to check data it exists already into database....
NSString *sqlStatement=[NSString stringWithFormat:@"insert into Persons(PersonName,CompanyName,ImgUrl)values(\"%@\",\"%@\",\"%@\")",model.personName,model.companyName,model.imgurl];
const char *insertSQL=[sqlStatement UTF8String];
char *errMsg;
sqlite3_exec(database, insertSQL, NULL,NULL,&errMsg);
NSLog(@"Add to Favourites");
}
}
我已經做了這一切對我的appdelegate讀取數據庫... – 2012-01-04 07:12:04
如果你的新PERSONNAME等於aName那麼不插入 – 2012-01-04 07:19:44
我找到了答案..感謝你..我使用UNIQUE for personName在我的sqlite數據庫中,並使用插入或忽略查詢語句,而不是查詢語句... – 2012-01-04 07:21:31