module Sequel::SqlAnywhere::DatasetMethods
Public Instance Methods
# File lib/sequel/adapters/shared/sqlanywhere.rb 299 def complex_expression_sql_append(sql, op, args) 300 case op 301 when :'||' 302 super(sql, :+, args) 303 when :<<, :>> 304 complex_expression_emulate_append(sql, op, args) 305 when :LIKE, :"NOT LIKE" 306 sql << '(' 307 literal_append(sql, args[0]) 308 sql << (op == :LIKE ? ' REGEXP ' : ' NOT REGEXP ') 309 pattern = String.new 310 last_c = '' 311 args[1].each_char do |c| 312 if c == '_' and not pattern.end_with?('\\') and last_c != '\\' 313 pattern << '.' 314 elsif c == '%' and not pattern.end_with?('\\') and last_c != '\\' 315 pattern << '.*' 316 elsif c == '[' and not pattern.end_with?('\\') and last_c != '\\' 317 pattern << '\[' 318 elsif c == ']' and not pattern.end_with?('\\') and last_c != '\\' 319 pattern << '\]' 320 elsif c == '*' and not pattern.end_with?('\\') and last_c != '\\' 321 pattern << '\*' 322 elsif c == '?' and not pattern.end_with?('\\') and last_c != '\\' 323 pattern << '\?' 324 else 325 pattern << c 326 end 327 if c == '\\' and last_c == '\\' 328 last_c = '' 329 else 330 last_c = c 331 end 332 end 333 literal_append(sql, pattern) 334 sql << " ESCAPE " 335 literal_append(sql, "\\") 336 sql << ')' 337 when :ILIKE, :"NOT ILIKE" 338 super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args) 339 when :extract 340 sql << 'datepart(' 341 literal_append(sql, args[0]) 342 sql << ',' 343 literal_append(sql, args[1]) 344 sql << ')' 345 else 346 super 347 end 348 end
Use today() for CURRENT_DATE and now() for CURRENT_TIMESTAMP and CURRENT_TIME
# File lib/sequel/adapters/shared/sqlanywhere.rb 356 def constant_sql_append(sql, constant) 357 case constant 358 when :CURRENT_DATE 359 sql << 'today()' 360 when :CURRENT_TIMESTAMP, :CURRENT_TIME 361 sql << 'now()' 362 else 363 super 364 end 365 end
Whether to convert smallint to boolean arguments for this dataset. Defaults to the IBMDB
module setting.
# File lib/sequel/adapters/shared/sqlanywhere.rb 243 def convert_smallint_to_bool 244 opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : db.convert_smallint_to_bool 245 end
Uses CROSS APPLY to join the given table into the current dataset.
# File lib/sequel/adapters/shared/sqlanywhere.rb 290 def cross_apply(table) 291 join_table(:cross_apply, table) 292 end
SqlAnywhere
uses \ to escape metacharacters, but a ‘]’ should not be escaped
# File lib/sequel/adapters/shared/sqlanywhere.rb 351 def escape_like(string) 352 string.gsub(/[\\%_\[]/){|m| "\\#{m}"} 353 end
Specify a table for a SELECT … INTO query.
# File lib/sequel/adapters/shared/sqlanywhere.rb 368 def into(table) 369 clone(:into => table) 370 end
SqlAnywhere
requires recursive CTEs to have column aliases.
# File lib/sequel/adapters/shared/sqlanywhere.rb 295 def recursive_cte_requires_column_aliases? 296 true 297 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 252 def supports_cte?(type=:select) 253 type == :select 254 end
SQLAnywhere supports GROUPING SETS
# File lib/sequel/adapters/shared/sqlanywhere.rb 257 def supports_grouping_sets? 258 true 259 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 269 def supports_is_true? 270 false 271 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 273 def supports_join_using? 274 false 275 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 261 def supports_multiple_column_in? 262 false 263 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 277 def supports_timestamp_usecs? 278 false 279 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 265 def supports_where_true? 266 false 267 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 281 def supports_window_clause? 282 true 283 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 285 def supports_window_functions? 286 true 287 end
Return a cloned dataset with the convert_smallint_to_bool
option set.
# File lib/sequel/adapters/shared/sqlanywhere.rb 248 def with_convert_smallint_to_bool(v) 249 clone(:convert_smallint_to_bool=>v) 250 end
Private Instance Methods
# File lib/sequel/adapters/shared/sqlanywhere.rb 440 def join_type_sql(join_type) 441 case join_type 442 when :cross_apply 443 'CROSS APPLY' 444 when :outer_apply 445 'OUTER APPLY' 446 else 447 super 448 end 449 end
SqlAnywhere
uses a preceding X for hex escaping strings
# File lib/sequel/adapters/shared/sqlanywhere.rb 390 def literal_blob_append(sql, v) 391 if v.empty? 392 literal_append(sql, "") 393 else 394 sql << "0x" << v.unpack("H*").first 395 end 396 end
Use 0 for false on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb 380 def literal_false 381 '0' 382 end
Use 1 for true on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb 375 def literal_true 376 '1' 377 end
Sybase supports multiple rows in INSERT.
# File lib/sequel/adapters/shared/sqlanywhere.rb 399 def multi_insert_sql_strategy 400 :values 401 end
SQLAnywhere does not natively support NULLS FIRST/LAST.
# File lib/sequel/adapters/shared/sqlanywhere.rb 404 def requires_emulating_nulls_first? 405 true 406 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 408 def select_into_sql(sql) 409 if i = @opts[:into] 410 sql << " INTO " 411 identifier_append(sql, i) 412 end 413 end
Sybase uses TOP N for limit.
# File lib/sequel/adapters/shared/sqlanywhere.rb 416 def select_limit_sql(sql) 417 l = @opts[:limit] 418 o = @opts[:offset] 419 if l || o 420 if l 421 sql << " TOP " 422 literal_append(sql, l) 423 else 424 sql << " TOP 2147483647" 425 end 426 427 if o 428 sql << " START AT (" 429 literal_append(sql, o) 430 sql << " + 1)" 431 end 432 end 433 end
Use WITH RECURSIVE instead of WITH if any of the CTEs is recursive
# File lib/sequel/adapters/shared/sqlanywhere.rb 436 def select_with_sql_base 437 opts[:with].any?{|w| w[:recursive]} ? "WITH RECURSIVE " : super 438 end
SQLAnywhere supports millisecond timestamp precision.
# File lib/sequel/adapters/shared/sqlanywhere.rb 452 def timestamp_precision 453 3 454 end