sqlite3 1.4.2 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/{API_CHANGES.rdoc → API_CHANGES.md} +3 -4
  3. data/CHANGELOG.md +641 -0
  4. data/CONTRIBUTING.md +34 -0
  5. data/FAQ.md +431 -0
  6. data/Gemfile +7 -14
  7. data/INSTALLATION.md +259 -0
  8. data/LICENSE-DEPENDENCIES +20 -0
  9. data/README.md +110 -0
  10. data/dependencies.yml +14 -0
  11. data/ext/sqlite3/aggregator.c +10 -10
  12. data/ext/sqlite3/backup.c +26 -13
  13. data/ext/sqlite3/database.c +89 -38
  14. data/ext/sqlite3/database.h +2 -0
  15. data/ext/sqlite3/extconf.rb +269 -84
  16. data/ext/sqlite3/sqlite3.c +5 -2
  17. data/ext/sqlite3/sqlite3_ruby.h +5 -2
  18. data/ext/sqlite3/statement.c +37 -28
  19. data/lib/sqlite3/constants.rb +1 -1
  20. data/lib/sqlite3/database.rb +55 -30
  21. data/lib/sqlite3/pragmas.rb +13 -6
  22. data/lib/sqlite3/resultset.rb +4 -12
  23. data/lib/sqlite3/statement.rb +2 -1
  24. data/lib/sqlite3/translator.rb +2 -3
  25. data/lib/sqlite3/version.rb +3 -5
  26. data/ports/archives/sqlite-autoconf-3450100.tar.gz +0 -0
  27. data/test/helper.rb +9 -0
  28. data/test/test_database.rb +182 -17
  29. data/test/test_deprecated.rb +10 -5
  30. data/test/test_encoding.rb +10 -0
  31. data/test/test_integration_resultset.rb +2 -2
  32. data/test/test_integration_statement.rb +2 -2
  33. data/test/test_pragmas.rb +22 -0
  34. data/test/test_result_set.rb +18 -8
  35. data/test/test_sqlite3.rb +9 -0
  36. data/test/test_statement.rb +28 -1
  37. data/test/test_statement_execute.rb +4 -0
  38. metadata +36 -144
  39. data/.travis.yml +0 -33
  40. data/CHANGELOG.rdoc +0 -318
  41. data/Manifest.txt +0 -60
  42. data/README.rdoc +0 -118
  43. data/Rakefile +0 -8
  44. data/appveyor.yml +0 -36
  45. data/faq/faq.rb +0 -145
  46. data/faq/faq.yml +0 -426
  47. data/rakelib/faq.rake +0 -9
  48. data/rakelib/gem.rake +0 -40
  49. data/rakelib/native.rake +0 -56
  50. data/rakelib/vendor_sqlite3.rake +0 -97
  51. data/setup.rb +0 -1333
@@ -18,7 +18,7 @@ module SQLite3
18
18
  # end
19
19
  # end
20
20
  #
21
- # It wraps the lower-level methods provides by the selected driver, and
21
+ # It wraps the lower-level methods provided by the selected driver, and
22
22
  # includes the Pragmas module for access to various pragma convenience
23
23
  # methods.
24
24
  #
@@ -39,7 +39,22 @@ module SQLite3
39
39
 
40
40
  class << self
41
41
 
42
- alias :open :new
42
+ # Without block works exactly as new.
43
+ # With block, like new closes the database at the end, but unlike new
44
+ # returns the result of the block instead of the database instance.
45
+ def open( *args )
46
+ database = new(*args)
47
+
48
+ if block_given?
49
+ begin
50
+ yield database
51
+ ensure
52
+ database.close
53
+ end
54
+ else
55
+ database
56
+ end
57
+ end
43
58
 
44
59
  # Quotes the given string, making it safe to use in an SQL statement.
45
60
  # It replaces all instances of the single-quote character with two
@@ -56,15 +71,27 @@ module SQLite3
56
71
 
57
72
  # call-seq: SQLite3::Database.new(file, options = {})
58
73
  #
