class SQLite3::Database
def initialize file, options = {}, zvfs = nil
- +extensions:+ Array[String | _ExtensionSpecifier] SQLite extensions to load into the database. See Database@SQLite+Extensions for more information.
- +default_transaction_mode:+ one of +:deferred+ (default), +:immediate+, or +:exclusive+. If a mode is not specified in a call to #transaction, this will be the default transaction mode.
- +results_as_hash:+ +boolish+ (default false), return rows as hashes instead of arrays
- +strict:+ +boolish+ (default false), disallow the use of double-quoted string literals (see https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted)
Other supported +options+:
- +utf16:+ +boolish+ (default false), is the filename's encoding UTF-16 (only needed if the filename encoding is not UTF_16LE or BE)
Supported encoding +options+:
- +flags:+ set the mode to a combination of SQLite3::Constants::Open flags.
- +readwrite:+ boolean (default false), true to set the mode to +READWRITE+
- +readonly:+ boolean (default false), true to set the mode to +READONLY+
- the default mode is READWRITE | CREATE
Supported permissions +options+:
Create a new Database object that opens the given file.
SQLite3::Database.new(file, options = {})
call-seq:
def initialize file, options = {}, zvfs = nil mode = Constants::Open::READWRITE | Constants::Open::CREATE file = file.to_path if file.respond_to? :to_path if file.encoding == ::Encoding::UTF_16LE || file.encoding == ::Encoding::UTF_16BE || options[:utf16] open16 file else # The three primary flag values for sqlite3_open_v2 are: # SQLITE_OPEN_READONLY # SQLITE_OPEN_READWRITE # SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE -- always used for sqlite3_open and sqlite3_open16 mode = Constants::Open::READONLY if options[:readonly] if options[:readwrite] raise "conflicting options: readonly and readwrite" if options[:readonly] mode = Constants::Open::READWRITE end if options[:flags] if options[:readonly] || options[:readwrite] raise "conflicting options: flags with readonly and/or readwrite" end mode = options[:flags] end open_v2 file.encode("utf-8"), mode, zvfs if options[:strict] disable_quirk_mode end end @tracefunc = nil @authorizer = nil @progress_handler = nil @collations = {} @functions = {} @results_as_hash = options[:results_as_hash] @readonly = mode & Constants::Open::READONLY != 0 @default_transaction_mode = options[:default_transaction_mode] || :deferred initialize_extensions(options[:extensions]) ForkSafety.track(self) if block_given? begin yield self ensure close end end end