INSERT execution speed can be decisive in your application. Let me show you the different solutions to do multiple INSERT with SQLiteVIEW.
For the demonstration we'll use a simple database containing 1 table. The table contains 3 columns: [Id] --> autoincremented integer primary key, [Temperature] --> float and [Sensor] --> string.
We are going to benchmark the following INSERT query repeated 50,000 times :
INSERT INTO MyTable (Sensor, Temperature) VALUES ("Thermocouple", "42");
As you can see below, this method is really easy to implement.
But it's also incredibly slow: more than 5min to execute 50,000 INSERT !
In this case we surround Execute with Begin transaction and Commit transaction.
INSERT performance are dramatically improved: ~ 1.6s to execute 50,000 INSERT !
Note that if an error occurred during the Execute, do a Rollback transaction allow you to retrieve the database as it was before Begin transaction.
Here we have the fastest method.
We create a statement with the following query:
INSERT INTO MyTable (Sensor, Temperature) VALUES (?, ?);
INSERT performance are improved again: ~ 1s to execute 50,000 INSERT !