module Sequel::SqlAnywhere::DatasetMethods
Constants
- APOS
- APOS_RE
- BACKSLASH_RE
- BLOB_START
- BOOL_FALSE
- BOOL_TRUE
- CROSS_APPLY
- DATEPART
- DATE_FUNCTION
- DOUBLE_APOS
- HSTAR
- NOT_REGEXP
- NOW_FUNCTION
- ONLY_OFFSET
- OUTER_APPLY
- QUAD_BACKSLASH
- REGEXP
- SQL_WITH_RECURSIVE
- START_AT
- TOP
- WILDCARD
Attributes
Override the default Sequel::SqlAnywhere.convert_smallint_to_bool setting for this dataset.
Public Instance Methods
SQLAnywhere uses + for string concatenation, and LIKE is case insensitive by default.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 317 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 << Sequel::Dataset::PAREN_OPEN literal_append(sql, args.at(0)) sql << Sequel::Dataset::SPACE << (op == :LIKE ? REGEXP : NOT_REGEXP) << Sequel::Dataset::SPACE pattern = '' last_c = '' args.at(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 << Sequel::Dataset::ESCAPE literal_append(sql, Sequel::Dataset::BACKSLASH) sql << Sequel::Dataset::PAREN_CLOSE when :ILIKE, :"NOT ILIKE" super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args) when :extract sql << DATEPART + Sequel::Dataset::PAREN_OPEN literal_append(sql, args.at(0)) sql << ',' literal_append(sql, args.at(1)) sql << Sequel::Dataset::PAREN_CLOSE else super end end
Use Date() and Now() for CURRENT_DATE and CURRENT_TIMESTAMP
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 374 def constant_sql_append(sql, constant) case constant when :CURRENT_DATE sql << DATE_FUNCTION when :CURRENT_TIMESTAMP, :CURRENT_TIME sql << NOW_FUNCTION else super end end
Whether to convert smallint to boolean arguments for this dataset. Defaults to the SqlAnywhere module setting.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 275 def convert_smallint_to_bool defined?(@convert_smallint_to_bool) ? @convert_smallint_to_bool : (@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 307 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 369 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 386 def into(table) clone(:into => table) end
SqlAnywhere requires recursive CTEs to have column aliases.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 312 def recursive_cte_requires_column_aliases? true end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 282 def supports_cte?(type=:select) type == :select || type == :insert end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 294 def supports_is_true? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 298 def supports_join_using? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 286 def supports_multiple_column_in? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 302 def supports_timestamp_usecs? false end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 290 def supports_where_true? false end
Private Instance Methods
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 454 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 408 def literal_blob_append(sql, v) if v.empty? literal_append(sql, "") else sql << BLOB_START << v.unpack(HSTAR).first end end
Use 0 for false on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 398 def literal_false BOOL_FALSE end
Use 1 for true on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 393 def literal_true BOOL_TRUE end
Sybase supports multiple rows in INSERT.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 417 def multi_insert_sql_strategy :values end
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 421 def select_into_sql(sql) if i = @opts[:into] sql << Sequel::Dataset::INTO identifier_append(sql, i) end end
Sybase uses TOP N for limit. For Sybase TOP (N) is used to allow the limit to be a bound variable.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 430 def select_limit_sql(sql) l = @opts[:limit] o = @opts[:offset] if l || o if l sql << TOP literal_append(sql, l) else sql << ONLY_OFFSET 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 450 def select_with_sql_base opts[:with].any?{|w| w[:recursive]} ? SQL_WITH_RECURSIVE : super end
SQLAnywhere supports millisecond timestamp precision.
# File lib/sequel/adapters/shared/sqlanywhere.rb, line 466 def timestamp_precision 3 end