Difference between revisions of "SQL Module"

From SolarStrike wiki
Jump to: navigation, search
(Created page with "== open == '''sqlitedb sqlite.open(string filename)''' Open an SQLite database file and return a handle to the database. If the file does not exist, it will be created for yo...")
 
(No difference)

Latest revision as of 14:01, 25 February 2016

open

sqlitedb sqlite.open(string filename)

Open an SQLite database file and return a handle to the database. If the file does not exist, it will be created for you.


close

sqlite.close(sqlitedb db)

Close an opened SQLite database.


execute

table sqlite.execute(sqlitedb db, string query)

Run a query on an opened SQLite database. Returns a table of results where each result is a table of field/value pairs. For example, pretend table 'people' contains the fields 'id', 'first_name', and 'last_name'. A query to grab known people might look like this:

db = sqlite.open("examples.db");
results = sqlite.execute(db, "SELECT * from `people`");

print("Results:\nID\tFirst Name\tLast Name");
for id,result in pairs(results) do
	printf("\t%d\t%s\t%s\n", result.id, result.first_name, result.last_name);
end

The output of which should look something like:

Results:
	ID	First Name	Last Name
	1	John		Smith
	2	Jane		Doe