[英]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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.