The Database class encapsulates single connection to an SQLite3 database. Its usage is very straightforward:
require "sqlite3"
db = SQLite3::Database.new( "data.db" )
db.execute("select * from table") do |row|
p row
end
db.close
Lower level methods are also provided.
Creates a new Database object that opens the given file, yields it, and closes it at the end.
Creates a new Database object that opens the given file.
Closes this database.
Returns true
if this database instance has been closed (see #close
).
Executes the given SQL statement.
Executes the given SQL statement.
Executes the given SQL statement.
Executes the given SQL statement.
A convenience method that returns the first row of a query result.
A convenience method that returns the first row of a query result.
A convenience method that returns the first value of the first row of a query result.
A convenience method that returns the first value of the first row of a query result.
Obtains the unique row ID of the last row to be inserted by this Database instance.
Prepares an sql statement.
Executes a query and gives back a ResultSet
.
Executes a query and gives back a ResultSet
.
Executes a query and yields a ResultSet
that will be closed at the end of the given block.
Executes a query and yields a ResultSet
that will be closed at the end of the given block.
Quotes the given string, making it safe to use in an SQL statement.
Creates a new Database object that opens the given file, yields it, and closes it at the end.
Executes the given SQL statement. If additional parameters are given, they are treated as bind variables, and are bound to the placeholders in the query.
Note that if any of the values passed to this are hashes, then the key/value pairs are each bound separately, with the key being used as the name of the placeholder to bind the value to.
Yields one Array(Value)
for each result.
Executes the given SQL statement. If additional parameters are given, they are treated as bind variables, and are bound to the placeholders in the query.
Note that if any of the values passed to this are hashes, then the key/value pairs are each bound separately, with the key being used as the name of the placeholder to bind the value to.
Returns an Array(Array(Value))
.
Executes the given SQL statement. If additional parameters are given, they are treated as bind variables, and are bound to the placeholders in the query.
Note that if any of the values passed to this are hashes, then the key/value pairs are each bound separately, with the key being used as the name of the placeholder to bind the value to.
Returns an Array(Array(Value))
.
Executes the given SQL statement. If additional parameters are given, they are treated as bind variables, and are bound to the placeholders in the query.
Note that if any of the values passed to this are hashes, then the key/value pairs are each bound separately, with the key being used as the name of the placeholder to bind the value to.
Yields one Array(Value)
for each result.
A convenience method that returns the first row of a query result.
A convenience method that returns the first row of a query result.
A convenience method that returns the first value of the first row of a query result.
A convenience method that returns the first value of the first row of a query result.
Obtains the unique row ID of the last row to be inserted by this Database instance.
This is an Int64
.
Executes a query and yields a ResultSet
that will be closed at the end of the given block.
Executes a query and yields a ResultSet
that will be closed at the end of the given block.
Quotes the given string, making it safe to use in an SQL statement. It replaces all instances of the single-quote character with two single-quote characters.