Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Message
| You shouldn't need to wipe the entire sandbox. Maybe set it to permit DLLs to be loaded, and to trust the main world file. Anyway, with the sqlite3.dll placed in the same directory as MUSHclient, the following example worked for me:
assert (package.loadlib("sqlite3.dll", "luaopen_luasql_sqlite3")) ()
-- create environment object
env = assert (luasql.sqlite3())
-- connect to data source
con = assert (env:connect ("databasename.sqlite3", "username", "password"))
-- empty our table
res = con:execute"DROP TABLE players"
res = assert (con:execute[[
CREATE TABLE players(
name varchar(50),
class varchar(50)
)
]])
-- add a few elements
list = {
{ name="Nick Gammon", class="mage", },
{ name="David Haley", class="warrior", },
{ name="Shadowfyr", class="priest", },
}
for i, p in pairs (list) do
res = assert (con:execute(string.format([[
INSERT INTO players
VALUES ('%s', '%s')]], p.name, p.class)
))
end
-- retrieve a cursor
cur = assert (con:execute ("SELECT * from players" ))
-- print all rows, the rows will be indexed by field names
row = cur:fetch ({}, "a")
while row do
print ("\n------ new row ---------\n")
table.foreach (row, print)
-- reusing the table of results
row = cur:fetch (row, "a")
end
-- close everything
cur:close()
con:close()
env:close()
Results were:
------ new row ---------
name Nick Gammon
class mage
------ new row ---------
name David Haley
class warrior
------ new row ---------
name Shadowfyr
class priest
This code created the database file "databasename.sqlite3" in the same directory that MUSHclient.exe was in.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|