Android SQLite BULK INSERT data speed Solutions

Source: Internet
Author: User
Tags sqlite database

Transfer from http://hi.baidu.com/hfutonline/blog/item/62b1e4de8bdf4b2e5882dd28.html

Recently when doing Android project encountered a problem, the application initialization needs to batch to SQLite to insert a large number of numbers, causing the application to start too slow.

Android using SQLite database, SQLite is a relatively lightweight database, after Google found that the problem of sqlite transaction processing, when SQLite inserts the data by default a statement is a transaction, how many times the number of data on the disk operation. My application initial 5,000 records that is to read and write disk operations 5,000 times.

Workaround:

Add a transaction, insert 5,000 as a transaction

Database.begintransaction (); Set up a start transaction manually

Data insertion Operation cycle

Database.settransactionsuccessful (); Set transaction success, do not set automatically rollback does not commit

Database.endtransaction (); Processing complete

To "pour out" the database:

Sqlite3 film.db ". Dump" > Output.sql

Using the output data, create an identical database (plus the above directive, which is the standard SQL database

Backed up):

Sqlite3 Film.db < Output.sql

When inserting a large amount of data, you may need to call this command first:

Begin

After inserting the data, remember to call this command, the data will be written into the database:

Commit

Android SQLite BULK INSERT data speed Solutions

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.