Methods
Public Class
Public Instance
Included modules
Attributes
| conversion_procs | [R] |
The conversion procs to use for this database |
Public Class methods
# File lib/sequel/adapters/sqlite.rb 115 def initialize(opts = OPTS) 116 super 117 @allow_regexp = typecast_value_boolean(opts[:setup_regexp_function]) 118 end
Public Instance methods
Whether this Database instance is setup to allow regexp matching. True if the :setup_regexp_function option was passed when creating the Database.
# File lib/sequel/adapters/sqlite.rb 172 def allow_regexp? 173 @allow_regexp 174 end
Connect to the database. Since SQLite is a file based database, available options are limited:
| :database |
database name (filename or ‘:memory:’ or file: URI) |
| :readonly |
open database in read-only mode; useful for reading static data that you do not want to modify |
| :disable_dqs |
disable double quoted strings in DDL and DML statements (requires |
| :timeout |
how long to wait for the database to be available if it is locked, given in milliseconds (default is 5000) |
| :setup_regexp_function |
enable use of Regexp objects with SQL |
'REGEXP' operator. If the value is :cached or "cached", caches the generated regexps, which can result in a memory leak if dynamic regexps are used. If the value is a Proc, it will be called with a string for the regexp and a string for the value to compare, and should return whether the regexp matches.
| :regexp_function_cache |
If setting |
determines the cache to use. It should either be a proc or a class, and it defaults to +Hash+. You can use +ObjectSpace::WeakKeyMap+ on Ruby 3.3+ to have the VM automatically remove regexps from the cache after they are no longer used.
# File lib/sequel/adapters/sqlite.rb 142 def connect(server) 143 opts = server_opts(server) 144 opts[:database] = ':memory:' if blank_object?(opts[:database]) 145 sqlite3_opts = {} 146 sqlite3_opts[:readonly] = typecast_value_boolean(opts[:readonly]) if opts.has_key?(:readonly) 147 # SEQUEL6: Make strict: true the default behavior 148 sqlite3_opts[:strict] = typecast_value_boolean(opts[:disable_dqs]) if opts.has_key?(:disable_dqs) 149 db = ::SQLite3::Database.new(opts[:database].to_s, sqlite3_opts) 150 db.busy_timeout(typecast_value_integer(opts.fetch(:timeout, 5000))) 151 152 if USE_EXTENDED_RESULT_CODES 153 db.extended_result_codes = true 154 end 155 156 connection_pragmas.each{|s| log_connection_yield(s, db){db.execute_batch(s)}} 157 158 if typecast_value_boolean(opts[:setup_regexp_function]) 159 setup_regexp_function(db, opts[:setup_regexp_function]) 160 end 161 162 class << db 163 attr_reader :prepared_statements 164 end 165 db.instance_variable_set(:@prepared_statements, {}) 166 167 db 168 end
Disconnect given connections from the database.
# File lib/sequel/adapters/sqlite.rb 177 def disconnect_connection(c) 178 c.prepared_statements.each_value{|v| v.first.close} 179 c.close 180 end
Run the given SQL with the given arguments and yield each row.
# File lib/sequel/adapters/sqlite.rb 183 def execute(sql, opts=OPTS, &block) 184 _execute(:select, sql, opts, &block) 185 end
Drop any prepared statements on the connection when executing DDL. This is because prepared statements lock the table in such a way that you can’t drop or alter the table while a prepared statement that references it still exists.
# File lib/sequel/adapters/sqlite.rb 195 def execute_ddl(sql, opts=OPTS) 196 synchronize(opts[:server]) do |conn| 197 conn.prepared_statements.values.each{|cps, s| cps.close} 198 conn.prepared_statements.clear 199 super 200 end 201 end
Run the given SQL with the given arguments and return the number of changed rows.
# File lib/sequel/adapters/sqlite.rb 188 def execute_dui(sql, opts=OPTS) 189 _execute(:update, sql, opts) 190 end
# File lib/sequel/adapters/sqlite.rb 203 def execute_insert(sql, opts=OPTS) 204 _execute(:insert, sql, opts) 205 end
# File lib/sequel/adapters/sqlite.rb 207 def freeze 208 @conversion_procs.freeze 209 super 210 end
Handle Integer and Float arguments, since SQLite can store timestamps as integers and floats.
# File lib/sequel/adapters/sqlite.rb 213 def to_application_timestamp(s) 214 case s 215 when String 216 super 217 when Integer 218 super(Time.at(s).to_s) 219 when Float 220 super(DateTime.jd(s).to_s) 221 else 222 raise Sequel::Error, "unhandled type when converting to : #{s.inspect} (#{s.class.inspect})" 223 end 224 end