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

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.



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 106

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.



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 121

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.



136
137
138
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 136

def insert(*values)
  execute_insert(insert_sql(*values))
end

#insert_sql(*values) ⇒ Object

Allow inserting of values directly from a dataset.



141
142
143
144
145
146
147
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 141

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.



150
151
152
# File 'lib/sequel_core/adapters/shared/sqlite.rb', line 150

def quoted_identifier(c)
  "`#{c}`"
end