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
302 def complex_expression_sql_append(sql, op, args)
303   case op
304   when :'||'
305     super(sql, :+, args)
306   when :<<, :>>
307     complex_expression_emulate_append(sql, op, args)
308   when :LIKE, :"NOT LIKE"
309     sql << '('
310     literal_append(sql, args[0])
311     sql << (op == :LIKE ? ' REGEXP ' : ' NOT REGEXP ')
312     pattern = String.new
313     last_c = ''
314     args[1].each_char do |c|
315       if  c == '_' and not pattern.end_with?('\\') and last_c != '\\'
316         pattern << '.'
317       elsif c == '%' and not pattern.end_with?('\\') and last_c != '\\'
318         pattern << '.*'
319       elsif c == '[' and not pattern.end_with?('\\') and last_c != '\\'
320         pattern << '\['
321       elsif c == ']' and not pattern.end_with?('\\') and last_c != '\\'
322         pattern << '\]'
323       elsif c == '*' and not pattern.end_with?('\\') and last_c != '\\'
324         pattern << '\*'
325       elsif c == '?' and not pattern.end_with?('\\') and last_c != '\\'
326         pattern << '\?'
327       else
328         pattern << c
329       end
330       if c == '\\' and last_c == '\\'
331         last_c = ''
332       else
333         last_c = c
334       end
335     end
336     literal_append(sql, pattern)
337     sql << " ESCAPE "
338     literal_append(sql, "\\")
339     sql << ')'
340   when :ILIKE, :"NOT ILIKE"
341     super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args)
342   when :extract
343     sql << 'datepart('
344     literal_append(sql, args[0])
345     sql << ','
346     literal_append(sql, args[1])
347     sql << ')'
348   else
349     super
350   end
351 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
359 def constant_sql_append(sql, constant)
360   case constant
361   when :CURRENT_DATE
362     sql << 'today()'
363   when :CURRENT_TIMESTAMP, :CURRENT_TIME
364     sql << 'now()'
365   else
366     super
367   end
368 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
250 def convert_smallint_to_bool
251   opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : db.convert_smallint_to_bool
252 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
293 def cross_apply(table)
294   join_table(:cross_apply, table)
295 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
354 def escape_like(string)
355   string.gsub(/[\\%_\[]/){|m| "\\#{m}"}
356 end
into(table) click to toggle source

Specify a table for a SELECT … INTO query.

    # File lib/sequel/adapters/shared/sqlanywhere.rb
371 def into(table)
372   clone(:into => table)
373 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
298 def recursive_cte_requires_column_aliases?
299   true
300 end
supports_cte?(type=:select) click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
259 def supports_cte?(type=:select)
260   type == :select
261 end
supports_grouping_sets?() click to toggle source

SQLAnywhere supports GROUPING SETS

    # File lib/sequel/adapters/shared/sqlanywhere.rb
264 def supports_grouping_sets?
265   true
266 end
supports_is_true?() click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
276 def supports_is_true?
277   false
278 end
supports_join_using?() click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
280 def supports_join_using?
281   false
282 end
supports_multiple_column_in?() click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
268 def supports_multiple_column_in?
269   false
270 end
supports_where_true?() click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
272 def supports_where_true?
273   false
274 end
supports_window_clause?() click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
284 def supports_window_clause?
285   true
286 end
supports_window_functions?() click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
288 def supports_window_functions?
289   true
290 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
255 def with_convert_smallint_to_bool(v)
256   clone(:convert_smallint_to_bool=>v)
257 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
378 def default_time_format
379   "'%H:%M:%S.%3N'"
380 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
383 def default_timestamp_format
384   "'%Y-%m-%d %H:%M:%S.%3N'"
385 end
join_type_sql(join_type) click to toggle source
Calls superclass method
    # File lib/sequel/adapters/shared/sqlanywhere.rb
453 def join_type_sql(join_type)
454   case join_type
455   when :cross_apply
456     'CROSS APPLY'
457   when :outer_apply
458     'OUTER APPLY'
459   else
460     super
461   end
462 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
403 def literal_blob_append(sql, v)
404   if v.empty?
405     literal_append(sql, "")
406   else
407     sql << "0x" << v.unpack("H*").first
408   end
409 end
literal_false() click to toggle source

Use 0 for false on Sybase

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

Use 1 for true on Sybase

    # File lib/sequel/adapters/shared/sqlanywhere.rb
388 def literal_true
389   '1'
390 end
multi_insert_sql_strategy() click to toggle source

Sybase supports multiple rows in INSERT.

    # File lib/sequel/adapters/shared/sqlanywhere.rb
412 def multi_insert_sql_strategy
413   :values
414 end
requires_emulating_nulls_first?() click to toggle source

SQLAnywhere does not natively support NULLS FIRST/LAST.

    # File lib/sequel/adapters/shared/sqlanywhere.rb
417 def requires_emulating_nulls_first?
418   true
419 end
select_into_sql(sql) click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
421 def select_into_sql(sql)
422   if i = @opts[:into]
423     sql << " INTO "
424     identifier_append(sql, i)
425   end
426 end
select_limit_sql(sql) click to toggle source

Sybase uses TOP N for limit.

    # File lib/sequel/adapters/shared/sqlanywhere.rb
429 def select_limit_sql(sql)
430   l = @opts[:limit]
431   o = @opts[:offset]
432   if l || o
433     if l
434       sql << " TOP "
435       literal_append(sql, l)
436     else
437       sql << " TOP 2147483647"
438     end
439 
440     if o 
441       sql << " START AT ("
442       literal_append(sql, o)
443       sql << " + 1)"
444     end
445   end
446 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
449 def select_with_sql_base
450   opts[:with].any?{|w| w[:recursive]} ? "WITH RECURSIVE " : super
451 end
timestamp_precision() click to toggle source

SQLAnywhere supports millisecond timestamp precision.

    # File lib/sequel/adapters/shared/sqlanywhere.rb
465 def timestamp_precision
466   3
467 end