@@ -4,16 +4,20 @@ def sql(s : String)
4
4
" #{ s.inspect } "
5
5
end
6
6
7
+ def sql (s : Bool )
8
+ " #{ s ? 1 : 0 } "
9
+ end
10
+
7
11
def sql (s )
8
12
" #{ s } "
9
13
end
10
14
11
15
def sqlite_type_for (v )
12
16
case v
13
- when String ; " text"
14
- when Int32 , Int64 ; " int"
15
- when Float32 , Float64 ; " float"
16
- when Time ; " text"
17
+ when String ; " text"
18
+ when Bool , Int32 , Int64 ; " int"
19
+ when Float32 , Float64 ; " float"
20
+ when Time ; " text"
17
21
else
18
22
raise " not implemented for #{ typeof (v)} "
19
23
end
@@ -143,12 +147,20 @@ describe Driver do
143
147
end
144
148
end
145
149
146
- {% for value in [1 , 1 _i64 , " hello" , 1.5 , 1.5 _f32 ] % }
150
+ {% for value in [true , false , 1 , 1 _i64 , " hello" , 1.5 , 1.5 _f32 ] % }
147
151
it " insert/get value {{value.id}} from table" do
148
152
with_db do |db |
149
153
db.exec " create table table1 (col1 #{ sqlite_type_for({{value}}) } )"
150
154
db.exec %( insert into table1 values (#{sql({{value}})}))
151
- db.scalar(" select col1 from table1" ).should eq({{value}})
155
+ db.query_one(" select col1 from table1" , as: typeof ({{value}})).should eq({{value}})
156
+ end
157
+ end
158
+
159
+ it " insert/get value {{value.id}} using bind" do
160
+ with_db do |db |
161
+ db.exec " create table table1 (col1 #{ sqlite_type_for({{value}}) } )"
162
+ db.exec %( insert into table1 (col1) values (?)) , {{value}}
163
+ db.query_one(" select col1 from table1" , as: typeof ({{value}})).should eq({{value}})
152
164
end
153
165
end
154
166
{% end % }
@@ -170,11 +182,7 @@ describe Driver do
170
182
value = Time .new(2016 , 7 , 22 , 15 , 0 , 0 , 0 )
171
183
db.exec " create table table1 (col1 #{ sqlite_type_for(value) } )"
172
184
db.exec %( insert into table1 values (?)) , value
173
-
174
- db.query " select col1 from table1" do |rs |
175
- rs.move_next
176
- rs.read(Time ).should eq(value)
177
- end
185
+ db.query_one(" select col1 from table1" , as: Time ).should eq(value)
178
186
end
179
187
end
180
188
0 commit comments