Module: ArJdbc::Sybase
- Defined in:
- lib/arjdbc/sybase/adapter.rb
Instance Method Summary collapse
-
#add_limit_offset!(sql, options) ⇒ Object
:nodoc:.
-
#modify_types(tp) ⇒ Object
:nodoc:.
- #remove_index(table_name, options = {}) ⇒ Object
-
#use_temp_table? ⇒ Boolean
If limit is not set at all, we can ignore offset; if limit is set but offset is zero, use normal select with simple SET ROWCOUNT.
- #zero_limit? ⇒ Boolean
Instance Method Details
#add_limit_offset!(sql, options) ⇒ Object
:nodoc:
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/arjdbc/sybase/adapter.rb', line 3 def add_limit_offset!(sql, ) # :nodoc: @limit = [:limit] @offset = [:offset] if use_temp_table? # Use temp table to hack offset with Sybase sql.sub!(/ FROM /i, ' INTO #artemp FROM ') elsif zero_limit? # "SET ROWCOUNT 0" turns off limits, so we havesy # to use a cheap trick. if sql =~ /WHERE/i sql.sub!(/WHERE/i, 'WHERE 1 = 2 AND ') elsif sql =~ /ORDER\s+BY/i sql.sub!(/ORDER\s+BY/i, 'WHERE 1 = 2 ORDER BY') else sql << 'WHERE 1 = 2' end end end |
#modify_types(tp) ⇒ Object
:nodoc:
34 35 36 37 38 39 40 |
# File 'lib/arjdbc/sybase/adapter.rb', line 34 def modify_types(tp) #:nodoc: tp[:primary_key] = "NUMERIC(22,0) IDENTITY PRIMARY KEY" tp[:integer][:limit] = nil tp[:boolean] = {:name => "bit"} tp[:binary] = {:name => "image"} tp end |
#remove_index(table_name, options = {}) ⇒ Object
42 43 44 |
# File 'lib/arjdbc/sybase/adapter.rb', line 42 def remove_index(table_name, = {}) execute "DROP INDEX #{table_name}.#{index_name(table_name, )}" end |
#use_temp_table? ⇒ Boolean
If limit is not set at all, we can ignore offset; if limit is set but offset is zero, use normal select with simple SET ROWCOUNT. Thus, only use the temp table if limit is set and offset > 0.
26 27 28 |
# File 'lib/arjdbc/sybase/adapter.rb', line 26 def use_temp_table? !@limit.nil? && !@offset.nil? && @offset > 0 end |
#zero_limit? ⇒ Boolean
30 31 32 |
# File 'lib/arjdbc/sybase/adapter.rb', line 30 def zero_limit? !@limit.nil? && @limit == 0 end |