将用户正则表达式匹配提供给数据库查询
feed user regex match into database query
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 以便能够执行查询。任何对不同方式的帮助或建议将不胜感激。
按照这些思路应该可行:
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
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 以便能够执行查询。任何对不同方式的帮助或建议将不胜感激。
按照这些思路应该可行:
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