sqlpostgres 1.2.6 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/Changelog.md +18 -0
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +12 -0
  4. data/README.rdoc +5 -2
  5. data/Rakefile +5 -24
  6. data/VERSION +1 -1
  7. data/lib/sqlpostgres/Connection.rb +8 -3
  8. data/lib/sqlpostgres/Cursor.rb +2 -2
  9. data/lib/sqlpostgres/Insert.rb +1 -1
  10. data/lib/sqlpostgres/PgBit.rb +1 -1
  11. data/lib/sqlpostgres/PgBox.rb +1 -1
  12. data/lib/sqlpostgres/PgCidr.rb +1 -1
  13. data/lib/sqlpostgres/PgCircle.rb +1 -1
  14. data/lib/sqlpostgres/PgInet.rb +1 -1
  15. data/lib/sqlpostgres/PgInterval.rb +1 -1
  16. data/lib/sqlpostgres/PgLineSegment.rb +1 -1
  17. data/lib/sqlpostgres/PgMacAddr.rb +1 -1
  18. data/lib/sqlpostgres/PgPath.rb +1 -1
  19. data/lib/sqlpostgres/PgPoint.rb +1 -1
  20. data/lib/sqlpostgres/PgPolygon.rb +1 -1
  21. data/lib/sqlpostgres/PgTime.rb +1 -1
  22. data/lib/sqlpostgres/PgTimeWithTimeZone.rb +1 -1
  23. data/lib/sqlpostgres/PgTimestamp.rb +1 -1
  24. data/lib/sqlpostgres/PgTwoPoints.rb +1 -1
  25. data/lib/sqlpostgres/PgWrapper.rb +1 -1
  26. data/lib/sqlpostgres/Select.rb +25 -25
  27. data/lib/sqlpostgres/Translate.rb +7 -29
  28. data/lib/sqlpostgres/Update.rb +1 -1
  29. data/rake_tasks/db.rake +17 -0
  30. data/rake_tasks/default.rake +1 -0
  31. data/rake_tasks/jeweler.rake +18 -0
  32. data/rake_tasks/test.rake +2 -0
  33. data/rake_tasks/test_spec.rake +3 -0
  34. data/rake_tasks/test_unit.rake +4 -0
  35. data/spec/Translate_spec.rb +533 -0
  36. data/spec/config/.gitignore +1 -0
  37. data/spec/config/config.yml +10 -0
  38. data/spec/config/database.yml.template +6 -0
  39. data/spec/connection_spec.rb +515 -0
  40. data/spec/cursor_spec.rb +288 -0
  41. data/spec/lib/database_config.rb +33 -0
  42. data/spec/lib/database_server.rb +42 -0
  43. data/spec/lib/postgres_template.rb +60 -0
  44. data/spec/lib/target_database_servers.rb +55 -0
  45. data/spec/lib/temporary_table.rb +45 -0
  46. data/spec/lib/test_config.rb +24 -0
  47. data/spec/lib/test_connection.rb +29 -0
  48. data/spec/lib/test_database.rb +57 -0
  49. data/spec/roundtrip_spec.rb +582 -0
  50. data/spec/spec_helper.rb +10 -0
  51. data/spec/support/all_characters.rb +18 -0
  52. data/spec/support/clear_default_connection.rb +5 -0
  53. data/spec/support/temporary_table.rb +24 -0
  54. data/spec/support/test_connections.rb +10 -0
  55. data/sqlpostgres.gemspec +35 -4
  56. data/test/Connection.test.rb +7 -5
  57. data/test/Select.test.rb +1 -1
  58. data/test/TestConfig.rb +9 -0
  59. data/test/TestUtil.rb +17 -3
  60. metadata +66 -9
  61. data/test/Translate.test.rb +0 -354
  62. data/test/roundtrip.test.rb +0 -565
