Skip to content

SQLite3 Module Database exec

DizzasTeR edited this page Nov 9, 2020 · 1 revision

SQLiteDatabase

exec

Executes a sqlite query

int SQLiteDatabase:exec(string query [, ...optionalParameters])

Parameters

  • string query — The query to execute
  • optional optionalParameters — Forward any extra parameters with the query (Used for prepared statements)

Returns

int - Return code

Example #1

local db = SQLite.openDatabase("test.db")

if db:tableExists("Test") then
    local r = db:exec("DROP TABLE Test")
    iprint("Dropped Table: Test", r)
end

if not db:tableExists("Test") then
    r = db:exec("CREATE TABLE Test(id INTEGER, name TEXT)")
    iprint("Exec #1", r)
end

local result = db:exec("INSERT INTO Test VALUES (1, 'dizz'), (2, 'xmomo'), (3, 'slc')")
iprint("Exec #2", result)

result = db:query("SELECT * FROM Test WHERE id = ? OR name = :genius OR name = ?", {3, [":genius"] = 'dizz', [3] = 'xmomo'}) -- The string based bind acts as [2] so for the last ? the bind slot should be 3
iprint("Query #1", result)

SQLite.closeDatabase(db)
Clone this wiki locally