sqlite3 1.3.5 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,35 @@
1
+ === 1.3.6 / 2012-04-16
2
+
3
+ * Enhancements
4
+ * Windows: build against SQLite 3.7.11
5
+ * Added SQLite3::ResultSet#each_hash for fetching each row as a hash.
6
+ * Added SQLite3::ResultSet#next_hash for fetching one row as a hash.
7
+
8
+ * Bugfixes
9
+ * Support both UTF-16LE and UTF-16BE encoding modes on PPC. Closes #63
10
+ * Protect parameters to custom functions from being garbage collected too
11
+ soon. Fixes #60. Thanks hirataya!
12
+ * Fix backwards compatibility with 1.2.5 with bind vars and `query` method.
13
+ Fixes #35.
14
+ * Fix double definition error caused by defining sqlite3_int64/uint64.
15
+ * Fix suspicious version regexp.
16
+
17
+ * Deprecations
18
+ * ArrayWithTypesAndFields#types is deprecated and the class will be removed
19
+ in version 2.0.0. Please use the `types` method on the ResultSet class
20
+ that created this object.
21
+ * ArrayWithTypesAndFields#fields is deprecated and the class will be removed
22
+ in version 2.0.0. Please use the `columns` method on the ResultSet class
23
+ that created this object.
24
+ * The ArrayWithTypesAndFields class will be removed in 2.0.0
25
+ * The ArrayWithTypes class will be removed in 2.0.0
26
+ * HashWithTypesAndFields#types is deprecated and the class will be removed
27
+ in version 2.0.0. Please use the `types` method on the ResultSet class
28
+ that created this object.
29
+ * HashWithTypesAndFields#fields is deprecated and the class will be removed
30
+ in version 2.0.0. Please use the `columns` method on the ResultSet class
31
+ that created this object.
32
+
1
33
  === 1.3.5 / 2011-12-03 - ZOMG Holidays are here Edition!
2
34
 
3
35
  * Enhancements
@@ -44,7 +44,9 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
44
44
  VALUE file;
45
45
  VALUE opts;
46
46
  VALUE zvfs;
47
+ #ifdef HAVE_SQLITE3_OPEN_V2
47
48
  int mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
49
+ #endif
48
50
  int status;
49
51
 
50
52
  Data_Get_Struct(self, sqlite3Ruby, ctx);
@@ -60,7 +62,7 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
60
62
  else Check_Type(opts, T_HASH);
61
63
 
62
64
  #ifdef HAVE_RUBY_ENCODING_H
63
- if(UTF16_LE_P(file)) {
65
+ if(UTF16_LE_P(file) || UTF16_BE_P(file)) {
64
66
  status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db);
65
67
  } else {
66
68
  #endif
@@ -76,14 +78,25 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
76
78
  #endif
77
79
 
78
80
  if (Qtrue == rb_hash_aref(opts, ID2SYM(rb_intern("readonly")))) {
81
+ #ifdef HAVE_SQLITE3_OPEN_V2
79
82
  mode = SQLITE_OPEN_READONLY;
83
+ #else
84
+ rb_raise(rb_eNotImpError, "sqlite3-ruby was compiled against a version of sqlite that does not support readonly databases");
85
+ #endif
80
86
  }
87
+ #ifdef HAVE_SQLITE3_OPEN_V2
81
88
  status = sqlite3_open_v2(
82
89
  StringValuePtr(file),
83
90
  &ctx->db,
84
91
  mode,
85
92
  NIL_P(zvfs) ? NULL : StringValuePtr(zvfs)
86
93
  );
94
+ #else
95
+ status = sqlite3_open(
96
+ StringValuePtr(file),
97
+ &ctx->db
98
+ );
99
+ #endif
87
100
  }
88
101
 
89
102
  #ifdef HAVE_RUBY_ENCODING_H
@@ -100,7 +113,11 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
100
113
  rb_iv_set(self, "@functions", rb_hash_new());
101
114
  rb_iv_set(self, "@results_as_hash", rb_hash_aref(opts, sym_results_as_hash));
102
115
  rb_iv_set(self, "@type_translation", rb_hash_aref(opts, sym_type_translation));
