Module: Sequel::SQLite::DatasetMethods
- Includes:
- Dataset::UnsupportedIntersectExceptAll
- Included in:
- DataObjects::SQLite::Dataset, JDBC::SQLite::Dataset, Dataset
- Defined in:
- lib/sequel_core/adapters/shared/sqlite.rb
Overview
Instance methods for datasets that connect to an SQLite database
Instance Method Summary collapse
-
#complex_expression_sql(op, args) ⇒ Object
SQLite does not support pattern matching via regular expressions.
-
#delete(opts = {}) ⇒ Object
SQLite performs a TRUNCATE style DELETE if no filter is specified.
-
#insert(*values) ⇒ Object
Insert the values into the database.
-
#insert_sql(*values) ⇒ Object
Allow inserting of values directly from a dataset.
-
#quoted_identifier(c) ⇒ Object
SQLite uses the nonstandard ‘ (backtick) for quoting identifiers.
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.
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 204 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 |
#delete(opts = {}) ⇒ Object
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.
219 220 221 222 223 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 219 def delete(opts = {}) # check if no filter is specified opts = @opts.merge(opts) super(opts[:where] ? opts : opts.merge(:where=>{1=>1})) end |
#insert(*values) ⇒ Object
Insert the values into the database.
226 227 228 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 226 def insert(*values) execute_insert(insert_sql(*values)) end |
#insert_sql(*values) ⇒ Object
Allow inserting of values directly from a dataset.
231 232 233 234 235 236 237 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 231 def insert_sql(*values) if (values.size == 1) && values.first.is_a?(Sequel::Dataset) "INSERT INTO #{source_list(@opts[:from])} #{values.first.sql};" else super(*values) end end |
#quoted_identifier(c) ⇒ Object
SQLite uses the nonstandard ‘ (backtick) for quoting identifiers.
240 241 242 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 240 def quoted_identifier(c) "`#{c}`" end |