Module: Sequel::SqlAnywhere::DatasetMethods
- Included in:
- JDBC::SqlAnywhere::Dataset, Dataset
- Defined in:
- lib/sequel/adapters/shared/sqlanywhere.rb
Constant Summary collapse
- BOOL_TRUE =
'1'.freeze
- BOOL_FALSE =
'0'.freeze
- INSERT_CLAUSE_METHODS =
Dataset.clause_methods(:insert, %w'with insert into columns values')
- SELECT_CLAUSE_METHODS =
Dataset.clause_methods(:select, %w'with select distinct limit columns into from join where group having order compounds lock')
- WILDCARD =
LiteralString.new('%').freeze
- TOP =
" TOP ".freeze
- START_AT =
" START AT ".freeze
- SQL_WITH_RECURSIVE =
"WITH RECURSIVE ".freeze
- DATE_FUNCTION =
'today()'.freeze
- NOW_FUNCTION =
'now()'.freeze
- DATEPART =
'datepart'.freeze
- REGEXP =
'REGEXP'.freeze
- NOT_REGEXP =
'NOT REGEXP'.freeze
- TIMESTAMP_USEC_FORMAT =
".%03d".freeze
- APOS =
Dataset::APOS
- APOS_RE =
Dataset::APOS_RE
- DOUBLE_APOS =
Dataset::DOUBLE_APOS
- BACKSLASH_RE =
/\\/.freeze
- QUAD_BACKSLASH =
"\\\\\\\\".freeze
- BLOB_START =
"0x".freeze
- HSTAR =
"H*".freeze
- CROSS_APPLY =
'CROSS APPLY'.freeze
- OUTER_APPLY =
'OUTER APPLY'.freeze
Instance Attribute Summary collapse
-
#convert_smallint_to_bool ⇒ Object
Whether to convert smallint to boolean arguments for this dataset.
Instance Method Summary collapse
-
#complex_expression_sql_append(sql, op, args) ⇒ Object
SQLAnywhere uses + for string concatenation, and LIKE is case insensitive by default.
-
#constant_sql_append(sql, constant) ⇒ Object
Use Date() and Now() for CURRENT_DATE and CURRENT_TIMESTAMP.
-
#cross_apply(table) ⇒ Object
Uses CROSS APPLY to join the given table into the current dataset.
-
#escape_like(string) ⇒ Object
SqlAnywhere uses \ to escape metacharacters, but a ‘]’ should not be escaped.
-
#into(table) ⇒ Object
Specify a table for a SELECT …
-
#recursive_cte_requires_column_aliases? ⇒ Boolean
SqlAnywhere requires recursive CTEs to have column aliases.
- #supports_is_true? ⇒ Boolean
- #supports_join_using? ⇒ Boolean
- #supports_multiple_column_in? ⇒ Boolean
- #supports_timestamp_usecs? ⇒ Boolean
- #supports_where_true? ⇒ Boolean
Instance Attribute Details
#convert_smallint_to_bool ⇒ Object
Whether to convert smallint to boolean arguments for this dataset. Defaults to the SqlAnywhere module setting.
267 268 269 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 267 def convert_smallint_to_bool defined?(@convert_smallint_to_bool) ? @convert_smallint_to_bool : (@convert_smallint_to_bool = @db.convert_smallint_to_bool) end |
Instance Method Details
#complex_expression_sql_append(sql, op, args) ⇒ Object
SQLAnywhere uses + for string concatenation, and LIKE is case insensitive by default.
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 305 def complex_expression_sql_append(sql, op, args) case op when :'||' super(sql, :+, args) when :<< sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} * POWER(2, #{literal(b)}))"} when :>> sql << complex_expression_arg_pairs(args){|a, b| "(#{literal(a)} / POWER(2, #{literal(b)}))"} 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 |
#constant_sql_append(sql, constant) ⇒ Object
Use Date() and Now() for CURRENT_DATE and CURRENT_TIMESTAMP
364 365 366 367 368 369 370 371 372 373 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 364 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 |
#cross_apply(table) ⇒ Object
Uses CROSS APPLY to join the given table into the current dataset.
295 296 297 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 295 def cross_apply(table) join_table(:cross_apply, table) end |
#escape_like(string) ⇒ Object
SqlAnywhere uses \ to escape metacharacters, but a ‘]’ should not be escaped
359 360 361 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 359 def escape_like(string) string.gsub(/[\\%_\[]/){|m| "\\#{m}"} end |
#into(table) ⇒ Object
Specify a table for a SELECT … INTO query.
376 377 378 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 376 def into(table) clone(:into => table) end |
#recursive_cte_requires_column_aliases? ⇒ Boolean
SqlAnywhere requires recursive CTEs to have column aliases.
300 301 302 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 300 def recursive_cte_requires_column_aliases? true end |
#supports_is_true? ⇒ Boolean
282 283 284 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 282 def supports_is_true? false end |
#supports_join_using? ⇒ Boolean
286 287 288 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 286 def supports_join_using? false end |
#supports_multiple_column_in? ⇒ Boolean
274 275 276 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 274 def supports_multiple_column_in? false end |
#supports_timestamp_usecs? ⇒ Boolean
290 291 292 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 290 def false end |
#supports_where_true? ⇒ Boolean
278 279 280 |
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 278 def supports_where_true? false end |