116
+ #ifdef HAVE_SQLITE3_OPEN_V2
103
117
  rb_iv_set(self, "@readonly", mode == SQLITE_OPEN_READONLY ? Qtrue : Qfalse);
118
+ #else
119
+ rb_iv_set(self, "@readonly", Qfalse);
120
+ #endif
104
121
 
105
122
  if(rb_block_given_p()) {
106
123
  rb_yield(self);
@@ -319,7 +336,9 @@ static void rb_sqlite3_func(sqlite3_context * ctx, int argc, sqlite3_value **arg
319
336
  params = xcalloc((size_t)argc, sizeof(VALUE *));
320
337
 
321
338
  for(i = 0; i < argc; i++) {
322
- params[i] = sqlite3val2rb(argv[i]);
339
+ VALUE param = sqlite3val2rb(argv[i]);
340
+ RB_GC_GUARD(param);
341
+ params[i] = param;
323
342
  }
324
343
  }
325
344
 
@@ -625,13 +644,12 @@ static VALUE collation(VALUE self, VALUE name, VALUE comparator)
625
644
  Data_Get_Struct(self, sqlite3Ruby, ctx);
626
645
  REQUIRE_OPEN_DB(ctx);
627
646
 
628
- CHECK(ctx->db, sqlite3_create_collation_v2(
647
+ CHECK(ctx->db, sqlite3_create_collation(
629
648
  ctx->db,
630
649
  StringValuePtr(name),
631
650
  SQLITE_UTF8,
632
651
  (void *)comparator,
633
- NIL_P(comparator) ? NULL : rb_comparator_func,
634
- NULL));
652
+ NIL_P(comparator) ? NULL : rb_comparator_func));
635
653
 
636
654
  /* Make sure our comparator doesn't get garbage collected. */
637
655
  rb_hash_aset(rb_iv_get(self, "@collations"), name, comparator);
@@ -639,10 +657,11 @@ static VALUE collation(VALUE self, VALUE name, VALUE comparator)
639
657
  return self;
640
658
  }
641
659
 
660
+ #ifdef HAVE_SQLITE3_LOAD_EXTENSION
642
661
  /* call-seq: db.load_extension(file)
643
662
  *
644
663
  * Loads an SQLite extension library from the named file. Extension
645
- * loading must be enabled using db.enable_load_extension(1) prior
664
+ * loading must be enabled using db.enable_load_extension(true) prior
646
665
  * to calling this API.
647
666
  */
648
667
  static VALUE load_extension(VALUE self, VALUE file)
@@ -664,7 +683,9 @@ static VALUE load_extension(VALUE self, VALUE file)
664
683
 
665
684
  return self;
666
685
  }
686
+ #endif
667
687
 
