模糊的SQLite3错误Youtube查询

时间:2014-01-11 19:45:11

标签: ruby sqlite youtube

我在ruby中编写了一个应用程序,它在youtube网站上查询从特定数据库中获取的一些关键字。在youtube查询完成后,生成的视频的ID和标题将插入到2个不同的dbs中。我运行了代码,我得到了这个例外:

C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.8-x86-mingw32/lib/sqlite3/database.rb:91:in `initialize': near "'tag:youtube.com,2008:video:3taEuL4EHAg'": syntax error (SQLite3::SQLException)

我的查询中的无效字符是否导致此错误?我使用的SQLite gem应该处理这些吗?

如果你需要这里的代码,那就是:

require "sqlite3"
require "youtube_it"

database = SQLite3::Database.new("data.db")
client = YouTubeIt::Client.new(:dev_key =>"myyoutubekey")

result = database.query("SELECT `keyphrase` FROM `keyphrases`")
result.each do |array|
  array.each do |result|
    results = client.videos_by(:query => "#{result}", :page => 1, :per_page => 10)
    results.videos.each do |videoone|
      database.query("INSERT OR IGNORE INTO `videos` (videoID,cachedTitle) VALUES ('#{videoone.video_id}','videoone.title')")

      rezultat = database.query("SELECT `id` FROM `keyphrases` WHERE `keyphrase` = '#{result}' ")
      rezultat.each do |n|
        id =  n.to_s.delete("[").delete("]").to_i
        database.query("INSERT INTO `keyphrase2videos` (keyphraseID,videoID) VALUES ('#{id}','#{videoone.video_id}'")
      end

    end

  end

end
p "Recored Entered"

1 个答案:

答案 0 :(得分:0)

我在VALUES子句中错过了一个“)”