module Sequel::SqlAnywhere::DatasetMethods
Public Instance Methods
# File lib/sequel/adapters/shared/sqlanywhere.rb 296 def complex_expression_sql_append(sql, op, args) 297 case op 298 when :'||' 299 super(sql, :+, args) 300 when :<<, :>> 301 complex_expression_emulate_append(sql, op, args) 302 when :LIKE, :"NOT LIKE" 303 sql << '(' 304 literal_append(sql, args[0]) 305 sql << (op == :LIKE ? ' REGEXP ' : ' NOT REGEXP ') 306 pattern = String.new 307 last_c = '' 308 args[1].each_char do |c| 309 if c == '_' and not pattern.end_with?('\\') and last_c != '\\' 310 pattern << '.' 311 elsif c == '%' and not pattern.end_with?('\\') and last_c != '\\' 312 pattern << '.*' 313 elsif c == '[' and not pattern.end_with?('\\') and last_c != '\\' 314 pattern << '\[' 315 elsif c == ']' and not pattern.end_with?('\\') and last_c != '\\' 316 pattern << '\]' 317 elsif c == '*' and not pattern.end_with?('\\') and last_c != '\\' 318 pattern << '\*' 319 elsif c == '?' and not pattern.end_with?('\\') and last_c != '\\' 320 pattern << '\?' 321 else 322 pattern << c 323 end 324 if c == '\\' and last_c == '\\' 325 last_c = '' 326 else 327 last_c = c 328 end 329 end 330 literal_append(sql, pattern) 331 sql << " ESCAPE " 332 literal_append(sql, "\\") 333 sql << ')' 334 when :ILIKE, :"NOT ILIKE" 335 super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args) 336 when :extract 337 sql << 'datepart(' 338 literal_append(sql, args[0]) 339 sql << ',' 340 literal_append(sql, args[1]) 341 sql << ')' 342 else 343 super 344 end 345 end
Use today() for CURRENT_DATE and now() for CURRENT_TIMESTAMP and CURRENT_TIME
# File lib/sequel/adapters/shared/sqlanywhere.rb 353 def constant_sql_append(sql, constant) 354 case constant 355 when :CURRENT_DATE 356 sql << 'today()' 357 when :CURRENT_TIMESTAMP, :CURRENT_TIME 358 sql << 'now()' 359 else 360 super 361 end 362 end
Whether to convert smallint to boolean arguments for this dataset. Defaults to the IBMDB
module setting.
# File lib/sequel/adapters/shared/sqlanywhere.rb 240 def convert_smallint_to_bool 241 opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : db.convert_smallint_to_bool 242 end
Uses CROSS APPLY to join the given table into the current dataset.
# File lib/sequel/adapters/shared/sqlanywhere.rb 287 def cross_apply(table) 288 join_table(:cross_apply, table) 289 end
SqlAnywhere
uses \ to escape metacharacters, but a ']' should not be escaped
# File lib/sequel/adapters/shared/sqlanywhere.rb 348 def escape_like(string) 349 string.gsub(/[\\%_\[]/){|m| "\\#{m}"} 350 end
Specify a table for a SELECT … INTO query.
# File lib/sequel/adapters/shared/sqlanywhere.rb 365 def into(table) 366 clone(:into => table) 367 end
SqlAnywhere
requires recursive CTEs to have column aliases.
# File lib/sequel/adapters/shared/sqlanywhere.rb 292 def recursive_cte_requires_column_aliases? 293 true 294 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 249 def supports_cte?(type=:select) 250 type == :select 251 end
SQLAnywhere supports GROUPING SETS
# File lib/sequel/adapters/shared/sqlanywhere.rb 254 def supports_grouping_sets? 255 true 256 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 266 def supports_is_true? 267 false 268 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 270 def supports_join_using? 271 false 272 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 258 def supports_multiple_column_in? 259 false 260 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 274 def supports_timestamp_usecs? 275 false 276 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 262 def supports_where_true? 263 false 264 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 278 def supports_window_clause? 279 true 280 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 282 def supports_window_functions? 283 true 284 end
Return a cloned dataset with the convert_smallint_to_bool
option set.
# File lib/sequel/adapters/shared/sqlanywhere.rb 245 def with_convert_smallint_to_bool(v) 246 clone(:convert_smallint_to_bool=>v) 247 end
Private Instance Methods
# File lib/sequel/adapters/shared/sqlanywhere.rb 437 def join_type_sql(join_type) 438 case join_type 439 when :cross_apply 440 'CROSS APPLY' 441 when :outer_apply 442 'OUTER APPLY' 443 else 444 super 445 end 446 end
SqlAnywhere
uses a preceding X for hex escaping strings
# File lib/sequel/adapters/shared/sqlanywhere.rb 387 def literal_blob_append(sql, v) 388 if v.empty? 389 literal_append(sql, "") 390 else 391 sql << "0x" << v.unpack("H*").first 392 end 393 end
Use 0 for false on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb 377 def literal_false 378 '0' 379 end
Use 1 for true on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb 372 def literal_true 373 '1' 374 end
Sybase supports multiple rows in INSERT.
# File lib/sequel/adapters/shared/sqlanywhere.rb 396 def multi_insert_sql_strategy 397 :values 398 end
SQLAnywhere does not natively support NULLS FIRST/LAST.
# File lib/sequel/adapters/shared/sqlanywhere.rb 401 def requires_emulating_nulls_first? 402 true 403 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 405 def select_into_sql(sql) 406 if i = @opts[:into] 407 sql << " INTO " 408 identifier_append(sql, i) 409 end 410 end
Sybase uses TOP N for limit.
# File lib/sequel/adapters/shared/sqlanywhere.rb 413 def select_limit_sql(sql) 414 l = @opts[:limit] 415 o = @opts[:offset] 416 if l || o 417 if l 418 sql << " TOP " 419 literal_append(sql, l) 420 else 421 sql << " TOP 2147483647" 422 end 423 424 if o 425 sql << " START AT (" 426 literal_append(sql, o) 427 sql << " + 1)" 428 end 429 end 430 end
Use WITH RECURSIVE instead of WITH if any of the CTEs is recursive
# File lib/sequel/adapters/shared/sqlanywhere.rb 433 def select_with_sql_base 434 opts[:with].any?{|w| w[:recursive]} ? "WITH RECURSIVE " : super 435 end
SQLAnywhere supports millisecond timestamp precision.
# File lib/sequel/adapters/shared/sqlanywhere.rb 449 def timestamp_precision 450 3 451 end