This repository has been archived by the owner on Apr 18, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
137 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,82 @@ | ||
require "helper" | ||
if RUBY_VERSION >= '1.9.1' | ||
require "helper" | ||
|
||
class TestDatabaseQueriesUtf16 < Test::Unit::TestCase | ||
def setup | ||
@db = SQLite3::Database.new(":memory:", :encoding => "utf-16") | ||
@db.execute("CREATE TABLE t1(id INTEGER PRIMARY KEY ASC, t TEXT, nu1 NUMERIC, i1 INTEGER, i2 INTEGER, no BLOB)") | ||
end | ||
class TestDatabaseQueriesUtf16 < Test::Unit::TestCase | ||
def setup | ||
@db = SQLite3::Database.new(":memory:", :encoding => "utf-16") | ||
@db.execute("CREATE TABLE t1(id INTEGER PRIMARY KEY ASC, t TEXT, nu1 NUMERIC, i1 INTEGER, i2 INTEGER, no BLOB)") | ||
end | ||
|
||
def teardown | ||
@db.close | ||
end | ||
def teardown | ||
@db.close | ||
end | ||
|
||
def test_tables_empty | ||
assert_equal [], @db.execute("SELECT * FROM t1") | ||
end | ||
def test_tables_empty | ||
assert_equal [], @db.execute("SELECT * FROM t1") | ||
end | ||
|
||
def test_execute | ||
@db.execute("INSERT INTO t1 VALUES(NULL, 'text1', 1.22, 42, 4294967296, NULL)") | ||
rows = @db.execute("SELECT * FROM t1") | ||
assert_equal 1, rows.size | ||
row = rows[0] | ||
assert_equal "text1".encode(Encoding::UTF_16LE), row[1] | ||
assert_equal Encoding::UTF_16LE, row[1].encoding | ||
assert_equal 1.22, row[2] | ||
assert_equal 42, row[3] | ||
assert_equal 4294967296, row[4] | ||
assert_nil row[5] | ||
end | ||
def test_execute | ||
@db.execute("INSERT INTO t1 VALUES(NULL, 'text1', 1.22, 42, 4294967296, NULL)") | ||
rows = @db.execute("SELECT * FROM t1") | ||
assert_equal 1, rows.size | ||
row = rows[0] | ||
assert_equal "text1".encode(Encoding::UTF_16LE), row[1] | ||
assert_equal Encoding::UTF_16LE, row[1].encoding | ||
assert_equal 1.22, row[2] | ||
assert_equal 42, row[3] | ||
assert_equal 4294967296, row[4] | ||
assert_nil row[5] | ||
end | ||
|
||
def test_execute_with_bindings | ||
blob = open("test/fixtures/SQLite.gif", "rb").read | ||
@db.execute("INSERT INTO t1 VALUES(?, ?, ?, ?, ?, ?)", nil, "text1", 1.22, 42, 4294967296, blob) | ||
rows = @db.execute("SELECT * FROM t1") | ||
assert_equal 1, rows.size | ||
row = rows[0] | ||
assert_equal "text1".encode(Encoding::UTF_16LE), row[1] | ||
assert_equal Encoding::UTF_16LE, row[1].encoding | ||
assert_equal 1.22, row[2] | ||
assert_equal 42, row[3] | ||
assert_equal 4294967296, row[4] | ||
assert_equal blob, row[5] | ||
assert_equal Encoding::ASCII_8BIT, row[5].encoding | ||
end | ||
def test_execute_with_bindings | ||
blob = open("test/fixtures/SQLite.gif", "rb").read | ||
@db.execute("INSERT INTO t1 VALUES(?, ?, ?, ?, ?, ?)", nil, "text1", 1.22, 42, 4294967296, blob) | ||
rows = @db.execute("SELECT * FROM t1") | ||
assert_equal 1, rows.size | ||
row = rows[0] | ||
assert_equal "text1".encode(Encoding::UTF_16LE), row[1] | ||
assert_equal Encoding::UTF_16LE, row[1].encoding | ||
assert_equal 1.22, row[2] | ||
assert_equal 42, row[3] | ||
assert_equal 4294967296, row[4] | ||
assert_equal blob, row[5] | ||
assert_equal Encoding::ASCII_8BIT, row[5].encoding | ||
end | ||
|
||
def test_execute_with_different_encodings | ||
expected_string = "text1" | ||
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::ASCII_8BIT)) | ||
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_8)) | ||
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_16LE)) | ||
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_16BE)) | ||
rows = @db.execute("SELECT * FROM t1") | ||
assert_equal 4, rows.size | ||
assert_equal expected_string, rows[0][1] | ||
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[1][1] | ||
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[2][1] | ||
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[3][1] | ||
assert_equal Encoding::ASCII_8BIT, rows[0][1].encoding | ||
assert_equal Encoding::UTF_16LE, rows[1][1].encoding | ||
assert_equal Encoding::UTF_16LE, rows[2][1].encoding | ||
assert_equal Encoding::UTF_16LE, rows[3][1].encoding | ||
end | ||
def test_execute_with_different_encodings | ||
expected_string = "text1" | ||
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::ASCII_8BIT)) | ||
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_8)) | ||
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_16LE)) | ||
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_16BE)) | ||
rows = @db.execute("SELECT * FROM t1") | ||
assert_equal 4, rows.size | ||
assert_equal expected_string, rows[0][1] | ||
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[1][1] | ||
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[2][1] | ||
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[3][1] | ||
assert_equal Encoding::ASCII_8BIT, rows[0][1].encoding | ||
assert_equal Encoding::UTF_16LE, rows[1][1].encoding | ||
assert_equal Encoding::UTF_16LE, rows[2][1].encoding | ||
assert_equal Encoding::UTF_16LE, rows[3][1].encoding | ||
end | ||
|
||
def test_execute_with_bad_query | ||
assert_raise(SQLite3::SQLException) { @db.execute("bad query") } | ||
assert_equal %Q{near "bad": syntax error}, @db.errmsg | ||
assert_equal 1, @db.errcode | ||
end | ||
def test_execute_with_bad_query | ||
assert_raise(SQLite3::SQLException) { @db.execute("bad query") } | ||
assert_equal %Q{near "bad": syntax error}, @db.errmsg | ||
assert_equal 1, @db.errcode | ||
end | ||
|
||
def test_last_insert_row_id | ||
@db.execute("INSERT INTO t1 VALUES(NULL, NULL, NULL, NULL, NULL, NULL)") | ||
id = @db.last_insert_row_id | ||
rows = @db.execute("SELECT * FROM t1 WHERE id = #{id}") | ||
assert_equal 1, rows.size | ||
end | ||
def test_last_insert_row_id | ||
@db.execute("INSERT INTO t1 VALUES(NULL, NULL, NULL, NULL, NULL, NULL)") | ||
id = @db.last_insert_row_id | ||
rows = @db.execute("SELECT * FROM t1 WHERE id = #{id}") | ||
assert_equal 1, rows.size | ||
end | ||
|
||
# def test_execute_with_closed_database | ||
# @db.close | ||
# @db.execute("SELECT * FROM t1") | ||
# end | ||
end | ||
# def test_execute_with_closed_database | ||
# @db.close | ||
# @db.execute("SELECT * FROM t1") | ||
# end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters