sqlite3 2.0.0-x86-linux-gnu

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,96 @@
1
+ require "sqlite3/constants"
2
+ require "sqlite3/errors"
3
+
4
+ module SQLite3
5
+ # The ResultSet object encapsulates the enumerability of a query's output.
6
+ # It is a simple cursor over the data that the query returns. It will
7
+ # very rarely (if ever) be instantiated directly. Instead, clients should
8
+ # obtain a ResultSet instance via Statement#execute.
9
+ class ResultSet
10
+ include Enumerable
11
+
12
+ # Create a new ResultSet attached to the given database, using the
13
+ # given sql text.
14
+ def initialize db, stmt
15
+ @db = db
16
+ @stmt = stmt
17
+ end
18
+
19
+ # Reset the cursor, so that a result set which has reached end-of-file
20
+ # can be rewound and reiterated.
21
+ def reset(*bind_params)
22
+ @stmt.reset!
23
+ @stmt.bind_params(*bind_params)
24
+ end
25
+
26
+ # Query whether the cursor has reached the end of the result set or not.
27
+ def eof?
28
+ @stmt.done?
29
+ end
30
+
31
+ # Obtain the next row from the cursor. If there are no more rows to be
32
+ # had, this will return +nil+.
33
+ #
34
+ # The returned value will be an array, unless Database#results_as_hash has
35
+ # been set to +true+, in which case the returned value will be a hash.
36
+ #
37
+ # For arrays, the column names are accessible via the +fields+ property,
38
+ # and the column types are accessible via the +types+ property.
39
+ #
40
+ # For hashes, the column names are the keys of the hash, and the column
41
+ # types are accessible via the +types+ property.
42
+ def next
43
+ @stmt.step
44
+ end
45
+
46
+ # Required by the Enumerable mixin. Provides an internal iterator over the
47
+ # rows of the result set.
48
+ def each
49
+ while (node = self.next)
50
+ yield node
51
+ end
52
+ end
53
+
54
+ # Provides an internal iterator over the rows of the result set where
55
+ # each row is yielded as a hash.
56
+ def each_hash
57
+ while (node = next_hash)
58
+ yield node
59
+ end
60
+ end
61
+
62
+ # Closes the statement that spawned this result set.
63
+ # <em>Use with caution!</em> Closing a result set will automatically
64
+ # close any other result sets that were spawned from the same statement.
65
+ def close
66
+ @stmt.close
67
+ end
68
+
69
+ # Queries whether the underlying statement has been closed or not.
70
+ def closed?
71
+ @stmt.closed?
72
+ end
73
+
74
+ # Returns the types of the columns returned by this result set.
75
+ def types
76
+ @stmt.types
77
+ end
78
+
79
+ # Returns the names of the columns returned by this result set.
80
+ def columns
81
+ @stmt.columns
82
+ end
83
+
84
+ # Return the next row as a hash
85
+ def next_hash
86
+ row = @stmt.step
87
+ return nil if @stmt.done?
88
+
89
+ @stmt.columns.zip(row).to_h
90
+ end
91
+ end
92
+
93
+ class HashResultSet < ResultSet # :nodoc:
94
+ alias_method :next, :next_hash
95
+ end
96
+ end
@@ -0,0 +1,190 @@
1
+ require "sqlite3/errors"
2
+ require "sqlite3/resultset"
3
+
4
+ class String
5
+ def to_blob
6
+ SQLite3::Blob.new(self)
7
+ end
8
+ end
9
+
10
+ module SQLite3
11
+ # A statement represents a prepared-but-unexecuted SQL query. It will rarely
12
+ # (if ever) be instantiated directly by a client, and is most often obtained
13
+ # via the Database#prepare method.
14
+ class Statement
15
+ include Enumerable
16
+
17
+ # This is any text that followed the first valid SQL statement in the text
18
+ # with which the statement was initialized. If there was no trailing text,
19
+ # this will be the empty string.
20
+ attr_reader :remainder
21
+
22
+ # call-seq: SQLite3::Statement.new(db, sql)
23
+ #
24
+ # Create a new statement attached to the given Database instance, and which
25
+ # encapsulates the given SQL text. If the text contains more than one
26
+ # statement (i.e., separated by semicolons), then the #remainder property
27
+ # will be set to the trailing text.
28
+ def initialize(db, sql)
29
+ raise ArgumentError, "prepare called on a closed database" if db.closed?
30
+
31
+ sql = sql.encode(Encoding::UTF_8) if sql && sql.encoding != Encoding::UTF_8
32
+
33
+ @connection = db
34
+ @columns = nil
35
+ @types = nil
36
+ @remainder = prepare db, sql
37
+ end
38
+
39
+ # Binds the given variables to the corresponding placeholders in the SQL
40
+ # text.
41
+ #
42
+ # See Database#execute for a description of the valid placeholder
43
+ # syntaxes.
44
+ #
45
+ # Example:
46
+ #
47
+ # stmt = db.prepare( "select * from table where a=? and b=?" )
48
+ # stmt.bind_params( 15, "hello" )
49
+ #
50
+ # See also #execute, #bind_param, Statement#bind_param, and
51
+ # Statement#bind_params.
52
+ def bind_params(*bind_vars)
53
+ index = 1
54
+ bind_vars.flatten.each do |var|
55
+ if Hash === var
56
+ var.each { |key, val| bind_param key, val }
57
+ else
58
+ bind_param index, var
59
+ index += 1
60
+ end
61
+ end
62
+ end
63
+
64
+ # Execute the statement. This creates a new ResultSet object for the
65
+ # statement's virtual machine. If a block was given, the new ResultSet will
66
+ # be yielded to it; otherwise, the ResultSet will be returned.
67
+ #
68
+ # Any parameters will be bound to the statement using #bind_params.
69
+ #
70
+ # Example:
71
+ #
72
+ # stmt = db.prepare( "select * from table" )
73
+ # stmt.execute do |result|
74
+ # ...
75
+ # end
76
+ #
77
+ # See also #bind_params, #execute!.
78
+ def execute(*bind_vars)
79
+ reset! if active? || done?
80
+
81
+ bind_params(*bind_vars) unless bind_vars.empty?
82
+ results = @connection.build_result_set self
83
+
84
+ step if column_count == 0
85
+
86
+ yield results if block_given?
87
+ results
88
+ end
89
+
90
+ # Execute the statement. If no block was given, this returns an array of
91
+ # rows returned by executing the statement. Otherwise, each row will be
92
+ # yielded to the block.
93
+ #
94
+ # Any parameters will be bound to the statement using #bind_params.
95
+ #
96
+ # Example:
97
+ #
98
+ # stmt = db.prepare( "select * from table" )
99
+ # stmt.execute! do |row|
100
+ # ...
101
+ # end
102
+ #
103
+ # See also #bind_params, #execute.
104
+ def execute!(*bind_vars, &block)
105
+ execute(*bind_vars)
106
+ block ? each(&block) : to_a
107
+ end
108
+
109
+ # Returns true if the statement is currently active, meaning it has an
110
+ # open result set.
111
+ def active?
112
+ !done?
113
+ end
114
+
115
+ # Return an array of the column names for this statement. Note that this
116
+ # may execute the statement in order to obtain the metadata; this makes it
117
+ # a (potentially) expensive operation.
118
+ def columns
119
+ get_metadata unless @columns
120
+ @columns
121
+ end
122
+
123
+ def each
124
+ loop do
125
+ val = step
126
+ break self if done?
127
+ yield val
128
+ end
129
+ end
130
+
131
+ # Return an array of the data types for each column in this statement. Note
132
+ # that this may execute the statement in order to obtain the metadata; this
133
+ # makes it a (potentially) expensive operation.
134
+ def types
135
+ must_be_open!
136
+ get_metadata unless @types
137
+ @types
138
+ end
139
+
140
+ # Performs a sanity check to ensure that the statement is not
141
+ # closed. If it is, an exception is raised.
142
+ def must_be_open! # :nodoc:
143
+ if closed?
144
+ raise SQLite3::Exception, "cannot use a closed statement"
145
+ end
146
+ end
147
+
148
+ # Returns a Hash containing information about the statement.
149
+ # The contents of the hash are implementation specific and may change in
150
+ # the future without notice. The hash includes information about internal
151
+ # statistics about the statement such as:
152
+ # - +fullscan_steps+: the number of times that SQLite has stepped forward
153
+ # in a table as part of a full table scan
154
+ # - +sorts+: the number of sort operations that have occurred
155
+ # - +autoindexes+: the number of rows inserted into transient indices
156
+ # that were created automatically in order to help joins run faster
157
+ # - +vm_steps+: the number of virtual machine operations executed by the
158
+ # prepared statement
159
+ # - +reprepares+: the number of times that the prepare statement has been
160
+ # automatically regenerated due to schema changes or changes to bound
161
+ # parameters that might affect the query plan
162
+ # - +runs+: the number of times that the prepared statement has been run
163
+ # - +filter_misses+: the number of times that the Bloom filter returned
164
+ # a find, and thus the join step had to be processed as normal
165
+ # - +filter_hits+: the number of times that a join step was bypassed
166
+ # because a Bloom filter returned not-found
167
+ def stat key = nil
168
+ if key
169
+ stat_for(key)
170
+ else
171
+ stats_as_hash
172
+ end
173
+ end
174
+
175
+ private
176
+
177
+ # A convenience method for obtaining the metadata about the query. Note
178
+ # that this will actually execute the SQL, which means it can be a
179
+ # (potentially) expensive operation.
180
+ def get_metadata
181
+ @columns = Array.new(column_count) do |column|
182
+ column_name column
183
+ end
184
+ @types = Array.new(column_count) do |column|
185
+ val = column_decltype(column)
186
+ val&.downcase
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,54 @@
1
+ require "sqlite3/constants"
2
+
3
+ module SQLite3
4
+ class Value
5
+ attr_reader :handle
6
+
7
+ def initialize(db, handle)
8
+ @driver = db.driver
9
+ @handle = handle
10
+ end
11
+
12
+ def null?
13
+ type == :null
14
+ end
15
+
16
+ def to_blob
17
+ @driver.value_blob(@handle)
18
+ end
19
+
20
+ def length(utf16 = false)
21
+ if utf16
22
+ @driver.value_bytes16(@handle)
23
+ else
24
+ @driver.value_bytes(@handle)
25
+ end
26
+ end
27
+
28
+ def to_f
29
+ @driver.value_double(@handle)
30
+ end
31
+
32
+ def to_i
33
+ @driver.value_int(@handle)
34
+ end
35
+
36
+ def to_int64
37
+ @driver.value_int64(@handle)
38
+ end
39
+
40
+ def to_s(utf16 = false)
41
+ @driver.value_text(@handle, utf16)
42
+ end
43
+
44
+ def type
45
+ case @driver.value_type(@handle)
46
+ when Constants::ColumnType::INTEGER then :int
47
+ when Constants::ColumnType::FLOAT then :float
48
+ when Constants::ColumnType::TEXT then :text
49
+ when Constants::ColumnType::BLOB then :blob
50
+ when Constants::ColumnType::NULL then :null
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module SQLite3
2
+ VERSION = "2.0.0"
3
+ end
data/lib/sqlite3.rb ADDED
@@ -0,0 +1,17 @@
1
+ # support multiple ruby version (fat binaries under windows)
2
+ begin
3
+ RUBY_VERSION =~ /(\d+\.\d+)/
4
+ require "sqlite3/#{$1}/sqlite3_native"
5
+ rescue LoadError
6
+ require "sqlite3/sqlite3_native"
7
+ end
8
+
9
+ require "sqlite3/database"
10
+ require "sqlite3/version"
11
+
12
+ module SQLite3
13
+ # Was sqlite3 compiled with thread safety on?
14
+ def self.threadsafe?
15
+ threadsafe > 0
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sqlite3
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: x86-linux-gnu
6
+ authors:
7
+ - Jamis Buck
8
+ - Luis Lavena
9
+ - Aaron Patterson
10
+ - Mike Dalessio
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2024-04-17 00:00:00.000000000 Z
15
+ dependencies: []
16
+ description: |
17
+ Ruby library to interface with the SQLite3 database engine (http://www.sqlite.org). Precompiled
18
+ binaries are available for common platforms for recent versions of Ruby.
19
+ email:
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files:
23
+ - CHANGELOG.md
24
+ - README.md
25
+ - ext/sqlite3/aggregator.c
26
+ - ext/sqlite3/backup.c
27
+ - ext/sqlite3/database.c
28
+ - ext/sqlite3/exception.c
29
+ - ext/sqlite3/sqlite3.c
30
+ - ext/sqlite3/statement.c
31
+ files:
32
+ - ".gemtest"
33
+ - CHANGELOG.md
34
+ - CONTRIBUTING.md
35
+ - FAQ.md
36
+ - INSTALLATION.md
37
+ - LICENSE
38
+ - README.md
39
+ - dependencies.yml
40
+ - ext/sqlite3/aggregator.c
41
+ - ext/sqlite3/aggregator.h
42
+ - ext/sqlite3/backup.c
43
+ - ext/sqlite3/backup.h
44
+ - ext/sqlite3/database.c
45
+ - ext/sqlite3/database.h
46
+ - ext/sqlite3/exception.c
47
+ - ext/sqlite3/exception.h
48
+ - ext/sqlite3/extconf.rb
49
+ - ext/sqlite3/sqlite3.c
50
+ - ext/sqlite3/sqlite3_ruby.h
51
+ - ext/sqlite3/statement.c
52
+ - ext/sqlite3/statement.h
53
+ - ext/sqlite3/timespec.h
54
+ - lib/sqlite3.rb
55
+ - lib/sqlite3/3.0/sqlite3_native.so
56
+ - lib/sqlite3/3.1/sqlite3_native.so
57
+ - lib/sqlite3/3.2/sqlite3_native.so
58
+ - lib/sqlite3/3.3/sqlite3_native.so
59
+ - lib/sqlite3/constants.rb
60
+ - lib/sqlite3/database.rb
61
+ - lib/sqlite3/errors.rb
62
+ - lib/sqlite3/pragmas.rb
63
+ - lib/sqlite3/resultset.rb
64
+ - lib/sqlite3/statement.rb
65
+ - lib/sqlite3/value.rb
66
+ - lib/sqlite3/version.rb
67
+ homepage: https://github.com/sparklemotion/sqlite3-ruby
68
+ licenses:
69
+ - BSD-3-Clause
70
+ metadata:
71
+ homepage_uri: https://github.com/sparklemotion/sqlite3-ruby
72
+ bug_tracker_uri: https://github.com/sparklemotion/sqlite3-ruby/issues
73
+ documentation_uri: https://www.rubydoc.info/gems/sqlite3
74
+ changelog_uri: https://github.com/sparklemotion/sqlite3-ruby/blob/master/CHANGELOG.md
75
+ source_code_uri: https://github.com/sparklemotion/sqlite3-ruby
76
+ rubygems_mfa_required: 'true'
77
+ post_install_message:
78
+ rdoc_options:
79
+ - "--main"
80
+ - README.md
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ - - "<"
89
+ - !ruby/object:Gem::Version
90
+ version: 3.4.dev
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 3.3.22
96
+ requirements: []
97
+ rubygems_version: 3.3.26
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Ruby library to interface with the SQLite3 database engine (http://www.sqlite.org).
101
+ test_files: []