ruby连接sqlite

2021-11-02 10:37:47 浏览数 (1)

示例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

0 人点赞