返回顶部

收藏

ruby连接sqlite

更多

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

标签:ruby,sqlite,数据库

收藏

0人收藏

支持

0

反对

0

发表评论