Deleting from a Sqlite Database

Just wondering if its possible to set the  number parameter to a variable in this statement.

local deleteD = [[DELETE FROM test WHERE id =1;]]

Thank you for you time

local stmt = db:prepare[[DELETE FROM test WHERE id = ?]]; stmt:bind\_values(id) stmt:step();

Thank’s for the reply but I must admit i don’t understand how those 3 lines work 

It’s a simple ‘bind’ statement that effectively replaces [[DELETE FROM test WHERE id =1;]]

The question mark (?) indicates a variable, in this case, the id you want to delete.

local stmt = db:prepare[[DELETE FROM test WHERE id = ?]];

To bind a variable to the question mark, you use this line. It replaces the question mark with the value of the variable id.

stmt:bind\_values(id)

This line actually executes the DELETE statement

stmt:step();

If perhaps you want to bind more than one variable to a statement, you simply use more question marks. For example:

local stmt = db:prepare[[DELETE FROM test WHERE name = ? AND age = ?]]; stmt:bind\_values(nameVar, ageVar) stmt:step()

;

Awesome Thank you for talking the time to explain that, thats very helpful and appreciated.

local stmt = db:prepare[[DELETE FROM test WHERE id = ?]]; stmt:bind\_values(id) stmt:step();

Thank’s for the reply but I must admit i don’t understand how those 3 lines work 

It’s a simple ‘bind’ statement that effectively replaces [[DELETE FROM test WHERE id =1;]]

The question mark (?) indicates a variable, in this case, the id you want to delete.

local stmt = db:prepare[[DELETE FROM test WHERE id = ?]];

To bind a variable to the question mark, you use this line. It replaces the question mark with the value of the variable id.

stmt:bind\_values(id)

This line actually executes the DELETE statement

stmt:step();

If perhaps you want to bind more than one variable to a statement, you simply use more question marks. For example:

local stmt = db:prepare[[DELETE FROM test WHERE name = ? AND age = ?]]; stmt:bind\_values(nameVar, ageVar) stmt:step()

;

Awesome Thank you for talking the time to explain that, thats very helpful and appreciated.