I’m running a basic database program in Corona SDK, and everything works. However it takes my code 5-10 seconds just to insert 100 rows of data (only 4 columns each) into the SqLite database. However if I run similar code in Java, it takes less than half a second. Am I doing something wrong with my code or is this just the way Corona SDK is?
Here is the code (Sorry i didn’t know how to work the bbcode tag):
require “sqlite3”
–Generate players
local players = {};
for i = 1, 100 do
local name;
local contact;
local power;
local r = math.random(1,2);
if (r == 1 ) then
name = “Joe”
else
name = “Hakeem”
end
contact = math.random(10,100);
power = math.random(10,100);
players[#players+1] = {name = name, contact = contact, power = power};
end
–Create player database
local path = system.pathForFile(“data.db”, system.DocumentsDirectory)
db = sqlite3.open( path )
db:exec[[
CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT, contact INTEGER, power INTEGER);
]]
print( "version " … sqlite3.version() )
for i = 1, #players do
local insertQuery = [[INSERT INTO test VALUES]] … [[(NULL,]] … [["]] … players[i].name… [["]]
… [[,]] … players[i].contact … [[,]] … players[i].power … [[);]]
print(insertQuery);
db:exec(insertQuery);
end
–Handle the applicationExit event to close the db
local function onSystemEvent( event )
if( event.type == “applicationExit” ) then
db:close()
end
end
Runtime:addEventListener( “system”, onSystemEvent )