From b3aae9b06d6d378459f71b89270372451961059f Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Tue, 20 Jul 2010 20:36:17 -0500 Subject: [PATCH] Sqlite3-ruby 1.3.1, itextomml 1.3.26 Update vendored sqlite3-ruby and tests for latest itextmml. --- test/unit/page_renderer_test.rb | 7 ++ vendor/plugins/sqlite3-ruby/CHANGELOG.rdoc | 11 ++- vendor/plugins/sqlite3-ruby/Manifest.txt | 2 + vendor/plugins/sqlite3-ruby/README.rdoc | 20 +++++ .../sqlite3-ruby/ext/sqlite3/database.c | 73 ++++++++++++++++- .../sqlite3-ruby/ext/sqlite3/extconf.rb | 4 + .../sqlite3-ruby/lib/sqlite3/database.rb | 2 + .../sqlite3-ruby/lib/sqlite3/statement.rb | 2 + .../sqlite3-ruby/lib/sqlite3/version.rb | 4 +- .../sqlite3-ruby/test/test_collation.rb | 82 +++++++++++++++++++ .../sqlite3-ruby/test/test_database.rb | 4 + .../sqlite3-ruby/test/test_deprecated.rb | 8 ++ .../sqlite3-ruby/test/test_encoding.rb | 8 +- .../sqlite3-ruby/test/test_integration.rb | 2 +- .../test/test_integration_pending.rb | 2 + .../test/test_statement_execute.rb | 35 ++++++++ 16 files changed, 257 insertions(+), 9 deletions(-) create mode 100644 vendor/plugins/sqlite3-ruby/test/test_collation.rb create mode 100644 vendor/plugins/sqlite3-ruby/test/test_statement_execute.rb diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index 0288e193..5e4d79f0 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -226,6 +226,13 @@ END_THM def test_have_latest_itex2mml + assert_markup_parsed_as( + %{

equation A\342\253\275B

}, + "equation $A\\sslash B$") + assert_markup_parsed_as( %{

boxed equation db, sqlite3_create_collation_v2( + ctx->db, + StringValuePtr(name), + SQLITE_UTF8, + (void *)comparator, + NIL_P(comparator) ? NULL : rb_comparator_func, + NULL)); + + /* Make sure our comparator doesn't get garbage collected. */ + rb_hash_aset(rb_iv_get(self, "@collations"), name, comparator); + + return self; +} + /* call-seq: db.load_extension(file) * * Loads an SQLite extension library from the named file. Extension @@ -623,6 +682,16 @@ static int enc_cb(void * _self, int UNUSED(columns), char **data, char **UNUSED( return 0; } +#else +static int enc_cb(void * _self, int UNUSED(columns), char **data, char **UNUSED(names)) +{ + VALUE self = (VALUE)_self; + + rb_iv_set(self, "@encoding", rb_str_new2(data[0])); + + return 0; +} +#endif /* call-seq: db.encoding * @@ -644,7 +713,6 @@ static VALUE db_encoding(VALUE self) return rb_iv_get(self, "@encoding"); } -#endif void init_sqlite3_database() { @@ -656,6 +724,7 @@ void init_sqlite3_database() rb_define_alloc_func(cSqlite3Database, allocate); rb_define_method(cSqlite3Database, "initialize", initialize, -1); + rb_define_method(cSqlite3Database, "collation", collation, 2); rb_define_method(cSqlite3Database, "close", sqlite3_rb_close, 0); rb_define_method(cSqlite3Database, "closed?", closed_p, 0); rb_define_method(cSqlite3Database, "total_changes", total_changes, 0); @@ -680,9 +749,7 @@ void init_sqlite3_database() rb_define_method(cSqlite3Database, "enable_load_extension", enable_load_extension, 1); #endif -#ifdef HAVE_RUBY_ENCODING_H rb_define_method(cSqlite3Database, "encoding", db_encoding, 0); -#endif id_utf16 = rb_intern("utf16"); sym_utf16 = ID2SYM(id_utf16); diff --git a/vendor/plugins/sqlite3-ruby/ext/sqlite3/extconf.rb b/vendor/plugins/sqlite3-ruby/ext/sqlite3/extconf.rb index 5a8ec34a..58989275 100644 --- a/vendor/plugins/sqlite3-ruby/ext/sqlite3/extconf.rb +++ b/vendor/plugins/sqlite3-ruby/ext/sqlite3/extconf.rb @@ -31,6 +31,10 @@ asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number' # Functions defined in 1.9 but not 1.8 have_func('rb_proc_arity') +unless have_func('sqlite3_initialize') && have_func('sqlite3_next_stmt') + abort "sqlite3-ruby only supports sqlite3 versions 3.6.16+, please upgrade!" +end + # These functions may not be defined have_func('sqlite3_column_database_name') have_func('sqlite3_enable_load_extension') diff --git a/vendor/plugins/sqlite3-ruby/lib/sqlite3/database.rb b/vendor/plugins/sqlite3-ruby/lib/sqlite3/database.rb index 4d3522fa..5a65eecd 100644 --- a/vendor/plugins/sqlite3-ruby/lib/sqlite3/database.rb +++ b/vendor/plugins/sqlite3-ruby/lib/sqlite3/database.rb @@ -33,6 +33,8 @@ module SQLite3 # module before performing a query, and if you have not enabled results as # hashes, then the results will all be indexible by field name. class Database + attr_reader :collations + include Pragmas class << self diff --git a/vendor/plugins/sqlite3-ruby/lib/sqlite3/statement.rb b/vendor/plugins/sqlite3-ruby/lib/sqlite3/statement.rb index ade99ef4..633244d4 100644 --- a/vendor/plugins/sqlite3-ruby/lib/sqlite3/statement.rb +++ b/vendor/plugins/sqlite3-ruby/lib/sqlite3/statement.rb @@ -64,6 +64,8 @@ module SQLite3 bind_params(*bind_vars) unless bind_vars.empty? @results = ResultSet.new(@connection, self) + step if 0 == column_count + yield @results if block_given? @results end diff --git a/vendor/plugins/sqlite3-ruby/lib/sqlite3/version.rb b/vendor/plugins/sqlite3-ruby/lib/sqlite3/version.rb index 71575622..22ce3cfd 100644 --- a/vendor/plugins/sqlite3-ruby/lib/sqlite3/version.rb +++ b/vendor/plugins/sqlite3-ruby/lib/sqlite3/version.rb @@ -4,13 +4,13 @@ module SQLite3 MAJOR = 1 MINOR = 3 - TINY = 0 + TINY = 1 BUILD = nil STRING = [ MAJOR, MINOR, TINY, BUILD ].compact.join( "." ) #:beta-tag: - VERSION = '1.3.0' + VERSION = '1.3.1' end end diff --git a/vendor/plugins/sqlite3-ruby/test/test_collation.rb b/vendor/plugins/sqlite3-ruby/test/test_collation.rb new file mode 100644 index 00000000..3400a461 --- /dev/null +++ b/vendor/plugins/sqlite3-ruby/test/test_collation.rb @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- + +require 'helper' + +module SQLite3 + class TestCollation < Test::Unit::TestCase + class Comparator + attr_reader :calls + def initialize + @calls = [] + end + + def compare left, right + @calls << [left, right] + left <=> right + end + end + + def setup + @db = SQLite3::Database.new(':memory:') + @create = "create table ex(id int, data string)" + @db.execute(@create); + [ [1, 'hello'], [2, 'world'] ].each do |vals| + @db.execute('insert into ex (id, data) VALUES (?, ?)', vals) + end + end + + def test_custom_collation + comparator = Comparator.new + + @db.collation 'foo', comparator + + assert_equal comparator, @db.collations['foo'] + @db.execute('select data from ex order by 1 collate foo') + assert_equal 1, comparator.calls.length + end + + def test_remove_collation + comparator = Comparator.new + + @db.collation 'foo', comparator + @db.collation 'foo', nil + + assert_nil @db.collations['foo'] + assert_raises(SQLite3::SQLException) do + @db.execute('select data from ex order by 1 collate foo') + end + end + + if RUBY_VERSION >= '1.9.1' + def test_encoding + comparator = Comparator.new + @db.collation 'foo', comparator + @db.execute('select data from ex order by 1 collate foo') + + a, b = *comparator.calls.first + + assert_equal Encoding.find('UTF-8'), a.encoding + assert_equal Encoding.find('UTF-8'), b.encoding + end + + def test_encoding_default_internal + warn_before = $-w + $-w = false + before_enc = Encoding.default_internal + + Encoding.default_internal = 'EUC-JP' + comparator = Comparator.new + @db.collation 'foo', comparator + @db.execute('select data from ex order by 1 collate foo') + + a, b = *comparator.calls.first + + assert_equal Encoding.find('EUC-JP'), a.encoding + assert_equal Encoding.find('EUC-JP'), b.encoding + ensure + Encoding.default_internal = before_enc + $-w = warn_before + end + end + end +end diff --git a/vendor/plugins/sqlite3-ruby/test/test_database.rb b/vendor/plugins/sqlite3-ruby/test/test_database.rb index 9c319a77..eda5147c 100644 --- a/vendor/plugins/sqlite3-ruby/test/test_database.rb +++ b/vendor/plugins/sqlite3-ruby/test/test_database.rb @@ -7,6 +7,10 @@ module SQLite3 @db = SQLite3::Database.new(':memory:') end + def test_encoding + assert @db.encoding, 'database has encoding' + end + def test_changes @db.execute("CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT, number integer)") assert_equal 0, @db.changes diff --git a/vendor/plugins/sqlite3-ruby/test/test_deprecated.rb b/vendor/plugins/sqlite3-ruby/test/test_deprecated.rb index eecef630..e1396cad 100644 --- a/vendor/plugins/sqlite3-ruby/test/test_deprecated.rb +++ b/vendor/plugins/sqlite3-ruby/test/test_deprecated.rb @@ -3,9 +3,17 @@ require 'helper' module SQLite3 class TestDeprecated < Test::Unit::TestCase def setup + super + @warn_before = $-w + $-w = false @db = SQLite3::Database.new(':memory:') end + def teardown + super + $-w = @warn_before + end + def test_query_with_many_bind_params assert_equal [[nil, 1]], @db.query("select ?, ?", nil, 1).to_a end diff --git a/vendor/plugins/sqlite3-ruby/test/test_encoding.rb b/vendor/plugins/sqlite3-ruby/test/test_encoding.rb index 9e28438c..107a0679 100644 --- a/vendor/plugins/sqlite3-ruby/test/test_encoding.rb +++ b/vendor/plugins/sqlite3-ruby/test/test_encoding.rb @@ -12,6 +12,9 @@ module SQLite3 end def test_default_internal_is_honored + warn_before = $-w + $-w = false + before_enc = Encoding.default_internal str = "壁に耳あり、障子に目あり" @@ -27,6 +30,7 @@ module SQLite3 assert_equal str, string.encode(str.encoding) ensure Encoding.default_internal = before_enc + $-w = warn_before end def test_blob_is_binary @@ -97,7 +101,7 @@ module SQLite3 def test_utf_8 str = "猫舌" - @db.execute(@insert, 10, str) + @db.execute(@insert, [10, str]) row = @db.execute("select data from ex") assert_equal @db.encoding, row.first.first.encoding assert_equal str, row.first.first @@ -105,7 +109,7 @@ module SQLite3 def test_euc_jp str = "猫舌".encode('EUC-JP') - @db.execute(@insert, 10, str) + @db.execute(@insert, [10, str]) row = @db.execute("select data from ex") assert_equal @db.encoding, row.first.first.encoding assert_equal str.encode('UTF-8'), row.first.first diff --git a/vendor/plugins/sqlite3-ruby/test/test_integration.rb b/vendor/plugins/sqlite3-ruby/test/test_integration.rb index 2721c8dd..3247e0fc 100644 --- a/vendor/plugins/sqlite3-ruby/test/test_integration.rb +++ b/vendor/plugins/sqlite3-ruby/test/test_integration.rb @@ -261,7 +261,7 @@ class TC_Database_Integration < Test::Unit::TestCase end def test_execute_batch_with_bind - @db.execute_batch( <<-SQL, 1 ) + @db.execute_batch( <<-SQL, [1] ) create table bar ( a, b, c ); insert into bar values ( 'one', 2, ? ); insert into bar values ( 'four', 5, ? ); diff --git a/vendor/plugins/sqlite3-ruby/test/test_integration_pending.rb b/vendor/plugins/sqlite3-ruby/test/test_integration_pending.rb index cb4bea68..2863899a 100644 --- a/vendor/plugins/sqlite3-ruby/test/test_integration_pending.rb +++ b/vendor/plugins/sqlite3-ruby/test/test_integration_pending.rb @@ -20,6 +20,8 @@ class TC_Integration_Pending < Test::Unit::TestCase end def test_busy_handler_outwait + skip("not working in 1.9") if RUBY_VERSION >= '1.9' + busy = Mutex.new busy.lock handler_call_count = 0 diff --git a/vendor/plugins/sqlite3-ruby/test/test_statement_execute.rb b/vendor/plugins/sqlite3-ruby/test/test_statement_execute.rb new file mode 100644 index 00000000..68da36d6 --- /dev/null +++ b/vendor/plugins/sqlite3-ruby/test/test_statement_execute.rb @@ -0,0 +1,35 @@ +require 'helper' + +module SQLite3 + class TestStatementExecute < Test::Unit::TestCase + def setup + @db = SQLite3::Database.new(':memory:') + @db.execute_batch( + "CREATE TABLE items (id integer PRIMARY KEY, number integer)") + end + + def test_execute_insert + ps = @db.prepare("INSERT INTO items (number) VALUES (:n)") + ps.execute('n'=>10) + assert_equal 1, @db.get_first_value("SELECT count(*) FROM items") + ps.close + end + + def test_execute_update + @db.execute("INSERT INTO items (number) VALUES (?)", [10]) + + ps = @db.prepare("UPDATE items SET number = :new WHERE number = :old") + ps.execute('old'=>10, 'new'=>20) + assert_equal 20, @db.get_first_value("SELECT number FROM items") + ps.close + end + + def test_execute_delete + @db.execute("INSERT INTO items (number) VALUES (?)", [20]) + ps = @db.prepare("DELETE FROM items WHERE number = :n") + ps.execute('n' => 20) + assert_equal 0, @db.get_first_value("SELECT count(*) FROM items") + ps.close + end + end +end