热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

将用户正则表达式匹配到数据库查询中-feeduserregexmatchintodatabasequery

classDatabaseincludeCinch::PluginDBSQLite3::Database.new(development.sqlite3)match
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

This part of an IRC bot. I am trying to have the matched regex that the user inputs directly inputed to the @db.execute to be able perform the query. Any help or suggestions for a different way to go would be appreciated.

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

1 个解决方案

#1


Something along these lines should work:

沿着这些方向的东西应该有效:

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

推荐阅读
author-avatar
拍友2502883387
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有