Class: OklahomaMixer::Query
- Inherits:
-
Object
- Object
- OklahomaMixer::Query
- Defined in:
- lib/oklahoma_mixer/query.rb,
lib/oklahoma_mixer/query/c.rb
Overview
:nodoc:
Defined Under Namespace
Modules: C
Instance Attribute Summary collapse
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
Instance Method Summary collapse
- #condition(column, operator, expression, no_index = false) ⇒ Object
- #free ⇒ Object
-
#initialize(table_pointer) ⇒ Query
constructor
A new instance of Query.
- #limit(max, offset = nil) ⇒ Object
- #order(column, str_num_asc_desc = nil) ⇒ Object
Constructor Details
Instance Attribute Details
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
10 11 12 |
# File 'lib/oklahoma_mixer/query.rb', line 10 def pointer @pointer end |
Instance Method Details
#condition(column, operator, expression, no_index = false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/oklahoma_mixer/query.rb', line 12 def condition(column, operator, expression, no_index = false) operator = operator.to_s negate = operator.sub!(/\A(?:!_?|not_)/, "") operator = case operator when /\A(?:=?=|eq(?:ua)?ls?\??)\z/ if expression.is_a? Numeric then :TDBQCNUMEQ else :TDBQCSTREQ end when /\Astr(?:ing)?_eq(?:ua)?ls?\??\z/ then :TDBQCSTREQ when /\Ainclude?s?\??\z/ then :TDBQCSTRINC when /\Astarts?_with\??\z/ then :TDBQCSTRBW when /\Aends?_with\??\z/ then :TDBQCSTREW when /\Aincludes?_all(?:_tokens?)?\??\z/ then :TDBQCSTRAND when /\Aincludes?_any(?:_tokens?)?\??\z/ then :TDBQCSTROR when /\Aeq(?:ua)?ls?_any(?:_tokens?)?\??\z/ then :TDBQCSTROREQ when /\A(?:~|=~|match(?:es)?\??)\z/ then :TDBQCSTRRX when /\Anum(?:ber)?_eq(?:ua)?ls?\??\z/ then :TDBQCNUMEQ when ">" then :TDBQCNUMGT when ">=" then :TDBQCNUMGE when "<" then :TDBQCNUMLT when "<=" then :TDBQCNUMLE when /\Abetween\??\z/ then :TDBQCNUMBT when /\Aany_num(?:ber)?\??\z/ then :TDBQCNUMOREQ when /\Aphrase_search\??\z/ then :TDBQCFTSPH when /\Aall_tokens?_search\??\z/ then :TDBQCFTSAND when /\Aany_tokens?_search\??\z/ then :TDBQCFTSOR when /\Aexpression_search\??\z/ then :TDBQCFTSEX else fail Error::QueryError, "unknown condition operator" end operator = C::CONDITIONS[operator] operator |= C::CONDITIONS[:TDBQCNEGATE] if negate operator |= C::CONDITIONS[:TDBQCNOIDX] if no_index C.addcond( @pointer, yield(column), operator, yield( expression.respond_to?(:source) ? expression.source : expression ) ) end |
#free ⇒ Object
69 70 71 |
# File 'lib/oklahoma_mixer/query.rb', line 69 def free C.del(@pointer) end |
#limit(max, offset = nil) ⇒ Object
65 66 67 |
# File 'lib/oklahoma_mixer/query.rb', line 65 def limit(max, offset = nil) C.setlimit(@pointer, max.to_i, offset.to_i) end |
#order(column, str_num_asc_desc = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/oklahoma_mixer/query.rb', line 53 def order(column, str_num_asc_desc = nil) str_num_asc_desc = case str_num_asc_desc.to_s when /\A(?:STR_)?ASC\z/i, "" then :TDBQOSTRASC when /\A(?:STR_)?DESC\z/i then :TDBQOSTRDESC when /\ANUM_ASC\z/i then :TDBQONUMASC when /\ANUM_DESC\z/i then :TDBQONUMDESC else fail Error::QueryError, "unknown order type" end C.setorder(@pointer, yield(column), C::ORDERS[str_num_asc_desc]) end |