module Sequel::SqlAnywhere::DatasetMethods
Public Instance Methods
# 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
Use today() for CURRENT_DATE and now() for CURRENT_TIMESTAMP and CURRENT_TIME
# 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
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
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
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
Specify a table for a SELECT … INTO query.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 370 def into(table) clone(:into => table) end
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
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 258 def supports_cte?(type=:select) type == :select end
SQLAnywhere supports GROUPING SETS
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 263 def supports_grouping_sets? true end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 275 def supports_is_true? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 279 def supports_join_using? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 267 def supports_multiple_column_in? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 271 def supports_where_true? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 283 def supports_window_clause? true end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 287 def supports_window_functions? true end
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
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
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
# 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
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
Use 0 for false on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 392 def literal_false '0' end
Use 1 for true on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 387 def literal_true '1' end
Sybase supports multiple rows in INSERT.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 411 def multi_insert_sql_strategy :values end
SQLAnywhere does not natively support NULLS FIRST/LAST.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 416 def requires_emulating_nulls_first? true end
# 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
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
Use WITH RECURSIVE instead of WITH if any of the CTEs is recursive
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 448 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 464 def timestamp_precision 3 end