Reputation: 1
I'm novice in SQLite. I have an int array: int[][] data = new int[32768][256]
.
So, I decided to use SQLite database to store data
content.
I want to create a table named "data_content" and put data in cells a
b
c
(c = data[a][b]
)
But I want to save (in the /sdcard/) that large amount of values (8 388 608
) in less than 1 minute, if possible.
How I can do that? I will very appreciate any code.
I'm very sorry about my English, I've used Google Translate sometimes.
Upvotes: 0
Views: 130
Reputation: 4899
If you really want to use SQLite just avoid inserting every single tuple as a separate statement. I would suggest you to use the UNION SELECT construct to pump data in in big chunks.
Something like:
INSERT INTO 'data_content'
SELECT 'data1_1' AS 'a', 'data1_2' AS 'b', 'data1_3' AS 'c'
UNION SELECT 'data2_1', 'data2_2', 'data2_3'
UNION SELECT 'data3_1', 'data3_2', 'data3_3'
UNION SELECT .....
The performance are fast even if to be honest (that's what TBH means actually) I would use a rather different table with 256+1 column with "excel-like" names and 32768 row. In this way you can insert everything with a considerable smaller amount of statements and you'll get benefit also while reading back the values thanks to the index you could create on the first column (which can be used as a "row number").
Using a text file and a zip compression can be fast while writing, but it's unpractical while reading because a text file is always red sequentially.
Upvotes: 1
Reputation: 41168
For fast saving you will be better off just using a flat file to store the data in, zipping it, and then saving it. The IO rate through to the SD card will be your main limitation so compression will save you a lot.
TBH you may be better off explaining WHY you want to do this as then you will get more targeted answers to your real problem...
Upvotes: 0