|
42 | 42 | it "should let us execute our statement" do
|
43 | 43 | statement = @client.prepare 'SELECT 1'
|
44 | 44 | statement.execute.class.should == Mysql2::Result
|
45 |
| - GC.start |
46 |
| - end |
47 |
| - |
48 |
| - # it "should raise an exception without a block" do |
49 |
| - # statement = @client.prepare 'SELECT 1' |
50 |
| - # statement.execute |
51 |
| - # lambda { statement.each }.should raise_error |
52 |
| - # end |
53 |
| - |
54 |
| - # it "should tell us about the fields" do |
55 |
| - # statement = @client.prepare 'SELECT 1 as foo, 2' |
56 |
| - # statement.execute |
57 |
| - # list = statement.fields |
58 |
| - # list.length.should == 2 |
59 |
| - # list.first.should == 'foo' |
60 |
| - # list[1].should == '2' |
61 |
| - # end |
62 |
| - |
63 |
| - # it "should let us iterate over results" do |
64 |
| - # statement = @client.prepare 'SELECT 1' |
65 |
| - # statement.execute |
66 |
| - # rows = [] |
67 |
| - # statement.each { |row| rows << row } |
68 |
| - # rows.should == [[1]] |
69 |
| - # end |
70 |
| - |
71 |
| - # it "should select dates" do |
72 |
| - # statement = @client.prepare 'SELECT NOW()' |
73 |
| - # statement.execute |
74 |
| - # rows = [] |
75 |
| - # statement.each { |row| rows << row } |
76 |
| - # rows.first.first.should be_kind_of Time |
77 |
| - # end |
78 |
| - |
79 |
| - # it "should pass in nil parameters" do |
80 |
| - # statement = @client.prepare 'SELECT * FROM (SELECT 1 as foo, 2) bar WHERE foo = ?' |
81 |
| - # statement.execute(nil).class.should == Mysql2::Result |
82 |
| - # end |
83 |
| - |
84 |
| - # it "should pass in Bignum parameters" do |
85 |
| - # statement = @client.prepare 'SELECT * FROM (SELECT 1 as foo, 2) bar WHERE foo = ?' |
86 |
| - # (lambda{ statement.execute(723623523423323223123) }).should raise_error(RangeError) |
87 |
| - # end |
88 |
| - |
89 |
| - # it "should pass in Float parameters" do |
90 |
| - # statement = @client.prepare 'SELECT * FROM (SELECT 2.3 as foo, 2) bar WHERE foo = ?' |
91 |
| - # statement.execute(2.4).class.should == Mysql2::Result |
92 |
| - # end |
93 |
| - |
94 |
| - # it "should pass in String parameters" do |
95 |
| - # statement = @client.prepare 'SELECT * FROM (SELECT "foo" as foo, 2) bar WHERE foo = ?' |
96 |
| - # statement.execute("blah").class.should == Mysql2::Result |
97 |
| - # end |
98 |
| - |
99 |
| - # it "should pass in Time parameters" do |
100 |
| - # statement = @client.prepare 'SELECT * FROM (SELECT CURRENT_TIMESTAMP() as foo, 2) bar WHERE foo = ?' |
101 |
| - # statement.execute(Time.now).class.should == Mysql2::Result |
102 |
| - # end |
103 |
| - |
104 |
| - # it "should pass in DateTime parameters" do |
105 |
| - # statement = @client.prepare 'SELECT * FROM (SELECT CURRENT_TIMESTAMP() as foo, 2) bar WHERE foo = ?' |
106 |
| - # statement.execute(DateTime.now).class.should == Mysql2::Result |
107 |
| - # end |
108 |
| - |
109 |
| - # it "should pass in Date parameters" do |
110 |
| - # statement = @client.prepare 'SELECT * FROM (SELECT CURRENT_DATE() as foo, 2) bar WHERE foo = ?' |
111 |
| - # statement.execute(Date.today) |
112 |
| - # end |
113 |
| - |
114 |
| - # context "utf8_db_field" do |
115 |
| - # before(:each) do |
116 |
| - # @client.query("DROP DATABASE IF EXISTS test_mysql2_stmt_utf8") |
117 |
| - # @client.query("CREATE DATABASE test_mysql2_stmt_utf8") |
118 |
| - # @client.query("USE test_mysql2_stmt_utf8") |
119 |
| - # @client.query("CREATE TABLE テーブル (整数 int, 文字列 varchar(32)) charset=utf8") |
120 |
| - # @client.query("INSERT INTO テーブル (整数, 文字列) VALUES (1, 'イチ'), (2, '弐'), (3, 'さん')") |
121 |
| - # end |
122 |
| - |
123 |
| - # after(:each) do |
124 |
| - # @client.query("DROP DATABASE test_mysql2_stmt_utf8") |
125 |
| - # end |
126 |
| - |
127 |
| - # it "should be able to retrieve utf8 field names correctly" do |
128 |
| - # statement = @client.prepare 'SELECT * FROM `テーブル`' |
129 |
| - # statement.fields.should == ['整数', '文字列'] |
130 |
| - # end |
131 |
| - # end |
| 45 | + end |
| 46 | + |
| 47 | + it "should raise an exception without a block" do |
| 48 | + statement = @client.prepare 'SELECT 1' |
| 49 | + statement.execute |
| 50 | + lambda { statement.each }.should raise_error |
| 51 | + end |
| 52 | + |
| 53 | + it "should tell us about the fields" do |
| 54 | + statement = @client.prepare 'SELECT 1 as foo, 2' |
| 55 | + statement.execute |
| 56 | + list = statement.fields |
| 57 | + list.length.should == 2 |
| 58 | + list.first.should == 'foo' |
| 59 | + list[1].should == '2' |
| 60 | + end |
| 61 | + |
| 62 | + it "should let us iterate over results" do |
| 63 | + statement = @client.prepare 'SELECT 1' |
| 64 | + result = statement.execute |
| 65 | + rows = [] |
| 66 | + result.each { |r| rows << r } |
| 67 | + rows.should == [{"1"=>1}] # as: hash |
| 68 | + end |
| 69 | + |
| 70 | + it "should select dates" do |
| 71 | + statement = @client.prepare 'SELECT NOW()' |
| 72 | + result = statement.execute |
| 73 | + result.first.first[1].should be_kind_of Time |
| 74 | + end |
| 75 | + |
| 76 | + it "should pass in nil parameters" do |
| 77 | + statement = @client.prepare 'SELECT * FROM (SELECT 1 as foo, 2) bar WHERE foo = ?' |
| 78 | + statement.execute(nil).class.should == Mysql2::Result |
| 79 | + end |
| 80 | + |
| 81 | + it "should pass in Bignum parameters" do |
| 82 | + statement = @client.prepare 'SELECT * FROM (SELECT 1 as foo, 2) bar WHERE foo = ?' |
| 83 | + (lambda{ statement.execute(723623523423323223123) }).should raise_error(RangeError) |
| 84 | + end |
| 85 | + |
| 86 | + it "should pass in Float parameters" do |
| 87 | + statement = @client.prepare 'SELECT * FROM (SELECT 2.3 as foo, 2) bar WHERE foo = ?' |
| 88 | + statement.execute(2.4).class.should == Mysql2::Result |
| 89 | + end |
| 90 | + |
| 91 | + it "should pass in String parameters" do |
| 92 | + statement = @client.prepare 'SELECT * FROM (SELECT "foo" as foo, 2) bar WHERE foo = ?' |
| 93 | + statement.execute("blah").class.should == Mysql2::Result |
| 94 | + end |
| 95 | + |
| 96 | + it "should pass in Time parameters" do |
| 97 | + statement = @client.prepare 'SELECT * FROM (SELECT CURRENT_TIMESTAMP() as foo, 2) bar WHERE foo = ?' |
| 98 | + statement.execute(Time.now).class.should == Mysql2::Result |
| 99 | + end |
| 100 | + |
| 101 | + it "should pass in DateTime parameters" do |
| 102 | + statement = @client.prepare 'SELECT * FROM (SELECT CURRENT_TIMESTAMP() as foo, 2) bar WHERE foo = ?' |
| 103 | + statement.execute(DateTime.now).class.should == Mysql2::Result |
| 104 | + end |
| 105 | + |
| 106 | + it "should pass in Date parameters" do |
| 107 | + statement = @client.prepare 'SELECT * FROM (SELECT CURRENT_DATE() as foo, 2) bar WHERE foo = ?' |
| 108 | + statement.execute(Date.today) |
| 109 | + end |
| 110 | + |
| 111 | + context "utf8_db_field" do |
| 112 | + before(:each) do |
| 113 | + @client.query("DROP DATABASE IF EXISTS test_mysql2_stmt_utf8") |
| 114 | + @client.query("CREATE DATABASE test_mysql2_stmt_utf8") |
| 115 | + @client.query("USE test_mysql2_stmt_utf8") |
| 116 | + @client.query("CREATE TABLE テーブル (整数 int, 文字列 varchar(32)) charset=utf8") |
| 117 | + @client.query("INSERT INTO テーブル (整数, 文字列) VALUES (1, 'イチ'), (2, '弐'), (3, 'さん')") |
| 118 | + end |
| 119 | + |
| 120 | + after(:each) do |
| 121 | + @client.query("DROP DATABASE test_mysql2_stmt_utf8") |
| 122 | + end |
| 123 | + |
| 124 | + it "should be able to retrieve utf8 field names correctly" do |
| 125 | + statement = @client.prepare 'SELECT * FROM `テーブル`' |
| 126 | + statement.fields.should == ['整数', '文字列'] |
| 127 | + end |
| 128 | + end |
132 | 129 | end
|
0 commit comments