lib/ronin/code/sql/expr.rb in ronin-sql-0.1.1 vs lib/ronin/code/sql/expr.rb in ronin-sql-0.2.0
- old
+ new
@@ -1,11 +1,11 @@
#
#--
# Ronin SQL - A Ronin library providing support for SQL related security
# tasks.
#
-# Copyright (c) 2007-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
+# Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
@@ -19,69 +19,38 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#++
#
-require 'ronin/code/sql/keyword'
+require 'ronin/code/sql/emittable'
require 'ronin/extensions/meta'
module Ronin
module Code
module SQL
class Expr
- # The style to use
- attr_reader :style
+ include Emittable
- def initialize(style)
- @style = style
- end
-
def in?(*range)
- In.new(@style,self,*range)
+ In.new(self,*range)
end
def ===(*range)
in?(*range)
end
def not_in?(*range)
in?(*range).not!
end
- def compile
- # place holder
- end
-
- def to_s
- compile
- end
-
protected
- def keyword(value)
- keyword_cache[value.to_sym]
- end
-
- def keywords(*values)
- values.map { |value| keyword(value) }
- end
-
- def self.keyword(name,value=name.to_s.upcase)
- name = name.to_s.downcase
-
- class_def("keyword_#{name}") do
- keyword(value)
- end
-
- return self
- end
-
def self.binary_op(op,*names)
names.each do |name|
class_def(name) do |expr|
- BinaryExpr.new(@style,op,self,expr)
+ BinaryExpr.new(op,self,expr)
end
end
return self
end
@@ -102,11 +71,11 @@
binary_op 'AND', :and
def self.like_op(op,*names)
names.each do |name|
class_def(name) do |expr,escape|
- LikeExpr.new(@style,op,self,expr,escape)
+ Like.new(op,self,expr,escape)
end
end
return self
end
@@ -117,76 +86,18 @@
like_op 'MATCH', :match
def self.unary_op(op,*names)
names.each do |name|
class_def(name) do
- UnaryExpr.new(@style,op,self)
+ UnaryExpr.new(op,self)
end
end
return self
end
unary_op 'NOT', :not!
unary_op 'EXISTS', :exists?
-
- def compile_space
- @style.compile_space
- end
-
- def preappend_space(str)
- @style.preappend_space(str)
- end
-
- def append_space(str)
- @style.append_space(str)
- end
-
- def space(*str)
- @style.space(*str)
- end
-
- def compile_newline
- @style.compile_newline
- end
-
- def quote_string(data)
- @style.quote_string(data)
- end
-
- def compile_keyword(name)
- @style.compile_keyword(name)
- end
-
- def compile_list(*expr)
- @style.compile_list(*expr)
- end
-
- def compile_datalist(*expr)
- @style.compile_list(*expr)
- end
-
- def compile_row(*expr)
- @style.compile_row(*expr)
- end
-
- def compile_data(data)
- @style.compile_data(data)
- end
-
- def compile_expr(*expr)
- @style.compile_expr(*expr)
- end
-
- def compile_statements(*statements)
- @style.compile_statements(*statements)
- end
-
- private
-
- def keyword_cache
- @keyword_cache ||= Hash.new { |hash,key| hash[key] = Keyword.new(@style,key) }
- end
end
end
end
end