module Sequel::SqlAnywhere::DatasetMethods

Public Instance Methods

complex_expression_sql_append(sql, op, args) click to toggle source
Calls superclass method
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 301
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 << '('
    literal_append(sql, args[0])
    sql << (op == :LIKE ? ' REGEXP ' : ' NOT REGEXP ')
    pattern = String.new
    last_c = ''
    args[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 << " ESCAPE "
    literal_append(sql, "\\")
    sql << ')'
  when :ILIKE, :"NOT ILIKE"
    super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args)
  when :extract
    sql << 'datepart('
    literal_append(sql, args[0])
    sql << ','
    literal_append(sql, args[1])
    sql << ')'
  else
    super
  end
end
constant_sql_append(sql, constant) click to toggle source

Use today() for CURRENT_DATE and now() for CURRENT_TIMESTAMP and CURRENT_TIME

Calls superclass method
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 358
def constant_sql_append(sql, constant)
  case constant
  when :CURRENT_DATE
    sql << 'today()'
  when :CURRENT_TIMESTAMP, :CURRENT_TIME
    sql << 'now()'
  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 IBMDB module setting.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 249
def convert_smallint_to_bool
  opts.has_key?(:convert_smallint_to_bool) ? opts[: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 292
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 353
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 370
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 297
def recursive_cte_requires_column_aliases?
  true
end
supports_cte?(type=:select) click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 258
def supports_cte?(type=:select)
  type == :select
end
supports_grouping_sets?() click to toggle source

SQLAnywhere supports GROUPING SETS

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 263
def supports_grouping_sets?
  true
end
supports_is_true?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 275
def supports_is_true?
  false
end
supports_join_using?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 279
def supports_join_using?
  false
end
supports_multiple_column_in?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 267
def supports_multiple_column_in?
  false
end
supports_where_true?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 271
def supports_where_true?
  false
end
supports_window_clause?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 283
def supports_window_clause?
  true
end
supports_window_functions?() click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 287
def supports_window_functions?
  true
end
with_convert_smallint_to_bool(v) click to toggle source

Return a cloned dataset with the #convert_smallint_to_bool option set.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 254
def with_convert_smallint_to_bool(v)
  clone(:convert_smallint_to_bool=>v)
end

Private Instance Methods

default_time_format() click to toggle source

SQLAnywhere only supports 3 digits after the decimal point for times.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 377
def default_time_format
  "'%H:%M:%S.%3N'"
end
default_timestamp_format() click to toggle source

SQLAnywhere only supports 3 digits after the decimal point for timestamps.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 382
def default_timestamp_format
  "'%Y-%m-%d %H:%M:%S.%3N'"
end
join_type_sql(join_type) click to toggle source
Calls superclass method
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 452
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 402
def literal_blob_append(sql, v)
  if v.empty?
    literal_append(sql, "")
  else
    sql << "0x" << v.unpack("H*").first
  end
end
literal_false() click to toggle source

Use 0 for false on Sybase

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 392
def literal_false
  '0'
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 397
def literal_string_append(sql, v)
  sql << "'" << v.gsub("\\", "\\\\\\\\").gsub("'", "''") << "'"
end
literal_true() click to toggle source

Use 1 for true on Sybase

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

Sybase supports multiple rows in INSERT.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 411
def multi_insert_sql_strategy
  :values
end
requires_emulating_nulls_first?() click to toggle source

SQLAnywhere does not natively support NULLS FIRST/LAST.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 416
def requires_emulating_nulls_first?
  true
end
select_into_sql(sql) click to toggle source
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 420
def select_into_sql(sql)
  if i = @opts[:into]
    sql << " INTO "
    identifier_append(sql, i)
  end
end
select_limit_sql(sql) click to toggle source

Sybase uses TOP N for limit.

# File lib/sequel/adapters/shared/sqlanywhere.rb, line 428
def select_limit_sql(sql)
  l = @opts[:limit]
  o = @opts[:offset]
  if l || o
    if l
      sql << " TOP "
      literal_append(sql, l)
    else
      sql << " TOP 2147483647"
    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 448
def select_with_sql_base
  opts[:with].any?{|w| w[:recursive]} ? "WITH RECURSIVE " : super
end
timestamp_precision() click to toggle source

SQLAnywhere supports millisecond timestamp precision.

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