59
- # Create a new Database object that opens the given file. If utf16
60
- # is +true+, the filename is interpreted as a UTF-16 encoded string.
74
+ # Create a new Database object that opens the given file.
75
+ #
76
+ # Supported permissions +options+:
77
+ # - the default mode is <tt>READWRITE | CREATE</tt>
78
+ # - +:readonly+: boolean (default false), true to set the mode to +READONLY+
79
+ # - +:readwrite+: boolean (default false), true to set the mode to +READWRITE+
80
+ # - +:flags+: set the mode to a combination of SQLite3::Constants::Open flags.
81
+ #
82
+ # Supported encoding +options+:
83
+ # - +:utf16+: boolean (default false), is the filename's encoding UTF-16 (only needed if the filename encoding is not UTF_16LE or BE)
84
+ #
85
+ # Other supported +options+:
86
+ # - +:strict+: boolean (default false), disallow the use of double-quoted string literals (see https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted)
87
+ # - +:results_as_hash+: boolean (default false), return rows as hashes instead of arrays
88
+ # - +:type_translation+: boolean (default false), enable type translation
89
+ # - +: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.
61
90
  #
62
- # By default, the new database will return result rows as arrays
63
- # (#results_as_hash) and has type translation disabled (#type_translation=).
64
-
65
91
  def initialize file, options = {}, zvfs = nil
66
92
  mode = Constants::Open::READWRITE | Constants::Open::CREATE
67
93
 
94
+ file = file.to_path if file.respond_to? :to_path
68
95
  if file.encoding == ::Encoding::UTF_16LE || file.encoding == ::Encoding::UTF_16BE || options[:utf16]
69
96
  open16 file
70
97
  else
@@ -87,6 +114,10 @@ module SQLite3
87
114
  end
88
115
 
89
116
  open_v2 file.encode("utf-8"), mode, zvfs
117
+
118
+ if options[:strict]
119
+ disable_quirk_mode
120
+ end
90
121
  end
91
122
 
92
123
  @tracefunc = nil
@@ -99,6 +130,7 @@ module SQLite3
99
130
  @type_translation = options[:type_translation]
100
131
  @type_translator = make_type_translator @type_translation
101
132
  @readonly = mode & Constants::Open::READONLY != 0
133
+ @default_transaction_mode = options[:default_transaction_mode] || :deferred
102
134
 
103
135
  if block_given?
104
136
  begin
@@ -111,9 +143,7 @@ module SQLite3
111
143
 
112
144
  def type_translation= value # :nodoc:
113
145
  warn(<<-eowarn) if $VERBOSE
114
- #{caller[0]} is calling SQLite3::Database#type_translation=
115
- SQLite3::Database#type_translation= is deprecated and will be removed
116
- in version 2.0.0.
146
+ #{caller[0]} is calling `SQLite3::Database#type_translation=` which is deprecated and will be removed in version 2.0.0.
117
147
  eowarn
118
148
  @type_translator = make_type_translator value
119
149
  @type_translation = value
@@ -184,9 +214,7 @@ in version 2.0.0.
184
214
  end
185
215
 
186
216
  warn(<<-eowarn) if $VERBOSE
187
- #{caller[0]} is calling SQLite3::Database#execute with nil or multiple bind params
188
- without using an array. Please switch to passing bind parameters as an array.
189
- Support for bind parameters as *args will be removed in 2.0.0.
217
+ #{caller[0]} is calling `SQLite3::Database#execute` with nil or multiple bind params without using an array. Please switch to passing bind parameters as an array. Support for bind parameters as *args will be removed in 2.0.0.
190
218
  eowarn
191
219
  end
192
220
 
@@ -237,15 +265,13 @@ Support for bind parameters as *args will be removed in 2.0.0.
237
265
  # rows.
238
266
  #
239
267
  # See also #execute_batch2 for additional ways of
240
- # executing statments.
268
+ # executing statements.
241
269
  def execute_batch( sql, bind_vars = [], *args )
242
270
  # FIXME: remove this stuff later
243
271
  unless [Array, Hash].include?(bind_vars.class)
244
272
  bind_vars = [bind_vars]
245
273
  warn(<<-eowarn) if $VERBOSE
246
- #{caller[0]} is calling SQLite3::Database#execute_batch with bind parameters
247
- that are not a list of a hash. Please switch to passing bind parameters as an
248
- array or hash. Support for this behavior will be removed in version 2.0.0.
274
+ #{caller[0]} is calling `SQLite3::Database#execute_batch` with bind parameters that are not a list of a hash. Please switch to passing bind parameters as an array or hash. Support for this behavior will be removed in version 2.0.0.
249
275
  eowarn
