Summary of problems encountered during project preparation and solutions (1)

Source: Internet
Author: User

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.
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.