Android implements SQLite’s method of adding, updating and deleting rows

This paper describes the method of adding, updating and deleting rows in SQLite by Android. Share with you for your reference, as follows:

The sqlitedatabase class exposes specific methods, such as insert, delete and update, which wrap the SQL statements required to perform these actions. Nevertheless, the execsql method allows you to execute any valid SQL statement on the database table, and these actions are what you want to do manually.

At any time, if you modify the value of the underlying database, you should call the refreshquery method of any cursor browsing on the current table.

Insert new row

To create a new row, construct a contentvalues object and use its put method to provide values for each column. Insert a new row by calling the insert method on the target database object and passing the contentvalues object into the method -- you need the name of the table -- as shown in the following fragment:

Update row

Updating rows also needs to be implemented through contentvalues.

Create a new contentvalues object and use the put method to specify a new value for each column you want to update. Call the update method of the database object, pass in the table name and the updated contentvalues object, and a where language to indicate which rows need to be updated.

The processing of the update is demonstrated in the following clip:

Delete row

To delete a row, you can simply call the delete method on the database object, specify the table name and a where statement to indicate which rows you want to delete, as shown in the following code:

For more Android related content, readers who are interested can view the topics on this site: summary of Android database operation skills, summary of activity operation skills of Android programming, summary of Android file operation skills, summary of SD card operation methods of Android programming and development, introduction and advanced tutorial of Android development, summary of Android resource operation skills Android view skills summary and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>