In this post, I’ll show you how your Android app could include ability to perform bulk data load into device SQLite database.
Platform: Ai2LiveComplete
Image below shows how the app will look like.
The components in the Design Editor are shown in the below diagram:
The blocks are shown in the diagram below.
- Screen.Initialize — used to check if first time installation. This is done by checking if any database table exists. If not, it will then invoke initDatabase procedure
- btnDropTable.Click – used to drop mytable. It also checks to see if it exist or not. If so, it drops table (NOTE: All data will be deleted)
- btnInitDb – once clicked, it will invoke initDatabase to re-create table and re-populate data
- initDtabase procedure – First it creates mytable Table and then it will bulk load data in one-shot. Please note that in one call, 4 rows are inserted into database table
- lpShowData.BeforePicking – Once this ListPicker is clicked, a query is executed to retrieve all data. Once retrieved, it will show data in a separate screen
- lpShowTables – Once this ListPicker is clicked, it will retrieve result from SQLite.DisplayTables blocks and will then show result in the ListPicker
Image below shows data once lpShowData is clicked. The first row is the column names and subsequent rows are the data in csv format
NOTES:
- Bulk insert into SQLite database has a limit of 500 rows. If you intend to insert over 500 rows, you’ll have to break your insert statements.
- You can easy convert a csv file into SQL CRUD (Create, Read, Update, Delete) statements using THIS online conversion tool
Variations:
If your SQL data is large, you can create variance of this app that pull data from your server.
Download apk
- Click HERE to download .apk