Module: Sequel::SqlAnywhere::DatasetMethods

Included in:
JDBC::SqlAnywhere::Dataset, Dataset
Defined in:
lib/sequel/adapters/shared/sqlanywhere.rb

Constant Summary collapse

BOOL_TRUE =
'1'.freeze
BOOL_FALSE =
'0'.freeze
WILDCARD =
LiteralString.new('%').freeze
TOP =
" TOP ".freeze
START_AT =
" START AT ".freeze
SQL_WITH_RECURSIVE =
"WITH RECURSIVE ".freeze
DATE_FUNCTION =
'today()'.freeze
NOW_FUNCTION =
'now()'.freeze
DATEPART =
'datepart'.freeze
REGEXP =
'REGEXP'.freeze
NOT_REGEXP =
'NOT REGEXP'.freeze
APOS =
"'".freeze
APOS_RE =
/'/.freeze
DOUBLE_APOS =
"''".freeze
BACKSLASH_RE =
/\\/.freeze
QUAD_BACKSLASH =
"\\\\\\\\".freeze
BLOB_START =
"0x".freeze
HSTAR =
"H*".freeze
CROSS_APPLY =
'CROSS APPLY'.freeze
OUTER_APPLY =
'OUTER APPLY'.freeze
ONLY_OFFSET =
" TOP 2147483647".freeze

Instance Method Summary collapse

Instance Method Details

#complex_expression_sql_append(sql, op, args) ⇒ Object

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



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 384

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) ⇒ Object

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



441
442
443
444
445
446
447
448
449
450
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 441

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_boolObject

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



335
336
337
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 335

def convert_smallint_to_bool
  opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : db.convert_smallint_to_bool
end

#convert_smallint_to_bool=(v) ⇒ Object

Override the default IBMDB.convert_smallint_to_bool setting for this dataset.



328
329
330
331
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 328

def convert_smallint_to_bool=(v)
  Sequel::Deprecation.deprecate("Sequel::SqlAnywhere::Dataset#convert_smallint_to_bool=", "Call with_convert_smallint_to_bool instead, which returns a modified copy instead of modifying the object")
  @opts[:convert_smallint_to_bool] = v
end

#cross_apply(table) ⇒ Object

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



374
375
376
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 374

def cross_apply(table)
  join_table(:cross_apply, table)
end

#escape_like(string) ⇒ Object

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



436
437
438
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 436

def escape_like(string)
  string.gsub(/[\\%_\[]/){|m| "\\#{m}"}
end

#into(table) ⇒ Object

Specify a table for a SELECT … INTO query.



453
454
455
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 453

def into(table)
  clone(:into => table)
end

#recursive_cte_requires_column_aliases?Boolean

SqlAnywhere requires recursive CTEs to have column aliases.

Returns:

  • (Boolean)


379
380
381
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 379

def recursive_cte_requires_column_aliases?
  true
end

#supports_cte?(type = :select) ⇒ Boolean

Returns:

  • (Boolean)


344
345
346
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 344

def supports_cte?(type=:select)
  type == :select || type == :insert
end

#supports_grouping_sets?Boolean

SQLAnywhere supports GROUPING SETS

Returns:

  • (Boolean)


349
350
351
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 349

def supports_grouping_sets?
  true
end

#supports_is_true?Boolean

Returns:

  • (Boolean)


361
362
363
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 361

def supports_is_true?
  false
end

#supports_join_using?Boolean

Returns:

  • (Boolean)


365
366
367
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 365

def supports_join_using?
  false
end

#supports_multiple_column_in?Boolean

Returns:

  • (Boolean)


353
354
355
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 353

def supports_multiple_column_in?
  false
end

#supports_timestamp_usecs?Boolean

Returns:

  • (Boolean)


369
370
371
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 369

def supports_timestamp_usecs?
  false
end

#supports_where_true?Boolean

Returns:

  • (Boolean)


357
358
359
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 357

def supports_where_true?
  false
end

#with_convert_smallint_to_bool(v) ⇒ Object

Return a cloned dataset with the convert_smallint_to_bool option set.



340
341
342
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 340

def with_convert_smallint_to_bool(v)
  clone(:convert_smallint_to_bool=>v)
end