ruby连接sqlite

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

示例1:

require 'sqlite'   
db = SQLite::Database.new("library.db")   
db.execute("select title,
author from books") do |row|  
p row   
end   
db.close 

示例2:

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