sqlite3-full 1.3.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/API_CHANGES.rdoc +50 -0
  4. data/CHANGELOG.rdoc +278 -0
  5. data/ChangeLog.cvs +88 -0
  6. data/Gemfile +15 -0
  7. data/LICENSE +34 -0
  8. data/Manifest.txt +52 -0
  9. data/README.rdoc +90 -0
  10. data/Rakefile +10 -0
  11. data/ext/sqlite3/backup.c +168 -0
  12. data/ext/sqlite3/backup.h +15 -0
  13. data/ext/sqlite3/database.c +825 -0
  14. data/ext/sqlite3/database.h +15 -0
  15. data/ext/sqlite3/exception.c +94 -0
  16. data/ext/sqlite3/exception.h +8 -0
  17. data/ext/sqlite3/extconf.rb +86 -0
  18. data/ext/sqlite3/sqlite3.c +97 -0
  19. data/ext/sqlite3/sqlite3_ruby.h +52 -0
  20. data/ext/sqlite3/sqlite3amalgamation.c +153367 -0
  21. data/ext/sqlite3/statement.c +447 -0
  22. data/ext/sqlite3/statement.h +16 -0
  23. data/faq/faq.rb +145 -0
  24. data/faq/faq.yml +426 -0
  25. data/lib/sqlite3/constants.rb +49 -0
  26. data/lib/sqlite3/database.rb +590 -0
  27. data/lib/sqlite3/errors.rb +44 -0
  28. data/lib/sqlite3/pragmas.rb +280 -0
  29. data/lib/sqlite3/resultset.rb +195 -0
  30. data/lib/sqlite3/statement.rb +144 -0
  31. data/lib/sqlite3/translator.rb +118 -0
  32. data/lib/sqlite3/value.rb +57 -0
  33. data/lib/sqlite3/version.rb +25 -0
  34. data/lib/sqlite3.rb +10 -0
  35. data/setup.rb +1333 -0
  36. data/tasks/faq.rake +9 -0
  37. data/tasks/gem.rake +38 -0
  38. data/tasks/native.rake +52 -0
  39. data/tasks/vendor_sqlite3.rake +91 -0
  40. data/test/helper.rb +18 -0
  41. data/test/test_backup.rb +33 -0
  42. data/test/test_collation.rb +82 -0
  43. data/test/test_database.rb +367 -0
  44. data/test/test_database_readonly.rb +29 -0
  45. data/test/test_deprecated.rb +44 -0
  46. data/test/test_encoding.rb +153 -0
  47. data/test/test_integration.rb +572 -0
  48. data/test/test_integration_open_close.rb +30 -0
  49. data/test/test_integration_pending.rb +115 -0
  50. data/test/test_integration_resultset.rb +159 -0
  51. data/test/test_integration_statement.rb +194 -0
  52. data/test/test_result_set.rb +37 -0
  53. data/test/test_sqlite3.rb +9 -0
  54. data/test/test_statement.rb +260 -0
  55. data/test/test_statement_execute.rb +35 -0
  56. metadata +205 -0
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+
3
+ module SQLite3
4
+ class TestDatabaseReadonly < SQLite3::TestCase
5
+ def setup
6
+ File.unlink 'test-readonly.db' if File.exists?('test-readonly.db')
7
+ @db = SQLite3::Database.new('test-readonly.db')
8
+ @db.execute("CREATE TABLE foos (id integer)")
9
+ @db.close
10
+ end
11
+
12
+ def teardown
13
+ @db.close unless @db.closed?
14
+ File.unlink 'test-readonly.db'
15
+ end
16
+
17
+ def test_open_readonly_database
18
+ @db = SQLite3::Database.new('test-readonly.db', :readonly => true)
19
+ assert @db.readonly?
20
+ end
21
+
22
+ def test_insert_readonly_database
23
+ @db = SQLite3::Database.new('test-readonly.db', :readonly => true)
24
+ assert_raise(SQLite3::ReadOnlyException) do
25
+ @db.execute("INSERT INTO foos (id) VALUES (12)")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ require 'helper'
2
+
3
+ module SQLite3
4
+ class TestDeprecated < SQLite3::TestCase
5
+ attr_reader :db
6
+
7
+ def setup
8
+ super
9
+ @warn_before = $-w
10
+ $-w = false
11
+ @db = SQLite3::Database.new(':memory:')
12
+ @db.execute 'CREATE TABLE test_table (name text, age int)'
13
+ end
14
+
15
+ def teardown
16
+ super
17
+ $-w = @warn_before
18
+ end
19
+
20
+ def test_query_with_many_bind_params_not_nil
21
+ assert_equal [[1, 2]], db.query('select ?, ?', 1, 2).to_a
22
+ end
23
+
24
+ def test_execute_with_many_bind_params_not_nil
25
+ assert_equal [[1, 2]], @db.execute("select ?, ?", 1, 2).to_a
26
+ end
27
+
28
+ def test_query_with_many_bind_params
29
+ assert_equal [[nil, 1]], @db.query("select ?, ?", nil, 1).to_a
30
+ end
31
+
32
+ def test_query_with_nil_bind_params
33
+ assert_equal [['foo']], @db.query("select 'foo'", nil).to_a
34
+ end
35
+
36
+ def test_execute_with_many_bind_params
37
+ assert_equal [[nil, 1]], @db.execute("select ?, ?", nil, 1)
38
+ end
39
+
40
+ def test_execute_with_nil_bind_params
41
+ assert_equal [['foo']], @db.execute("select 'foo'", nil)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,153 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'helper'
4
+
5
+ module SQLite3
6
+ class TestEncoding < SQLite3::TestCase
7
+ def setup
8
+ @db = SQLite3::Database.new(':memory:')
9
+ @create = "create table ex(id int, data string)"
10
+ @insert = "insert into ex(id, data) values (?, ?)"
11
+ @db.execute(@create);
12
+ end
13
+
14
+ def test_select_encoding_on_utf_16
15
+ str = "foo"
16
+ db = SQLite3::Database.new(':memory:'.encode('UTF-16LE'))
17
+ db.execute @create
18
+ db.execute "insert into ex (id, data) values (1, \"#{str}\")"
19
+
20
+ stmt = db.prepare 'select * from ex where data = ?'
21
+ ['US-ASCII', 'UTF-16LE', 'EUC-JP', 'UTF-8'].each do |enc|
22
+ stmt.bind_param 1, str.encode(enc)
23
+ assert_equal 1, stmt.to_a.length
24
+ stmt.reset!
25
+ end
26
+ end
27
+
28
+ def test_insert_encoding
29
+ str = "foo"
30
+ db = SQLite3::Database.new(':memory:'.encode('UTF-16LE'))
31
+ db.execute @create
32
+ stmt = db.prepare @insert
33
+
34
+ ['US-ASCII', 'UTF-16LE', 'UTF-16BE', 'EUC-JP', 'UTF-8'].each_with_index do |enc,i|
35
+ stmt.bind_param 1, i
36
+ stmt.bind_param 2, str.encode(enc)
37
+ stmt.to_a
38
+ stmt.reset!
39
+ end
40
+
41
+ db.execute('select data from ex').flatten.each do |s|
42
+ assert_equal str, s
43
+ end
44
+ end
45
+
46
+ def test_default_internal_is_honored
47
+ warn_before = $-w
48
+ $-w = false
49
+
50
+ before_enc = Encoding.default_internal
51
+
52
+ str = "壁に耳あり、障子に目あり"
53
+ stmt = @db.prepare('insert into ex(data) values (?)')
54
+ stmt.bind_param 1, str
55
+ stmt.step
56
+
57
+ Encoding.default_internal = 'EUC-JP'
58
+ string = @db.execute('select data from ex').first.first
59
+
60
+ assert_equal Encoding.default_internal, string.encoding
61
+ assert_equal str.encode('EUC-JP'), string
62
+ assert_equal str, string.encode(str.encoding)
63
+ ensure
64
+ Encoding.default_internal = before_enc
65
+ $-w = warn_before
66
+ end
67
+
68
+ def test_blob_is_binary
69
+ str = "猫舌"
70
+ @db.execute('create table foo(data text)')
71
+ stmt = @db.prepare('insert into foo(data) values (?)')
72
+ stmt.bind_param(1, SQLite3::Blob.new(str))
73
+ stmt.step
74
+
75
+ string = @db.execute('select data from foo').first.first
76
+ assert_equal Encoding.find('ASCII-8BIT'), string.encoding
77
+ assert_equal str, string.force_encoding('UTF-8')
78
+ end
79
+
80
+ def test_blob_is_ascii8bit
81
+ str = "猫舌"
82
+ @db.execute('create table foo(data text)')
83
+ stmt = @db.prepare('insert into foo(data) values (?)')
84
+ stmt.bind_param(1, str.dup.force_encoding("ASCII-8BIT"))
85
+ stmt.step
86
+
87
+ string = @db.execute('select data from foo').first.first
88
+ assert_equal Encoding.find('ASCII-8BIT'), string.encoding
89
+ assert_equal str, string.force_encoding('UTF-8')
90
+ end
91
+
92
+ def test_blob_with_eucjp
93
+ str = "猫舌".encode("EUC-JP")
94
+ @db.execute('create table foo(data text)')
95
+ stmt = @db.prepare('insert into foo(data) values (?)')
96
+ stmt.bind_param(1, SQLite3::Blob.new(str))
97
+ stmt.step
98
+
99
+ string = @db.execute('select data from foo').first.first
100
+ assert_equal Encoding.find('ASCII-8BIT'), string.encoding
101
+ assert_equal str, string.force_encoding('EUC-JP')
102
+ end
103
+
104
+ def test_db_with_eucjp
105
+ db = SQLite3::Database.new(':memory:'.encode('EUC-JP'))
106
+ assert_equal(Encoding.find('UTF-8'), db.encoding)
107
+ end
108
+
109
+ def test_db_with_utf16
110
+ utf16 = ([1].pack("I") == [1].pack("N")) ? "UTF-16BE" : "UTF-16LE"
111
+
112
+ db = SQLite3::Database.new(':memory:'.encode(utf16))
113
+ assert_equal(Encoding.find(utf16), db.encoding)
114
+ end
115
+
116
+ def test_statement_eucjp
117
+ str = "猫舌"
118
+ @db.execute("insert into ex(data) values ('#{str}')".encode('EUC-JP'))
119
+ row = @db.execute("select data from ex")
120
+ assert_equal @db.encoding, row.first.first.encoding
121
+ assert_equal str, row.first.first
122
+ end
123
+
124
+ def test_statement_utf8
125
+ str = "猫舌"
126
+ @db.execute("insert into ex(data) values ('#{str}')")
127
+ row = @db.execute("select data from ex")
128
+ assert_equal @db.encoding, row.first.first.encoding
129
+ assert_equal str, row.first.first
130
+ end
131
+
132
+ def test_encoding
133
+ assert_equal Encoding.find("UTF-8"), @db.encoding
134
+ end
135
+
136
+ def test_utf_8
137
+ str = "猫舌"
138
+ @db.execute(@insert, [10, str])
139
+ row = @db.execute("select data from ex")
140
+ assert_equal @db.encoding, row.first.first.encoding
141
+ assert_equal str, row.first.first
142
+ end
143
+
144
+ def test_euc_jp
145
+ str = "猫舌".encode('EUC-JP')
146
+ @db.execute(@insert, [10, str])
147
+ row = @db.execute("select data from ex")
148
+ assert_equal @db.encoding, row.first.first.encoding
149
+ assert_equal str.encode('UTF-8'), row.first.first
150
+ end
151
+
152
+ end if RUBY_VERSION >= '1.9.1'
153
+ end