File: handle-big-endian.diff

package info (click to toggle)
ruby-sqlite3 1.3.9-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 468 kB
  • ctags: 769
  • sloc: ruby: 3,824; ansic: 1,198; makefile: 10
file content (49 lines) | stat: -rw-r--r-- 1,860 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Description: handle big endian architectures
Author: David Suárez <david.sephirot@gmail.com>
Reviewed-By: Antonio Terceiro <terceiro@debian.org>
Bug-Debian: http://bugs.debian.org/745929

--- a/ext/sqlite3/statement.c
+++ b/ext/sqlite3/statement.c
@@ -240,7 +240,7 @@ static VALUE bind_param(VALUE self, VALU
 
 
 #ifdef HAVE_RUBY_ENCODING_H
-        if (UTF16_LE_P(value)) {
+        if (UTF16_LE_P(value) || UTF16_BE_P(value)) {
           status = sqlite3_bind_text16(
               ctx->st,
               index,
--- a/test/test_encoding.rb
+++ b/test/test_encoding.rb
@@ -13,12 +13,13 @@ module SQLite3
 
     def test_select_encoding_on_utf_16
       str = "foo"
-      db = SQLite3::Database.new(':memory:'.encode('UTF-16LE'))
+      utf16 = ([1].pack("I") == [1].pack("N")) ? "UTF-16BE" : "UTF-16LE"
+      db = SQLite3::Database.new(':memory:'.encode(utf16))
       db.execute @create
       db.execute "insert into ex (id, data) values (1, \"#{str}\")"
 
       stmt = db.prepare 'select * from ex where data = ?'
-      ['US-ASCII', 'UTF-16LE', 'EUC-JP', 'UTF-8'].each do |enc|
+      ['US-ASCII', utf16, 'EUC-JP', 'UTF-8'].each do |enc|
         stmt.bind_param 1, str.encode(enc)
         assert_equal 1, stmt.to_a.length
         stmt.reset!
@@ -27,11 +28,12 @@ module SQLite3
 
     def test_insert_encoding
       str = "foo"
-      db = SQLite3::Database.new(':memory:'.encode('UTF-16LE'))
+      utf16 = ([1].pack("I") == [1].pack("N")) ? "UTF-16BE" : "UTF-16LE"
+      db = SQLite3::Database.new(':memory:'.encode(utf16))
       db.execute @create
       stmt = db.prepare @insert
 
-      ['US-ASCII', 'UTF-16LE', 'UTF-16BE', 'EUC-JP', 'UTF-8'].each_with_index do |enc,i|
+      ['US-ASCII', utf16, 'EUC-JP', 'UTF-8'].each_with_index do |enc,i|
         stmt.bind_param 1, i
         stmt.bind_param 2, str.encode(enc)
         stmt.to_a