Principle: First detect the database in the specified table, whether there is already a data record we want to insert, if it already exists, do not insert this data record (that is, ignore the insertion operation), if not already exist, only insert this data record (that is, the insertion operation)
We're using the Fmdb framework here.
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];
ios-prevent the insertion of duplicate data records into the SQLite database: