module Sequel::SqlAnywhere::DatasetMethods
Public Instance Methods
# File lib/sequel/adapters/shared/sqlanywhere.rb 288 def complex_expression_sql_append(sql, op, args) 289 case op 290 when :'||' 291 super(sql, :+, args) 292 when :<<, :>> 293 complex_expression_emulate_append(sql, op, args) 294 when :LIKE, :"NOT LIKE" 295 sql << '(' 296 literal_append(sql, args[0]) 297 sql << (op == :LIKE ? ' REGEXP ' : ' NOT REGEXP ') 298 pattern = String.new 299 last_c = '' 300 args[1].each_char do |c| 301 if c == '_' and not pattern.end_with?('\\') and last_c != '\\' 302 pattern << '.' 303 elsif c == '%' and not pattern.end_with?('\\') and last_c != '\\' 304 pattern << '.*' 305 elsif c == '[' and not pattern.end_with?('\\') and last_c != '\\' 306 pattern << '\[' 307 elsif c == ']' and not pattern.end_with?('\\') and last_c != '\\' 308 pattern << '\]' 309 elsif 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 else 314 pattern << c 315 end 316 if c == '\\' and last_c == '\\' 317 last_c = '' 318 else 319 last_c = c 320 end 321 end 322 literal_append(sql, pattern) 323 sql << " ESCAPE " 324 literal_append(sql, "\\") 325 sql << ')' 326 when :ILIKE, :"NOT ILIKE" 327 super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args) 328 when :extract 329 sql << 'datepart(' 330 literal_append(sql, args[0]) 331 sql << ',' 332 literal_append(sql, args[1]) 333 sql << ')' 334 else 335 super 336 end 337 end
Use today() for CURRENT_DATE and now() for CURRENT_TIMESTAMP and CURRENT_TIME
# File lib/sequel/adapters/shared/sqlanywhere.rb 345 def constant_sql_append(sql, constant) 346 case constant 347 when :CURRENT_DATE 348 sql << 'today()' 349 when :CURRENT_TIMESTAMP, :CURRENT_TIME 350 sql << 'now()' 351 else 352 super 353 end 354 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 279 def cross_apply(table) 280 join_table(:cross_apply, table) 281 end
SqlAnywhere
uses \ to escape metacharacters, but a ']' should not be escaped
# File lib/sequel/adapters/shared/sqlanywhere.rb 340 def escape_like(string) 341 string.gsub(/[\\%_\[]/){|m| "\\#{m}"} 342 end
Specify a table for a SELECT … INTO query.
# File lib/sequel/adapters/shared/sqlanywhere.rb 357 def into(table) 358 clone(:into => table) 359 end
SqlAnywhere
requires recursive CTEs to have column aliases.
# File lib/sequel/adapters/shared/sqlanywhere.rb 284 def recursive_cte_requires_column_aliases? 285 true 286 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
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 424 def join_type_sql(join_type) 425 case join_type 426 when :cross_apply 427 'CROSS APPLY' 428 when :outer_apply 429 'OUTER APPLY' 430 else 431 super 432 end 433 end
SqlAnywhere
uses a preceding X for hex escaping strings
# File lib/sequel/adapters/shared/sqlanywhere.rb 379 def literal_blob_append(sql, v) 380 if v.empty? 381 literal_append(sql, "") 382 else 383 sql << "0x" << v.unpack("H*").first 384 end 385 end
Use 0 for false on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb 369 def literal_false 370 '0' 371 end
Use 1 for true on Sybase
# File lib/sequel/adapters/shared/sqlanywhere.rb 364 def literal_true 365 '1' 366 end
Sybase supports multiple rows in INSERT.
# File lib/sequel/adapters/shared/sqlanywhere.rb 388 def multi_insert_sql_strategy 389 :values 390 end
# File lib/sequel/adapters/shared/sqlanywhere.rb 392 def select_into_sql(sql) 393 if i = @opts[:into] 394 sql << " INTO " 395 identifier_append(sql, i) 396 end 397 end
Sybase uses TOP N for limit.
# File lib/sequel/adapters/shared/sqlanywhere.rb 400 def select_limit_sql(sql) 401 l = @opts[:limit] 402 o = @opts[:offset] 403 if l || o 404 if l 405 sql << " TOP " 406 literal_append(sql, l) 407 else 408 sql << " TOP 2147483647" 409 end 410 411 if o 412 sql << " START AT (" 413 literal_append(sql, o) 414 sql << " + 1)" 415 end 416 end 417 end
Use WITH RECURSIVE instead of WITH if any of the CTEs is recursive
# File lib/sequel/adapters/shared/sqlanywhere.rb 420 def select_with_sql_base 421 opts[:with].any?{|w| w[:recursive]} ? "WITH RECURSIVE " : super 422 end
SQLAnywhere supports millisecond timestamp precision.
# File lib/sequel/adapters/shared/sqlanywhere.rb 436 def timestamp_precision 437 3 438 end