1. How to determine data duplication
Select count (1) From 'table name' where execution condition =?
You only need to write this SQL statement in the defined method to solve the problem of data duplication. If the returned value is equal to 1, the data is duplicated. That is to say, when inserting a database, we can first determine that if the return value of the method with this statement is not equal to 1, we can perform our own operations. Here is a simple code example:
1) database Method
Public String isrepeathistroy (String title ){
Sqlitedatabase DB = This. getwritabledatabase ();
String content = NULL;
String SQL = "select count (1) From t_zhang _ Where title =? ";
Cursor cur = dB. rawquery (SQL, new string [] {Title });
If (cur. movetonext ()){
Content = cur. getstring (cur. getcolumnindex ("count (1 )"));
}
Return content;
}
2) usage in the Activity Class
If (! Dao. isrepeathistroy (searchword). Equals ("1 ")){
Dao. insertbaikepv (tool. getuuid (), bigtyp, searchword, time1); // if the data is not repeated, insert the database.
}