do_sqlite3 0.9.11-x86-mswin32-60 → 0.9.12-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/LICENSE +1 -1
  2. data/Manifest.txt +15 -4
  3. data/Rakefile +7 -207
  4. data/ext/do_sqlite3_ext/do_sqlite3_ext.c +187 -71
  5. data/ext/do_sqlite3_ext/extconf.rb +2 -0
  6. data/lib/do_sqlite3/version.rb +1 -1
  7. data/lib/do_sqlite3_ext.so +0 -0
  8. data/spec/command_spec.rb +8 -0
  9. data/spec/connection_spec.rb +18 -0
  10. data/spec/lib/rspec_immediate_feedback_formatter.rb +3 -0
  11. data/spec/reader_spec.rb +8 -0
  12. data/spec/result_spec.rb +9 -0
  13. data/spec/spec_helper.rb +88 -17
  14. data/spec/typecast/array_spec.rb +8 -0
  15. data/spec/typecast/bigdecimal_spec.rb +8 -0
  16. data/spec/typecast/boolean_spec.rb +8 -0
  17. data/spec/typecast/byte_array_spec.rb +9 -0
  18. data/spec/typecast/class_spec.rb +8 -0
  19. data/spec/typecast/date_spec.rb +8 -0
  20. data/spec/typecast/datetime_spec.rb +8 -0
  21. data/spec/typecast/float_spec.rb +8 -0
  22. data/spec/typecast/integer_spec.rb +8 -0
  23. data/spec/typecast/nil_spec.rb +10 -0
  24. data/spec/typecast/range_spec.rb +8 -0
  25. data/spec/typecast/string_spec.rb +8 -0
  26. data/spec/typecast/time_spec.rb +8 -0
  27. data/tasks/gem.rake +61 -0
  28. data/tasks/install.rake +15 -0
  29. data/tasks/native.rake +35 -0
  30. data/tasks/release.rake +75 -0
  31. data/tasks/retrieve.rake +104 -0
  32. data/tasks/spec.rake +18 -0
  33. metadata +73 -41
  34. data/.gitignore +0 -3
  35. data/buildfile +0 -27
  36. data/ext-java/src/main/java/DoSqlite3ExtService.java +0 -23
  37. data/ext-java/src/main/java/do_sqlite3/Sqlite3DriverDefinition.java +0 -26
  38. data/spec/integration/do_sqlite3_spec.rb +0 -278
  39. data/spec/integration/logging_spec.rb +0 -53
  40. data/spec/integration/quoting_spec.rb +0 -23
  41. data/spec/spec.opts +0 -2
  42. data/spec/unit/transaction_spec.rb +0 -34
