Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Lua
➜ Using SQLite3 in MUSHclient
Using SQLite3 in MUSHclient
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Meerkat
(8 posts) Bio
|
Date
| Mon 22 Sep 2008 04:54 AM (UTC) |
Message
| What I want is one of these:
http://nessie.de/mroth/lua-sqlite3/index.html
http://luaforge.net/frs/?group_id=75&release_id=796
Just SQLite3 or even SQLite2 functionality. It would really help me out. How would I go about installing it so MUSHclient would be compatible? | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #1 on Mon 22 Sep 2008 05:16 AM (UTC) |
Message
| See:
http://www.gammon.com.au/forum/?id=5983
Although that discusses mySQL, the concept is the same. You might need to change the loadlib to load a different DLL (and now it is package.loadlib instead of loadlib). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Meerkat
(8 posts) Bio
|
Date
| Reply #2 on Mon 22 Sep 2008 05:27 AM (UTC) Amended on Mon 22 Sep 2008 05:56 AM (UTC) by Meerkat
|
Message
| It's just the following that I don't know how to do properly:
-- load the MySQL dll
loadlib ("mysql.dll", "luaopen_luasqlmysql") ()
And other related loading.
I have the sqlite3.dll from http://www.keplerproject.org/luasql/ in the same dir as MUSHclient. What is the second arg I pass to package.loadlib? I just can't figure it out.
I'm really new to Lua as well as MUSHclient, so I don't have experience with any of this. The documentation for LuaSQL is pretty lacking.
If you could figure it out for me, I would appreciate that very much.
EDIT: Also, is there anything I need to do in the Sandbox? | Top |
|
Posted by
| Meerkat
(8 posts) Bio
|
Date
| Reply #3 on Mon 22 Sep 2008 06:07 AM (UTC) Amended on Mon 22 Sep 2008 06:23 AM (UTC) by Meerkat
|
Message
| I got a bit further.
Wiped out the whole sandbox.
Then I did this:
package.loadlib("sqlite3.dll", "luaopen_luasql_sqlite3")
Seemed to work. Not sure where to go from there though.
EDIT: Got it.
package.loadlib("sqlite3.dll", "luaopen_luasql_sqlite3")()
env = assert (luasql.sqlite3()) | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #4 on Mon 22 Sep 2008 06:41 AM (UTC) Amended on Mon 22 Sep 2008 06:47 AM (UTC) by Nick Gammon
|
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 |
|
Posted by
| WillFa
USA (525 posts) Bio
|
Date
| Reply #5 on Sat 13 Dec 2008 09:05 PM (UTC) |
Message
| The sqlite3.dll should be in lua\luasql\sqlite3.dll, just a few subdirs from where Mushclient.exe is located.
Here's the same example with a few minor tweaks.
require "luasql.sqlite3" --much simpler
-- create environment object
env = assert (luasql.sqlite3())
-- connect to data source
con = assert (env:connect ("databasename.sqlite3")) -- sqlite doesn't implement usernames and pw's. not needed.
-- 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", },
{ name="Spellbound", class="ranger"}, --Me too, Me too!
}
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
cur:fetch (row, "a") --redundant to do row = :fetch(row) though output parameters aren't typical to Lua.
while row do
print ("\n------ new row ---------\n")
for k,v in pairs(row) do print(k,v) end
-- reusing the table of results
row = cur:fetch (row, "a")
end
-- close everything
cur:close()
con:close()
env:close()
| Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
22,546 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top