Database:exec(sql, [params...])method
Executes a SQL query with support for parameters to bind values dynamically
Parameters
sql
A string that contains a SQL query.
[params...]
One or more optional string that contains parameters for the query. Each '?' characters in the query will be replaced by the corresponding argument in order.
Return value
Returns the result of the SQL statement as rows (each row is represented as a Luatable with column names as keys), the number of rows affected for non-SELECT statements, or nil if there is no result.
Example
--! luart-extensions
import sqlite
-- Create an in-:memory: database
local db = sqlite.Database(":memory:")
-- Create a new table "users"
db:exec([[CREATE TABLE users (
id integer PRIMARY KEY,
name text NOT NULL,
age integer)]])
-- Insert a new row
db:exec("INSERT INTO users (name, age) VALUES(?, ?)", "John", 32)
-- Get a row from the SELECT statement
local row = db:exec("SELECT * FROM users WHERE(name == 'John')")
print(row.name, row.age)