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
306 def complex_expression_sql_append(sql, op, args)
307   case op
308   when :'||'
309     super(sql, :+, args)
310   when :<<, :>>
311     complex_expression_emulate_append(sql, op, args)
312   when :LIKE, :"NOT LIKE"
313     sql << '('
314     literal_append(sql, args[0])
315     sql << (op == :LIKE ? ' REGEXP ' : ' NOT REGEXP ')
316     pattern = String.new
317     last_c = ''
318     args[1].each_char do |c|
319       if  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       elsif c == '*' and not pattern.end_with?('\\') and last_c != '\\'
328         pattern << '\*'
329       elsif c == '?' and not pattern.end_with?('\\') and last_c != '\\'
330         pattern << '\?'
331       else
332         pattern << c
333       end
334       if c == '\\' and last_c == '\\'
335         last_c = ''
336       else
337         last_c = c
338       end
339     end
340     literal_append(sql, pattern)
341     sql << " ESCAPE "
342     literal_append(sql, "\\")
343     sql << ')'
344   when :ILIKE, :"NOT ILIKE"
345     super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args)
346   when :extract
347     sql << 'datepart('
348     literal_append(sql, args[0])
349     sql << ','
350     literal_append(sql, args[1])
351     sql << ')'
352   else
353     super
354   end
355 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
363 def constant_sql_append(sql, constant)
364   case constant
365   when :CURRENT_DATE
366     sql << 'today()'
367   when :CURRENT_TIMESTAMP, :CURRENT_TIME
368     sql << 'now()'
369   else
370     super
371   end
372 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
297 def cross_apply(table)
298   join_table(:cross_apply, table)
299 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
358 def escape_like(string)
359   string.gsub(/[\\%_\[]/){|m| "\\#{m}"}
360 end
into(table) click to toggle source

Specify a table for a SELECT … INTO query.

    # File lib/sequel/adapters/shared/sqlanywhere.rb
375 def into(table)
376   clone(:into => table)
377 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
302 def recursive_cte_requires_column_aliases?
303   true
304 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_timestamp_usecs?() click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
284 def supports_timestamp_usecs?
285   false
286 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
288 def supports_window_clause?
289   true
290 end
supports_window_functions?() click to toggle source
    # File lib/sequel/adapters/shared/sqlanywhere.rb
292 def supports_window_functions?
293   true
294 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

join_type_sql(join_type) click to toggle source
Calls superclass method
    # File lib/sequel/adapters/shared/sqlanywhere.rb
447 def join_type_sql(join_type)
448   case join_type
449   when :cross_apply
450     'CROSS APPLY'
451   when :outer_apply
452     'OUTER APPLY'
453   else
454     super
455   end
456 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
397 def literal_blob_append(sql, v)
398   if v.empty?
399     literal_append(sql, "")
400   else
401     sql << "0x" << v.unpack("H*").first
402   end
403 end
literal_false() click to toggle source

Use 0 for false on Sybase

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

Use 1 for true on Sybase

    # File lib/sequel/adapters/shared/sqlanywhere.rb
382 def literal_true
383   '1'
384 end
multi_insert_sql_strategy() click to toggle source

Sybase supports multiple rows in INSERT.

    # File lib/sequel/adapters/shared/sqlanywhere.rb
406 def multi_insert_sql_strategy
407   :values
408 end
requires_emulating_nulls_first?() click to toggle source

SQLAnywhere does not natively support NULLS FIRST/LAST.

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

Sybase uses TOP N for limit.

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

SQLAnywhere supports millisecond timestamp precision.

    # File lib/sequel/adapters/shared/sqlanywhere.rb
459 def timestamp_precision
460   3
461 end