Reading SQLite data lists-bad practices in blog writing

Source: Internet
Author: User

Recently, the SQLite database was used due to functional requirements. I found a lot of useful knowledge on the Internet. Although many articles are the same, everyone knows it here!

In the Data Reading function, no matter which version of the article, the while method is used to read the data. The Code is as follows:

/*** Query list * @ throws exception */Public void selectlist () throws exception {dbhelper = new dbhelper (this. getcontext (); dbhelper. open (); cursor returncursor = dbhelper. findlist ("user", new string [] {"ID", "username", "password"}, "username = 'test'", null, null, "id DESC"); While (returncursor. movetonext () {string id = returncursor. getstring (returncursor. getcolumnindexorthrow ("ID"); string username = returncursor. getstring (returncursor. getcolumnindexorthrow ("username"); string Password = returncursor. getstring (returncursor. getcolumnindexorthrow ("password "));}}

Maybe you have modified the above Code in your own application, but it is estimated that there are also a lot of obfuscation like me. The original copy is no longer available! Then the problem arises. I am working on resumable upload of Android files. Test results, there is always a file that cannot be passed to the server. The reason is that on this while, the while condition is whether the next row is read successfully. If yes, the cursor is located at the next data position, therefore, the first data cannot be read.
This problem is understandable. It is estimated that the problem has been corrected after debugging, but it turned out to be overwhelming on the Internet. After reading more than a dozen articles, none of them have been corrected. Although I agree with everyone's suggestions, this trend is not good after all.
Paste the modified Code:

/*** Query list * @ throws exception */Public void selectlist () throws exception {dbhelper = new dbhelper (this. getcontext (); dbhelper. open (); cursor returncursor = dbhelper. findlist ("user", new string [] {"ID", "username", "password"}, "username = 'test'", null, null, "id DESC"); If (returncursor. movetofirst () {do {string id = returncursor. getstring (returncursor. getcolumnindexorthrow ("ID"); string username = returncursor. getstring (returncursor. getcolumnindexorthrow ("username"); string Password = returncursor. getstring (returncursor. getcolumnindexorthrow ("password");} while (returncursor. movetonext ());}}

 

The above Code does not return values. It is only used for demonstration!

In fact, there is nothing to worry about when an error occurs during reposted articles, but we hope that you can modify your original blog in time after discovering the error to develop a good atmosphere. Take responsibility for your own blog and start from yourself!

 

Related Article

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.