First I created a database with table "test" which has fields: 'id' (integer size 11, auto-increment, not-NULL, primary key), and 'name' (type text, not-NULL).
I inserted a few test rows to work with: Then I wrote up some simple code to test with:
Code: Select all
db = sqlite.open("test.db");
results = sqlite.execute(db, "SELECT * from `test`");
print("Results:");
print("\tID", "Name");
for id,result in pairs(results) do
printf("\t%s\t%s\n", result.id, result.name);
end
sqlite.close(db);
Code: Select all
Running './scripts/test/sqlite.lua'
Results:
ID Name
1 row1
2 row2
3 row3
Lets just use table.print() for the results this time, just to clean things up.
Code: Select all
results = sqlite.execute(db, "SELECT `name` from `test` WHERE `id` = 2");
table.print(results);
Code: Select all
Running './scripts/test/sqlite.lua'
1: table: 0x027F7228
name: row2
If you want to try it out, it is available as of version 1.93 from the main download page.