首先感谢 @arcange 提供 SteemSQL服务,SteemSQL是一个包含STEEM区块链数据的公共MS-SQL数据库。
First thanks @arcange for providing SteemSQL services, SteemSQL is a public MS-SQL database with all the blockchain data in it.
其实SteemSQL上线之初我马上试用过,但是因为当时第一版只包含一些区块链的transaction数据,用起来还有诸多不便,所以后来SteemData一上线,我就转移战场了,尽管我从来未接触过MongoDB。之后,SteemData一直能满足我的需求,所以就懒得转战回来,但是我依然默默关注这个项目,看着它经过十多次升级变得越来越好,也看着很多STEEMIT的朋友开始使用这个数据库。
今天 @jubi 和我说使用SteemSQL 查询中文标题遇到一些困难,用WHERE title like '%第一次%'
作为查询条件,查询不到相关数据,但是用英文则可以查询,我答应帮他看看。话说最近他在中文区举办两期谷哥点名活动,人气火爆,而第一次就是第二期活动的主题。估计太火爆,参与人数众多,单纯地靠人工看帖和整理有些辛苦,于是他想着用程序把整理帖子自动化吧。大家都在成长,这非常好。说到SteemSQL最近,中文区的很多朋友都在用,比如 @ace108, 以及 @joythewanderer, 他们还出过一些向导贴,大家感兴趣可以去翻一翻。
又扯远了,言归正传
安装pymssql
我懒得去下桌面软件,还是直接用Python吧
Python下可以使用pyodbc 以及 pymssql啥的,我选择的是pymssql
直接在命令行下直接安装指令
pip3 install pymssql
嘎,报一大堆错误, 其它啥的都不认识,我关注的大概三句
Running setup.py bdist_wheel for pymssql ... error
setup.py: Not using bundled FreeTDS
_mssql.c:266:22: fatal error: sqlfront.h: No such file or directory
去官网查了一下
http://pymssql.org/en/stable/building_and_developing.html
有这样一句
FreeTDS >= 0.91 including development files. Please research your OS usual software distribution channels, e.g, freetds-dev or freetds-devel packages.
缺啥补啥
sudo apt-get install freetds-dev
pip3 install pymssql
成功!
执行
SteemSQL 官网地址: http://steemsql.com/
但是很遗憾上边的链接信息不全,没有Database的信息
或许连上之后,就直接可以查出来,不过我在SteemSQL发布的帖子中找到了连接信息
Server: sql.steemsql.com
User: steemit
Password: steemit
Database name: DBSteem
import pymssql
conn = pymssql.connect(host ="sql.steemsql.com",database ="DBSteem",user="steemit",password="steemit")
在Python里用这个直接连上了,很好。
试着查了一下
cur = conn.cursor()
cur.execute("SELECT title FROM Comments WHERE author= 'oflyhigh' and title like '%区块链%'")
因为我昨天刚写了一篇文章,
使用PHP查询STEEM区块链 / Using PHP to query the STEEM blockchain
为啥就查不到呢?
然后换个关键词
cur.execute("SELECT title FROM Comments WHERE author= 'oflyhigh' and title like '%PHP%'")
('How to install Apache、MYSQL、PHP5 and run a Wordpress website on BananaPi',), ('拖了很久的事情终于完成了,将PHP 5.4 升级到 PHP 5.6',), ('使用PHP查询STEEM区块链 / Using PHP to query the STEEM blockchain',)
查出来的文章包含我的最新文章
排查
那么是哪里有问题导致的呢?
我第一个直觉是编码问题
然后,我把链接改成
conn = pymssql.connect(host ="sql.steemsql.com",database ="DBSteem",user="steemit",password="steemit", charset="utf8")
结果依旧
又去把FreeTDS的配置文件中加上字符集设置
sudo find / -name freetds.conf
sudo vi /etc/freetds/freetds.conf
sudo vi /usr/share/freetds/freetds.conf
通通加上:
client charset = UTF-8
结果依旧
尽管我觉得没必要,但是,又在Python文件中加上
#-*- coding: utf-8 -*-
结果依旧
从查出的结果能正常显示来看,数据应该是按UTF-8存储的,那问题出在哪里呢?三把板斧用完了,我的找新招数了。
研究半天,发现个新玩意,就是在查询内容前加个N
详情见
https://docs.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql
Prefix Unicode character string constants with the letter N. Without the N prefix, the string is converted to the default code page of the database. This default code page may not recognize certain characters.
把我的查询改成:
cur.execute("SELECT title FROM Comments WHERE author= 'oflyhigh' and title like N'%区块链%'")
查询结果如下:
我也曾经文青过,18年前写的小诗 《花儿》,学laoyao,咱也放到区块链上
使用PHP查询STEEM区块链 / Using PHP to query the STEEM blockchain
珍惜羽毛 / STEEM区块链忠实的记录你的操作 / 获得共同操作账户的真实操作者
YY 一个基于STEEM区块链的聊天工具
STEEM区块链忠实的记录你的言行&操作
终于可行了
再查谷歌点名贴
现在在回头查参加谷歌点名的第二次活动的帖子,主题为第一次
cur.execute("SELECT title,created FROM Comments WHERE title like N'%第一次%' and created > '2017/08/01' order by created")
rows = cur.fetchall()
for row in rows: print("{}\t{}".format(row[0], row[1]))
结果如下:
Magic Clay 你第一次用黏土做了什么呢? 2017-08-01 14:13:45
第一次花費從steemit賺到的收益 ! The first time I get the 'real' money from steemit! 2017-08-02 06:11:21
第一次与你们的对话,my first conversation with y'all . 2017-08-03 18:32:51
第一次在steemit cn发文 感谢steemit让我能接触Bitcoin 2017-08-04 17:09:18
第一次人体解剖课上的惊悚事件 2017-08-07 11:30:48
第一次 - 離鄉別井 | “谷哥点名”活动 2017-08-09 07:10:30
相约大美新疆,第一次在第13届全国冬运会现场 Meet the beauty of Xinjiang,first time in China national winter games 2017-08-09 08:31:15
My first encounter with steemit/我与steemit的第一次邂逅 | 谷歌点名 2017-08-09 10:15:33
我人生的N种第一次 2017-08-09 10:31:48
第一次认识这个世界 2017-08-09 10:52:12
第一次 - 英國行山篇 "谷歌点名"活動 Hiking South Downs Way England 2017-08-09 11:00:00
【参加谷哥点名】我在Steemit的第一次发帖 2017-08-09 13:07:39
第一次离开熟悉的地方外出闯荡 2017-08-09 14:12:33
成就人生的第一次 2017-08-09 14:26:54
第一次 // First Time 2017-08-09 17:11:42
人生第一次——不仅有酸甜苦辣,更有悲欢离合 2017-08-09 18:12:18
第一次 - The First Time (Chinese content only but feel free to comment in English if you understsand) - (by @ace108) 2017-08-10 00:34:03
第一次, 细看妈妈的皱纹| “谷哥点名”活动 2017-08-10 01:11:24
爱上第一次--First Exploration 2017-08-10 01:22:15
如何看待你人生中的第一次? 2017-08-10 01:24:48
?? 老道茶館 ??-請上坐,喝杯茶,說點事;今日話題-第一次 (跨域合作:茶館X谷哥点名) ?? LAODR Tea House ?? 170810 2017-08-10 02:06:03
#隨筆2 第一次 | 谷哥点名 2017-08-10 03:55:33
第一次在星级大酒店吃饭 2017-08-10 04:09:12
第一次绝恋--最后的初恋 The first but also last love. 2017-08-10 04:37:30
第一次品味人生百态 My First Time - Ups and Downs in Life 2017-08-10 05:10:51
第一次 ── 我和我的友生 2017-08-10 05:14:57
第一次拿到在steemit上写作的钱 2017-08-10 05:44:24
领导,今天是我第一次喝酒,可不可以。。。 2017-08-10 06:52:42
第一次去博物馆之中国古代的酒具 The ancient wine cups of the Chinese history 2017-08-10 11:40:54
第一次去油菜花地里玩,种下了心灵里的树 2017-08-10 13:56:00
My first and long leave from my hometown // 第一次離鄉別井 2017-08-10 18:45:03
The first time i made my rose steamed buns 第一次做玫瑰花馒头! 2017-08-10 21:50:18
第一次 — 住在大学宿舍经历 / 谷哥点名活动 | My university life, my first time living in a university hostel 2017-08-10 23:03:06
第一次 - 在第一次家族旅行 - 台中 (內有家族旅行的心得)| The first time - My first family trip - Tai Chung 2017-08-11 01:16:42
很多第一次的第一次 | "谷哥点名" 2017-08-11 01:30:00
第一次“体验”做父母的感觉 / The First Time for Being a "Parent" | 谷歌点名 2017-08-11 04:10:27
第一次来华文区时的情景与华文区如何发展 2017-08-11 06:23:21
第一次注册域名 2017-08-11 08:18:54
第一次,科學研究的第一次/ “谷哥点名”活动 The First time: The Tirst Time for Scientific Research 2017-08-11 09:15:57
第一次去海边 —— “温良恭俭让”的北威尔士海滨小镇兰迪德诺 2017-08-11 09:28:42
第二期“谷哥点名”活動: 第一次 離鄉別井 2017-08-11 09:36:03
我的第一次的虛擬人生 2017-08-11 10:22:18
一天之内的两个第一次 2017-08-11 10:37:51
总算没辜负 @jubi 小友的信任
补充
@jubi 用另外一种方法
WHERE contains(title, '第一次')
可以查出部分数据
我搜索了一下,contains是基于全文索引进行查询
但结果可能受系统分词方法的影响导致不全
当然,也可能是我不会使用的缘故 😭
也加俩第一次关键字参赛,重在参与
另外,万一中奖呢,哈哈哈
建议一下你加个 WAIT (NOLOCK) 比如:
也是昨天找furion问steemsql缺数据的问题他告诉我的。 这样不会把数据库锁住。我用Oracle没这必要但MS SQL Server 好像这比较好。 呵呵。。。我也来看个究竟。 哦,我在中间。:-) ![](Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
感谢专家指点
MSSQL我很少用,除了以前做项目的时候接触过一两次
以后和你们多学习
另外, steemsql少数据你找furion干啥,他是steemdata的 😀
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
哦错了,是 arcange. 我也找 furion 问sbds.那里数据也好像过时。
MSSQL 我也刚开始用。不是专家。 :-)
Oracle 的就用过很多年了。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
WAIT (NOLOCK) 顺便查了一下 NOLOCK 懂了个大概,感谢大神!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
别客气。我非大神。 也是最近得指点上网找了下才知。 :-)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
hi @oflyhigh...... A very useful post for all steemit users around the world, hoping those who read it can post every piece of their writing beautifully by using such a good basic procedure, organized and nice to read, how not to. Using the clues you share can give birth to works that look very unusual.
Continue to work @oflyhigh good luck continued and many gave birth to the benefits for many people
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
谢谢O哥,我也试着查过中文关键字,但是怎么都出不了数据
原来是少了个N,我试过用%%代替一个%,也试过%%ch,都出不来,谢谢解答疑惑。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
其实和字段的存储方式有关
我查了一下title字段存储成nvarchar
加个N前缀,就强制使用UNICODE编码,而不是转换成数据库默认编码
具体细节我也不太懂,好多年没怎么用了
我第一直觉就是编码问题,但是也是试了好几种办法才找到当前方案的
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
👍 真是学习了!中文关键字真是大难题。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
互相学习
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
English translation please?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Yes please :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks, very informative, I am following you now @oflyhigh
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for sharing with us! I hope you enjoy the upvote!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
赞,收藏先。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
谢谢
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
O 哥哥 這個很實用啊 👍
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
谢谢夸奖
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
万一中奖了呢……
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
😀
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
O婶威武啊
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
诗王威武!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
嘩嘩很強!我的第一次現在排18,看來沒有机会得獎了🙈
會否越新的文章會較容易排在前面?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我文章中的排序吗?是按时间排序的
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
那即是我还有机會中獎了🙈🙈🙈🙈
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
必须中奖!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
承你貴言!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我也今天剛剛参加了,沒有看到我的 lol'
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
啊
第二期“谷哥点名”活動: 第一次 離鄉別井 2017-08-11 09:36:03
@krischy
冤枉好人,该当何罪? 😭
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
是小妹沒看清楚 , 我來跪玻璃 😭 😭
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
这这这让我如何忍心呢 😭 😭 😭 😭 😭 😭
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
排隊好嗎?我已經排了半小時了...
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
老实跪着去,别吱声!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
可以輪我跪了嗎!?(大喜過望,眼放光芒)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for sharing.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hii @oflyhigh successful greetings
Nice to meet you
#introduce my name @ firzee0717,
I come from #aceh Sumatra.
Welcome to #steemit for those of you who want to succeed here, I also want the same thing.
I'm also new here #Steem is still a lot to learn from seniors.
Nice to meet you all !!
Please help to promote me
And Please for others follow and Upvote My account @ firzee0717
I love you all
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
很实用哎
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
谢谢夸奖
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我看到很多第一次的標題!支持支持!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
谢谢美女支持
加了好多第一次,哈哈,算作弊不?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
還是你利害,什麼問題也能解決!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
应该说google+百度啥都能解决 😀
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
这样就方便多了,哈哈,还是o哥厉害。
也可以用来查询别的数据。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
大家都很厉害的啦
我也是现学现卖
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@jubi 。。。o哥帮你那么大的忙是不是应该打赏一下:)
现在您也可以打赏STEEMIT作者
https://steemit.com/cn/@beautifulbella/steemit-now-you-can-tip-steemit-author
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
得先去研究下你发的这个打赏机器人先。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Your voting will force your voice to give me strength. thanks.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Support me and enter here https://steemit.com/help/@gr3g0r/hi-i-m-from-venezuela your collaboration is important @gr3g0r Follow Me!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I cant understand a word what this post says but it looks cool.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This language is so sexy...
Fap fap fap fap fap... Fap fap. Fap? Fap fap fap!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
关键知识点:like N'%区块链%'"
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
follow me please
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Tanpa uang semua jadi kacau,, bila uang banyak saudara pun jadi rame
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
看到我自己的文 = 已經參加了,可以放心去睡了 XD
雖然看不明白內容 (逃)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Really post is very nice and impressive but i don,t know this language
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I wish I could understand chinese. I am learning chinese through google translator. New language is always good.
Upvoted
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @oflyhigh!
Your post was mentioned in the hit parade in the following categories:
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
哇!谢谢分享^^值得收藏
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
顶一下,现在正被这个中文字符编码显示问题困扰中。@justyy 把我引过来的。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit