db_exec
Executes INSERT, UPDATE, DELETE, or DDL statements on the SQLite database. Returns the number of rows affected. For DDL statements (CREATE TABLE, etc.), the affected row count is 0.
Signature
Section titled “Signature”db_exec(sql, [params])
asyncParameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
sql |
string | The SQL statement to execute |
params |
table? | Optional array of positional parameters for prepared statements (? placeholders) |
Returns
Section titled “Returns”| Value | Type | Description |
|---|---|---|
| affected | number | Number of rows affected |
Example
Section titled “Example”local affected = db_exec("INSERT INTO products (id, name, price) VALUES (?, ?, ?)", { "prod-1", "Widget", 9.99})log("inserted " .. affected .. " row(s)")See Also
Section titled “See Also”- db_query - Execute SELECT queries