Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ruby的SQLite3,无法搜索结果数组(在数组上迭代,就像它是一个巨大的元素一样)_Ruby_Parsing_Sqlite - Fatal编程技术网

使用Ruby的SQLite3,无法搜索结果数组(在数组上迭代,就像它是一个巨大的元素一样)

使用Ruby的SQLite3,无法搜索结果数组(在数组上迭代,就像它是一个巨大的元素一样),ruby,parsing,sqlite,Ruby,Parsing,Sqlite,我已经试着找到答案有一段时间了,我不确定我是否问错了问题,但到目前为止我没有运气 我有一个查询SQLite表生成的数组。我还有一个从csv文件生成的时间数组。我试图从SQL表中提取时间[0]作为id号,并检查它是否存在于数组中 array = [] SQLite3::Database.new("t.db") do |db| db.execute ("SELECT t FROM ts") do |row| array << row end end ti

我已经试着找到答案有一段时间了,我不确定我是否问错了问题,但到目前为止我没有运气

我有一个查询SQLite表生成的数组。我还有一个从csv文件生成的时间数组。我试图从SQL表中提取时间[0]作为id号,并检查它是否存在于数组中

array = []
SQLite3::Database.new("t.db") do |db|
    db.execute ("SELECT t FROM ts") do |row|
        array << row
    end
end

times = CSV.read('times1.csv')

times.each do |time|
    #puts "This is the trip id: #{time[0]}"
    if array.include? time[0]
        puts time[0]
        end
end
这是真正让我感到困惑的奇怪部分。我知道2345在数组中只出现一到两次,但是当我运行这段代码时,它似乎会打印每个元素找到的匹配项,比如说找到的匹配项5000次。我觉得从SQLite生成的数组有问题,但我一辈子都搞不清楚

有什么想法吗?谢谢

在这里:

db.execute ("SELECT t FROM ts") do |row|
您的行是一个数组,其唯一元素是您要查找的t。这意味着您最终得到的是数组中的数组,而不是数字数组,当然还有您的数组。包括吗?时间[0]检查失败,因为数组仅包含其他数组

你可能想说:

array << row[0]
收集数组中的t值

array << row[0]