module Sequel::SqlAnywhere::DatasetMethods
Public Instance Methods
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 288 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
Use today() for CURRENT_DATE and now() for CURRENT_TIMESTAMP and CURRENT_TIME
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 345 def constant_sql_append(sql, constant) case constant when :CURRENT_DATE sql << 'today()' when :CURRENT_TIMESTAMP, :CURRENT_TIME sql << 'now()' else super end end
Whether to convert smallint to boolean arguments for this dataset. Defaults to the IBMDB module setting.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 240 def convert_smallint_to_bool opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : db.convert_smallint_to_bool end
Uses CROSS APPLY to join the given table into the current dataset.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 279 def cross_apply(table) join_table(:cross_apply, table) end
SqlAnywhere uses \ to escape metacharacters, but a ']' should not be escaped
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 340 def escape_like(string) string.gsub(/[\\%_\[]/){|m| "\\#{m}"} end
Specify a table for a SELECT … INTO query.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 357 def into(table) clone(:into => table) end
SqlAnywhere requires recursive CTEs to have column aliases.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 284 def recursive_cte_requires_column_aliases? true end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 249 def supports_cte?(type=:select) type == :select end
SQLAnywhere supports GROUPING SETS
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 254 def supports_grouping_sets? true end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 266 def supports_is_true? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 270 def supports_join_using? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 258 def supports_multiple_column_in? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 274 def supports_timestamp_usecs? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 262 def supports_where_true? false end
Return a cloned dataset with the #convert_smallint_to_bool option set.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 245 def with_convert_smallint_to_bool(v) clone(:convert_smallint_to_bool=>v) end
Private Instance Methods
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 424 def join_type_sql(join_type) case join_type when :cross_apply 'CROSS APPLY' when :outer_apply 'OUTER APPLY' else super end end
SqlAnywhere uses a preceding X for hex escaping strings
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 379 def literal_blob_append(sql, v) if v.empty? literal_append(sql, "") else sql << "0x" << v.unpack("H*").first end end
Use 0 for false on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 369 def literal_false '0' end
Use 1 for true on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 364 def literal_true '1' end
Sybase supports multiple rows in INSERT.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 388 def multi_insert_sql_strategy :values end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 392 def select_into_sql(sql) if i = @opts[:into] sql << " INTO " identifier_append(sql, i) end end
Sybase uses TOP N for limit.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 400 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
Use WITH RECURSIVE instead of WITH if any of the CTEs is recursive
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 420 def select_with_sql_base opts[:with].any?{|w| w[:recursive]} ? "WITH RECURSIVE " : super end
SQLAnywhere supports millisecond timestamp precision.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 436 def timestamp_precision 3 end