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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ problem with mysql and lua and mushclient
|
problem with mysql and lua and mushclient
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Zl
(3 posts) Bio
|
| Date
| Sun 24 Jan 2010 04:24 PM (UTC) Amended on Sun 24 Jan 2010 04:33 PM (UTC) by Zl
|
| Message
| I am so happy that you are still developing mushclient.
I have problem with database and lua and mushclient.
I write program juas like what you metioned in a quite old post.
------------------------------------------------------
function database()
-- 载入 ODBC 外部扩展库
assert (package.loadlib ("odbc.dll", "luaopen_luasqlodbc")) ()
-- 创建环境对象
env = assert (luasql.odbc())
-- 连接数据库
con = assert (env:connect ("xx", -- DSN 名称
"xxxx", -- 用户名
"xxxxxx")) -- 密码
-- empty our table
con:execute"DROP TABLE players"
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
assert (con:execute(string.format([[
INSERT INTO players
VALUES ('%s', '%s')]], p.name, p.class)
))
end -- for loop
-- 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 -- while loop
-- close everything
cur:close()
con:close()
env:close()
end
-------------------------------------------------
when I execute this function in mushclient( /database() )there's no result in the mushclient interface.
I checked the database and found that the table is right there.
what is the problem?
----------------------------------------------------
lua5.1
odbc.dll
mysql5.1
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Sun 24 Jan 2010 08:03 PM (UTC) |
| Message
| It worked fine for me, once I put in a valid DSN name, username and password. When you said "the table is right there" did it have the data in it?
You need to set up the ODBC control panel for this to work. It might be easier to use mySQL, or use the new Sqlite3 interfaces which are now in MUSHclient. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Zl
(3 posts) Bio
|
| Date
| Reply #2 on Mon 25 Jan 2010 06:54 AM (UTC) Amended on Mon 25 Jan 2010 06:58 AM (UTC) by Zl
|
| Message
| I am using mysql and also setup the ODBC,however the table in database is ok and there's three row in the table.I am sure that the table is build by the program, so I think both odbc and mysql work well.
I execute "select * from players" via mysql command line client and the result is ok.
so I think the problem may cause by this code:
cur = assert (con:execute ("SELECT * from players" ))
--------------------------------------------------
I tried to show some result with Note()
cur = assert (con:execute ("SELECT * from players" ))
Note(cur) --result:ODBC cursor (00DE6BF8)
p=cur:getcolnames()
Note(p[1]) --result:name
row = cur:fetch (row, "a")
Note(row[1]) --result:[string "Script file"]
--:164: attempt to index global 'row'
--(a nil value)
---------------------------------------------------
this is result from mysql client:
mysql> select * from players;
+-------------+---------+
| name | class |
+-------------+---------+
| Nick Gammon | mage |
| David Haley | warrior |
| Shadowfyr | priest |
+-------------+---------+
3 rows in set (0.81 sec)
mysql>
--------------------------------------------------
by the way,I am using mushclient 4.18 | | Top |
|
| Posted by
| Zl
(3 posts) Bio
|
| Date
| Reply #3 on Mon 25 Jan 2010 07:12 AM (UTC) |
| Message
| I tried mushclient 4.43 with mysql.dll and libmysql.dll
the problem was solved.
but I still want to know why it failed when I use 4.18 with odbc.dll?
as I mentioned in the last post,the table can be created successfully means the odbc and mysqlserver is ok,isn't it?
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Mon 25 Jan 2010 09:23 AM (UTC) |
| Message
| | Well I don't know for sure. Version 4.18 is quite a few versions ago (like, 29) and was released about 2.5 years ago. Maybe in the release notes there is some reference to what the problem might be, but as a general rule, if software fails, try the latest version. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | 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.
16,437 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top