Class: SQLite3::Query
Defined Under Namespace
Modules: Description
Instance Method Summary collapse
- #ask(*args) ⇒ Object
-
#initialize(sql, statement) ⇒ Query
constructor
A new instance of Query.
- #run(*args) ⇒ Object
- #select(*args) ⇒ Object
Constructor Details
#initialize(sql, statement) ⇒ Query
Returns a new instance of Query.
2 3 4 5 6 |
# File 'lib/sqlite3/query.rb', line 2 def initialize(sql, statement) expect! statement => SQLite3::Statement @sql, @statement = sql, statement end |
Instance Method Details
#ask(*args) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sqlite3/query.rb', line 67 def ask(*args) results = run(*args) row = results.first results.reset if !row then nil elsif row.length == 1 then row.first else row end end |
#run(*args) ⇒ Object
8 9 10 11 |
# File 'lib/sqlite3/query.rb', line 8 def run(*args) # STDERR.puts "Q: #{@sql} #{args.map(&:inspect).join(", ")}" @statement.execute *args end |
#select(*args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sqlite3/query.rb', line 13 def select(*args) @klass ||= SQLite3::Record.for_columns(@statement.columns) ary = run(*args).map do |rec| @klass.build *rec end ary.extend Description ary.columns = @statement.columns ary end |