How to use SQLITE Runintransactionasync

Asked

Viewed 69 times

0

I need to insert a large amount of lines (exactly 221) when I start my WP application. Actually I’m using arrays and loop repetition for, so I’m losing performance when starting the app.

I did some research on RunInTransactionAsync, I didn’t find much but, there is some way to leave this insert faster?

for (var i = 0; i < 221; i++)
{
   var hino = new hinos() { numHino = array.numeroHinos[i], favHino = array.favHinos, nomeHino = array.nomeHinos[i], catHino = array.categoriaHinos[i], letraHino = array.letraHinos[i] };
   await con.InsertAsync(hino);                 
}

2 answers

0

One of the ways is among a transaction and reuse Smtm(Statement that is compiled) but this would use a lower API.

I don’t know the API that you have available but there are several steps in a statement sqlite: sqlite3_prepare() -- compile the query
sqlite3_step() -- reproduces
sqlite3_finalize() -- ends

My suggestion is to use the same value as the sqlite3_prepare()

-1

A suggestion I saw here is to make this way:

INSERT INTO 'tablename'
          SELECT 'data1' AS 'column1', 'data2' AS 'column2'
UNION ALL SELECT 'data1', 'data2'
UNION ALL SELECT 'data1', 'data2'
UNION ALL SELECT 'data1', 'data2'

At the time I didn’t implement, I changed my concept, I hope it helps you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.