250
276
  end
251
277
 
@@ -258,9 +284,7 @@ array or hash. Support for this behavior will be removed in version 2.0.0.
258
284
  end
259
285
 
260
286
  warn(<<-eowarn) if $VERBOSE
261
- #{caller[0]} is calling SQLite3::Database#execute_batch with nil or multiple bind params
262
- without using an array. Please switch to passing bind parameters as an array.
263
- Support for this behavior will be removed in version 2.0.0.
287
+ #{caller[0]} is calling `SQLite3::Database#execute_batch` with nil or multiple bind params without using an array. Please switch to passing bind parameters as an array. Support for this behavior will be removed in version 2.0.0.
264
288
  eowarn
265
289
  end
266
290
 
@@ -294,7 +318,7 @@ Support for this behavior will be removed in version 2.0.0.
294
318
  # a block can be passed to parse the values accordingly.
295
319
  #
296
320
  # See also #execute_batch for additional ways of
297
- # executing statments.
321
+ # executing statements.
298
322
  def execute_batch2(sql, &block)
299
323
  if block_given?
300
324
  result = exec_batch(sql, @results_as_hash)
@@ -307,7 +331,7 @@ Support for this behavior will be removed in version 2.0.0.
307
331
  end
308
332
 
309
333
  # This is a convenience method for creating a statement, binding
310
- # paramters to it, and calling execute:
334
+ # parameters to it, and calling execute:
311
335
  #
312
336
  # result = db.query( "select * from foo where a=?", [5])
313
337
  # # is the same as
@@ -327,9 +351,7 @@ Support for this behavior will be removed in version 2.0.0.
327
351
  end
328
352
 
329
353
  warn(<<-eowarn) if $VERBOSE
330
- #{caller[0]} is calling SQLite3::Database#query with nil or multiple bind params
331
- without using an array. Please switch to passing bind parameters as an array.
332
- Support for this will be removed in version 2.0.0.
354
+ #{caller[0]} is calling `SQLite3::Database#query` with nil or multiple bind params without using an array. Please switch to passing bind parameters as an array. Support for this will be removed in version 2.0.0.
333
355
  eowarn
334
356
  end
335
357
 
@@ -536,10 +558,10 @@ Support for this will be removed in version 2.0.0.
536
558
  # db.create_aggregate_handler( LengthsAggregateHandler )
537
559
  # puts db.get_first_value( "select lengths(name) from A" )
538
560
  def create_aggregate_handler( handler )
539
- # This is a compatiblity shim so the (basically pointless) FunctionProxy
561
+ # This is a compatibility shim so the (basically pointless) FunctionProxy
540
562
  # "ctx" object is passed as first argument to both step() and finalize().
541
563
  # Now its up to the library user whether he prefers to store his
542
- # temporaries as instance varibales or fields in the FunctionProxy.
564
+ # temporaries as instance variables or fields in the FunctionProxy.
543
565
  # The library user still must set the result value with
544
566
  # FunctionProxy.result= as there is no backwards compatible way to
545
567
  # change this.
@@ -574,7 +596,7 @@ Support for this will be removed in version 2.0.0.
574
596
  # The functions arity is the arity of the +step+ method.
575
597
  def define_aggregator( name, aggregator )
576
598
  # Previously, this has been implemented in C. Now this is just yet
577
- # another compatiblity shim
599
+ # another compatibility shim
578
600
  proxy = Class.new do
579
601
  @template = aggregator
580
602
  @name = name
@@ -612,8 +634,10 @@ Support for this will be removed in version 2.0.0.
612
634
  # by SQLite, so attempting to nest a transaction will result in a runtime
613
635
  # exception.
614
636
  #
615
- # The +mode+ parameter may be either <tt>:deferred</tt> (the default),
637
+ # The +mode+ parameter may be either <tt>:deferred</tt>,
616
638
  # <tt>:immediate</tt>, or <tt>:exclusive</tt>.
639
+ # If `nil` is specified, the default transaction mode, which was
640
+ # passed to #initialize, is used.
617
641
  #
618
642
  # If a block is given, the database instance is yielded to it, and the
619
643
  # transaction is committed when the block terminates. If the block
@@ -624,7 +648,8 @@ Support for this will be removed in version 2.0.0.
624
648
  # If a block is not given, it is the caller's responsibility to end the
625
649
  # transaction explicitly, either by calling #commit, or by calling
626
650
  # #rollback.
627
- def transaction( mode = :deferred )
651
+ def transaction( mode = nil )
652
+ mode = @default_transaction_mode if mode.nil?
628
653
  execute "begin #{mode.to_s} transaction"
629
654
 
630
655
  if block_given?
@@ -11,7 +11,7 @@ module SQLite3
11
11
 
12
12
  # Returns +true+ or +false+ depending on the value of the named pragma.
13
13
  def get_boolean_pragma( name )
14
- get_first_value( "PRAGMA #{name}" ) != "0"
14
+ get_first_value( "PRAGMA #{name}" ) != 0
15
15
  end
16
16
 
17
17
  # Sets the given pragma to the given boolean value. The value itself
@@ -42,11 +42,11 @@ module SQLite3
42
42
  # Requests the given pragma (and parameters), and if the block is given,
43
43
  # each row of the result set will be yielded to it. Otherwise, the results
44
44
  # are returned as an array.
45
- def get_query_pragma( name, *parms, &block ) # :yields: row
46
- if parms.empty?
45
+ def get_query_pragma( name, *params, &block ) # :yields: row
46
+ if params.empty?
47
47
  execute( "PRAGMA #{name}", &block )
48
48
  else
49
- args = "'" + parms.join("','") + "'"
49
+ args = "'" + params.join("','") + "'"
50
50
  execute( "PRAGMA #{name}( #{args} )", &block )
51
51
  end
52
52
  end
@@ -260,7 +260,7 @@ module SQLite3
260
260
  def full_column_names=( mode )
261
261
  set_boolean_pragma "full_column_names", mode
262
262
  end
263
-
263
+
264
264
  def fullfsync
265
265
  get_boolean_pragma "fullfsync"
266
266
  end
@@ -356,7 +356,7 @@ module SQLite3
356
356
  def parser_trace=( mode )
357
357
  set_boolean_pragma "parser_trace", mode
358
358
  end
359
-
359
+
360
360
  def query_only
361
361
  get_boolean_pragma "query_only"
362
362
  end
@@ -543,6 +543,13 @@ module SQLite3
543
543
 
544
544
  tweak_default(new_row) if needs_tweak_default
545
545
 
546
+ # Ensure the type value is downcased. On Mac and Windows
547
+ # platforms this value is now being returned as all upper
548
+ # case.
549
+ if new_row['type']
550
+ new_row['type'] = new_row['type'].downcase
551
+ end
552
+
546
553
  if block_given?
547
554
  yield new_row
548
555
  else
@@ -20,18 +20,14 @@ module SQLite3
20
20
 
21
21
  def types
22
22
  warn(<<-eowarn) if $VERBOSE
23
- #{caller[0]} is calling #{self.class}#types. This method will be removed in
24
- sqlite3 version 2.0.0, please call the `types` method on the SQLite3::ResultSet
25
- object that created this object
23
+ #{caller[0]} is calling `#{self.class}#types` which is deprecated and will be removed in sqlite3 version 2.0.0. Please call the `types` method on the SQLite3::ResultSet object that created this object.
26
24
  eowarn
27
25
  @types
28
26
  end
29
27
 
30
28
  def fields
31
29
  warn(<<-eowarn) if $VERBOSE
32
- #{caller[0]} is calling #{self.class}#fields. This method will be removed in
33
- sqlite3 version 2.0.0, please call the `columns` method on the SQLite3::ResultSet
34
- object that created this object
30
+ #{caller[0]} is calling `#{self.class}#fields` which is deprecated and will be removed in sqlite3 version 2.0.0. Please call the `columns` method on the SQLite3::ResultSet object that created this object.
35
31
  eowarn
36
32
  @fields
37
33
  end
@@ -45,18 +41,14 @@ object that created this object
45
41
 
46
42
  def types
47
43
  warn(<<-eowarn) if $VERBOSE
48
- #{caller[0]} is calling #{self.class}#types. This method will be removed in
49
- sqlite3 version 2.0.0, please call the `types` method on the SQLite3::ResultSet
50
- object that created this object
44
+ #{caller[0]} is calling `#{self.class}#types` which is deprecated and will be removed in sqlite3 version 2.0.0. Please call the `types` method on the SQLite3::ResultSet object that created this object.
51
45
  eowarn
52
46
  @types
53
47
  end
54
48
 
55
49
  def fields
56
50
  warn(<<-eowarn) if $VERBOSE
57
- #{caller[0]} is calling #{self.class}#fields. This method will be removed in
58
- sqlite3 version 2.0.0, please call the `columns` method on the SQLite3::ResultSet
59
- object that created this object
51
+ #{caller[0]} is calling `#{self.class}#fields` which is deprecated and will be removed in sqlite3 version 2.0.0. Please call the `columns` method on the SQLite3::ResultSet object that created this object.
60
52
  eowarn
61
53
  @fields
62
54
  end
@@ -137,7 +137,8 @@ module SQLite3
137
137
  column_name column
138
138
  end
139
139
  @types = Array.new(column_count) do |column|
140
- column_decltype column
140
+ val = column_decltype(column)
141
+ val.nil? ? nil : val.downcase
141
142
  end
142
143
  end
143
144
  end
@@ -36,14 +36,13 @@ module SQLite3
36
36
  # The block should return the translated value.
37
37
  def add_translator( type, &block ) # :yields: type, value
38
38
  warn(<<-eowarn) if $VERBOSE
39
- #{caller[0]} is calling `add_translator`.
40
- Built in translators are deprecated and will be removed in version 2.0.0
39
+ #{caller[0]} is calling `SQLite3::Translator#add_translator`. Built-in translators are deprecated and will be removed in version 2.0.0.
41
40
  eowarn
42
41
  @translators[ type_name( type ) ] = block
43
42
  end
44
43
 
45
44
  # Translate the given string value to a value of the given type. In the
46
- # absense of an installed translator block for the given type, the value
45
+ # absence of an installed translator block for the given type, the value
47
46
  # itself is always returned. Further, +nil+ values are never translated,
48
47
  # and are always passed straight through regardless of the type parameter.
49
48
  def translate( type, value )
@@ -1,16 +1,14 @@
1
1
  module SQLite3
2
2
 
3
- VERSION = '1.4.2'
3
+ VERSION = "1.7.2"
4
4
 
5
5
  module VersionProxy
6
-
7
6
  MAJOR = 1
8
- MINOR = 4
7
+ MINOR = 7
9
8
  TINY = 2
10
9
  BUILD = nil
11
10
 
12
11
  STRING = [ MAJOR, MINOR, TINY, BUILD ].compact.join( "." )
13
- #:beta-tag:
14
12
 
15
13
  VERSION = ::SQLite3::VERSION
16
14
  end
@@ -18,7 +16,7 @@ module SQLite3
18
16
  def self.const_missing(name)
19
17
  return super unless name == :Version
20
18
  warn(<<-eowarn) if $VERBOSE
21
- #{caller[0]}: SQLite::Version will be removed in sqlite3-ruby version 2.0.0
19
+ #{caller[0]}: `SQLite::Version` will be removed in sqlite3-ruby version 2.0.0
22
20
  eowarn
23
21
  VersionProxy
24
22
  end
data/test/helper.rb CHANGED
@@ -1,6 +1,15 @@
1
1
  require 'sqlite3'
2
2
  require 'minitest/autorun'
3
3
 
4
+ if ENV['GITHUB_ACTIONS'] == 'true' || ENV['CI']
5
+ $VERBOSE = nil
6
+ end
7
+
8
+ puts "info: sqlite3-ruby version: #{SQLite3::VERSION}/#{SQLite3::VersionProxy::STRING}"
9
+ puts "info: sqlite3 version: #{SQLite3::SQLITE_VERSION}/#{SQLite3::SQLITE_LOADED_VERSION}"
10
+ puts "info: sqlcipher?: #{SQLite3.sqlcipher?}"
11
+ puts "info: threadsafe?: #{SQLite3.threadsafe?}"
12
+
4
13
  unless RUBY_VERSION >= "1.9"
5
14
  require 'iconv'
6
15
  end