S
S
sstas2021-12-20 12:50:22
Android
sstas, 2021-12-20 12:50:22

How to speed up writing array to sqlite db on unity?

Hello, the task is to fill the database with data from the array, there are 30.000+ elements in the array, and it takes longer than 7 minutes, to measure, it takes 5:15 minutes to loop 50k requests, and this is on a PC (target platform is android), in general, this Is it normal or am I doing something wrong?

public static void ExecuteQueryWithoutAnswer(string query)
  {
    OpenConnection();
    Debug.Log("001");
    for (int i = 0; i < 50000; i++)
    {
      query = "insert into Main (Name, LongCode, ShortCode, Price) values (1,1,1,1)";
    }
    command.CommandText = query;
    command.ExecuteNonQuery();

    }
    Debug.Log("002");
    CloseConnection();
  }


PS added a loop to the following construction, now the database is filled in a couple of seconds
using(SqliteTransaction transaction = connection.BeginTransaction())
{

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-12-20
@sstas

Make one request, not 50 thousand.
Combine requests into one through a semicolon.
At least 100 lines.
Before executing requests, start a transaction
After - complete

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question