sqlite3-ruby 1.3.0.beta.1 → 1.3.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,19 @@
1
+ === 1.3.0.beta.2 / 2010-05-15
2
+
3
+ * Enhancements
4
+ * Added support for type translations [tenderlove]
5
+
6
+ @db.translator.add_translator('sometime') do |type, thing|
7
+ 'output' # this will be returned as value for that column
8
+ end
9
+
10
+ * Bugfixes
11
+ * Allow extension compilation search for common lib paths [kashif]
12
+ (lookup /usr/local, /opt/local and /usr)
13
+ * Corrected extension compilation under MSVC [romuloceccon]
14
+ * Define load_extension functionality based on availability [tenderlove]
15
+ * Deprecation notices for Database#query. Fixes RF #28192
16
+
1
17
  === 1.3.0.beta.1 / 2010-05-10
2
18
 
3
19
  * Enhancements
@@ -28,10 +28,13 @@ lib/sqlite3/value.rb
28
28
  lib/sqlite3/version.rb
29
29
  setup.rb
30
30
  tasks/faq.rake
31
+ tasks/gem.rake
31
32
  tasks/native.rake
32
33
  tasks/vendor_sqlite3.rake
33
34
  test/helper.rb
34
35
  test/test_database.rb
36
+ test/test_deprecated.rb
37
+ test/test_encoding.rb
35
38
  test/test_integration.rb
36
39
  test/test_integration_open_close.rb
37
40
  test/test_integration_pending.rb
@@ -1,8 +1,8 @@
1
1
  = SQLite3/Ruby Interface
2
2
 
3
- * http://sqlite3-ruby.rubyforge.org
4
- * http://rubyforge.org/projects/sqlite3-ruby
5
3
  * http://github.com/luislavena/sqlite3-ruby
4
+ * http://rubyforge.org/projects/sqlite-ruby
5
+ * http://sqlite-ruby.rubyforge.org
6
6
 
7
7
  == DESCRIPTION
8
8
 
@@ -14,7 +14,10 @@ Note that this module is NOT compatible with SQLite 2.x.
14
14
 
15
15
  == Compilation and Installation
16
16
 
17
- Simply do the following, after installing SQLite3:
17
+ Install SQLite3, enabling option SQLITE_ENABLE_COLUMN_METADATA (see
18
+ www.sqlite.org/compile.html for details).
19
+
20
+ Then do the following:
18
21
 
19
22
  ruby setup.rb config
20
23
  ruby setup.rb setup
@@ -41,7 +44,7 @@ FAQ, please send them to jamis@37signals.com
41
44
 
42
45
  The source repository is accessible via git:
43
46
 
44
- git clone git://github.com/jamis/sqlite3-ruby.git
47
+ git clone git://github.com/luislavena/sqlite3-ruby.git
45
48
 
46
49
  == Contact Information
47
50
 
@@ -460,7 +460,7 @@ static VALUE errmsg(VALUE self)
460
460
  * Return an integer representing the last error to have occurred with this
461
461
  * database.
462
462
  */
