Module: JdbcSpec::Sybase

Defined in:
lib/jdbc_adapter/jdbc_sybase.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.adapter_selectorObject



3
4
5
# File 'lib/jdbc_adapter/jdbc_sybase.rb', line 3

def self.adapter_selector
  [/sybase/i, lambda{|cfg,adapt| adapt.extend(JdbcSpec::Sybase)}]
end

Instance Method Details

#add_limit_offset!(sql, options) ⇒ Object

:nodoc:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jdbc_adapter/jdbc_sybase.rb', line 7

def add_limit_offset!(sql, options) # :nodoc:
  @limit = options[:limit]
  @offset = options[: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

#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.

Returns:

  • (Boolean)


30
31
32
# File 'lib/jdbc_adapter/jdbc_sybase.rb', line 30

def use_temp_table?
  !@limit.nil? && !@offset.nil? && @offset > 0
end

#zero_limit?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/jdbc_adapter/jdbc_sybase.rb', line 34

def zero_limit?
  !@limit.nil? && @limit == 0
end