0
class Database
  include Cinch::Plugin

  DB = SQLite3::Database.new('development.sqlite3')
  match /(select .* from gears where .* like .*)/i 

  def execute(m)
    @db = SQLite3::Database.new('development.sqlite3')
    #m.reply @db.execute("select * from gears where lab like 'Primary'") 
  end
end

IRC 机器人的这一部分。我正在尝试将用户输入的匹配正则表达式直接输入到@db.execute 以便能够执行查询。任何有关不同方式的帮助或建议将不胜感激。

4

1 回答 1

1

这些方面的东西应该起作用:

def execute(m)
  @db = SQLite3::Database.new('development.sqlite3')
  input = m.input # or however you're getting the input into this function
  regex = /(select .* from gears where .* like .*)/i 
  db_query_string = regex.match(input).to_s
  m.reply @db.execute(db_query_string) 
end
于 2015-05-12T19:12:52.627 回答