Module: Sequel::SQLite::DatasetMethods

Included in:
Amalgalite::Dataset, DataObjects::SQLite::Dataset, JDBC::SQLite::Dataset, Dataset
Defined in:
lib/sequel/adapters/shared/sqlite.rb

Overview

Instance methods for datasets that connect to an SQLite database

Constant Summary collapse

SELECT_CLAUSE_ORDER =
%w'distinct columns from join where group having compounds order limit'.freeze

Instance Method Summary collapse

Instance Method Details

#complex_expression_sql(op, args) ⇒ Object

SQLite does not support pattern matching via regular expressions. SQLite is case insensitive (depending on pragma), so use LIKE for ILIKE.



242
243
244
245
246
247
248
249
250
251
252
# File 'lib/sequel/adapters/shared/sqlite.rb', line 242

def complex_expression_sql(op, args)
  case op
  when :~, :'!~', :'~*', :'!~*'
    raise Error, "SQLite does not support pattern matching via regular expressions"
  when :LIKE, :'NOT LIKE', :ILIKE, :'NOT ILIKE'
    # SQLite is case insensitive for ASCII, and non case sensitive for other character sets
    "#{'NOT ' if [:'NOT LIKE', :'NOT ILIKE'].include?(op)}(#{literal(args.at(0))} LIKE #{literal(args.at(1))})"
  else
    super(op, args)
  end
end

#deleteObject

SQLite performs a TRUNCATE style DELETE if no filter is specified. Since we want to always return the count of records, add a condition that is always true and then delete.



257
258
259
# File 'lib/sequel/adapters/shared/sqlite.rb', line 257

def delete
  @opts[:where] ? super : filter(1=>1).delete
end

#insert(*values) ⇒ Object

Insert the values into the database.



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

def insert(*values)
  execute_insert(insert_sql(*values))
end

#insert_sql(*values) ⇒ Object

Allow inserting of values directly from a dataset.



267
268
269
270
271
272
273
# File 'lib/sequel/adapters/shared/sqlite.rb', line 267

def insert_sql(*values)
  if (values.size == 1) && values.first.is_a?(Sequel::Dataset)
    "#{insert_sql_base}#{source_list(@opts[:from])} #{values.first.sql};"
  else
    super(*values)
  end
end

#quoted_identifier(c) ⇒ Object

SQLite uses the nonstandard ‘ (backtick) for quoting identifiers.



276
277
278
# File 'lib/sequel/adapters/shared/sqlite.rb', line 276

def quoted_identifier(c)
  "`#{c}`"
end

#supports_intersect_except_all?Boolean

SQLite does not support INTERSECT ALL or EXCEPT ALL

Returns:

  • (Boolean)


281
282
283
# File 'lib/sequel/adapters/shared/sqlite.rb', line 281

def supports_intersect_except_all?
  false
end

#supports_is_true?Boolean

SQLite does not support IS TRUE

Returns:

  • (Boolean)


286
287
288
# File 'lib/sequel/adapters/shared/sqlite.rb', line 286

def supports_is_true?
  false
end