同じレコードをinsertしちゃうと重複レコードが−。
消すには…と消し方を探るより,重複なしでselectしたものを 別の表にコピーしてそれをマスターにしちゃえばいい。
create table newhoge as select distinct * from hoge; drop table hoge; alter table newhoge rename to hoge;
UNIQUE属性を付けた表を作ってそこにコピーのほうがいいか。
create table newhoge (id int UNIQUE, foo real, bar text) insert into newhoge select distinct * from hoge; drop table hoge; alter table newhoge rename to hoge;
Rubyから開く:
require 'sqlite3'
db = SQLite3::Database.new("ファイル")
# db.results_as_hash = true
db.execute("SQL文") do |row|
# executeに直接ブロックを渡すとrowごとイテレータ
end
execute2メソッドだと,最初のrowに見出しが返る。