@@ -1,278 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- describe "DataObjects::Sqlite3" do
5
- include Sqlite3SpecHelpers
6
-
7
- it "should raise error on bad connection string" do
8
- pending
9
- # lambda { DataObjects::Connection.new("sqlite3:///ac0d9iopalmsdcasd/asdc9pomasd/test.db") }.should raise_error("unable to open database file")
10
- end
11
-
12
- if JRUBY
13
- it "should accept either DO or JDBC style URLs on JRuby" do
14
- pending
15
- @connection = DataObjects::Connection.new("jdbc:sqlite:test.db") # note the sqlite not sqlite3!
16
- @connection = DataObjects::Connection.new("sqlite3://#{File.expand_path(File.dirname(__FILE__))}/test.db")
17
- end
18
- end
19
-
20
- end
21
-
22
- NOW = DateTime.now
23
-
24
- describe "DataObjects::Sqlite3::Result" do
25
- include Sqlite3SpecHelpers
26
-
27
- before(:all) do
28
- @connection = DataObjects::Connection.new("sqlite3://#{File.expand_path(File.dirname(__FILE__))}/test.db")
29
- end
30
-
31
- before do
32
- class ::Person; end
33
- end
34
-
35
- after :all do
36
- @connection.close
37
- end
38
-
39
- after do
40
- Object.send(:remove_const, :Person)
41
- end
42
-
43
- it "should raise an error for a bad query" do
44
- command = @connection.create_command("INSER INTO table_which_doesnt_exist (id) VALUES (1)")
45
- lambda { command.execute_non_query }.should raise_error(Sqlite3Error, /near "INSER": syntax error/)
46
-
47
- command = @connection.create_command("INSERT INTO table_which_doesnt_exist (id) VALUES (1)")
48
- lambda { command.execute_non_query }.should raise_error(Sqlite3Error, /no such table: table_which_doesnt_exist/)
49
-
50
- command = @connection.create_command("SELECT * FROM table_which_doesnt_exist")
51
- lambda { command.execute_reader }.should raise_error(Sqlite3Error, /no such table: table_which_doesnt_exist/)
52
- end
53
-
54
- it "should return the affected rows and insert_id" do
55
- command = @connection.create_command("DROP TABLE users")
56
- command.execute_non_query rescue nil
57
- command = @connection.create_command("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, type TEXT, age INTEGER, created_at DATETIME, balance DECIMAL default '0.00')")
58
- result = command.execute_non_query
59
- command = @connection.create_command("INSERT INTO users (name) VALUES ('test')")
60
- result = command.execute_non_query
61
- result.insert_id.should == 1
62
- result.to_i.should == 1
63
- end
64
-
65
- it "should do a reader query" do
66
- command = @connection.create_command("SELECT * FROM users")
67
- reader = command.execute_reader
68
-
69
- lambda { reader.values }.should raise_error(Sqlite3Error, /Reader is not initialized/)
70
-
71
- while ( reader.next! )
72
- lambda { reader.values }.should_not raise_error
73
- reader.values.should be_a_kind_of(Array)
74
- end
75
-
76
- lambda { reader.values }.should raise_error(Sqlite3Error, /Reader is not initialized/)
77
-
78
- reader.close
79
- end
80
-
81
- it "should do a parameterized reader query" do
82
- command = @connection.create_command("SELECT * FROM users WHERE id = ?")
83
- reader = command.execute_reader(1)
84
- reader.next!
85
-
86
- reader.values[0].should == 1
87
-
88
- reader.next!
89
-
90
- lambda { reader.values }.should raise_error(Sqlite3Error, /Reader is not initialized/)
91
-
92
- reader.close
93
- end
94
-
95
- it "should do a custom typecast reader" do
96
- command = @connection.create_command("SELECT name, id FROM users")
97
- command.set_types [String, String]
98
- reader = command.execute_reader
99
-
100
- while ( reader.next! )
101
- reader.fields.should == ["name", "id"]
102
- reader.values.each { |v| v.should be_a_kind_of(String) }
103
- end
104
-
105
- reader.close
106
-
107
- end
108
-
109
- it "should handle a null value" do
110
- id = insert("INSERT INTO users (name) VALUES (NULL)")
111
- select("SELECT name from users WHERE name is null") do |reader|
112
- reader.values[0].should == nil
113
- end
114
- end
115
-
116
- it "should not convert empty strings to null" do
117
- id = insert("INSERT INTO users (name) VALUES ('')")
118
- select("SELECT name FROM users WHERE id = ?", [String], id) do |reader|
119
- reader.values.first.should == ''
120
- end
121
- end
122
-
123
- it "should raise an error when you pass too many or too few types for the expected result set" do
124
- lambda { select("SELECT name, id FROM users", [String, Integer, String]) }.should raise_error(Sqlite3Error, /Field-count mismatch. Expected 3 fields, but the query yielded 2/)
125
- end
126
-
127
- it "should do a custom typecast reader with Class" do
128
- id = insert("INSERT INTO users (name, age, type) VALUES (?, ?, ?)", 'Sam', 30, Person)
129
-
130
- select("SELECT name, age, type FROM users WHERE id = ?", [String, Integer, Class], id) do |reader|
131
- reader.fields.should == ["name", "age", "type"]
132
- reader.values.should == ["Sam", 30, Person]
133
- end
134
-
135
- exec("DELETE FROM users WHERE id = ?", id)
136
- end
137
-
138
- [
139
- NOW.strftime('%Y-%m-%dT%H:%M:%S'),
140
- NOW.strftime('%Y-%m-%d %H:%M:%S')
141
- ].each do |raw_value|
142
- it "should return #{NOW.to_s} using the LOCAL timezone when typecasting '#{raw_value}'" do
143
-
144
- # Insert a timezone-less DateTime into the DB
145
- id = insert("INSERT INTO users (name, age, type, created_at) VALUES (?, ?, ?, ?)", 'Sam', 30, Person, raw_value)
146
-
147
- select("SELECT created_at FROM users WHERE id = ?", [DateTime], id) do |reader|
148
- reader.values.last.to_s.should == NOW.to_s
149
- end
150
-
151
- exec("DELETE FROM users WHERE id = ?", id)
152
- end
153
- end
154
-
155
- it "should not blow up when an empty string for a timestamp is used" do
156
- id = insert("INSERT INTO users (name, age, type, created_at) VALUES (?, ?, ?, ?)", 'Sam', 30, Person, "")
157
-
158
- select("SELECT created_at FROM users WHERE id = ?", [DateTime], id) do |reader|
159
- reader.values.last.should == nil
160
- end
161
- end
162
-
163
- it "should return DateTimes using the same timezone that was used to insert it" do
164
- pending "improved support for timezone checking"
165
-
166
- dates = [
167
- NOW,
168
- NOW.new_offset( (-11 * 3600).to_r / 86400), # GMT -11:00
169
- NOW.new_offset( (-9 * 3600 + 10 * 60).to_r / 86400), # GMT -9:10
170
- NOW.new_offset( (-8 * 3600).to_r / 86400), # GMT -08:00
171
- NOW.new_offset( (+3 * 3600).to_r / 86400), # GMT +03:00
172
- NOW.new_offset( (+5 * 3600 + 30 * 60).to_r / 86400) # GMT +05:30 (New Delhi)
173
- ]
174
-
175
- dates.each do |date|
176
- id = insert("INSERT INTO users (name, age, type, created_at) VALUES (?, ?, ?, ?)", 'Sam', 30, Person, date)
177
-
178
- select("SELECT created_at FROM users WHERE id = ?", [DateTime], id) do |reader|
179
- reader.values.last.year.should == date.year
180
- reader.values.last.month.should == date.month
181
- reader.values.last.day.should == date.day
182
- reader.values.last.hour.should == date.hour
183
- reader.values.last.min.should == date.min
184
- reader.values.last.sec.should == date.sec
185
- reader.values.last.zone.should == date.zone
186
- end
187
-
188
- exec("DELETE FROM users WHERE id = ?", id)
189
- end
190
- end
191
-
192
- it "should return a BigDecimal" do
193
- pending "We need to introduce something like Proxy for typeasting where each SQL type will have _rules_ of casting" if JRUBY
194
- balance = BigDecimal.new('10000000000.00')
195
-
196
- #looks like inserting BigDecimals is not implemented in SQLITE's jdbc driver http://zentus.com/sqlitejdbc/src/src/org/sqlite/Unused.java
197
- id = insert("INSERT INTO users (name, age, type, created_at, balance) VALUES (?, ?, ?, ?, ?)", 'Scott', 27, Person, DateTime.now, balance)
198
-
199
- select("SELECT balance FROM users WHERE id = ?", [BigDecimal], id) do |reader|
200
- reader.values.last.should == balance
201
- end
202
- end
203
-
204
- unless JRUBY
205
-
206
- describe "quoting" do
207
-
208
- before do
209
- @connection.create_command("DROP TABLE IF EXISTS sail_boats").execute_non_query
210
- @connection.create_command("CREATE TABLE sail_boats ( id INTEGER PRIMARY KEY, name VARCHAR(50), port VARCHAR(50), notes VARCHAR(50), vintage BOOLEAN )").execute_non_query
211
- command = @connection.create_command("INSERT INTO sail_boats (id, name, port, name, vintage) VALUES (?, ?, ?, ?, ?)")
212
- command.execute_non_query(1, "A", "C", "Fortune Pig!", false)
213
- command.execute_non_query(2, "B", "B", "Happy Cow!", true)
214
- command.execute_non_query(3, "C", "A", "Spoon", true)
215
- end
216
-
217
- after do
218
- @connection.create_command("DROP TABLE sail_boats").execute_non_query
219
- end
220
-
221
- it "should quote a String" do
222
- command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
223
- result = command.execute_non_query("John Doe")
224
- result.to_i.should == 1
225
- end
226
-
227
- it "should quote multiple values" do
228
- command = @connection.create_command("INSERT INTO users (name, age) VALUES (?, ?)")
229
- result = command.execute_non_query("Sam Smoot", 1)
230
- result.to_i.should == 1
231
- end
232
-
233
-
234
- it "should handle boolean columns gracefully" do
235
- command = @connection.create_command("INSERT INTO sail_boats (id, name, port, name, vintage) VALUES (?, ?, ?, ?, ?)")
236
- result = command.execute_non_query(4, "Scooner", "Port au Prince", "This is one gangster boat!", true)
237
- result.to_i.should == 1
238
- end
239
-
240
- it "should quote an Array" do
241
- command = @connection.create_command("SELECT id, notes FROM sail_boats WHERE (id IN ?)")
242
- reader = command.execute_reader([1, 2, 3])
243
-
244
- i = 1
245
- while(reader.next!)
246
- reader.values[0].should == i
247
- i += 1
248
- end
249
- end
250
-
251
- it "should quote an Array with NULL values returned" do
252
- command = @connection.create_command("SELECT id, NULL AS notes FROM sail_boats WHERE (id IN ?)")
253
- reader = command.execute_reader([1, 2, 3])
254
-
255
- i = 1
256
- while(reader.next!)
257
- reader.values[0].should == i
258
- i += 1
259
- end
260
- end
261
-
262
- it "should quote an Array with NULL values returned AND set_types called" do
263
- command = @connection.create_command("SELECT id, NULL AS notes FROM sail_boats WHERE (id IN ?)")
264
- command.set_types [ Integer, String ]
265
-
266
- reader = command.execute_reader([1, 2, 3])
267
-
268
- i = 1
269
- while(reader.next!)
270
- reader.values[0].should == i
271
- i += 1
272
- end
273
- end
274
-
275
- end # describe "quoting"
276
-
277
- end
278
- end
@@ -1,53 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- describe DataObjects::Sqlite3::Command do
5
-
6
- before(:each) do
7
- @connection = DataObjects::Connection.new("sqlite3://#{File.expand_path(File.dirname(__FILE__))}/test.db")
8
- end
9
-
10
- after(:each) do
11
- @connection.close
12
- end
13
-
14
- describe "Executing a Reader" do
15
-
16
- it "should log reader queries when the level is Debug (0)" do
17
- pending "SQLiteJDBC does not implement java.sql.Statement#toString" if JRUBY
18
- command = @connection.create_command("SELECT * FROM users")
19
- @mock_logger = mock('MockLogger', :level => 0)
20
- DataObjects::Sqlite3.should_receive(:logger).and_return(@mock_logger)
21
- @mock_logger.should_receive(:debug).with(/\([\d.]+\) SELECT \* FROM users/)
22
- command.execute_reader.close
23
- end
24
-
25
- it "shouldn't log reader queries when the level isn't Debug (0)" do
26
- command = @connection.create_command("SELECT * FROM users")
27
- @mock_logger = mock('MockLogger', :level => 1)
28
- DataObjects::Sqlite3.should_receive(:logger).and_return(@mock_logger)
29
- @mock_logger.should_not_receive(:debug)
30
- command.execute_reader.close
31
- end
32
- end
33
-
34
- describe "Executing a Non-Query" do
35
- it "should log non-query statements when the level is Debug (0)" do
36
- pending "SQLiteJDBC does not implement java.sql.Statement#toString" if JRUBY
37
- command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
38
- @mock_logger = mock('MockLogger', :level => 0)
39
- DataObjects::Sqlite3.should_receive(:logger).and_return(@mock_logger)
40
- @mock_logger.should_receive(:debug).with(/\([\d.]+\) INSERT INTO users \(name\) VALUES \('Blah'\)/)
41
- command.execute_non_query('Blah')
42
- end
43
-
44
- it "shouldn't log non-query statements when the level isn't Debug (0)" do
45
- command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
46
- @mock_logger = mock('MockLogger', :level => 1)
47
- DataObjects::Sqlite3.should_receive(:logger).and_return(@mock_logger)
48
- @mock_logger.should_not_receive(:debug)
49
- command.execute_non_query('Blah')
50
- end
51
- end
52
-
53
- end
@@ -1,23 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- unless JRUBY
5
-
6
- describe DataObjects::Sqlite3::Command do
7
-
8
- before(:each) do
9
- @connection = DataObjects::Connection.new("sqlite3://#{File.expand_path(File.dirname(__FILE__))}/test.db")
10
- @command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
11
- end
12
-
13
- it "should properly quote a string" do
14
- @command.quote_string("O'Hare").should == "'O''Hare'"
15
- @command.quote_string("Willy O'Hare & Johnny O'Toole").should == "'Willy O''Hare & Johnny O''Toole'"
16
- @command.quote_string("Billy\\Bob").should == "'Billy\\Bob'"
17
- @command.quote_string("The\\Backslasher\\Rises\\Again").should == "'The\\Backslasher\\Rises\\Again'"
18
- @command.quote_string("Scott \"The Rage\" Bauer").should == "'Scott \"The Rage\" Bauer'"
19
- end
20
-
21
- end
22
-
23
- end
data/spec/spec.opts DELETED
@@ -1,2 +0,0 @@
1
- --format specdoc
2
- --colour
@@ -1,34 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- describe DataObjects::Sqlite3::Transaction do
5
-
6
- before :each do
7
- @connection = mock("connection")
8
- DataObjects::Connection.should_receive(:new).with("mock://mock/mock").once.and_return(@connection)
9
- @transaction = DataObjects::Sqlite3::Transaction.new("mock://mock/mock")
10
- @transaction.id.replace("id")
11
- @command = mock("command")
12
- end
13
-
14
- {
15
- :begin => "BEGIN",
16
- :commit => "COMMIT",
17
- :rollback => "ROLLBACK",
18
- :rollback_prepared => "ROLLBACK",
19
- :prepare => nil
20
- }.each do |method, commands|
21
- it "should execute #{commands.inspect} on ##{method}" do
22
- if commands.is_a?(String)
23
- @command.should_receive(:execute_non_query).once
24
- @connection.should_receive(:create_command).once.with(commands).and_return(@command)
25
- @transaction.send(method)
26
- elsif commands.nil?
27
- @command.should_not_receive(:execute_non_query)
28
- @connection.should_not_receive(:create_command)
29
- @transaction.send(method)
30
- end
31
- end
32
- end
33
-
34
- end