Module: Sequel::SQLite::DatasetMethods
- Includes:
- Dataset::UnsupportedIntersectExceptAll, Dataset::UnsupportedIsTrue
- Included in:
- 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
Instance Method Summary collapse
-
#complex_expression_sql(op, args) ⇒ Object
SQLite does not support pattern matching via regular expressions.
-
#delete(opts = (defarg=true;{})) ⇒ 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.
205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/sequel/adapters/shared/sqlite.rb', line 205 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 = (defarg=true;{})) ⇒ 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.
220 221 222 223 224 225 226 227 228 |
# File 'lib/sequel/adapters/shared/sqlite.rb', line 220 def delete(opts = (defarg=true;{})) # check if no filter is specified if defarg @opts[:where] ? super() : filter(1=>1).delete else opts = @opts.merge(opts) super(opts[:where] ? opts : opts.merge(:where=>{1=>1})) end end |
#insert(*values) ⇒ Object
Insert the values into the database.
231 232 233 |
# File 'lib/sequel/adapters/shared/sqlite.rb', line 231 def insert(*values) execute_insert(insert_sql(*values)) end |
#insert_sql(*values) ⇒ Object
Allow inserting of values directly from a dataset.
236 237 238 239 240 241 242 |
# File 'lib/sequel/adapters/shared/sqlite.rb', line 236 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.
245 246 247 |
# File 'lib/sequel/adapters/shared/sqlite.rb', line 245 def quoted_identifier(c) "`#{c}`" end |