lib/ronin/code/sql/field.rb in ronin-sql-0.1.1 vs lib/ronin/code/sql/field.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.
@@ -20,65 +20,82 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#++
#
require 'ronin/code/sql/expr'
+require 'ronin/code/sql/as'
require 'ronin/code/sql/between'
+require 'ronin/code/sql/asc'
+require 'ronin/code/sql/desc'
module Ronin
module Code
module SQL
class Field < Expr
- def initialize(style,name,prefix=nil)
- super(style)
-
+ def initialize(symbols,name,prefix=nil)
+ @symbols = symbols
@prefix = prefix
@name = name
end
- def *
- field_cache[:"*"]
+ def field(name)
+ sym = @symbols.symbol("#{path}.#{name}")
+ sym.value ||= Field.new(@symbols,name,self)
+
+ return sym
end
+ def all
+ field('*')
+ end
+
+ alias * all
+
def id
- field_cache[:id]
+ field('id')
end
+
+ def as(name)
+ As.new(self,name)
+ end
def between(start,stop)
Between.new(self,start,stop)
end
def <=>(range)
between(range.begin,range.end)
end
- def compile
- if @prefix
- return "#{@prefix}.#{@name}"
- else
- return @name.to_s
- end
+ def asc
+ Asc.new(self)
end
- def to_sym
- compile.to_sym
+ def desc
+ Desc.new(self)
end
+ def emit
+ [path.to_sym]
+ end
+
protected
- def method_missing(sym,*args)
- if (args.length==0 && @prefix.nil?)
- return field_cache[sym]
+ def path
+ if @prefix
+ return "#{@prefix}.#{@name}"
+ else
+ return "#{@name}"
end
-
- raise(NoMethodError,sym.id2name)
end
- private
+ def method_missing(name,*arguments,&block)
+ if (arguments.empty? && @prefix.nil? && block.nil?)
+ return field(name)
+ end
- def field_cache
- @field_cache ||= Hash.new { |hash,key| hash[key] = Field.new(@style,key,self) }
+ raise(NoMethodError,sym.id2name)
end
end
end
end