示例1:
代码语言:javascript复制require 'sqlite'
db = SQLite::Database.new("library.db")
db.execute("select title,
author from books") do |row|
p row
end
db.close
示例2:
代码语言:javascript复制db = SQLite3::Database.new 'abc.db'
rows = db.execute <<-SQL
create table numbers(
name varchar(30),
val int
);
SQL
{
"one"=>1,
"two"=>2,
}.each do |pair|
db.execute "insert into numbers values(?,?)",pair
end
db.execute("select * from numbers") do |row|
p row
end