SQlite 3 Ruby只能添加一列数据

时间:2016-04-08 00:01:33

标签: ruby sqlite

这让我疯了!我有一些数组,我想放入SQLite数据库。每次我运行我的代码时它只放入第一个数组,然后所有其余的都得到“Null”我可以改变数组的顺序但不管数组是第一个总是进入但其余的不是

这是我的代码,用于设置数据库

require 'sqlite3'

DBNAME= 'resultsdb.sqlite'
File.delete(DBNAME) if File.exists?DBNAME 

$db= SQLite3::Database.new(DBNAME)
$db.execute("Create TABLE althete (date, event, pos, array1, array2, array3, agecat, gender, genderposition, array4, array5, array6)")

以下是插入数组的代码,

$positions.each do |position|
  $db.execute("INSERT INTO althete (pos) VALUES ('#{position}')")
end 

$events.each do |event|
  $db.execute("INSERT INTO althete (array1) VALUES ('#{event}')")
end

对于我想要进入同一个表的其他十个数组,我有类似的声明。

对不起,我的代码可能非常草率,因为我还在学习ruby,任何帮助都会非常感激。

0 个答案:

没有答案