Module: Sequel::SQLite::DatasetMethods
- Included in:
- 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.
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 122 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, do a specific count in the case of no filter.
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 137 def delete(opts = {}) # check if no filter is specified opts = @opts.merge(opts) unless opts[:where] @db.transaction(opts[:server]) do unfiltered_count = count execute_dui(delete_sql(opts)) unfiltered_count end else execute_dui(delete_sql(opts)) end end |
#insert(*values) ⇒ Object
Insert the values into the database.
152 153 154 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 152 def insert(*values) execute_insert(insert_sql(*values)) end |
#insert_sql(*values) ⇒ Object
Allow inserting of values directly from a dataset.
157 158 159 160 161 162 163 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 157 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.
166 167 168 |
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 166 def quoted_identifier(c) "`#{c}`" end |