| Class | Sequel::SQLite::Database |
| In: |
lib/sequel/adapters/sqlite.rb
|
| Parent: | Sequel::Database |
| conversion_procs | [R] | The conversion procs to use for this database |
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) |
# File lib/sequel/adapters/sqlite.rb, line 100
100: def connect(server)
101: opts = server_opts(server)
102: opts[:database] = ':memory:' if blank_object?(opts[:database])
103: sqlite3_opts = {}
104: sqlite3_opts[:readonly] = typecast_value_boolean(opts[:readonly]) if opts.has_key?(:readonly)
105: db = ::SQLite3::Database.new(opts[:database].to_s, sqlite3_opts)
106: db.busy_timeout(opts.fetch(:timeout, 5000))
107:
108: connection_pragmas.each{|s| log_connection_yield(s, db){db.execute_batch(s)}}
109:
110: class << db
111: attr_reader :prepared_statements
112: end
113: db.instance_variable_set(:@prepared_statements, {})
114:
115: db
116: end
Disconnect given connections from the database.
# File lib/sequel/adapters/sqlite.rb, line 119
119: def disconnect_connection(c)
120: c.prepared_statements.each_value{|v| v.first.close}
121: c.close
122: 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, line 137
137: def execute_ddl(sql, opts=OPTS)
138: synchronize(opts[:server]) do |conn|
139: conn.prepared_statements.values.each{|cps, s| cps.close}
140: conn.prepared_statements.clear
141: super
142: end
143: end
# File lib/sequel/adapters/sqlite.rb, line 145
145: def execute_insert(sql, opts=OPTS)
146: _execute(:insert, sql, opts)
147: end
# File lib/sequel/adapters/sqlite.rb, line 149
149: def freeze
150: @conversion_procs.freeze
151: super
152: end
Handle Integer and Float arguments, since SQLite can store timestamps as integers and floats.
# File lib/sequel/adapters/sqlite.rb, line 155
155: def to_application_timestamp(s)
156: case s
157: when String
158: super
159: when Integer
160: super(Time.at(s).to_s)
161: when Float
162: super(DateTime.jd(s).to_s)
163: else
164: raise Sequel::Error, "unhandled type when converting to : #{s.inspect} (#{s.class.inspect})"
165: end
166: end