sam / do fork watch download tarball
public
Rubygem
Description: DataObjects
Homepage: http://rubyforge.org/projects/dorb
Clone URL: git://github.com/sam/do.git
Made new boolean specs pass.
sam (author)
Thu Apr 10 10:01:08 -0700 2008
commit  5454b903bf426cf79304f56e9fc10b6aac694169
tree    eea8c138482948940ed8feb553524b2c289e9ea7
parent  c08266a0f2388a5214dcca0c34ceb7e040c6fdb5
...
11
12
13
 
 
14
15
16
...
188
189
190
 
 
 
 
191
192
193
...
379
380
381
382
 
383
384
385
...
11
12
13
14
15
16
17
18
...
190
191
192
193
194
195
196
197
198
199
...
385
386
387
 
388
389
390
391
0
@@ -11,6 +11,8 @@
0
 #define CONST_GET(scope, constant) (rb_funcall(scope, ID_CONST_GET, 1, rb_str_new2(constant)))
0
 #define SQLITE3_CLASS(klass, parent) (rb_define_class_under(mSqlite3, klass, parent))
0
 
0
+#define TRUE_CLASS CONST_GET(rb_mKernel, "TrueClass")
0
+
0
 VALUE mDO;
0
 VALUE cDO_Quoting;
0
 VALUE cDO_Connection;
0
@@ -188,6 +190,10 @@ VALUE cCommand_set_types(VALUE self, VALUE array) {
0
   return array;
0
 }
0
 
0
+VALUE cCommand_quote_boolean(VALUE self, VALUE value) {
0
+ return rb_str_new2(value == TRUE_CLASS ? "'t'" : "'f'");
0
+}
0
+
0
 VALUE cCommand_execute_non_query(int argc, VALUE *argv[], VALUE self) {
0
   sqlite3 *db;
0
   char *error_message;
0
@@ -379,7 +385,7 @@ void Init_do_sqlite3() {
0
   rb_define_method(cCommand, "set_types", cCommand_set_types, 1);
0
   rb_define_method(cCommand, "execute_non_query", cCommand_execute_non_query, -1);
0
   rb_define_method(cCommand, "execute_reader", cCommand_execute_reader, -1);
0
-
0
+ rb_define_method(cCommand, "quote_boolean", cCommand_quote_boolean, 1);
0
   cResult = SQLITE3_CLASS("Result", cDO_Result);
0
   
0
   cReader = SQLITE3_CLASS("Reader", cDO_Reader);
...
29
30
31
32
 
33
34
 
35
36
37
...
88
89
90
91
 
92
93
94
95
96
 
 
 
 
97
98
99
...
109
110
111
 
 
 
 
 
 
 
112
113
114
...
29
30
31
 
32
33
 
34
35
36
37
...
88
89
90
 
91
92
 
 
 
 
93
94
95
96
97
98
99
...
109
110
111
112
113
114
115
116
117
118
119
120
121
0
@@ -29,9 +29,9 @@ describe "DataObjects::Sqlite3::Result" do
0
     lambda { command.execute_reader }.should raise_error("no such table: table_which_doesnt_exist")
0
   end
0
   
0
- it "should return the affected rows and insert_id" do
0
+ it "should return the affected rows and insert_id" do
0
     command = @connection.create_command("DROP TABLE users")
0
- command.execute_non_query
0
+ command.execute_non_query rescue nil
0
     command = @connection.create_command("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)")
0
     result = command.execute_non_query
0
     command = @connection.create_command("INSERT INTO users (name) VALUES ('test')")
0
@@ -88,12 +88,12 @@ describe "DataObjects::Sqlite3::Result" do
0
     
0
     before do
0
       begin
0
- @connection.create_command("CREATE TABLE sail_boats ( id INTEGER PRIMARY KEY, name VARCHAR(50), port VARCHAR(50), notes VARCHAR(50) )").execute_non_query
0
+ @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
0
       end
0
- command = @connection.create_command("INSERT INTO sail_boats (id, name, port, name) VALUES (?, ?, ?, ?)")
0
- command.execute_non_query(1, "A", "C", "Fortune Pig!")
0
- command.execute_non_query(2, "B", "B", "Happy Cow!")
0
- command.execute_non_query(3, "C", "A", "Spoon")
0
+ command = @connection.create_command("INSERT INTO sail_boats (id, name, port, name, vintage) VALUES (?, ?, ?, ?, ?)")
0
+ command.execute_non_query(1, "A", "C", "Fortune Pig!", false)
0
+ command.execute_non_query(2, "B", "B", "Happy Cow!", true)
0
+ command.execute_non_query(3, "C", "A", "Spoon", true)
0
     end
0
     
0
     it "should quote a String" do
0
@@ -109,6 +109,13 @@ describe "DataObjects::Sqlite3::Result" do
0
       result.to_i.should == 1
0
     end
0
     
0
+
0
+ it "should handle boolean columns gracefully" do
0
+ command = @connection.create_command("INSERT INTO sail_boats (id, name, port, name, vintage) VALUES (?, ?, ?, ?, ?)")
0
+ result = command.execute_non_query(4, "Scooner", "Port au Prince", "This is one gangster boat!", true)
0
+ result.to_i.should == 1
0
+ end
0
+
0
     it "should quote an Array" do
0
       command = @connection.create_command("SELECT id, notes FROM sail_boats WHERE (id IN ?)")
0
       reader = command.execute_reader([1, 2, 3])

Comments

    No one has commented yet.