463
- static VALUE errcode(VALUE self)
463
+ static VALUE errcode_(VALUE self)
464
464
  {
465
465
  sqlite3RubyPtr ctx;
466
466
  Data_Get_Struct(self, sqlite3Ruby, ctx);
@@ -665,14 +665,20 @@ void init_sqlite3_database()
665
665
  rb_define_method(cSqlite3Database, "define_aggregator", define_aggregator, 2);
666
666
  rb_define_method(cSqlite3Database, "interrupt", interrupt, 0);
667
667
  rb_define_method(cSqlite3Database, "errmsg", errmsg, 0);
668
- rb_define_method(cSqlite3Database, "errcode", errcode, 0);
668
+ rb_define_method(cSqlite3Database, "errcode", errcode_, 0);
669
669
  rb_define_method(cSqlite3Database, "complete?", complete_p, 1);
670
670
  rb_define_method(cSqlite3Database, "changes", changes, 0);
671
671
  rb_define_method(cSqlite3Database, "authorizer=", set_authorizer, 1);
672
672
  rb_define_method(cSqlite3Database, "busy_handler", busy_handler, -1);
673
673
  rb_define_method(cSqlite3Database, "busy_timeout=", set_busy_timeout, 1);
674
+
675
+ #ifdef HAVE_SQLITE3_LOAD_EXTENSION
674
676
  rb_define_method(cSqlite3Database, "load_extension", load_extension, 1);
677
+ #endif
678
+
679
+ #ifdef HAVE_SQLITE3_ENABLE_LOAD_EXTENSION
675
680
  rb_define_method(cSqlite3Database, "enable_load_extension", enable_load_extension, 1);
681
+ #endif
676
682
 
677
683
  #ifdef HAVE_RUBY_ENCODING_H
678
684
  rb_define_method(cSqlite3Database, "encoding", db_encoding, 0);
@@ -6,14 +6,23 @@ require 'mkmf'
6
6
 
7
7
  RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
8
8
 
9
- $CFLAGS << ' -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion' <<
10
- ' -Wmissing-noreturn -Winline'
9
+ sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr'])
11
10
 
12
- sqlite = dir_config 'sqlite3', '/opt/local/include', '/opt/local/lib'
11
+ if RUBY_PLATFORM =~ /mswin/
12
+ $CFLAGS << ' -W3'
13
+ else
14
+ $CFLAGS << ' -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion' <<
15
+ ' -Wmissing-noreturn -Winline'
16
+ end
13
17
 
14
18
  def asplode missing
15
- abort "#{missing} is missing. Try 'port install sqlite3 +universal' " +
16
- "or 'yum install sqlite3-devel'"
19
+ if RUBY_PLATFORM =~ /mswin/
20
+ abort "#{missing} is missing. Install SQLite3 from " +
21
+ "http://www.sqlite.org/ first."
22
+ else
23
+ abort "#{missing} is missing. Try 'port install sqlite3 +universal' " +
24
+ "or 'yum install sqlite3-devel'"
25
+ end
17
26
  end
18
27
 
19
28
  asplode('sqlite3.h') unless find_header 'sqlite3.h'
@@ -21,6 +30,10 @@ asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'
21
30
 
22
31
  # Functions defined in 1.9 but not 1.8
23
32
  have_func('rb_proc_arity')
24
- have_func('rb_obj_method_arity')
33
+
34
+ # These functions may not be defined
35
+ have_func('sqlite3_column_database_name')
36
+ have_func('sqlite3_enable_load_extension')
37
+ have_func('sqlite3_load_extension')
25
38
 
26
39
  create_makefile('sqlite3/sqlite3_native')
@@ -378,6 +378,8 @@ static VALUE bind_parameter_count(VALUE self)
378
378
  return INT2NUM((long)sqlite3_bind_parameter_count(ctx->st));
379
379
  }
380
380
 
