do_postgres 0.10.7-x86-mswin32-60 → 0.10.8-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.markdown +5 -0
- data/ext/do_postgres/do_common.c +10 -53
- data/ext/do_postgres/do_postgres.c +11 -3
- data/lib/do_postgres/1.8/do_postgres.so +0 -0
- data/lib/do_postgres/1.9/do_postgres.so +0 -0
- data/lib/do_postgres/version.rb +1 -1
- data/spec/typecast/date_spec.rb +24 -0
- data/tasks/compile.rake +1 -1
- data/tasks/spec.rake +0 -1
- metadata +13 -13
data/ChangeLog.markdown
CHANGED
data/ext/do_postgres/do_common.c
CHANGED
@@ -53,9 +53,10 @@ VALUE data_objects_const_get(VALUE scope, const char *constant) {
|
|
53
53
|
void data_objects_debug(VALUE connection, VALUE string, struct timeval *start) {
|
54
54
|
struct timeval stop;
|
55
55
|
VALUE message;
|
56
|
+
do_int64 duration;
|
56
57
|
|
57
58
|
gettimeofday(&stop, NULL);
|
58
|
-
|
59
|
+
duration = (stop.tv_sec - start->tv_sec) * 1000000 + stop.tv_usec - start->tv_usec;
|
59
60
|
|
60
61
|
message = rb_funcall(cDO_Logger_Message, ID_NEW, 3, string, rb_time_new(start->tv_sec, start->tv_usec), INT2NUM(duration));
|
61
62
|
|
@@ -65,6 +66,7 @@ void data_objects_debug(VALUE connection, VALUE string, struct timeval *start) {
|
|
65
66
|
void data_objects_raise_error(VALUE self, const struct errcodes *errors, int errnum, const char *message, VALUE query, VALUE state) {
|
66
67
|
const char *exception_type = "SQLError";
|
67
68
|
const struct errcodes *e;
|
69
|
+
VALUE uri, exception;
|
68
70
|
|
69
71
|
for (e = errors; e->error_name; e++) {
|
70
72
|
if (e->error_no == errnum) {
|
@@ -74,9 +76,9 @@ void data_objects_raise_error(VALUE self, const struct errcodes *errors, int err
|
|
74
76
|
}
|
75
77
|
}
|
76
78
|
|
77
|
-
|
79
|
+
uri = rb_funcall(rb_iv_get(self, "@connection"), rb_intern("to_s"), 0);
|
78
80
|
|
79
|
-
|
81
|
+
exception = rb_funcall(
|
80
82
|
data_objects_const_get(mDO, exception_type),
|
81
83
|
ID_NEW,
|
82
84
|
5,
|
@@ -116,8 +118,8 @@ void data_objects_assert_file_exists(char *file, const char *message) {
|
|
116
118
|
}
|
117
119
|
|
118
120
|
VALUE data_objects_build_query_from_args(VALUE klass, int count, VALUE *args) {
|
119
|
-
VALUE array = rb_ary_new();
|
120
121
|
int i;
|
122
|
+
VALUE array = rb_ary_new();
|
121
123
|
|
122
124
|
for (i = 0; i < count; i++) {
|
123
125
|
rb_ary_push(array, args[i]);
|
@@ -176,8 +178,6 @@ VALUE data_objects_timezone_to_offset(int hour_offset, int minute_offset) {
|
|
176
178
|
VALUE data_objects_parse_date(const char *date) {
|
177
179
|
static char const *const _fmt_date = "%4d-%2d-%2d";
|
178
180
|
int year = 0, month = 0, day = 0;
|
179
|
-
int jd, ajd;
|
180
|
-
VALUE rational;
|
181
181
|
|
182
182
|
switch (sscanf(date, _fmt_date, &year, &month, &day)) {
|
183
183
|
case 0:
|
@@ -185,16 +185,7 @@ VALUE data_objects_parse_date(const char *date) {
|
|
185
185
|
return Qnil;
|
186
186
|
}
|
187
187
|
|
188
|
-
#ifdef HAVE_NO_DATETIME_NEWBANG
|
189
188
|
return rb_funcall(rb_cDate, ID_NEW, 3, INT2NUM(year), INT2NUM(month), INT2NUM(day));
|
190
|
-
#else
|
191
|
-
|
192
|
-
jd = data_objects_jd_from_date(year, month, day);
|
193
|
-
ajd = (jd * 2) - 1; // Math from Date.jd_to_ajd
|
194
|
-
rational = rb_funcall(rb_mKernel, ID_RATIONAL, 2, INT2NUM(ajd), INT2NUM(2));
|
195
|
-
|
196
|
-
return rb_funcall(rb_cDate, ID_NEW_DATE, 3, rational, INT2NUM(0), INT2NUM(2299161));
|
197
|
-
#endif
|
198
189
|
}
|
199
190
|
|
200
191
|
VALUE data_objects_parse_time(const char *date) {
|
@@ -224,10 +215,9 @@ VALUE data_objects_parse_date_time(const char *date) {
|
|
224
215
|
int tokens_read;
|
225
216
|
const char *fmt_datetime;
|
226
217
|
|
227
|
-
VALUE
|
218
|
+
VALUE offset;
|
228
219
|
|
229
|
-
int year, month, day, hour, min, sec, hour_offset, minute_offset
|
230
|
-
do_int64 num, den;
|
220
|
+
int year, month, day, hour, min, sec, hour_offset, minute_offset;
|
231
221
|
|
232
222
|
struct tm timeinfo;
|
233
223
|
time_t target_time;
|
@@ -304,40 +294,9 @@ VALUE data_objects_parse_date_time(const char *date) {
|
|
304
294
|
rb_raise(eDataError, "Couldn't parse date: %s", date);
|
305
295
|
}
|
306
296
|
|
307
|
-
#ifdef HAVE_NO_DATETIME_NEWBANG
|
308
297
|
offset = data_objects_timezone_to_offset(hour_offset, minute_offset);
|
309
298
|
return rb_funcall(rb_cDateTime, ID_NEW, 7, INT2NUM(year), INT2NUM(month), INT2NUM(day),
|
310
299
|
INT2NUM(hour), INT2NUM(min), INT2NUM(sec), offset);
|
311
|
-
#else
|
312
|
-
jd = data_objects_jd_from_date(year, month, day);
|
313
|
-
|
314
|
-
/*
|
315
|
-
* Generate ajd with fractional days for the time.
|
316
|
-
* Extracted from Date#jd_to_ajd, Date#day_fraction_to_time, and Rational#+ and #-.
|
317
|
-
*
|
318
|
-
* TODO: These are 64bit numbers; is reduce() really necessary?
|
319
|
-
*/
|
320
|
-
|
321
|
-
num = (hour * 1440) + (min * 24);
|
322
|
-
num -= (hour_offset * 1440) + (minute_offset * 24);
|
323
|
-
den = (24 * 1440);
|
324
|
-
data_objects_reduce(&num, &den);
|
325
|
-
|
326
|
-
num = (num * 86400) + (sec * den);
|
327
|
-
den = den * 86400;
|
328
|
-
data_objects_reduce(&num, &den);
|
329
|
-
|
330
|
-
num += jd * den;
|
331
|
-
|
332
|
-
num = (num * 2) - den;
|
333
|
-
den *= 2;
|
334
|
-
data_objects_reduce(&num, &den);
|
335
|
-
|
336
|
-
ajd = rb_funcall(rb_mKernel, ID_RATIONAL, 2, rb_ull2inum(num), rb_ull2inum(den));
|
337
|
-
offset = data_objects_timezone_to_offset(hour_offset, minute_offset);
|
338
|
-
|
339
|
-
return rb_funcall(rb_cDateTime, ID_NEW_DATE, 3, ajd, offset, INT2NUM(2299161));
|
340
|
-
#endif
|
341
300
|
}
|
342
301
|
|
343
302
|
VALUE data_objects_cConnection_character_set(VALUE self) {
|
@@ -371,17 +330,15 @@ VALUE data_objects_cConnection_quote_date(VALUE self, VALUE value) {
|
|
371
330
|
* into Ruby-strings so we can easily typecast later
|
372
331
|
*/
|
373
332
|
VALUE data_objects_cCommand_set_types(int argc, VALUE *argv, VALUE self) {
|
333
|
+
VALUE entry, sub_entry;
|
334
|
+
int i, j;
|
374
335
|
VALUE type_strings = rb_ary_new();
|
375
336
|
VALUE array = rb_ary_new();
|
376
337
|
|
377
|
-
int i, j;
|
378
|
-
|
379
338
|
for (i = 0; i < argc; i++) {
|
380
339
|
rb_ary_push(array, argv[i]);
|
381
340
|
}
|
382
341
|
|
383
|
-
VALUE entry, sub_entry;
|
384
|
-
|
385
342
|
for (i = 0; i < RARRAY_LEN(array); i++) {
|
386
343
|
entry = rb_ary_entry(array, i);
|
387
344
|
|
@@ -610,7 +610,15 @@ VALUE do_postgres_cReader_close(VALUE self) {
|
|
610
610
|
}
|
611
611
|
|
612
612
|
VALUE do_postgres_cReader_next(VALUE self) {
|
613
|
-
|
613
|
+
|
614
|
+
VALUE reader = rb_iv_get(self, "@reader");
|
615
|
+
|
616
|
+
if(reader == Qnil) {
|
617
|
+
rb_raise(eConnectionError, "This result set has already been closed.");
|
618
|
+
return Qfalse;
|
619
|
+
}
|
620
|
+
|
621
|
+
PGresult *pg_reader = DATA_PTR(reader);
|
614
622
|
|
615
623
|
int row_count = NUM2INT(rb_iv_get(self, "@row_count"));
|
616
624
|
int field_count = NUM2INT(rb_iv_get(self, "@field_count"));
|
@@ -642,8 +650,8 @@ VALUE do_postgres_cReader_next(VALUE self) {
|
|
642
650
|
field_type = rb_ary_entry(field_types, i);
|
643
651
|
|
644
652
|
// Always return nil if the value returned from Postgres is null
|
645
|
-
if (!PQgetisnull(
|
646
|
-
value = do_postgres_typecast(PQgetvalue(
|
653
|
+
if (!PQgetisnull(pg_reader, position, i)) {
|
654
|
+
value = do_postgres_typecast(PQgetvalue(pg_reader, position, i), PQgetlength(pg_reader, position, i), field_type, enc);
|
647
655
|
}
|
648
656
|
else {
|
649
657
|
value = Qnil;
|
Binary file
|
Binary file
|
data/lib/do_postgres/version.rb
CHANGED
data/spec/typecast/date_spec.rb
CHANGED
@@ -6,4 +6,28 @@ require 'data_objects/spec/shared/typecast/date_spec'
|
|
6
6
|
describe 'DataObjects::Postgres with Date' do
|
7
7
|
it_should_behave_like 'supporting Date'
|
8
8
|
it_should_behave_like 'supporting Date autocasting'
|
9
|
+
|
10
|
+
describe 'exotic dates' do
|
11
|
+
|
12
|
+
before do
|
13
|
+
@connection = DataObjects::Connection.new(CONFIG.uri)
|
14
|
+
@connection.create_command("INSERT INTO widgets (release_date) VALUES ('0001-01-01')").execute_non_query
|
15
|
+
|
16
|
+
@command = @connection.create_command("SELECT release_date FROM widgets WHERE release_date = '0001-01-01'")
|
17
|
+
@reader = @command.execute_reader
|
18
|
+
@reader.next!
|
19
|
+
@values = @reader.values
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
@reader.close
|
24
|
+
@connection.close
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return the number of created rows' do
|
28
|
+
@values.first.should == Date.civil(1, 1, 1)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
9
33
|
end
|
data/tasks/compile.rake
CHANGED
data/tasks/spec.rake
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: do_postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 39
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 10
|
9
|
-
-
|
10
|
-
version: 0.10.
|
9
|
+
- 8
|
10
|
+
version: 0.10.8
|
11
11
|
platform: x86-mswin32-60
|
12
12
|
authors:
|
13
13
|
- Dirkjan Bussink
|
@@ -18,23 +18,23 @@ cert_chain: []
|
|
18
18
|
date: 2011-03-29 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
22
|
none: false
|
23
23
|
requirements:
|
24
24
|
- - "="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
hash:
|
26
|
+
hash: 39
|
27
27
|
segments:
|
28
28
|
- 0
|
29
29
|
- 10
|
30
|
-
-
|
31
|
-
version: 0.10.
|
32
|
-
version_requirements: *id001
|
30
|
+
- 8
|
31
|
+
version: 0.10.8
|
33
32
|
name: data_objects
|
34
33
|
prerelease: false
|
35
34
|
type: :runtime
|
35
|
+
requirement: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
39
39
|
requirements:
|
40
40
|
- - ~>
|
@@ -44,12 +44,12 @@ dependencies:
|
|
44
44
|
- 2
|
45
45
|
- 5
|
46
46
|
version: "2.5"
|
47
|
-
version_requirements: *id002
|
48
47
|
name: rspec
|
49
48
|
prerelease: false
|
50
49
|
type: :development
|
50
|
+
requirement: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ~>
|
@@ -59,10 +59,10 @@ dependencies:
|
|
59
59
|
- 0
|
60
60
|
- 7
|
61
61
|
version: "0.7"
|
62
|
-
version_requirements: *id003
|
63
62
|
name: rake-compiler
|
64
63
|
prerelease: false
|
65
64
|
type: :development
|
65
|
+
requirement: *id003
|
66
66
|
description: Implements the DataObjects API for PostgreSQL
|
67
67
|
email: d.bussink@gmail.com
|
68
68
|
executables: []
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
requirements: []
|
173
173
|
|
174
174
|
rubyforge_project: dorb
|
175
|
-
rubygems_version: 1.8.
|
175
|
+
rubygems_version: 1.8.14
|
176
176
|
signing_key:
|
177
177
|
specification_version: 3
|
178
178
|
summary: DataObjects PostgreSQL Driver
|