【发布时间】:2015-05-12 17:46:19
【问题描述】:
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 以便能够执行查询。任何有关不同方式的帮助或建议将不胜感激。
【问题讨论】:
-
是否有某些原因您不能获取用户提供的字符串并直接使用它?用户输入的示例是什么?
-
我想使用正则表达式,因为可能有多个输入。一个示例输入是“select * from gears where Lab like 'Primary'”,另一个示例是“select * from gears where RU like 40”。区别在于“。*”所在的正则表达式。如果我在哪里使用字符串,我将不得不为所有查询可能性编码,而不仅仅是填写空白情况。 @Micah
-
好吧,那应该相当简单。我假设
execute(m)是我们正在研究的方法,其中m是字符串输入? -
是 "m.reply " 是如果输入匹配的正则表达式,则在 irc 通道中返回的内容。
标签: sql ruby regex sqlite cinch