如何在linux上用Lua连接Steem数据库 | How to connect Steem database on Linux by Lua
Steem database uses MSSQL, on linux we have to connect it with ODBC, so we need install freetds, unixODBC at first. I used fedora. Similar for other linux distribution.
Step 1: install freetds, unixODBC:
yum install freetds unixODBC
Step 2: config freetds.conf, add below:
[steemDB]
host = sql.steemsql.com
port = 1433
tds version = 8.0
Step 3: config odbcinst.ini, add below:
[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/libtdsodbc.so
Setup = /usr/lib/libtdsS.so
UsageCount = 1
Step 4: config odbc.ini, add below:
[steemDB]
Description = MSSQL Server
Driver = freetds
Database = DBSteem
ServerName = steemDB
TDS_Version = 8.0
Step 5: install luasql:
luarocks install luasql-odbc
Step 6: test the config with below lua code:
luasql = assert (require "luasql.odbc")
env = assert(luasql.odbc())
con = assert (env:connect ("steemDB","steemit","steemit"))
cur = assert (con:execute ("select voting_power from Accounts where name='alanzheng'" ))
row = cur:fetch ({}, "voting_power")
while row do
table.foreach (row, print)
row = cur:fetch (row, "voting_power")
end
cur:close()
con:close()
env:close()
Result:
1 8027
I used my name, you can change to yours or something. :-)
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @alanzheng I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Amazing