@@ -1,565 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'bundler/setup'
5
- $:.unshift(File.dirname(__FILE__))
6
- require 'TestSetup'
7
- require 'bigdecimal'
8
- require 'date'
9
-
10
- # Test putting stuff in using Insert and getting it back out using
11
- # Select.
12
-
13
- class RoundTripTest < Test
14
-
15
- include SqlPostgres
16
- include TestUtil
17
-
18
- def test
19
- testCases = [
20
- [
21
- ["integer", "int", "int4"],
22
- [-2147483648, +2147483647, nil]
23
- ],
24
- [
25
- ["smallint", "int2"],
26
- [-32768, +32767, nil]
27
- ],
28
- [
29
- [
30
- "smallint[]", "int2[]",
31
- "integer[]", "int[]", "int4[]",
32
- "bigint[]", "int8[]",
33
- ],
34
- [[], [1], [1, 2], [-1, 0, 1], [[1, 2], [3, 4]], [[1, 2], [3, 4]], nil],
35
- ],
36
- [
37
- ["bigint", "int8"],
38
- [-9223372036854775808, +9223372036854775807, nil]
39
- ],
40
- [
41
- ["real", "float4"],
42
- [-1e30, -3.14159, +3.14159, 1e30, nil]
43
- ],
44
- [
45
- ["real[]", "float4[]"],
46
- [
47
- [[-1e30, -3.14159], [+3.14159, 1e30]],
48
- nil
49
- ]
50
- ],
51
- [
52
- ["decimal (7, 6)", "numeric (7, 6)"],
53
- [BigDecimal("-3.14159"), BigDecimal("+3.14159"), nil]
54
- ],
55
- [
56
- ["double precision", "float8"],
57
- [-1e290, -3.1415926535897, +3.1415926535897, 1e290, nil]
58
- ],
59
- [
60
- ["double precision[]", "float8[]"],
61
- [
62
- [[-1e290, -3.1415926535897], [+3.1415926535897, 1e290]],
63
- nil
64
- ]
65
- ],
66
- [
67
- ["serial", "serial4"],
68
- [1, +2147483647]
69
- ],
70
- [
71
- ["bigserial", "serial8"],
72
- [1, +9223372036854775807]
73
- ],
74
- [
75
- ["text", "varchar(255)", "character varying (255)"],
76
- [
77
- "",
78
- "Fool's gold",
79
- allCharacters(1),
80
- nil
81
- ]
82
- ],
83
- [
84
- ["text[]", "varchar(255)[]", "character varying(255)[]"],
85
- [
86
- [], ["foo"], ["foo", "bar", "fool's gold"],
87
- ["\\", "fool's", "a,b,c", "{}", "\"Hello!\"", "\001"],
88
- # Can't get this character arrays to work with the full
89
- # suite of characters, but we don't use character arrays
90
- # anyhow.
91
- # [allCharacters(1)],
92
- [["a", "b"], ["c", "d"]],
93
- nil,
94
- ]
95
- ],
96
- [
97
- ["character(4)", "char(4)"],
98
- ["foo ", "'\"\001 ", nil]
99
- ],
100
- [
101
- ["character(4)[]", "char(4)[]"],
102
- [
103
- [["foo ", "'\"\001 "], [" ", " a b"]],
104
- nil
105
- ]
106
- ],
107
- [
108
- ["character", "char"],
109
- ["a", "\001", "'", '"', nil]
110
- ],
111
- [
112
- ["character[]", "char[]"],
113
- [["a", "b"], ["c", "d"]],
114
- nil
115
- ],
116
- [
117
- ['"char"'],
118
- ["\001", "\037", " ", "~", "\127", "\130", "\277", "\300", "\377"],
119
- ],
120
- [
121
- ["name"],
122
- ["foo", nil]
123
- ],
124
- [
125
- ["name[]"],
126
- [
127
- [["foo", "bar"], ["baz", "quux"]],
128
- nil
129
- ]
130
- ],
131
- [
132
- ["bytea"],
133
- [
134
- "",
135
- allCharacters,
136
- nil,
137
- "\xc1\xb7",
138
- "\\123",
139
- "\\668G\345\256L\245",
140
- ],
141
- ],
142
- # Can't get this to work, but we don't use byte array arrays anyhow.
143
- # [
144
- # ["bytea[]"],
145
- # [
146
- # [["foo", "bar"], ["baz", "quux"]],
147
- # ["\\", "\000", allCharacters],
148
- # nil
149
- # ]
150
- # ],
151
- [
152
- ["timestamp", "timestamp without time zone"],
153
- [
154
- PgTimestamp.new(1900, 1, 1, 0, 0, 0),
155
- PgTimestamp.new(1999, 12, 31, 23, 59, 59),
156
- nil
157
- ]
158
- ],
159
- [
160
- ["timestamp[]", "timestamp without time zone[]"],
161
- [
162
- [
163
- PgTimestamp.new(1900, 1, 1, 0, 0, 0),
164
- PgTimestamp.new(1999, 12, 31, 23, 59, 59)
165
- ],
166
- nil
167
- ]
168
- ],
169
- [
170
- ["timestamp with time zone"],
171
- [
172
- {
173
- 'in'=>DateTime.civil(2001, 1, 1, 0, 0, 0, Rational(7, 24)),
174
- 'out'=>DateTime.civil(2000, 12, 31, 10, 0, 0, Rational(-7, 24)),
175
- },
176
- DateTime.civil(1900, 12, 31, 23, 59, 59, Rational(0, 24)),
177
- nil
178
- ]
179
- ],
180
- [
181
- ["timestamp with time zone[]"],
182
- [
183
- [
184
- DateTime.civil(2001, 1, 1, 0, 0, 0, Rational(7, 24)),
185
- DateTime.civil(1900, 12, 31, 23, 59, 59, Rational(0, 24)),
186
- ],
187
- nil
188
- ]
189
- ],
190
- [
191
- ["interval"],
192
- [
193
- PgInterval.new,
194
- PgInterval.new('seconds'=>1),
195
- PgInterval.new('minutes'=>1),
196
- PgInterval.new('hours'=>1),
197
- PgInterval.new('days'=>1),
198
- PgInterval.new('days'=>2),
199
- {
200
- 'in'=>PgInterval.new('weeks'=>1),
201
- 'out'=>PgInterval.new('days'=>7),
202
- },
203
- PgInterval.new('months'=>1),
204
- PgInterval.new('months'=>2),
205
- PgInterval.new('years'=>1),
206
- PgInterval.new('years'=>2),
207
- {
208
- 'in'=>PgInterval.new('decades'=>1),
209
- 'out'=>PgInterval.new('years'=>10),
210
- },
211
- {
212
- 'in'=>PgInterval.new('centuries'=>1),
213
- 'out'=>PgInterval.new('years'=>100),
214
- },
215
- {
216
- 'in'=>PgInterval.new('millennia'=>1),
217
- 'out'=>PgInterval.new('years'=>1000),
218
- },
219
- {
220
- 'in'=>PgInterval.new('millennia'=>1, 'centuries'=>2, 'decades'=>3,
221
- 'years'=>4, 'months'=>5, 'weeks'=>6,
222
- 'days'=>7, 'hours'=>8, 'minutes'=>9,
223
- 'seconds'=>10),
224
- 'out'=>PgInterval.new('years'=>1234, 'months'=>5, 'days'=>49,
225
- 'hours'=>8, 'minutes'=>9, 'seconds'=>10),
226
- },
227
- PgInterval.new('days'=>-1),
228
- {
229
- 'in'=>PgInterval.new('days'=>1, 'ago'=>true),
230
- 'out'=>PgInterval.new('days'=>-1),
231
- },
232
- {
233
- 'in'=>PgInterval.new('days'=>-1, 'ago'=>true),
234
- 'out'=>PgInterval.new('days'=>1),
235
- },
236
- PgInterval.new('seconds'=>1.1),
237
- {
238
- 'in'=>PgInterval.new('hours'=>1, 'minutes'=>-1, 'seconds'=>1),
239
- 'out'=>PgInterval.new('hours'=>0, 'minutes'=>59, 'seconds'=>1),
240
- },
241
- nil
242
- ]
243
- ],
244
- [
245
- ["interval[]"],
246
- [
247
- [
248
- [
249
- PgInterval.new('days'=>1),
250
- PgInterval.new('hours'=>2),
251
- ],
252
- [
253
- PgInterval.new('minutes'=>3),
254
- PgInterval.new('seconds'=>4),
255
- ],
256
- ],
257
- nil,
258
- ]
259
- ],
260
- [
261
- ["date"],
262
- [Date.civil(2001, 1, 1), Date.civil(1900, 12, 31), nil]
263
- ],
264
- [
265
- ["date[]"],
266
- [[Date.civil(2001, 1, 1), Date.civil(1900, 12, 31)], nil]
267
- ],
268
- [
269
- ["time"],
270
- [PgTime.new(0, 0, 0), PgTime.new(23, 59, 59), nil]
271
- ],
272
- [
273
- ["time[]"],
274
- [[PgTime.new(0, 0, 0), PgTime.new(23, 59, 59)], nil]
275
- ],
276
- [
277
- ["time with time zone"],
278
- [
279
- PgTimeWithTimeZone.new(0, 0, 0, 0, 0),
280
- PgTimeWithTimeZone.new(12, 0, 0, 0, 30),
281
- PgTimeWithTimeZone.new(12, 0, 0, -8, 0),
282
- PgTimeWithTimeZone.new(23, 59, 59, +8, 0),
283
- nil
284
- ]
285
- ],
286
- [
287
- ["time with time zone[]"],
288
- [
289
- [
290
- PgTimeWithTimeZone.new(0, 0, 0, 0, 0),
291
- PgTimeWithTimeZone.new(23, 59, 59, +8, 0),
292
- ],
293
- nil
294
- ]
295
- ],
296
- [
297
- ["boolean"],
298
- [false, true, nil],
299
- ],
300
- [
301
- ["boolean[]"],
302
- [
303
- [false, true],
304
- [[false, false], [false, true], [true, false], [true, true]],
305
- nil,
306
- ]
307
- ],
308
- [
309
- ["point"],
310
- [
311
- PgPoint.new(0, 0),
312
- PgPoint.new(1.2, -3),
313
- PgPoint.new(1e20, -1e20),
314
- nil,
315
- ],
316
- ],
317
- [
318
- ["point[]"],
319
- [
320
- [PgPoint.new(0, 0), PgPoint.new(1.2, -3), PgPoint.new(1e20, -1e20)],
321
- nil,
322
- ],
323
- ],
324
- [
325
- ["lseg"],
326
- [
327
- PgLineSegment.new(0, 0, 0, 0),
328
- PgLineSegment.new(1.2, -2, 1e10, -1e10),
329
- nil
330
- ]
331
- ],
332
- [
333
- ["lseg[]"],
334
- [
335
- [
336
- PgLineSegment.new(0, 0, 0, 0),
337
- PgLineSegment.new(1.2, -2, 1e10, -1e10),
338
- ],
339
- nil
340
- ]
341
- ],
342
- [
343
- ["box"],
344
- [
345
- PgBox.new(0, 0, 0, 0),
346
- PgBox.new(1e10, -2, 1.2, -1e10),
347
- nil
348
- ]
349
- ],
350
- # Can't get this to work, but we don't use box arrays anyhow.
351
- # [
352
- # ["box[]"],
353
- # [
354
- # [
355
- # PgBox.new(0, 0, 0, 0),
356
- # PgBox.new(1.2, -2, 1e10, -1e10),
357
- # ],
358
- # nil
359
- # ]
360
- # ],
361
- [
362
- ["path"],
363
- [
364
- PgPath.new(false, PgPoint.new(1, 2)),
365
- PgPath.new(true, PgPoint.new(1, 2), PgPoint.new(3, 4)),
366
- nil,
367
- ]
368
- ],
369
- [
370
- ["path[]"],
371
- [
372
- [
373
- PgPath.new(false, PgPoint.new(1, 2)),
374
- PgPath.new(true, PgPoint.new(1, 2), PgPoint.new(3, 4)),
375
- ],
376
- nil
377
- ]
378
- ],
379
- [
380
- ["polygon"],
381
- [
382
- PgPolygon.new(PgPoint.new(1, 2)),
383
- PgPolygon.new(PgPoint.new(1, 2), PgPoint.new(3, 4)),
384
- nil,
385
- ]
386
- ],
387
- [
388
- ["polygon[]"],
389
- [
390
- [
391
- PgPolygon.new(PgPoint.new(1, 2)),
392
- PgPolygon.new(PgPoint.new(1, 2), PgPoint.new(3, 4)),
393
- ],
394
- nil
395
- ]
396
- ],
397
- [
398
- ["circle"],
399
- [
400
- PgCircle.new(0, 0, 0),
401
- PgCircle.new(1, 2, 3),
402
- nil,
403
- ]
404
- ],
405
- [
406
- ["circle[]"],
407
- [
408
- [
409
- PgCircle.new(0, 0, 0),
410
- PgCircle.new(1, 2, 3),
411
- ],
412
- nil,
413
- ]
414
- ],
415
- [
416
- ["bit varying", "bit varying(6)"],
417
- [
418
- PgBit.new,
419
- PgBit.new("0"),
420
- PgBit.new("010101"),
421
- nil
422
- ]
423
- ],
424
- [
425
- ["bit varying[]", "bit varying(6)[]"],
426
- [
427
- [
428
- PgBit.new,
429
- PgBit.new("0"),
430
- PgBit.new("010101"),
431
- ],
432
- nil
433
- ]
434
- ],
435
- [
436
- ["bit(1)", "bit"],
437
- [
438
- PgBit.new("1"),
439
- PgBit.new("0"),
440
- nil
441
- ]
442
- ],
443
- [
444
- ["bit(1)[]", "bit[]"],
445
- [
446
- [
447
- PgBit.new("1"),
448
- PgBit.new("0"),
449
- ],
450
- nil
451
- ]
452
- ],
453
- [
454
- ["inet"],
455
- [
456
- PgInet.new("0.0.0.0/0"),
457
- {
458
- 'in'=>PgInet.new("255.255.255.255/32"),
459
- 'out'=>PgInet.new("255.255.255.255"),
460
- },
461
- PgInet.new("255.255.255.255"),
462
- PgInet.new("1.2.0.0/16"),
463
- nil
464
- ],
465
- ],
466
- [
467
- ["inet[]"],
468
- [
469
- [
470
- PgInet.new("255.255.255.255"),
471
- PgInet.new("1.2.0.0/16")
472
- ],
473
- nil,
474
- ],
475
- ],
476
- [
477
- ["cidr"],
478
- [
479
- PgCidr.new("0.0.0.0/0"),
480
- PgCidr.new("255.255.255.255/32"),
481
- PgCidr.new("1.2.0.0/16"),
482
- nil,
483
- ],
484
- ],
485
- [
486
- ["cidr[]"],
487
- [
488
- [
489
- PgCidr.new("0.0.0.0/0"),
490
- PgCidr.new("255.255.255.255/32")
491
- ],
492
- nil,
493
- ],
494
- ],
495
- [
496
- ["macaddr"],
497
- [
498
- PgMacAddr.new("08:00:2b:01:02:03"),
499
- PgMacAddr.new("00:00:00:00:00:00"),
500
- nil,
501
- ]
502
- ],
503
- [
504
- ["macaddr[]"],
505
- [
506
- [
507
- PgMacAddr.new("08:00:2b:01:02:03"),
508
- PgMacAddr.new("00:00:00:00:00:00"),
509
- ],
510
- nil,
511
- ]
512
- ],
513
- ]
514
- makeTestConnection do |connection|
515
- connection.exec("set client_min_messages = 'warning'")
516
- for testCase in testCases
517
- columnTypes, values = *testCase
518
- for columnType in columnTypes
519
- assertInfo("For column type #{columnType}") do
520
- connection.exec("create temporary table #{table1} "\
521
- "(v #{columnType})")
522
- for value in values
523
- assertInfo("For value #{value.inspect}") do
524
- if value.is_a?(Hash)
525
- value_in = value['in']
526
- value_out = value['out']
527
- else
528
- value_in = value
529
- value_out = value
530
- end
531
- connection.exec("delete from #{table1}")
532
- insert = Insert.new(table1, connection)
533
- case columnType
534
- when 'bytea[]'
535
- insert.insert_bytea_array('v', value_in)
536
- when /\[\]/
537
- insert.insert_array('v', value_in)
538
- when '"char"'
539
- insert.insert_qchar('v', value_in)
540
- when 'bytea'
541
- insert.insert_bytea('v', value_in)
542
- else
543
- insert.insert('v', value_in)
544
- end
545
- insert.exec
546
- select = Select.new(connection)
547
- select.select('v')
548
- select.from(table1)
549
- result = select.exec[0]['v']
550
- if result.respond_to?(:encoding)
551
- result = result.force_encoding('ASCII-8BIT')
552
- end
553
- assertEquals(result, value_out)
554
- end
555
- end
556
- connection.exec("drop table #{table1}")
557
- end
558
- end
559
- end
560
- end
561
- end
562
-
563
- end
564
-
565
- RoundTripTest.new.run if $0 == __FILE__