381
+ #ifdef HAVE_SQLITE3_COLUMN_DATABASE_NAME
382
+
381
383
  /* call-seq: stmt.database_name(column_index)
382
384
  *
383
385
  * Return the database name for the column at +column_index+
@@ -392,6 +394,8 @@ static VALUE database_name(VALUE self, VALUE index)
392
394
  sqlite3_column_database_name(ctx->st, NUM2INT(index)));
393
395
  }
394
396
 
397
+ #endif
398
+
395
399
  void init_sqlite3_statement()
396
400
  {
397
401
  cSqlite3Statement = rb_define_class_under(mSqlite3, "Statement", rb_cObject);
@@ -408,5 +412,8 @@ void init_sqlite3_statement()
408
412
  rb_define_method(cSqlite3Statement, "column_name", column_name, 1);
409
413
  rb_define_method(cSqlite3Statement, "column_decltype", column_decltype, 1);
410
414
  rb_define_method(cSqlite3Statement, "bind_parameter_count", bind_parameter_count, 0);
415
+
416
+ #ifdef HAVE_SQLITE3_COLUMN_DATABASE_NAME
411
417
  rb_define_method(cSqlite3Statement, "database_name", database_name, 1);
418
+ #endif
412
419
  }
@@ -104,13 +104,30 @@ module SQLite3
104
104
  #
105
105
  # See also #execute2, #query, and #execute_batch for additional ways of
106
106
  # executing statements.
107
- def execute sql, *bind_vars, &block
107
+ def execute sql, bind_vars = [], *args, &block
108
108
  # FIXME: This is a terrible hack and should be removed but is required
109
109
  # for older versions of rails
110
110
  hack = Object.const_defined?(:ActiveRecord) && sql =~ /^PRAGMA index_list/
111
111
 
112
+ if bind_vars.nil? || !args.empty?
113
+ if args.empty?
114
+ bind_vars = []
115
+ else
116
+ bind_vars = [nil] + args
117
+ end
118
+
119
+ warn(<<-eowarn) if $VERBOSE
120
+ #{caller[0]} is calling SQLite3::Database#execute with nil or multiple bind params
121
+ without using an array. Please switch to passing bind parameters as an array.
122
+ eowarn
123
+ end
124
+
112
125
  prepare( sql ) do |stmt|
113
- stmt.bind_params( *bind_vars )
126
+ stmt.bind_params(bind_vars)
127
+ if type_translation
128
+ stmt = ResultSet.new(self, stmt).to_a
129
+ end
130
+
114
131
  if block_given?
115
132
  stmt.each do |row|
116
133
  if @results_as_hash
@@ -171,7 +188,31 @@ module SQLite3
171
188
  #
172
189
  # This always returns +nil+, making it unsuitable for queries that return
173
190
  # rows.
174
- def execute_batch( sql, *bind_vars )
191
+ def execute_batch( sql, bind_vars = [], *args )
192
+ # FIXME: remove this stuff later
193
+ unless [Array, Hash].include?(bind_vars.class)
194
+ bind_vars = [bind_vars]
195
+ warn(<<-eowarn) if $VERBOSE
196
+ #{caller[0]} is calling SQLite3::Database#execute_batch with bind parameters
197
+ that are not a list of a hash. Please switch to passing bind parameters as an
198
+ array or hash.
199
+ eowarn
200
+ end
201
+
202
+ # FIXME: remove this stuff later
203
+ if bind_vars.nil? || !args.empty?
204
+ if args.empty?
205
+ bind_vars = []
206
+ else
207
+ bind_vars = [nil] + args
208
+ end
209
+
210
+ warn(<<-eowarn) if $VERBOSE
211
+ #{caller[0]} is calling SQLite3::Database#execute_batch with nil or multiple bind params
212
+ without using an array. Please switch to passing bind parameters as an array.
213
+ eowarn
214
+ end
215
+
175
216
  sql = sql.strip
176
217
  until sql.empty? do
177
218
  prepare( sql ) do |stmt|
@@ -198,8 +239,22 @@ module SQLite3
198
239
  # returned, or you could have problems with locks on the table. If called
199
240
  # with a block, +close+ will be invoked implicitly when the block
200
241
  # terminates.
201
- def query( sql, *bind_vars )
202
- result = prepare( sql ).execute( *bind_vars )
242
+ def query( sql, bind_vars = [], *args )
243
+
244
+ if bind_vars.nil? || !args.empty?
245
+ if args.empty?
246
+ bind_vars = []
247
+ else
248
+ bind_vars = [nil] + args
249
+ end
250
+
251
+ warn(<<-eowarn) if $VERBOSE
252
+ #{caller[0]} is calling SQLite3::Database#query with nil or multiple bind params
253
+ without using an array. Please switch to passing bind parameters as an array.
254
+ eowarn
255
+ end
256
+
257
+ result = prepare( sql ).execute( bind_vars )
203
258
  if block_given?
204
259
  begin
205
260
  yield result
@@ -94,7 +94,9 @@ module SQLite3
94
94
  # Required by the Enumerable mixin. Provides an internal iterator over the
95
95
  # rows of the result set.
96
96
  def each( &block )
97
- @stmt.each(&block)
97
+ while node = self.next
98
+ yield node
99
+ end
98
100
  end
99
101
 
100
102
  # Closes the statement that spawned this result set.
@@ -44,7 +44,12 @@ module SQLite3
44
44
  # and are always passed straight through regardless of the type parameter.
45
45
  def translate( type, value )
46
46
  unless value.nil?
47
- @translators[ type_name( type ) ].call( type, value )
47
+ # FIXME: this is a hack to support Sequel
48
+ if type && %w{ datetime timestamp }.include?(type.downcase)
49
+ @translators[ type_name( type ) ].call( type, value.to_s )
50
+ else
51
+ @translators[ type_name( type ) ].call( type, value )
52
+ end
48
53
  end
49
54
  end
50
55
 
@@ -5,12 +5,12 @@ module SQLite3
5
5
  MAJOR = 1
6
6
  MINOR = 3
7
7
  TINY = 0
8
- BUILD = "beta.1"
8
+ BUILD = "beta.2"
9
9
 
10
10
  STRING = [ MAJOR, MINOR, TINY, BUILD ].compact.join( "." )
11
11
  #:beta-tag:
12
12
 
13
- VERSION = '1.3.0.beta.1'
13
+ VERSION = '1.3.0.beta.2'
14
14
  end
15
15
 
16
16
  end
@@ -0,0 +1,31 @@
1
+ begin
2
+ require 'hoe'
3
+ rescue LoadError
4
+ # try with rubygems?
5
+ require 'rubygems'
6
+ require 'hoe'
7
+ end
8
+
9
+ Hoe.plugin :debugging, :doofus, :git
10
+
11
+ HOE = Hoe.spec 'sqlite3-ruby' do
12
+ developer 'Jamis Buck', 'jamis@37signals.com'
13
+ developer 'Luis Lavena', 'luislavena@gmail.com'
14
+ developer 'Aaron Patterson', 'aaron@tenderlovemaking.com'
15
+
16
+ self.readme_file = 'README.rdoc'
17
+ self.history_file = 'CHANGELOG.rdoc'
18
+ self.extra_rdoc_files = FileList['*.rdoc', 'ext/**/*.c']
19
+
20
+ spec_extras[:required_ruby_version] = Gem::Requirement.new('>= 1.8.6')
21
+ spec_extras[:required_rubygems_version] = '>= 1.3.5'
22
+ spec_extras[:extensions] = ["ext/sqlite3/extconf.rb"]
23
+
24
+ extra_dev_deps << ['rake-compiler', "~> 0.7.0"]
25
+
26
+ clean_globs.push('**/test.db')
27
+ end
28
+
29
+ Hoe.add_include_dirs '.'
30
+
31
+ # vim: syntax=ruby
@@ -20,7 +20,7 @@ Rake::ExtensionTask.new('sqlite3_native', HOE.spec) do |ext|
20
20
  ext.config_options << "--with-sqlite3-dir=#{sqlite3_lib}"