688
+ #ifdef HAVE_SQLITE3_ENABLE_LOAD_EXTENSION
668
689
  /* call-seq: db.enable_load_extension(onoff)
669
690
  *
670
691
  * Enable or disable extension loading.
@@ -672,13 +693,23 @@ static VALUE load_extension(VALUE self, VALUE file)
672
693
  static VALUE enable_load_extension(VALUE self, VALUE onoff)
673
694
  {
674
695
  sqlite3RubyPtr ctx;
696
+ int onoffparam;
675
697
  Data_Get_Struct(self, sqlite3Ruby, ctx);
676
698
  REQUIRE_OPEN_DB(ctx);
677
699
 
678
- CHECK(ctx->db, sqlite3_enable_load_extension(ctx->db, (int)NUM2INT(onoff)));
700
+ if (Qtrue == onoff) {
701
+ onoffparam = 1;
702
+ } else if (Qfalse == onoff) {
703
+ onoffparam = 0;
704
+ } else {
705
+ onoffparam = (int)NUM2INT(onoff);
706
+ }
707
+
708
+ CHECK(ctx->db, sqlite3_enable_load_extension(ctx->db, onoffparam));
679
709
 
680
710
  return self;
681
711
  }
712
+ #endif
682
713
 
683
714
  #ifdef HAVE_RUBY_ENCODING_H
684
715
  static int enc_cb(void * _self, int UNUSED(columns), char **data, char **UNUSED(names))
@@ -43,5 +43,9 @@ have_func('sqlite3_backup_init')
43
43
  have_func('sqlite3_column_database_name')
44
44
  have_func('sqlite3_enable_load_extension')
45
45
  have_func('sqlite3_load_extension')
46
+ have_func('sqlite3_open_v2')
47
+ have_func('sqlite3_prepare_v2')
48
+ have_type('sqlite3_int64', 'sqlite3.h')
49
+ have_type('sqlite3_uint64', 'sqlite3.h')
46
50
 
47
51
  create_makefile('sqlite3/sqlite3_native')
@@ -21,6 +21,7 @@
21
21
 
22
22
  #define UTF8_P(_obj) (rb_enc_get_index(_obj) == rb_utf8_encindex())
23
23
  #define UTF16_LE_P(_obj) (rb_enc_get_index(_obj) == rb_enc_find_index("UTF-16LE"))
24
+ #define UTF16_BE_P(_obj) (rb_enc_get_index(_obj) == rb_enc_find_index("UTF-16BE"))
24
25
  #define SQLITE3_UTF8_STR_NEW2(_obj) \
25
26
  (rb_enc_associate_index(rb_str_new2(_obj), rb_utf8_encindex()))
26
27
 
@@ -33,6 +34,14 @@
33
34
 
34
35
  #include <sqlite3.h>
35
36
 
37
+ #ifndef HAVE_TYPE_SQLITE3_INT64
38
+ typedef sqlite_int64 sqlite3_int64;
39
+ #endif
40
+
41
+ #ifndef HAVE_TYPE_SQLITE3_UINT64
42
+ typedef sqlite_uint64 sqlite3_uint64;
43
+ #endif
44
+
36
45
  extern VALUE mSqlite3;
37
46
  extern VALUE cSqlite3Blob;
38
47
 
@@ -49,7 +49,11 @@ static VALUE initialize(VALUE self, VALUE db, VALUE sql)
49
49
  }
50
50
  #endif
51
51
 
52
+ #ifdef HAVE_SQLITE3_PREPARE_V2
52
53
  status = sqlite3_prepare_v2(
54
+ #else
55
+ status = sqlite3_prepare(
56
+ #endif
53
57
  db_ctx->db,
54
58
  (const char *)StringValuePtr(sql),
55
59
  (int)RSTRING_LEN(sql),
@@ -359,7 +363,7 @@ static VALUE column_name(VALUE self, VALUE index)
359
363
 
360
364
  name = sqlite3_column_name(ctx->st, (int)NUM2INT(index));
361
365
 
362
- if(name) return rb_str_new2(name);
366
+ if(name) return SQLITE3_UTF8_STR_NEW2(name);
363
367
  return Qnil;
364
368
  }
365
369
 
@@ -1,6 +1,6 @@
1
1
  # support multiple ruby version (fat binaries under windows)
2
2
  begin
3
- RUBY_VERSION =~ /(\d+.\d+)/
3
+ RUBY_VERSION =~ /(\d+\.\d+)/
4
4
  require "sqlite3/#{$1}/sqlite3_native"
5
5
  rescue LoadError
6
6
  require 'sqlite3/sqlite3_native'
@@ -236,7 +236,7 @@ Support for this behavior will be removed in version 2.0.0.
236
236
  # This is a convenience method for creating a statement, binding
237
237
  # paramters to it, and calling execute:
238
238
  #
239
- # result = db.query( "select * from foo where a=?", 5 )
239
+ # result = db.query( "select * from foo where a=?", [5])
240
240
  # # is the same as
241
241
  # result = db.prepare( "select * from foo where a=?" ).execute( 5 )
242
242
  #
@@ -250,7 +250,7 @@ Support for this behavior will be removed in version 2.0.0.
250
250
  if args.empty?
251
251
  bind_vars = []
252
252
  else
253
- bind_vars = [nil] + args
253
+ bind_vars = [bind_vars] + args
254
254
  end
255
255
 
256
256
  warn(<<-eowarn) if $VERBOSE
@@ -10,23 +10,61 @@ module SQLite3
10
10
  class ResultSet
11
11
  include Enumerable
12
12
 
13
- # The class of which we return an object in case we want an Array as
14
- # result. (ArrayFields is installed.)
15
- class ArrayWithTypes < Array
13
+ class ArrayWithTypes < Array # :nodoc:
16
14
  attr_accessor :types
17
15
  end
18
16
 
19
- # The class of which we return an object in case we want an Array as
20
- # result. (ArrayFields is not installed.)
21
- class ArrayWithTypesAndFields < Array
22
- attr_accessor :types
23
- attr_accessor :fields
17
+ class ArrayWithTypesAndFields < Array # :nodoc:
18
+ attr_writer :types
19
+ attr_writer :fields
20
+
21
+ def types
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
26
+ eowarn
27
+ @types
28
+ end
29
+
30
+ def fields
31
+ 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
35
+ eowarn
36
+ @fields
37
+ end
24
38
  end
25
39
 
26
40
  # The class of which we return an object in case we want a Hash as
27
41
  # result.
28
- class HashWithTypes < Hash
29
- attr_accessor :types
42
+ class HashWithTypesAndFields < Hash # :nodoc:
43
+ attr_writer :types
44
+ attr_writer :fields
45
+
46
+ def types
47
+ 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
51
+ eowarn
52
+ @types
53
+ end
54
+
55
+ def fields
56
+ 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
60
+ eowarn
61
+ @fields
62
+ end
63
+
64
+ def [] key
65
+ key = fields[key] if key.is_a? Numeric
66
+ super key
67
+ end
30
68
  end
31
69
 
32
70
  # Create a new ResultSet attached to the given database, using the
@@ -63,6 +101,10 @@ module SQLite3
63
101
  # For hashes, the column names are the keys of the hash, and the column
64
102
  # types are accessible via the +types+ property.
65
103
  def next
104
+ if @db.results_as_hash
105
+ return next_hash
106
+ end
107
+
66
108
  row = @stmt.step
67
109
  return nil if @stmt.done?
68
110
 
@@ -72,33 +114,39 @@ module SQLite3
72
114
  end
73
115
  end
74
116
 
75
- if @db.results_as_hash
76
- new_row = HashWithTypes[*@stmt.columns.zip(row).flatten]
77
- row.each_with_index { |value,idx|
78
- new_row[idx] = value
79
- }
80
- row = new_row
117
+ if row.respond_to?(:fields)
118
+ # FIXME: this can only happen if the translator returns something
119
+ # that responds to `fields`. Since we're removing the translator
120
+ # in 2.0, we can remove this branch in 2.0.
121
+ row = ArrayWithTypes.new(row)
81
122
  else
82
- if row.respond_to?(:fields)
83
- row = ArrayWithTypes.new(row)
84
- else
85
- row = ArrayWithTypesAndFields.new(row)
86
- end
87
- row.fields = @stmt.columns
123
+ # FIXME: the `fields` and `types` methods are deprecated on this
124
+ # object for version 2.0, so we can safely remove this branch
125
+ # as well.
126
+ row = ArrayWithTypesAndFields.new(row)
88
127
  end
89
128
 
129
+ row.fields = @stmt.columns
90
130
  row.types = @stmt.types
91
131
  row
92
132
  end
93
133
 
94
134
  # Required by the Enumerable mixin. Provides an internal iterator over the
95
135
  # rows of the result set.
96
- def each( &block )
136
+ def each
97
137
  while node = self.next
98
138
  yield node
99
139
  end
100
140
  end
101
141
 
142
+ # Provides an internal iterator over the rows of the result set where
143
+ # each row is yielded as a hash.
144
+ def each_hash
145
+ while node = next_hash
146
+ yield node
147
+ end
148
+ end
149
+
102
150
  # Closes the statement that spawned this result set.
103
151
  # <em>Use with caution!</em> Closing a result set will automatically
104
152
  # close any other result sets that were spawned from the same statement.
@@ -121,6 +169,27 @@ module SQLite3
121
169
  @stmt.columns
122
170
  end
123
171
 
124
- end
172
+ # Return the next row as a hash
173
+ def next_hash
174
+ row = @stmt.step
175
+ return nil if @stmt.done?
176
+
177
+ # FIXME: type translation is deprecated, so this can be removed
178
+ # in 2.0
179
+ if @db.type_translation
180
+ row = @stmt.types.zip(row).map do |type, value|
181
+ @db.translator.translate( type, value )
182
+ end
183
+ end
184
+
185
+ # FIXME: this can be switched to a regular hash in 2.0
186
+ row = HashWithTypesAndFields[*@stmt.columns.zip(row).flatten]
125
187
 
188
+ # FIXME: these methods are deprecated for version 2.0, so we can remove
189
+ # this code in 2.0
190
+ row.fields = @stmt.columns
191
+ row.types = @stmt.types
192
+ row
193
+ end
194
+ end
126
195
  end
@@ -120,23 +120,6 @@ module SQLite3
120
120
  @types
121
121
  end
122
122
 
123
- # A convenience method for obtaining the metadata about the query. Note
124
- # that this will actually execute the SQL, which means it can be a
125
- # (potentially) expensive operation.
126
- def get_metadata
127
- @columns = []
128
- @types = []
129
-
130
- column_count.times do |column|
131
- @columns << column_name(column)
132
- @types << column_decltype(column)
133
- end
134
-
135
- @columns.freeze
136
- @types.freeze
137
- end
138
- private :get_metadata
139
-
140
123
  # Performs a sanity check to ensure that the statement is not
141
124
  # closed. If it is, an exception is raised.
142
125
  def must_be_open! # :nodoc:
@@ -144,5 +127,18 @@ module SQLite3
144
127
  raise SQLite3::Exception, "cannot use a closed statement"
145
128
  end
146
129
  end
130
+
131
+ private
132
+ # A convenience method for obtaining the metadata about the query. Note
133
+ # that this will actually execute the SQL, which means it can be a
134
+ # (potentially) expensive operation.
135
+ def get_metadata
136
+ @columns = Array.new(column_count) do |column|
137
+ column_name column
138
+ end
139
+ @types = Array.new(column_count) do |column|
140
+ column_decltype column
141
+ end
142
+ end
147
143
  end
148
144
  end
@@ -1,12 +1,12 @@
1
1
  module SQLite3
2
2
 
3
- VERSION = '1.3.5'
3
+ VERSION = '1.3.6'
4
4
 
5
5
  module VersionProxy
6
6
 
7
7
  MAJOR = 1
8
8
  MINOR = 3
9
- TINY = 4
9
+ TINY = 6
10
10
  BUILD = nil
11
11
 
12
12
  STRING = [ MAJOR, MINOR, TINY, BUILD ].compact.join( "." )
@@ -4,8 +4,8 @@ require 'rake/extensiontask'
4
4
  # NOTE: version used by cross compilation of Windows native extension
5
5
  # It do not affect compilation under other operating systems
6
6
  # The version indicated is the minimum DLL suggested for correct functionality
7
- BINARY_VERSION = "3.7.9"
8
- URL_VERSION = "3070900"
7
+ BINARY_VERSION = "3.7.11"
8
+ URL_VERSION = "3071100"
9
9
 
10
10
  # build sqlite3_native C extension
11
11
  Rake::ExtensionTask.new('sqlite3_native', HOE.spec) do |ext|
@@ -1,3 +1,14 @@
1
1
  require 'sqlite3'
2
2
  require 'test/unit'
3
- require 'iconv'
3
+
4
+ unless RUBY_VERSION >= "1.9"
5
+ require 'iconv'
6
+ end
7
+
8
+ module SQLite3
9
+ class TestCase < Test::Unit::TestCase
10
+ unless RUBY_VERSION >= '1.9'
11
+ undef :default_test
12
+ end
13
+ end
14
+ end
@@ -1,7 +1,7 @@
1
- require File.expand_path('helper', File.dirname(__FILE__))
1
+ require 'helper'
2
2
 
3
3
  module SQLite3
4
- class TestBackup < Test::Unit::TestCase
4
+ class TestBackup < SQLite3::TestCase
5
5
  def setup
6
6
  @sdb = SQLite3::Database.new(':memory:')
7
7
  @ddb = SQLite3::Database.new(':memory:')
@@ -3,7 +3,7 @@
3
3
  require 'helper'
4
4
 
5
5
  module SQLite3
6
- class TestCollation < Test::Unit::TestCase
6
+ class TestCollation < SQLite3::TestCase
7
7
  class Comparator
8
8
  attr_reader :calls
9
9
  def initialize
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  module SQLite3
4
- class TestDatabase < Test::Unit::TestCase
4
+ class TestDatabase < SQLite3::TestCase
5
5
  attr_reader :db
6
6
 
7
7
  def setup
@@ -77,8 +77,12 @@ module SQLite3
77
77
  # determine if Ruby is running on Big Endian platform
78
78
  utf16 = ([1].pack("I") == [1].pack("N")) ? "UTF-16BE" : "UTF-16LE"
79
79
 
80
- db = SQLite3::Database.new(Iconv.conv(utf16, 'UTF-8', ':memory:'),
81
- :utf16 => true)
80
+ if RUBY_VERSION >= "1.9"
81
+ db = SQLite3::Database.new(':memory:'.encode(utf16), :utf16 => true)
82
+ else
83
+ db = SQLite3::Database.new(Iconv.conv(utf16, 'UTF-8', ':memory:'),
84
+ :utf16 => true)
85
+ end
82
86
  assert db
83
87
  end
84
88
 
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  module SQLite3
4
- class TestDatabaseReadonly < Test::Unit::TestCase
4
+ class TestDatabaseReadonly < SQLite3::TestCase
5
5
  def setup
6
6
  File.unlink 'test-readonly.db' if File.exists?('test-readonly.db')
7
7
  @db = SQLite3::Database.new('test-readonly.db')
@@ -1,12 +1,15 @@
1
1
  require 'helper'
2
2
 
3
3
  module SQLite3
4
- class TestDeprecated < Test::Unit::TestCase
4
+ class TestDeprecated < SQLite3::TestCase
5
+ attr_reader :db
6
+
5
7
  def setup
6
8
  super
7
9
  @warn_before = $-w
8
10
  $-w = false
9
11
  @db = SQLite3::Database.new(':memory:')
12
+ @db.execute 'CREATE TABLE test_table (name text, age int)'
10
13
  end
11
14
 
12
15
  def teardown
@@ -14,6 +17,10 @@ module SQLite3
14
17
  $-w = @warn_before
15
18
  end
16
19
 
20
+ def test_query_with_many_bind_params_not_nil
21
+ assert_equal [[1, 2]], db.query('select ?, ?', 1, 2).to_a
22
+ end
23
+
17
24
  def test_execute_with_many_bind_params_not_nil
18
25
  assert_equal [[1, 2]], @db.execute("select ?, ?", 1, 2).to_a
19
26
  end
@@ -3,7 +3,7 @@
3
3
  require 'helper'
4
4
 
5
5
  module SQLite3
6
- class TestEncoding < Test::Unit::TestCase
6
+ class TestEncoding < SQLite3::TestCase
7
7
  def setup
8
8
  @db = SQLite3::Database.new(':memory:')
9
9
  @create = "create table ex(id int, data string)"
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TC_Database_Integration < Test::Unit::TestCase
3
+ class TC_Database_Integration < SQLite3::TestCase
4
4
  def setup
5
5
  @db = SQLite3::Database.new(":memory:")
6
6
  @db.transaction do
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TC_OpenClose < Test::Unit::TestCase
3
+ class TC_OpenClose < SQLite3::TestCase
4
4
  def test_create_close
5
5
  begin
6
6
  db = SQLite3::Database.new( "test-create.db" )
@@ -3,7 +3,7 @@ require 'helper'
3
3
  require 'thread'
4
4
  require 'benchmark'
5
5
 
6
- class TC_Integration_Pending < Test::Unit::TestCase
6
+ class TC_Integration_Pending < SQLite3::TestCase
7
7
  def setup
8
8
  @db = SQLite3::Database.new("test.db")
9
9
  @db.transaction do
@@ -1,6 +1,6 @@
1
1
  require 'helper'
2
2
 
3
- class TC_ResultSet < Test::Unit::TestCase
3
+ class TC_ResultSet < SQLite3::TestCase
4
4
  def setup
5
5
  @db = SQLite3::Database.new(":memory:")
6
6
  @db.transaction do
@@ -98,8 +98,11 @@ class TC_ResultSet < Test::Unit::TestCase
98
98
  def test_next_results_as_hash
99
99
  @db.results_as_hash = true
100
100
  @result.reset( 1 )
101
- assert_equal( { "a" => 1, "b" => "foo", 0 => 1, 1 => "foo" },
102
- @result.next )
101
+ hash = @result.next
102
+ assert_equal( { "a" => 1, "b" => "foo" },
103
+ hash )
104
+ assert_equal hash[0], 1
105
+ assert_equal hash[1], "foo"
103
106
  end
104
107
 
105
108
  def test_tainted_results_as_hash
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'helper')
1
+ require 'helper'
2
2
 
3
- class TC_Statement < Test::Unit::TestCase
3
+ class TC_Statement < SQLite3::TestCase
4
4
  def setup
5
5
  @db = SQLite3::Database.new(":memory:")
6
6
  @db.transaction do
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ module SQLite3
4
+ class TestResultSet < SQLite3::TestCase
5
+ def test_each_hash
6
+ db = SQLite3::Database.new ':memory:'
7
+ db.execute "create table foo ( a integer primary key, b text )"
8
+ list = ('a'..'z').to_a
9
+ list.each do |t|
10
+ db.execute "insert into foo (b) values (\"#{t}\")"
11
+ end
12
+
13
+ rs = db.prepare('select * from foo').execute
14
+ rs.each_hash do |hash|
15
+ assert_equal list[hash['a'] - 1], hash['b']
16
+ end
17
+ end
18
+
19
+ def test_next_hash
20
+ db = SQLite3::Database.new ':memory:'
21
+ db.execute "create table foo ( a integer primary key, b text )"
22
+ list = ('a'..'z').to_a
23
+ list.each do |t|
24
+ db.execute "insert into foo (b) values (\"#{t}\")"
25
+ end
26
+
27
+ rs = db.prepare('select * from foo').execute
28
+ rows = []
29
+ while row = rs.next_hash
30
+ rows << row
31
+ end
32
+ rows.each do |hash|
33
+ assert_equal list[hash['a'] - 1], hash['b']
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  module SQLite3
4
- class TestSQLite3 < Test::Unit::TestCase
4
+ class TestSQLite3 < SQLite3::TestCase
5
5
  def test_libversion
6
6
  assert_not_nil SQLite3.libversion
7
7
  end
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  module SQLite3
4
- class TestStatement < Test::Unit::TestCase
4
+ class TestStatement < SQLite3::TestCase
5
5
  def setup
6
6
  @db = SQLite3::Database.new(':memory:')
7
7
  @stmt = SQLite3::Statement.new(@db, "select 'foo'")
@@ -1,7 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  module SQLite3
4
- class TestStatementExecute < Test::Unit::TestCase
4
+ class TestStatementExecute < SQLite3::TestCase
5
5
  def setup
6
6
  @db = SQLite3::Database.new(':memory:')
7
7
  @db.execute_batch(
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 5
10
- version: 1.3.5
9
+ - 6
10
+ version: 1.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jamis Buck
@@ -17,68 +17,68 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-12-03 00:00:00 Z
20
+ date: 2012-04-16 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- name: rake-compiler
23
+ name: rdoc
24
24
  prerelease: false
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- hash: 3
30
+ hash: 19
31
31
  segments:
32
- - 0
33
- - 7
34
- - 0
35
- version: 0.7.0
32
+ - 3
33
+ - 10
34
+ version: "3.10"
36
35
  type: :development
37
36
  version_requirements: *id001
38
37
  - !ruby/object:Gem::Dependency
39
- name: mini_portile
38
+ name: rake-compiler
40
39
  prerelease: false
41
40
  requirement: &id002 !ruby/object:Gem::Requirement
42
41
  none: false
43
42
  requirements:
44
43
  - - ~>
45
44
  - !ruby/object:Gem::Version
46
- hash: 19
45
+ hash: 3
47
46
  segments:
48
47
  - 0
49
- - 2
50
- - 2
51
- version: 0.2.2
48
+ - 7
49
+ - 0
50
+ version: 0.7.0
52
51
  type: :development
53
52
  version_requirements: *id002
54
53
  - !ruby/object:Gem::Dependency
55
- name: hoe
54
+ name: mini_portile
56
55
  prerelease: false
57
56
  requirement: &id003 !ruby/object:Gem::Requirement
58
57
  none: false
59
58
  requirements:
60
59
  - - ~>
61
60
  - !ruby/object:Gem::Version
62
- hash: 27
61
+ hash: 19
63
62
  segments:
63
+ - 0
64
+ - 2
64
65
  - 2
65
- - 12
66
- version: "2.12"
66
+ version: 0.2.2
67
67
  type: :development
68
68
  version_requirements: *id003
69
69
  - !ruby/object:Gem::Dependency
70
- name: rdoc
70
+ name: hoe
71
71
  prerelease: false
72
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- hash: 19
77
+ hash: 7
78
78
  segments:
79
79
  - 3
80
- - 10
81
- version: "3.10"
80
+ - 0
81
+ version: "3.0"
82
82
  type: :development
83
83
  version_requirements: *id004
84
84
  description: |-
@@ -96,15 +96,15 @@ executables: []
96
96
  extensions:
97
97
  - ext/sqlite3/extconf.rb
98
98
  extra_rdoc_files:
99
+ - API_CHANGES.rdoc
100
+ - CHANGELOG.rdoc
99
101
  - Manifest.txt
100
102
  - README.rdoc
101
- - CHANGELOG.rdoc
102
- - API_CHANGES.rdoc
103
- - ext/sqlite3/sqlite3.c
104
103
  - ext/sqlite3/backup.c
105
- - ext/sqlite3/statement.c
106
104
  - ext/sqlite3/database.c
107
105
  - ext/sqlite3/exception.c
106
+ - ext/sqlite3/sqlite3.c
107
+ - ext/sqlite3/statement.c
108
108
  files:
109
109
  - API_CHANGES.rdoc
110
110
  - CHANGELOG.rdoc
@@ -156,6 +156,7 @@ files:
156
156
  - test/test_sqlite3.rb
157
157
  - test/test_statement.rb
158
158
  - test/test_statement_execute.rb
159
+ - test/test_result_set.rb
159
160
  - .gemtest
160
161
  homepage: http://github.com/luislavena/sqlite3-ruby
161
162
  licenses: []
@@ -191,22 +192,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  requirements: []
192
193
 
193
194
  rubyforge_project: sqlite3
194
- rubygems_version: 1.8.12
195
+ rubygems_version: 1.8.21
195
196
  signing_key:
196
197
  specification_version: 3
197
198
  summary: This module allows Ruby programs to interface with the SQLite3 database engine (http://www.sqlite.org)
198
199
  test_files:
200
+ - test/test_backup.rb
201
+ - test/test_collation.rb
199
202
  - test/test_database.rb
200
- - test/test_integration_open_close.rb
201
203
  - test/test_database_readonly.rb
202
- - test/test_statement.rb
203
- - test/test_integration_resultset.rb
204
204
  - test/test_deprecated.rb
205
- - test/test_backup.rb
206
205
  - test/test_encoding.rb
207
- - test/test_sqlite3.rb
208
- - test/test_collation.rb
209
206
  - test/test_integration.rb
210
- - test/test_statement_execute.rb
211
- - test/test_integration_statement.rb
207
+ - test/test_integration_open_close.rb
212
208
  - test/test_integration_pending.rb
209
+ - test/test_integration_resultset.rb
210
+ - test/test_integration_statement.rb
211
+ - test/test_result_set.rb
212
+ - test/test_sqlite3.rb
213
+ - test/test_statement.rb
214
+ - test/test_statement_execute.rb