I want to do a bunch of inserts into a database, if I do them one by one, it takes quite a while (seconds or more,lots of disk thrashing) for relatively few entries (eg 10's of entries). So I surrounded the insertions/updates with db:_begin(), db:_commit(), db:_end()
local dbh = db:get_database("database"), res
if map_room_count > db_room_count
then
update_db = true
display("Updating DB")
db:_begin()
local i, r
for i, r in pairs(endresult)
do
res = db:add(dbh.area_rooms, {room = r, id = i, area=area.current})
if res == nil
then
display("error adding room")
end
end
db:_commit()
db:_end()
end
but that throws up an error
attempt to call method '_begin' (a nil value)>
Am I using db:_begin(), db:_commit(), db:_end() for their intended purpose and am I using them correctly?