Sqlite3-ruby 1.3.1, itextomml 1.3.26

Update vendored sqlite3-ruby and tests
for latest itextmml.
This commit is contained in:
Jacques Distler 2010-07-20 20:36:17 -05:00
parent 29224d6bcc
commit b3aae9b06d
16 changed files with 257 additions and 9 deletions

View file

@ -226,6 +226,13 @@ END_THM
def test_have_latest_itex2mml
assert_markup_parsed_as(
%{<p>equation <math class='maruku-mathml' displa} +
%{y='inline' xmlns='http://www.w3.org/1998/Math/} +
%{MathML'><mi>A</mi><mo>\342\253\275</mo><mi>B</} +
%{mi></math></p>},
"equation $A\\sslash B$")
assert_markup_parsed_as(
%{<p>boxed equation <math class='maruku-mathml' } +
%{display='inline' xmlns='http://www.w3.org/1998} +

View file

@ -1,3 +1,12 @@
=== 1.3.1 / 2010-07-09
* Enhancements
* Custom collations may be defined using SQLite3::Database#collation
* Bugfixes
* Statements returning 0 columns are automatically stepped. [RF #28308]
* SQLite3::Database#encoding works on 1.8 and 1.9
=== 1.3.0 / 2010-06-06
* Enhancements
@ -6,7 +15,7 @@
This closes: Bug #27300, Bug #27241, Patch #16020
* Improved UTF, Unicode, M17N, all that handling and proper BLOB handling [tenderlove, nurse]
* Added support for type translations [tenderlove]
@db.translator.add_translator('sometime') do |type, thing|
'output' # this will be returned as value for that column
end

View file

@ -32,6 +32,7 @@ tasks/gem.rake
tasks/native.rake
tasks/vendor_sqlite3.rake
test/helper.rb
test/test_collation.rb
test/test_database.rb
test/test_deprecated.rb
test/test_encoding.rb
@ -42,3 +43,4 @@ test/test_integration_resultset.rb
test/test_integration_statement.rb
test/test_sqlite3.rb
test/test_statement.rb
test/test_statement_execute.rb

View file

@ -3,6 +3,7 @@
* http://github.com/luislavena/sqlite3-ruby
* http://rubyforge.org/projects/sqlite-ruby
* http://sqlite-ruby.rubyforge.org
* http://groups.google.com/group/sqlite3-ruby
== DESCRIPTION
@ -33,6 +34,25 @@ If you have sqlite3 installed in a non-standard location, you can specify the lo
gem install sqlite3-ruby -- --with-sqlite3-include=/opt/local/include \
--with-sqlite3-lib=/opt/local/lib
= SUPPORT!!!
== OMG! Something has gone wrong! Where do I get help?
The best place to get help is from the
{sqlite3-ruby mailing list}[http://groups.google.com/group/sqlite3-ruby] which
can be found here:
* http://groups.google.com/group/sqlite3-ruby
== I've found a bug! Where do I file it?
Uh oh. After contacting the mailing list, you've found that you've actually
discovered a bug. You can file the bug at the
{github issues page}[http://github.com/luislavena/sqlite3-ruby/issues]
which can be found here:
* http://github.com/luislavena/sqlite3-ruby/issues
== Usage
For help figuring out the SQLite3/Ruby interface, check out the

View file

@ -91,6 +91,7 @@ static VALUE initialize(int argc, VALUE *argv, VALUE self)
rb_iv_set(self, "@authorizer", Qnil);
rb_iv_set(self, "@encoding", Qnil);
rb_iv_set(self, "@busy_handler", Qnil);
rb_iv_set(self, "@collations", rb_hash_new());
rb_iv_set(self, "@results_as_hash", rb_hash_aref(opts, sym_results_as_hash));
rb_iv_set(self, "@type_translation", rb_hash_aref(opts, sym_type_translation));
@ -571,6 +572,64 @@ static VALUE set_busy_timeout(VALUE self, VALUE timeout)
return self;
}
int rb_comparator_func(void * ctx, int a_len, const void * a, int b_len, const void * b)
{
VALUE comparator;
VALUE a_str;
VALUE b_str;
VALUE comparison;
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding * internal_encoding;
internal_encoding = rb_default_internal_encoding();
#endif
comparator = (VALUE)ctx;
a_str = rb_str_new((const char *)a, a_len);
b_str = rb_str_new((const char *)b, b_len);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(a_str, rb_utf8_encindex());
rb_enc_associate_index(b_str, rb_utf8_encindex());
if(internal_encoding) {
a_str = rb_str_export_to_enc(a_str, internal_encoding);
b_str = rb_str_export_to_enc(b_str, internal_encoding);
}
#endif
comparison = rb_funcall(comparator, rb_intern("compare"), 2, a_str, b_str);
return NUM2INT(comparison);
}
/* call-seq: db.collation(name, comparator)
*
* Add a collation with name +name+, and a +comparator+ object. The
* +comparator+ object should implement a method called "compare" that takes
* two parameters and returns an integer less than, equal to, or greater than
* 0.
*/
static VALUE collation(VALUE self, VALUE name, VALUE comparator)
{
sqlite3RubyPtr ctx;
Data_Get_Struct(self, sqlite3Ruby, ctx);
REQUIRE_OPEN_DB(ctx);
CHECK(ctx->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);

View file

@ -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')

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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, ? );

View file

@ -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

View file

@ -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