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 101 def initialize(opts = OPTS) 102 super 103 @allow_regexp = typecast_value_boolean(opts[:setup_regexp_function]) 104 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 154 def allow_regexp? 155 @allow_regexp 156 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 |
: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 126 def connect(server) 127 opts = server_opts(server) 128 opts[:database] = ':memory:' if blank_object?(opts[:database]) 129 sqlite3_opts = {} 130 sqlite3_opts[:readonly] = typecast_value_boolean(opts[:readonly]) if opts.has_key?(:readonly) 131 db = ::SQLite3::Database.new(opts[:database].to_s, sqlite3_opts) 132 db.busy_timeout(typecast_value_integer(opts.fetch(:timeout, 5000))) 133 134 if USE_EXTENDED_RESULT_CODES 135 db.extended_result_codes = true 136 end 137 138 connection_pragmas.each{|s| log_connection_yield(s, db){db.execute_batch(s)}} 139 140 if typecast_value_boolean(opts[:setup_regexp_function]) 141 setup_regexp_function(db, opts[:setup_regexp_function]) 142 end 143 144 class << db 145 attr_reader :prepared_statements 146 end 147 db.instance_variable_set(:@prepared_statements, {}) 148 149 db 150 end
Disconnect given connections from the database.
# File lib/sequel/adapters/sqlite.rb 159 def disconnect_connection(c) 160 c.prepared_statements.each_value{|v| v.first.close} 161 c.close 162 end
Run the given SQL with the given arguments and yield each row.
# File lib/sequel/adapters/sqlite.rb 165 def execute(sql, opts=OPTS, &block) 166 _execute(:select, sql, opts, &block) 167 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 177 def execute_ddl(sql, opts=OPTS) 178 synchronize(opts[:server]) do |conn| 179 conn.prepared_statements.values.each{|cps, s| cps.close} 180 conn.prepared_statements.clear 181 super 182 end 183 end
Run the given SQL with the given arguments and return the number of changed rows.
# File lib/sequel/adapters/sqlite.rb 170 def execute_dui(sql, opts=OPTS) 171 _execute(:update, sql, opts) 172 end
# File lib/sequel/adapters/sqlite.rb 185 def execute_insert(sql, opts=OPTS) 186 _execute(:insert, sql, opts) 187 end
# File lib/sequel/adapters/sqlite.rb 189 def freeze 190 @conversion_procs.freeze 191 super 192 end
Handle Integer and Float arguments, since SQLite
can store timestamps as integers and floats.
# File lib/sequel/adapters/sqlite.rb 195 def to_application_timestamp(s) 196 case s 197 when String 198 super 199 when Integer 200 super(Time.at(s).to_s) 201 when Float 202 super(DateTime.jd(s).to_s) 203 else 204 raise Sequel::Error, "unhandled type when converting to : #{s.inspect} (#{s.class.inspect})" 205 end 206 end