Created
August 27, 2018 12:22
-
-
Save seki/1e74ce4e196d2d4ef9ce619212743ec1 to your computer and use it in GitHub Desktop.
sqlite3-util.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SQLite3::Database | |
def statement(s) | |
if @cache.nil? | |
@cache = Hash.new { |h, k| h[k] = self.prepare(k) } | |
end | |
@cache[s] | |
end | |
end | |
class SQLite3::Statement | |
def get_first_row(*bind_vars) | |
execute(*bind_vars).first | |
end | |
def get_first_value(*bind_vars) | |
execute(*bind_vars).each { |row| return row[0] } | |
nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment