Module | Sequel::SQLite::DatasetMethods |
In: |
lib/sequel/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/adapters/shared/sqlite.rb, line 205 205: def complex_expression_sql(op, args) 206: case op 207: when :~, '!~''!~', '~*''~*', '!~*''!~*' 208: raise Error, "SQLite does not support pattern matching via regular expressions" 209: when :LIKE, 'NOT LIKE''NOT LIKE', :ILIKE, 'NOT ILIKE''NOT ILIKE' 210: # SQLite is case insensitive for ASCII, and non case sensitive for other character sets 211: "#{'NOT ' if [:'NOT LIKE', :'NOT ILIKE'].include?(op)}(#{literal(args.at(0))} LIKE #{literal(args.at(1))})" 212: else 213: super(op, args) 214: end 215: 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/adapters/shared/sqlite.rb, line 220 220: def delete(opts = (defarg=true;{})) 221: # check if no filter is specified 222: if defarg 223: @opts[:where] ? super() : filter(1=>1).delete 224: else 225: opts = @opts.merge(opts) 226: super(opts[:where] ? opts : opts.merge(:where=>{1=>1})) 227: end 228: end
Insert the values into the database.
# File lib/sequel/adapters/shared/sqlite.rb, line 231 231: def insert(*values) 232: execute_insert(insert_sql(*values)) 233: end
Allow inserting of values directly from a dataset.
# File lib/sequel/adapters/shared/sqlite.rb, line 236 236: def insert_sql(*values) 237: if (values.size == 1) && values.first.is_a?(Sequel::Dataset) 238: "INSERT INTO #{source_list(@opts[:from])} #{values.first.sql};" 239: else 240: super(*values) 241: end 242: end