Module: Sequel::SqlAnywhere::DatasetMethods

Included in:
JDBC::SqlAnywhere::Dataset, Dataset
Defined in:
lib/sequel/adapters/shared/sqlanywhere.rb

Instance Method Summary collapse

Instance Method Details

#complex_expression_sql_append(sql, op, args) ⇒ Object


296
297
298
299
300
301
302
303
304
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
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 296

def complex_expression_sql_append(sql, op, args)
  case op
  when :'||'
    super(sql, :+, args)
  when :<<, :>>
    complex_expression_emulate_append(sql, op, args)
  when :LIKE, :"NOT LIKE"
    sql << '('
    literal_append(sql, args[0])
    sql << (op == :LIKE ? ' REGEXP ' : ' NOT REGEXP ')
    pattern = String.new
    last_c = ''
    args[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 << " ESCAPE "
    literal_append(sql, "\\")
    sql << ')'
  when :ILIKE, :"NOT ILIKE"
    super(sql, (op == :ILIKE ? :LIKE : :"NOT LIKE"), args)
  when :extract
    sql << 'datepart('
    literal_append(sql, args[0])
    sql << ','
    literal_append(sql, args[1])
    sql << ')'
  else
    super
  end
end

#constant_sql_append(sql, constant) ⇒ Object

Use today() for CURRENT_DATE and now() for CURRENT_TIMESTAMP and CURRENT_TIME


353
354
355
356
357
358
359
360
361
362
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 353

def constant_sql_append(sql, constant)
  case constant
  when :CURRENT_DATE
    sql << 'today()'
  when :CURRENT_TIMESTAMP, :CURRENT_TIME
    sql << 'now()'
  else
    super
  end
end

#convert_smallint_to_boolObject

Whether to convert smallint to boolean arguments for this dataset. Defaults to the IBMDB module setting.


240
241
242
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 240

def convert_smallint_to_bool
  opts.has_key?(:convert_smallint_to_bool) ? opts[:convert_smallint_to_bool] : db.convert_smallint_to_bool
end

#cross_apply(table) ⇒ Object

Uses CROSS APPLY to join the given table into the current dataset.


287
288
289
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 287

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


348
349
350
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 348

def escape_like(string)
  string.gsub(/[\\%_\[]/){|m| "\\#{m}"}
end

#into(table) ⇒ Object

Specify a table for a SELECT … INTO query.


365
366
367
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 365

def into(table)
  clone(:into => table)
end

#recursive_cte_requires_column_aliases?Boolean

SqlAnywhere requires recursive CTEs to have column aliases.

Returns:

  • (Boolean)

292
293
294
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 292

def recursive_cte_requires_column_aliases?
  true
end

#supports_cte?(type = :select) ⇒ Boolean

Returns:

  • (Boolean)

249
250
251
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 249

def supports_cte?(type=:select)
  type == :select
end

#supports_grouping_sets?Boolean

SQLAnywhere supports GROUPING SETS

Returns:

  • (Boolean)

254
255
256
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 254

def supports_grouping_sets?
  true
end

#supports_is_true?Boolean

Returns:

  • (Boolean)

266
267
268
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 266

def supports_is_true?
  false
end

#supports_join_using?Boolean

Returns:

  • (Boolean)

270
271
272
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 270

def supports_join_using?
  false
end

#supports_multiple_column_in?Boolean

Returns:

  • (Boolean)

258
259
260
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 258

def supports_multiple_column_in?
  false
end

#supports_timestamp_usecs?Boolean

Returns:

  • (Boolean)

274
275
276
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 274

def supports_timestamp_usecs?
  false
end

#supports_where_true?Boolean

Returns:

  • (Boolean)

262
263
264
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 262

def supports_where_true?
  false
end

#supports_window_clause?Boolean

Returns:

  • (Boolean)

278
279
280
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 278

def supports_window_clause?
  true
end

#supports_window_functions?Boolean

Returns:

  • (Boolean)

282
283
284
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 282

def supports_window_functions?
  true
end

#with_convert_smallint_to_bool(v) ⇒ Object

Return a cloned dataset with the convert_smallint_to_bool option set.


245
246
247
# File 'lib/sequel/adapters/shared/sqlanywhere.rb', line 245

def with_convert_smallint_to_bool(v)
  clone(:convert_smallint_to_bool=>v)
end