module Sequel::SqlAnywhere::DatasetMethods

Constants

APOS
APOS_RE
BACKSLASH_RE
BLOB_START
BOOL_FALSE
BOOL_TRUE
CROSS_APPLY
DATEPART
DATE_FUNCTION
DOUBLE_APOS
HSTAR
NOT_REGEXP
NOW_FUNCTION
ONLY_OFFSET
OUTER_APPLY
QUAD_BACKSLASH
REGEXP
SQL_WITH_RECURSIVE
START_AT
TOP
WILDCARD

Attributes

convert_smallint_to_bool[W]

Override the default Sequel::SqlAnywhere.convert_smallint_to_bool setting for this dataset.

Public Instance Methods

complex_expression_sql_append(sql, op, args) click to toggle source

SQLAnywhere uses + for string concatenation, and LIKE is case insensitive by default.

Calls superclass method
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 317
def complex_expression_sql_append(sql, op, args)
  case op
  when :'||'
    super(sql, :+, args)
  when :<<, :>>
    complex_expression_emulate_append(sql, op, args)
  when :LIKE, :"NOT LIKE"
    sql << Sequel::Dataset::PAREN_OPEN
    literal_append(sql, args.at(0))
    sql << Sequel::Dataset::SPACE << (op == :LIKE ? REGEXP : NOT_REGEXP) << Sequel::Dataset::SPACE
    pattern = ''
    last_c = ''
    args.at(1).each_char do |c|
      if  c == '_' and not pattern.end_with?('\') and last_c != '\'
        pattern << '.'
      elsif c == '%' and not pattern.end_with?('\') and last_c != '\'
        pattern << '.*'
      elsif c == '[' and not pattern.end_with?('\') and last_c != '\'
        pattern << '\['
      elsif c == ']' and not pattern.end_with?('\') and last_c != '\'
        pattern << '\]'
      elsif c == '*' and not pattern.end_with?('\') and last_c != '\'
        pattern << '\*'
      elsif c == '?' and not pattern.end_with?('\') and last_c != '\'
        pattern << '\?'
      else
        pattern << c
      end
      if c == '\' and last_c == '\'
        last_c = ''
      else
        last_c = c
      end
    end
    literal_append(sql, pattern)
    sql << Sequel::Dataset::ESCAPE
    literal_append(sql, Sequel::Dataset::BACKSLASH)
    sql << Sequel::Dataset::PAREN_CLOSE
  when :ILIKE, :"NOT ILIKE"
    super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args)
  when :extract
    sql << DATEPART + Sequel::Dataset::PAREN_OPEN
    literal_append(sql, args.at(0))
    sql << ','
    literal_append(sql, args.at(1))
    sql << Sequel::Dataset::PAREN_CLOSE
  else
    super
  end
end
constant_sql_append(sql, constant) click to toggle source

Use Date() and Now() for CURRENT_DATE and CURRENT_TIMESTAMP

Calls superclass method
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 374
def constant_sql_append(sql, constant)
  case constant
  when :CURRENT_DATE
    sql << DATE_FUNCTION
  when :CURRENT_TIMESTAMP, :CURRENT_TIME
    sql << NOW_FUNCTION
  else
    super
  end
end
convert_smallint_to_bool() click to toggle source

Whether to convert smallint to boolean arguments for this dataset. Defaults to the SqlAnywhere module setting.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 275
def convert_smallint_to_bool
  defined?(@convert_smallint_to_bool) ? @convert_smallint_to_bool : (@convert_smallint_to_bool = @db.convert_smallint_to_bool)
end
cross_apply(table) click to toggle source

Uses CROSS APPLY to join the given table into the current dataset.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 307
def cross_apply(table)
  join_table(:cross_apply, table)
end
escape_like(string) click to toggle source

SqlAnywhere uses \ to escape metacharacters, but a ']' should not be escaped

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 369
def escape_like(string)
  string.gsub(/[\%_\[]/){|m| "\\#{m}"}
end
into(table) click to toggle source

Specify a table for a SELECT … INTO query.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 386
def into(table)
  clone(:into => table)
end
recursive_cte_requires_column_aliases?() click to toggle source

SqlAnywhere requires recursive CTEs to have column aliases.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 312
def recursive_cte_requires_column_aliases?
  true
end
supports_cte?(type=:select) click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 282
def supports_cte?(type=:select)
  type == :select || type == :insert
end
supports_is_true?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 294
def supports_is_true?
  false
end
supports_join_using?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 298
def supports_join_using?
  false
end
supports_multiple_column_in?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 286
def supports_multiple_column_in?
  false
end
supports_timestamp_usecs?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 302
def supports_timestamp_usecs?
  false
end
supports_where_true?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 290
def supports_where_true?
  false
end

Private Instance Methods

join_type_sql(join_type) click to toggle source
Calls superclass method
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 454
def join_type_sql(join_type)
  case join_type
  when :cross_apply
    CROSS_APPLY
  when :outer_apply
    OUTER_APPLY
  else
    super
  end
end
literal_blob_append(sql, v) click to toggle source

SqlAnywhere uses a preceding X for hex escaping strings

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 408
def literal_blob_append(sql, v)
  if v.empty?
    literal_append(sql, "")
  else
    sql << BLOB_START << v.unpack(HSTAR).first
  end
end
literal_false() click to toggle source

Use 0 for false on Sybase

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 398
def literal_false
  BOOL_FALSE
end
literal_string_append(sql, v) click to toggle source

SQL fragment for String. Doubles \ and ' by default.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 403
def literal_string_append(sql, v)
  sql << APOS << v.gsub(BACKSLASH_RE, QUAD_BACKSLASH).gsub(APOS_RE, DOUBLE_APOS) << APOS
end
literal_true() click to toggle source

Use 1 for true on Sybase

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 393
def literal_true
  BOOL_TRUE
end
multi_insert_sql_strategy() click to toggle source

Sybase supports multiple rows in INSERT.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 417
def multi_insert_sql_strategy
  :values
end
select_into_sql(sql) click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 421
def select_into_sql(sql)
  if i = @opts[:into]
    sql << Sequel::Dataset::INTO
    identifier_append(sql, i)
  end
end
select_limit_sql(sql) click to toggle source

Sybase uses TOP N for limit. For Sybase TOP (N) is used to allow the limit to be a bound variable.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 430
def select_limit_sql(sql)
  l = @opts[:limit]
  o = @opts[:offset]
  if l || o
    if l
      sql << TOP
      literal_append(sql, l)
    else
      sql << ONLY_OFFSET
    end

    if o 
      sql << START_AT + "("
      literal_append(sql, o)
      sql << " + 1)"
    end
  end
end
select_with_sql_base() click to toggle source

Use WITH RECURSIVE instead of WITH if any of the CTEs is recursive

Calls superclass method
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 450
def select_with_sql_base
  opts[:with].any?{|w| w[:recursive]} ? SQL_WITH_RECURSIVE : super
end
timestamp_precision() click to toggle source

SQLAnywhere supports millisecond timestamp precision.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 466
def timestamp_precision
  3
end