21
21
  else
22
22
  ext.cross_compile = true
23
- ext.cross_platform = ['i386-mswin32', 'i386-mingw32']
23
+ ext.cross_platform = ['i386-mswin32-60', 'i386-mingw32']
24
24
  ext.cross_config_options << "--with-sqlite3-dir=#{sqlite3_lib}"
25
25
  end
26
26
  end
@@ -7,6 +7,18 @@ module SQLite3
7
7
  @db = SQLite3::Database.new(':memory:')
8
8
  end
9
9
 
10
+ def test_changes
11
+ @db.execute("CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT, number integer)")
12
+ assert_equal 0, @db.changes
13
+ @db.execute("INSERT INTO items (number) VALUES (10)")
14
+ assert_equal 1, @db.changes
15
+ @db.execute_batch(
16
+ "UPDATE items SET number = (number + :nn) WHERE (number = :n)",
17
+ {"nn" => 20, "n" => 10})
18
+ assert_equal 1, @db.changes
19
+ assert_equal [[30]], @db.execute("select number from items")
20
+ end
21
+
10
22
  def test_new
11
23
  db = SQLite3::Database.new(':memory:')
12
24
  assert db
@@ -263,5 +275,17 @@ module SQLite3
263
275
  @db.close
264
276
  end
265
277
  end
278
+
279
+ def test_execute_with_empty_bind_params
280
+ assert_equal [['foo']], @db.execute("select 'foo'", [])
281
+ end
282
+
283
+ def test_query_with_named_bind_params
284
+ assert_equal [['foo']], @db.query("select :n", {'n' => 'foo'}).to_a
285
+ end
286
+
287
+ def test_execute_with_named_bind_params
288
+ assert_equal [['foo']], @db.execute("select :n", {'n' => 'foo'})
289
+ end
266
290
  end
267
291
  end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ module SQLite3
