Module | Sequel::SQLite::DatasetMethods |
In: |
lib/sequel_core/adapters/shared/sqlite.rb
|
Instance methods for datasets that connect to an SQLite database
SQLite does not support pattern matching via regular expressions. SQLite is case insensitive (depending on pragma), so use LIKE for ILIKE.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 145 145: def complex_expression_sql(op, args) 146: case op 147: when :~, '!~''!~', '~*''~*', '!~*''!~*' 148: raise Error, "SQLite does not support pattern matching via regular expressions" 149: when :LIKE, 'NOT LIKE''NOT LIKE', :ILIKE, 'NOT ILIKE''NOT ILIKE' 150: # SQLite is case insensitive for ASCII, and non case sensitive for other character sets 151: "#{'NOT ' if [:'NOT LIKE', :'NOT ILIKE'].include?(op)}(#{literal(args.at(0))} LIKE #{literal(args.at(1))})" 152: else 153: super(op, args) 154: end 155: end
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.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 160 160: def delete(opts = {}) 161: # check if no filter is specified 162: opts = @opts.merge(opts) 163: super(opts[:where] ? opts : opts.merge(:where=>{1=>1})) 164: end
Insert the values into the database.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 167 167: def insert(*values) 168: execute_insert(insert_sql(*values)) 169: end
Allow inserting of values directly from a dataset.
# File lib/sequel_core/adapters/shared/sqlite.rb, line 172 172: def insert_sql(*values) 173: if (values.size == 1) && values.first.is_a?(Sequel::Dataset) 174: "INSERT INTO #{source_list(@opts[:from])} #{values.first.sql};" 175: else 176: super(*values) 177: end 178: end