标签:
原则:先检测该数据库的指定表中,是否已经存在我们要插入的这条数据记录,若已经存在,则不插入这条数据记录(即忽略此次插入操作),若尚不存在,才插入这条数据记录(即才执行此次插入操作)
我们这里使用的是FMDB框架
FMDatabase *collectionBookDB = [FavoriteBooksDataBase favoriteBooksDataBase];
NSString *sqlObjectiveString = [NSString stringWithFormat:@"INSERT INTO t_favoriteBooks (bookName, author, publisher, publishmentDate, briefIntroduction, bookImageURL, bookIdentifier) SELECT ‘%@‘,‘%@‘,‘%@‘,‘%@‘,‘%@‘,‘%@‘, %d WHERE NOT EXISTS (SELECT * FROM t_favoriteBooks WHERE bookIdentifier=%d)", book.bookName, book.author, book.publisher, book.publishmentDate, book.briefIntroduction, book.bookImageURL, book.bookIdentifier, book.bookIdentifier];
BOOL collectionBookResult = [collectionBookDB executeUpdate:sqlObjectiveString];
标签:
原文地址:http://www.cnblogs.com/hello-Huashan/p/4734753.html