module Sequel::SqlAnywhere::DatasetMethods
Public Instance Methods
# 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
Use today() for CURRENT_DATE and now() for CURRENT_TIMESTAMP and CURRENT_TIME
# 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
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
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
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
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
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
# File lib/sequel/adapters/shared/sqlanywhere.rb 259 def supports_cte?(type=:select) 260 type == :select 261 end
SQLAnywhere supports GROUPING SETS
# File lib/sequel/adapters/shared/sqlanywhere.rb 264 def supports_grouping_sets? 265 true 266 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 276 def supports_is_true? 277 false 278 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 280 def supports_join_using? 281 false 282 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 268 def supports_multiple_column_in? 269 false 270 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 284 def supports_timestamp_usecs? 285 false 286 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 272 def supports_where_true? 273 false 274 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 288 def supports_window_clause? 289 true 290 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 292 def supports_window_functions? 293 true 294 end
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
# 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
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
Use 0 for false on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb 387 def literal_false 388 '0' 389 end
Use 1 for true on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb 382 def literal_true 383 '1' 384 end
Sybase supports multiple rows in INSERT.
# File lib/sequel/adapters/shared/sqlanywhere.rb 406 def multi_insert_sql_strategy 407 :values 408 end
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
# 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
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
Use WITH RECURSIVE instead of WITH if any of the CTEs is recursive
# 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
SQLAnywhere supports millisecond timestamp precision.
# File lib/sequel/adapters/shared/sqlanywhere.rb 459 def timestamp_precision 460 3 461 end