4
+ class TestDeprecated < Test::Unit::TestCase
5
+ def setup
6
+ @db = SQLite3::Database.new(':memory:')
7
+ end
8
+
9
+ def test_query_with_many_bind_params
10
+ assert_equal [[nil, 1]], @db.query("select ?, ?", nil, 1).to_a
11
+ end
12
+
13
+ def test_query_with_nil_bind_params
14
+ assert_equal [['foo']], @db.query("select 'foo'", nil).to_a
15
+ end
16
+
17
+ def test_execute_with_many_bind_params
18
+ assert_equal [[nil, 1]], @db.execute("select ?, ?", nil, 1)
19
+ end
20
+
21
+ def test_execute_with_nil_bind_params
22
+ assert_equal [['foo']], @db.execute("select 'foo'", nil)
23
+ end
24
+ end
25
+ end
@@ -71,6 +71,18 @@ class TC_ResultSet < Test::Unit::TestCase
71
71
  end
72
72
  end
73
73
 
74
+ def test_type_translation_execute
75
+ @db.type_translation = true
76
+ @db.execute "create table bar ( a integer, b america )"
77
+ @db.execute "insert into bar (a, b) values (NULL, '1974-07-25 14:39:00')"
78
+
79
+ @db.translator.add_translator('america') do |type, thing|
80
+ 'america'
81
+ end
82
+
83
+ assert_equal [[nil, 'america']], @db.execute("select * from bar")
84
+ end
85
+
74
86
  def test_type_translation_with_null_column
75
87
  @db.type_translation = true
76
88
  @db.execute "create table bar ( a integer, b time, c string )"
@@ -7,11 +7,15 @@ module SQLite3
7
7
  @stmt = SQLite3::Statement.new(@db, "select 'foo'")
8
8
  end
9
9
 
10
+ ###
11
+ # This method may not exist depending on how sqlite3 was compiled
10
12
  def test_database_name
11
13
  @db.execute('create table foo(text BLOB)')
12
14
  @db.execute('insert into foo(text) values (?)',SQLite3::Blob.new('hello'))
13
15
  stmt = @db.prepare('select text from foo')
14
- assert_equal 'main', stmt.database_name(0)
16
+ if stmt.respond_to?(:database_name)
17
+ assert_equal 'main', stmt.database_name(0)
18
+ end
15
19
  end
16
20
 
17
21
  def test_prepare_blob
@@ -189,5 +193,15 @@ module SQLite3
189
193
  stmt = SQLite3::Statement.new(@db, "select ?, ?, ?")
190
194
  assert_equal 3, stmt.bind_parameter_count
191
195
  end
196
+
197
+ def test_execute_with_varargs
198
+ stmt = @db.prepare('select ?, ?')
199
+ assert_equal [[nil, nil]], stmt.execute(nil, nil).to_a
200
+ end
201
+
202
+ def test_execute_with_hash
203
+ stmt = @db.prepare('select :n, :h')
204
+ assert_equal [[10, nil]], stmt.execute('n' => 10, 'h' => nil).to_a
205
+ end
192
206
  end
193
207
  end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 3
8
8
  - 0
9
9
  - beta
10
- - 1
11
- version: 1.3.0.beta.1
10
+ - 2
11
+ version: 1.3.0.beta.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Jamis Buck
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-05-10 00:00:00 -03:00
21
+ date: 2010-05-15 00:00:00 -03:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -117,10 +117,13 @@ files:
117
117
  - lib/sqlite3/version.rb
118
118
  - setup.rb
119
119
  - tasks/faq.rake
120
+ - tasks/gem.rake
120
121
  - tasks/native.rake
121
122
  - tasks/vendor_sqlite3.rake
122
123
  - test/helper.rb
123
124
  - test/test_database.rb
125
+ - test/test_deprecated.rb
126
+ - test/test_encoding.rb
124
127
  - test/test_integration.rb
125
128
  - test/test_integration_open_close.rb
126
129
  - test/test_integration_pending.rb
@@ -129,7 +132,7 @@ files:
129
132
  - test/test_sqlite3.rb
130
133
  - test/test_statement.rb
131
134
  has_rdoc: true
132
- homepage: http://sqlite3-ruby.rubyforge.org
135
+ homepage: http://github.com/luislavena/sqlite3-ruby
133
136
  licenses: []
134
137
 
135
138
  post_install_message:
@@ -170,6 +173,7 @@ test_files:
170
173
  - test/test_integration.rb
171
174
  - test/test_statement.rb
172
175
  - test/test_integration_pending.rb
176
+ - test/test_deprecated.rb
173
177
  - test/test_integration_statement.rb
174
178
  - test/test_encoding.rb
175
179
  - test/test_integration_resultset.rb