I have a Ruby hash with variables:
- a two-element array of strings
- an integer
I have tried the two following ways to insert the elements from the hash to a SQLite 3 DB:
myRubyHash.each do |k, v|
x=[k[0],k[1],v]
db.execute "INSERT INTO MyTable VALUES ( ?, ?, ? )", x
end
And,
myRubyHash.each do |x|
db.execute "INSERT INTO MyTable VALUES ( ?, ?, ? )", x
end
The first being considerably faster (but still quite slow). Is there a faster way to go about this?
If it helps, my SQLite 3 table was created by:
rows = db.execute <<-SQL
CREATE TABLE Assoc_words_p (
name1 varchar(30),
name2 varchar(30),
val int,
PRIMARY KEY (name1,name2)
);
SQL
Thanks
I found the prepare statement can be used as follows: