rdo-mysql 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/ext/rdo_mysql/driver.c +22 -0
- data/ext/rdo_mysql/tuples.c +3 -0
- data/lib/rdo/mysql/version.rb +1 -1
- data/spec/mysql/bind_params_spec.rb +681 -0
- metadata +4 -2
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This is the MySQL driver for [RDO—Ruby Data Objects](https://github.com/d11wtq/rdo).
|
4
4
|
|
5
|
-
[![Build Status](https://secure.travis-ci.org/d11wtq/rdo-mysql.png)](http://travis-ci.org/d11wtq/rdo-mysql)
|
5
|
+
[![Build Status](https://secure.travis-ci.org/d11wtq/rdo-mysql.png?branch=master)](http://travis-ci.org/d11wtq/rdo-mysql)
|
6
6
|
|
7
7
|
Refer to the RDO project [README](https://github.com/d11wtq/rdo) for full usage information.
|
8
8
|
|
data/ext/rdo_mysql/driver.c
CHANGED
@@ -134,6 +134,25 @@ static VALUE rdo_mysql_driver_quote(VALUE self, VALUE obj) {
|
|
134
134
|
return rb_str_new2(quoted);
|
135
135
|
}
|
136
136
|
|
137
|
+
/** Find any Time/DateTime arguments and ensure they use the system time zone */
|
138
|
+
static void rdo_mysql_driver_normalize_date_times_bang(VALUE * args, int argc) {
|
139
|
+
int i;
|
140
|
+
for (i = 0; i < argc; ++i) {
|
141
|
+
if (rb_funcall(args[i], rb_intern("kind_of?"), 1, rb_path2class("DateTime"))) {
|
142
|
+
VALUE offset = rb_funcall(
|
143
|
+
rb_funcall(rb_path2class("DateTime"), rb_intern("now"), 0),
|
144
|
+
rb_intern("offset"),
|
145
|
+
0);
|
146
|
+
|
147
|
+
args[i] = rb_funcall(args[i], rb_intern("new_offset"), 1, offset);
|
148
|
+
args[i] = rb_funcall(args[i], rb_intern("strftime"), 1, rb_str_new2("%Y-%m-%d %H:%M:%S"));
|
149
|
+
} else if (rb_funcall(args[i], rb_intern("kind_of?"), 1, rb_cTime)) {
|
150
|
+
args[i] = rb_funcall(args[i], rb_intern("localtime"), 0);
|
151
|
+
args[i] = rb_funcall(args[i], rb_intern("strftime"), 1, rb_str_new2("%Y-%m-%d %H:%M:%S"));
|
152
|
+
}
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
137
156
|
/** Execute a statement with possible bind parameters */
|
138
157
|
static VALUE rdo_mysql_driver_execute(int argc, VALUE * args, VALUE self) {
|
139
158
|
if (argc < 1) {
|
@@ -147,6 +166,8 @@ static VALUE rdo_mysql_driver_execute(int argc, VALUE * args, VALUE self) {
|
|
147
166
|
RDO_ERROR("Cannot execute query: connection is not open");
|
148
167
|
}
|
149
168
|
|
169
|
+
rdo_mysql_driver_normalize_date_times_bang(&args[1], argc - 1);
|
170
|
+
|
150
171
|
VALUE stmt = RDO_INTERPOLATE(self, args, argc);
|
151
172
|
|
152
173
|
if (mysql_real_query(driver->conn,
|
@@ -164,6 +185,7 @@ static VALUE rdo_mysql_driver_execute(int argc, VALUE * args, VALUE self) {
|
|
164
185
|
/** Initializer driver during extension initialization */
|
165
186
|
void Init_rdo_mysql_driver(void) {
|
166
187
|
rb_require("rdo/mysql/driver");
|
188
|
+
rb_require("date");
|
167
189
|
|
168
190
|
VALUE cMySQL = rb_path2class("RDO::MySQL::Driver");
|
169
191
|
|
data/ext/rdo_mysql/tuples.c
CHANGED
@@ -43,6 +43,9 @@ VALUE rdo_mysql_tuple_list_new(MYSQL_RES * res, int encoding) {
|
|
43
43
|
|
44
44
|
/** Cast the given value to a Ruby type */
|
45
45
|
static VALUE rdo_mysql_cast_value(char * v, unsigned long len, MYSQL_FIELD f, int enc) {
|
46
|
+
if (v == NULL)
|
47
|
+
return Qnil;
|
48
|
+
|
46
49
|
switch (f.type) {
|
47
50
|
case MYSQL_TYPE_NULL:
|
48
51
|
return Qnil;
|
data/lib/rdo/mysql/version.rb
CHANGED
@@ -0,0 +1,681 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "date"
|
3
|
+
require "bigdecimal"
|
4
|
+
|
5
|
+
describe RDO::MySQL::Driver, "bind params" do
|
6
|
+
let(:options) { connection_uri }
|
7
|
+
let(:connection) { RDO.connect(options) }
|
8
|
+
|
9
|
+
let(:table) do
|
10
|
+
"CREATE TABLE test (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT)"
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:tuple) { connection.execute("SELECT * FROM test").first }
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
connection.execute("DROP TABLE IF EXISTS test")
|
17
|
+
connection.execute(table)
|
18
|
+
connection.execute(*insert)
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:each) do
|
22
|
+
begin
|
23
|
+
connection.execute("DROP TABLE IF EXISTS test")
|
24
|
+
ensure
|
25
|
+
connection.close
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "nil param" do
|
30
|
+
context "against a varchar field" do
|
31
|
+
let(:table) do
|
32
|
+
<<-SQL
|
33
|
+
CREATE TABLE test (
|
34
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
35
|
+
value VARCHAR(32)
|
36
|
+
)
|
37
|
+
SQL
|
38
|
+
end
|
39
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", nil] }
|
40
|
+
|
41
|
+
it "is inferred correctly" do
|
42
|
+
tuple.should == {id: 1, value: nil}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "against a char field" do
|
47
|
+
let(:table) do
|
48
|
+
<<-SQL
|
49
|
+
CREATE TABLE test (
|
50
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
51
|
+
value CHAR(3)
|
52
|
+
)
|
53
|
+
SQL
|
54
|
+
end
|
55
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", nil] }
|
56
|
+
|
57
|
+
it "is inferred correctly" do
|
58
|
+
tuple.should == {id: 1, value: nil}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "against a text field" do
|
63
|
+
let(:table) do
|
64
|
+
<<-SQL
|
65
|
+
CREATE TABLE test (
|
66
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
67
|
+
value TEXT
|
68
|
+
)
|
69
|
+
SQL
|
70
|
+
end
|
71
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", nil] }
|
72
|
+
|
73
|
+
it "is inferred correctly" do
|
74
|
+
tuple.should == {id: 1, value: nil}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "against a blob field" do
|
79
|
+
let(:table) do
|
80
|
+
<<-SQL
|
81
|
+
CREATE TABLE test (
|
82
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
83
|
+
value BLOB
|
84
|
+
)
|
85
|
+
SQL
|
86
|
+
end
|
87
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", nil] }
|
88
|
+
|
89
|
+
it "is inferred correctly" do
|
90
|
+
tuple.should == {id: 1, value: nil}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "against an integer field" do
|
95
|
+
let(:table) do
|
96
|
+
<<-SQL
|
97
|
+
CREATE TABLE test (
|
98
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
99
|
+
value INT
|
100
|
+
)
|
101
|
+
SQL
|
102
|
+
end
|
103
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", nil] }
|
104
|
+
|
105
|
+
it "is inferred correctly" do
|
106
|
+
tuple.should == {id: 1, value: nil}
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "against a float field" do
|
111
|
+
let(:table) do
|
112
|
+
<<-SQL
|
113
|
+
CREATE TABLE test (
|
114
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
115
|
+
value FLOAT
|
116
|
+
)
|
117
|
+
SQL
|
118
|
+
end
|
119
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", nil] }
|
120
|
+
|
121
|
+
it "is inferred correctly" do
|
122
|
+
tuple.should == {id: 1, value: nil}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "against a date field" do
|
127
|
+
let(:table) do
|
128
|
+
<<-SQL
|
129
|
+
CREATE TABLE test (
|
130
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
131
|
+
value DATE
|
132
|
+
)
|
133
|
+
SQL
|
134
|
+
end
|
135
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", nil] }
|
136
|
+
|
137
|
+
it "is inferred correctly" do
|
138
|
+
tuple.should == {id: 1, value: nil}
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "against a datetime field" do
|
143
|
+
let(:table) do
|
144
|
+
<<-SQL
|
145
|
+
CREATE TABLE test (
|
146
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
147
|
+
value DATETIME
|
148
|
+
)
|
149
|
+
SQL
|
150
|
+
end
|
151
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", nil] }
|
152
|
+
|
153
|
+
it "is inferred correctly" do
|
154
|
+
tuple.should == {id: 1, value: nil}
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context "against a timestamp field" do
|
159
|
+
let(:table) do
|
160
|
+
<<-SQL
|
161
|
+
CREATE TABLE test (
|
162
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
163
|
+
value TIMESTAMP NULL
|
164
|
+
)
|
165
|
+
SQL
|
166
|
+
end
|
167
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", nil] }
|
168
|
+
|
169
|
+
it "is inferred correctly" do
|
170
|
+
tuple.should == {id: 1, value: nil}
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "String param" do
|
176
|
+
context "against a varchar field" do
|
177
|
+
let(:table) do
|
178
|
+
<<-SQL
|
179
|
+
CREATE TABLE test (
|
180
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
181
|
+
value VARCHAR(32)
|
182
|
+
)
|
183
|
+
SQL
|
184
|
+
end
|
185
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", "bob"] }
|
186
|
+
|
187
|
+
it "is inferred correctly" do
|
188
|
+
tuple.should == {id: 1, value: "bob"}
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "against a char field" do
|
193
|
+
let(:table) do
|
194
|
+
<<-SQL
|
195
|
+
CREATE TABLE test (
|
196
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
197
|
+
value CHAR(3)
|
198
|
+
)
|
199
|
+
SQL
|
200
|
+
end
|
201
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", "bob"] }
|
202
|
+
|
203
|
+
it "is inferred correctly" do
|
204
|
+
tuple.should == {id: 1, value: "bob"}
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context "against a text field" do
|
209
|
+
let(:table) do
|
210
|
+
<<-SQL
|
211
|
+
CREATE TABLE test (
|
212
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
213
|
+
value TEXT
|
214
|
+
)
|
215
|
+
SQL
|
216
|
+
end
|
217
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", "bob"] }
|
218
|
+
|
219
|
+
it "is inferred correctly" do
|
220
|
+
tuple.should == {id: 1, value: "bob"}
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context "against a blob field" do
|
225
|
+
let(:table) do
|
226
|
+
<<-SQL
|
227
|
+
CREATE TABLE test (
|
228
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
229
|
+
value BLOB
|
230
|
+
)
|
231
|
+
SQL
|
232
|
+
end
|
233
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", "\x00\x11\x22"] }
|
234
|
+
|
235
|
+
it "is inferred correctly" do
|
236
|
+
tuple.should == {id: 1, value: "\x00\x11\x22"}
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context "against an integer field" do
|
241
|
+
let(:table) do
|
242
|
+
<<-SQL
|
243
|
+
CREATE TABLE test (
|
244
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
245
|
+
value INT
|
246
|
+
)
|
247
|
+
SQL
|
248
|
+
end
|
249
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", "42"] }
|
250
|
+
|
251
|
+
it "is inferred correctly" do
|
252
|
+
tuple.should == {id: 1, value: 42}
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context "against a float field" do
|
257
|
+
let(:table) do
|
258
|
+
<<-SQL
|
259
|
+
CREATE TABLE test (
|
260
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
261
|
+
value FLOAT
|
262
|
+
)
|
263
|
+
SQL
|
264
|
+
end
|
265
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", "42.4"] }
|
266
|
+
|
267
|
+
it "is inferred correctly" do
|
268
|
+
tuple.should == {id: 1, value: 42.4}
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context "against a date field" do
|
273
|
+
let(:table) do
|
274
|
+
<<-SQL
|
275
|
+
CREATE TABLE test (
|
276
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
277
|
+
value DATE
|
278
|
+
)
|
279
|
+
SQL
|
280
|
+
end
|
281
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", "2012-10-03"] }
|
282
|
+
|
283
|
+
it "is inferred correctly" do
|
284
|
+
tuple.should == {id: 1, value: Date.new(2012, 10, 3)}
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
context "against a datetime field" do
|
289
|
+
let(:table) do
|
290
|
+
<<-SQL
|
291
|
+
CREATE TABLE test (
|
292
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
293
|
+
value DATETIME
|
294
|
+
)
|
295
|
+
SQL
|
296
|
+
end
|
297
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", "2012-10-03 00:09:36"] }
|
298
|
+
|
299
|
+
it "is inferred correctly" do
|
300
|
+
tuple.should == {id: 1, value: DateTime.new(2012, 10, 3, 0, 9, 36, DateTime.now.zone)}
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
context "against a timestamp field" do
|
305
|
+
let(:table) do
|
306
|
+
<<-SQL
|
307
|
+
CREATE TABLE test (
|
308
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
309
|
+
value TIMESTAMP
|
310
|
+
)
|
311
|
+
SQL
|
312
|
+
end
|
313
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", "2012-10-03 00:09:36"] }
|
314
|
+
|
315
|
+
it "is inferred correctly" do
|
316
|
+
tuple.should == {id: 1, value: DateTime.new(2012, 10, 3, 0, 9, 36, DateTime.now.zone)}
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
describe "Fixnum param" do
|
322
|
+
context "against an integer field" do
|
323
|
+
let(:table) do
|
324
|
+
<<-SQL
|
325
|
+
CREATE TABLE test (
|
326
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
327
|
+
value INT
|
328
|
+
)
|
329
|
+
SQL
|
330
|
+
end
|
331
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", 42] }
|
332
|
+
|
333
|
+
it "is inferred correctly" do
|
334
|
+
tuple.should == {id: 1, value: 42}
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
context "against a varchar field" do
|
339
|
+
let(:table) do
|
340
|
+
<<-SQL
|
341
|
+
CREATE TABLE test (
|
342
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
343
|
+
value VARCHAR(32)
|
344
|
+
)
|
345
|
+
SQL
|
346
|
+
end
|
347
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", 42] }
|
348
|
+
|
349
|
+
it "is inferred correctly" do
|
350
|
+
tuple.should == {id: 1, value: "42"}
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
context "against a char field" do
|
355
|
+
let(:table) do
|
356
|
+
<<-SQL
|
357
|
+
CREATE TABLE test (
|
358
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
359
|
+
value CHAR(3)
|
360
|
+
)
|
361
|
+
SQL
|
362
|
+
end
|
363
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", 42] }
|
364
|
+
|
365
|
+
it "is inferred correctly" do
|
366
|
+
tuple.should == {id: 1, value: "42"}
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
context "against a text field" do
|
371
|
+
let(:table) do
|
372
|
+
<<-SQL
|
373
|
+
CREATE TABLE test (
|
374
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
375
|
+
value TEXT
|
376
|
+
)
|
377
|
+
SQL
|
378
|
+
end
|
379
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", 42] }
|
380
|
+
|
381
|
+
it "is inferred correctly" do
|
382
|
+
tuple.should == {id: 1, value: "42"}
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
context "against a blob field" do
|
387
|
+
let(:table) do
|
388
|
+
<<-SQL
|
389
|
+
CREATE TABLE test (
|
390
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
391
|
+
value TEXT
|
392
|
+
)
|
393
|
+
SQL
|
394
|
+
end
|
395
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", 42] }
|
396
|
+
|
397
|
+
it "is inferred correctly" do
|
398
|
+
tuple.should == {id: 1, value: "42"}
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
context "against a float field" do
|
403
|
+
let(:table) do
|
404
|
+
<<-SQL
|
405
|
+
CREATE TABLE test (
|
406
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
407
|
+
value FLOAT
|
408
|
+
)
|
409
|
+
SQL
|
410
|
+
end
|
411
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", 42] }
|
412
|
+
|
413
|
+
it "is inferred correctly" do
|
414
|
+
tuple[:value].should be_a_kind_of(Float)
|
415
|
+
tuple.should == {id: 1, value: 42.0}
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
describe "Float param" do
|
421
|
+
context "against a float field" do
|
422
|
+
let(:table) do
|
423
|
+
<<-SQL
|
424
|
+
CREATE TABLE test (
|
425
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
426
|
+
value FLOAT
|
427
|
+
)
|
428
|
+
SQL
|
429
|
+
end
|
430
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", 42.6] }
|
431
|
+
|
432
|
+
it "is inferred correctly" do
|
433
|
+
tuple.should == {id: 1, value: 42.6}
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
context "against an integer field" do
|
438
|
+
let(:table) do
|
439
|
+
<<-SQL
|
440
|
+
CREATE TABLE test (
|
441
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
442
|
+
value INT
|
443
|
+
)
|
444
|
+
SQL
|
445
|
+
end
|
446
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", 42.2] }
|
447
|
+
|
448
|
+
it "is inferred correctly" do
|
449
|
+
tuple.should == {id: 1, value: 42}
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
context "against a varchar field" do
|
454
|
+
let(:table) do
|
455
|
+
<<-SQL
|
456
|
+
CREATE TABLE test (
|
457
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
458
|
+
value VARCHAR(32)
|
459
|
+
)
|
460
|
+
SQL
|
461
|
+
end
|
462
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", 42.2] }
|
463
|
+
|
464
|
+
it "is inferred correctly" do
|
465
|
+
tuple.should == {id: 1, value: "42.2"}
|
466
|
+
end
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
describe "BigDecimal param" do
|
471
|
+
context "against a decimal field" do
|
472
|
+
let(:table) do
|
473
|
+
<<-SQL
|
474
|
+
CREATE TABLE test (
|
475
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
476
|
+
value DECIMAL(4,2)
|
477
|
+
)
|
478
|
+
SQL
|
479
|
+
end
|
480
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", BigDecimal("17.56")] }
|
481
|
+
|
482
|
+
it "is inferred correctly" do
|
483
|
+
tuple.should == {id: 1, value: BigDecimal("17.56")}
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
context "against a float field" do
|
488
|
+
let(:table) do
|
489
|
+
<<-SQL
|
490
|
+
CREATE TABLE test (
|
491
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
492
|
+
value FLOAT
|
493
|
+
)
|
494
|
+
SQL
|
495
|
+
end
|
496
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", BigDecimal("17.56")] }
|
497
|
+
|
498
|
+
it "is inferred correctly" do
|
499
|
+
tuple.should == {id: 1, value: 17.56}
|
500
|
+
end
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
describe "Date param" do
|
505
|
+
context "against a date field" do
|
506
|
+
let(:table) do
|
507
|
+
<<-SQL
|
508
|
+
CREATE TABLE test (
|
509
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
510
|
+
value DATE
|
511
|
+
)
|
512
|
+
SQL
|
513
|
+
end
|
514
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", Date.new(1983, 5, 3)] }
|
515
|
+
|
516
|
+
it "is inferred correctly" do
|
517
|
+
tuple.should == {id: 1, value: Date.new(1983, 5, 3)}
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
context "against a varchar field" do
|
522
|
+
let(:table) do
|
523
|
+
<<-SQL
|
524
|
+
CREATE TABLE test (
|
525
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
526
|
+
value VARCHAR(32)
|
527
|
+
)
|
528
|
+
SQL
|
529
|
+
end
|
530
|
+
let(:insert) { ["INSERT INTO test (value) VALUES (?)", Date.new(1983, 5, 3)] }
|
531
|
+
|
532
|
+
it "is inferred correctly" do
|
533
|
+
tuple.should == {id: 1, value: "1983-05-03"}
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
538
|
+
describe "DateTime param" do
|
539
|
+
context "against a datetime field" do
|
540
|
+
let(:table) do
|
541
|
+
<<-SQL
|
542
|
+
CREATE TABLE test (
|
543
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
544
|
+
value DATETIME
|
545
|
+
)
|
546
|
+
SQL
|
547
|
+
end
|
548
|
+
|
549
|
+
let(:insert) do
|
550
|
+
[
|
551
|
+
"INSERT INTO test (value) VALUES (?)",
|
552
|
+
DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)
|
553
|
+
]
|
554
|
+
end
|
555
|
+
|
556
|
+
it "is inferred correctly" do
|
557
|
+
tuple.should == {id: 1, value: DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)}
|
558
|
+
end
|
559
|
+
|
560
|
+
context "with a time zone" do
|
561
|
+
let(:insert) do
|
562
|
+
[
|
563
|
+
"INSERT INTO test (value) VALUES (?)",
|
564
|
+
DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone).new_offset(0)
|
565
|
+
]
|
566
|
+
end
|
567
|
+
|
568
|
+
it "is inferred correctly" do
|
569
|
+
tuple.should == {id: 1, value: DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)}
|
570
|
+
end
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
context "against a timestamp field" do
|
575
|
+
let(:table) do
|
576
|
+
<<-SQL
|
577
|
+
CREATE TABLE test (
|
578
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
579
|
+
value TIMESTAMP
|
580
|
+
)
|
581
|
+
SQL
|
582
|
+
end
|
583
|
+
|
584
|
+
let(:insert) do
|
585
|
+
[
|
586
|
+
"INSERT INTO test (value) VALUES (?)",
|
587
|
+
DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)
|
588
|
+
]
|
589
|
+
end
|
590
|
+
|
591
|
+
it "is inferred correctly" do
|
592
|
+
tuple.should == {id: 1, value: DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)}
|
593
|
+
end
|
594
|
+
|
595
|
+
context "with a time zone" do
|
596
|
+
let(:insert) do
|
597
|
+
[
|
598
|
+
"INSERT INTO test (value) VALUES (?)",
|
599
|
+
DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone).new_offset(0)
|
600
|
+
]
|
601
|
+
end
|
602
|
+
|
603
|
+
it "is inferred correctly" do
|
604
|
+
tuple.should == {id: 1, value: DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)}
|
605
|
+
end
|
606
|
+
end
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
describe "Time param" do
|
611
|
+
context "against a datetime field" do
|
612
|
+
let(:table) do
|
613
|
+
<<-SQL
|
614
|
+
CREATE TABLE test (
|
615
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
616
|
+
value DATETIME
|
617
|
+
)
|
618
|
+
SQL
|
619
|
+
end
|
620
|
+
|
621
|
+
let(:insert) do
|
622
|
+
[
|
623
|
+
"INSERT INTO test (value) VALUES (?)",
|
624
|
+
Time.local(1983, 5, 3, 7, 18, 54)
|
625
|
+
]
|
626
|
+
end
|
627
|
+
|
628
|
+
it "is inferred correctly" do
|
629
|
+
tuple.should == {id: 1, value: DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)}
|
630
|
+
end
|
631
|
+
|
632
|
+
context "with a time zone" do
|
633
|
+
let(:insert) do
|
634
|
+
[
|
635
|
+
"INSERT INTO test (value) VALUES (?)",
|
636
|
+
Time.local(1983, 5, 3, 7, 18, 54).utc
|
637
|
+
]
|
638
|
+
end
|
639
|
+
|
640
|
+
it "is inferred correctly" do
|
641
|
+
tuple.should == {id: 1, value: DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)}
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
context "against a timestamp field" do
|
647
|
+
let(:table) do
|
648
|
+
<<-SQL
|
649
|
+
CREATE TABLE test (
|
650
|
+
id INT PRIMARY KEY AUTO_INCREMENT,
|
651
|
+
value TIMESTAMP
|
652
|
+
)
|
653
|
+
SQL
|
654
|
+
end
|
655
|
+
|
656
|
+
let(:insert) do
|
657
|
+
[
|
658
|
+
"INSERT INTO test (value) VALUES (?)",
|
659
|
+
Time.local(1983, 5, 3, 7, 18, 54)
|
660
|
+
]
|
661
|
+
end
|
662
|
+
|
663
|
+
it "is inferred correctly" do
|
664
|
+
tuple.should == {id: 1, value: DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)}
|
665
|
+
end
|
666
|
+
|
667
|
+
context "with a time zone" do
|
668
|
+
let(:insert) do
|
669
|
+
[
|
670
|
+
"INSERT INTO test (value) VALUES (?)",
|
671
|
+
Time.local(1983, 5, 3, 7, 18, 54).utc
|
672
|
+
]
|
673
|
+
end
|
674
|
+
|
675
|
+
it "is inferred correctly" do
|
676
|
+
tuple.should == {id: 1, value: DateTime.new(1983, 5, 3, 7, 18, 54, DateTime.now.zone)}
|
677
|
+
end
|
678
|
+
end
|
679
|
+
end
|
680
|
+
end
|
681
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdo-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdo
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/rdo/mysql/driver.rb
|
87
87
|
- lib/rdo/mysql/version.rb
|
88
88
|
- rdo-mysql.gemspec
|
89
|
+
- spec/mysql/bind_params_spec.rb
|
89
90
|
- spec/mysql/driver_spec.rb
|
90
91
|
- spec/mysql/type_cast_spec.rb
|
91
92
|
- spec/spec_helper.rb
|
@@ -114,6 +115,7 @@ signing_key:
|
|
114
115
|
specification_version: 3
|
115
116
|
summary: MySQL Driver for RDO
|
116
117
|
test_files:
|
118
|
+
- spec/mysql/bind_params_spec.rb
|
117
119
|
- spec/mysql/driver_spec.rb
|
118
120
|
- spec/mysql/type_cast_spec.rb
|
119
121
|
- spec/spec_helper.rb
|