如何在linux上用Lua连接Steem数据库 | How to connect Steem database on Linux by Lua

in #utopian-io7 years ago (edited)

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

Sort:  

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

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.029
BTC 75243.81
ETH 2872.09
USDT 1.00
SBD 2.49