Class Sequel::SQLite::Database
In: lib/sequel/adapters/sqlite.rb
Parent: Sequel::Database

Methods

Included Modules

::Sequel::SQLite::DatabaseMethods

Attributes

conversion_procs  [R]  The conversion procs to use for this database

Public Instance methods

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)

[Source]

     # 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.

[Source]

     # 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

Run the given SQL with the given arguments and yield each row.

[Source]

     # File lib/sequel/adapters/sqlite.rb, line 125
125:       def execute(sql, opts=OPTS, &block)
126:         _execute(:select, sql, opts, &block)
127:       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.

[Source]

     # 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

Run the given SQL with the given arguments and return the number of changed rows.

[Source]

     # File lib/sequel/adapters/sqlite.rb, line 130
130:       def execute_dui(sql, opts=OPTS)
131:         _execute(:update, sql, opts)
132:       end

[Source]

     # File lib/sequel/adapters/sqlite.rb, line 145
145:       def execute_insert(sql, opts=OPTS)
146:         _execute(:insert, sql, opts)
147:       end

[Source]

     # 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.

[Source]

     # 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

[Validate]