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
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