Skip to content

Instantly share code, notes, and snippets.

@yoshinari-nomura
Created February 5, 2019 12:54
Show Gist options
  • Save yoshinari-nomura/4fd46ae3707469537bd5dc364e24f12b to your computer and use it in GitHub Desktop.
Save yoshinari-nomura/4fd46ae3707469537bd5dc364e24f12b to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
# Please add INDEX to speedup the SQL queries which use LIKE clauses:
#
# sqlite3 "#{DICT_FILE}" 'CREATE INDEX dict_key ON dict (key COLLATE NOCASE);'
SQLITE = "sqlite3"
DICT_FILE = "'#{ENV['HOME']}/foo/bar/mouseoverdictionary.sqlite'"
word = ARGV.shift
## XXX: sanitizing is required for WORD.
sql = "SELECT * FROM dict WHERE key COLLATE NOCASE LIKE '#{word}%' LIMIT 100;"
IO.popen "#{SQLITE} #{DICT_FILE} \"#{sql}\"" do |f|
while line = f.gets
line.sub!('|', "\n")
line.gsub!(' \ ', "\n")
print line
print "\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment