do_postgres 0.9.10.1 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/LICENSE +1 -1
- data/Manifest.txt +0 -1
- data/Rakefile +38 -16
- data/buildfile +5 -4
- data/ext/do_postgres_ext/do_postgres_ext.c +27 -13
- data/ext/do_postgres_ext/extconf.rb +7 -2
- data/lib/do_postgres.rb +8 -1
- data/lib/do_postgres/version.rb +1 -1
- data/spec/integration/do_postgres_spec.rb +44 -5
- data/spec/integration/logging_spec.rb +5 -3
- data/spec/integration/quoting_spec.rb +17 -15
- data/spec/integration/timezone_spec.rb +6 -1
- data/spec/spec_helper.rb +1 -1
- metadata +7 -8
- data/TODO +0 -4
data/History.txt
CHANGED
data/LICENSE
CHANGED
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -9,8 +9,8 @@ JRUBY = RUBY_PLATFORM =~ /java/
|
|
9
9
|
WINDOWS = Gem.win_platform?
|
10
10
|
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
|
11
11
|
|
12
|
-
AUTHOR = "
|
13
|
-
EMAIL = "
|
12
|
+
AUTHOR = "Dirkjan Bussink"
|
13
|
+
EMAIL = "d.bussink@gmail.com"
|
14
14
|
GEM_NAME = "do_postgres"
|
15
15
|
GEM_VERSION = DataObjects::Postgres::VERSION
|
16
16
|
GEM_DEPENDENCIES = if JRUBY
|
@@ -18,32 +18,54 @@ GEM_DEPENDENCIES = if JRUBY
|
|
18
18
|
else
|
19
19
|
[["data_objects", GEM_VERSION]]
|
20
20
|
end
|
21
|
-
GEM_CLEAN = ['**/*.{o,so,bundle,log,a,gem,dSYM,obj,pdb,lib,def,exp,DS_Store}',
|
22
|
-
|
21
|
+
GEM_CLEAN = ['**/*.{o,so,bundle,jar,log,a,gem,dSYM,obj,pdb,lib,def,exp,DS_Store}',
|
22
|
+
'ext/Makefile', 'ext-java/target']
|
23
|
+
GEM_EXTRAS = if JRUBY
|
24
|
+
{
|
25
|
+
:has_rdoc => false,
|
26
|
+
:platform => 'java'
|
27
|
+
}
|
28
|
+
else
|
29
|
+
{
|
30
|
+
:has_rdoc => false,
|
31
|
+
:extensions => 'ext/do_postgres_ext/extconf.rb'
|
32
|
+
}
|
33
|
+
end
|
23
34
|
|
24
35
|
PROJECT_NAME = "dorb"
|
25
36
|
PROJECT_URL = "http://rubyforge.org/projects/dorb"
|
26
|
-
PROJECT_DESCRIPTION = PROJECT_SUMMARY = "A DataObject.rb driver for
|
37
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY = "A DataObject.rb driver for PostgreSQL"
|
27
38
|
|
28
|
-
JAVA_DRIVER = true
|
29
39
|
|
30
40
|
# RCov is run by default, except on the JRuby platform, or if NO_RCOV env is true
|
31
41
|
RUN_RCOV = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
|
32
42
|
|
33
43
|
if (tasks_dir = ROOT.parent + 'tasks').directory?
|
34
44
|
require tasks_dir + 'hoe'
|
45
|
+
require tasks_dir + 'ext_helper_java'
|
46
|
+
|
47
|
+
setup_java_extension "#{GEM_NAME}_ext", HOE.spec
|
48
|
+
end
|
49
|
+
|
50
|
+
if JRUBY
|
51
|
+
HOE.spec.files += ['lib/do_postgres_ext.jar']
|
52
|
+
HOE.spec.require_paths = Dir['lib']
|
35
53
|
end
|
36
54
|
|
37
55
|
# compile the extension
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
56
|
+
if JRUBY
|
57
|
+
Rake::Task['compile:jruby'].invoke
|
58
|
+
else
|
59
|
+
begin
|
60
|
+
gem('rake-compiler')
|
61
|
+
require 'rake/extensiontask'
|
62
|
+
Rake::ExtensionTask.new('do_postgres_ext', HOE.spec)
|
63
|
+
rescue LoadError
|
64
|
+
warn "To cross-compile, install rake-compiler (gem install rake-compiler)"
|
65
|
+
if tasks_dir.directory?
|
66
|
+
require tasks_dir + 'ext_helper'
|
67
|
+
setup_c_extension('do_postgres_ext', HOE.spec)
|
68
|
+
end
|
47
69
|
end
|
48
70
|
end
|
49
71
|
|
@@ -68,7 +90,7 @@ desc 'Run specifications'
|
|
68
90
|
Spec::Rake::SpecTask.new(:spec) do |t|
|
69
91
|
t.spec_opts << '--format' << 'specdoc' << '--colour'
|
70
92
|
t.spec_opts << '--loadby' << 'random'
|
71
|
-
t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb')
|
93
|
+
t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb').map { |f| f.to_s }
|
72
94
|
|
73
95
|
begin
|
74
96
|
t.rcov = RUN_RCOV
|
data/buildfile
CHANGED
@@ -1,26 +1,27 @@
|
|
1
|
-
# Apache Buildr buildfile for
|
1
|
+
# Apache Buildr buildfile for do_postgres
|
2
2
|
# see http://incubator.apache.org/buildr/ for more information on Apache Buildr
|
3
3
|
require 'buildr'
|
4
4
|
require 'pathname'
|
5
5
|
|
6
6
|
VERSION_NUMBER = '1.0'
|
7
7
|
JDBC_SUPPORT = ['data_objects:jdbc:jar:1.0']
|
8
|
+
TARGET_DIR = 'pkg/classes'
|
8
9
|
repositories.remote << 'http://www.ibiblio.org/maven2/'
|
9
10
|
|
10
11
|
define 'do_postgres' do
|
11
12
|
project.version = VERSION_NUMBER
|
12
13
|
project.group = 'data_objects.rb'
|
13
14
|
|
14
|
-
manifest['Copyright'] = 'Alex Coles (C) 2008'
|
15
|
+
manifest['Copyright'] = 'Alex Coles (C) 2008-2009'
|
15
16
|
|
16
17
|
compile.using :target => '1.5', :lint => 'all', :deprecation => 'true'
|
17
18
|
|
18
19
|
define 'ext-java' do
|
19
|
-
package
|
20
|
+
package(:jar).clean.include(TARGET_DIR)
|
20
21
|
|
21
22
|
jdbc_support_jar = file('../../do_jdbc/lib/do_jdbc_internal.jar')
|
22
23
|
jdbc_support = artifact('data_objects:jdbc:jar:1.0').from(jdbc_support_jar)
|
23
24
|
|
24
|
-
compile.with
|
25
|
+
compile.into(TARGET_DIR).with(JDBC_SUPPORT)
|
25
26
|
end
|
26
27
|
end
|
@@ -10,9 +10,10 @@
|
|
10
10
|
#undef PACKAGE_TARNAME
|
11
11
|
#undef PACKAGE_VERSION
|
12
12
|
#include <ruby.h>
|
13
|
-
#include <version.h>
|
14
13
|
#include <string.h>
|
15
14
|
#include <math.h>
|
15
|
+
#include <ctype.h>
|
16
|
+
#include <time.h>
|
16
17
|
|
17
18
|
#define ID_CONST_GET rb_intern("const_get")
|
18
19
|
#define ID_PATH rb_intern("path")
|
@@ -50,6 +51,7 @@ static ID ID_LOGGER;
|
|
50
51
|
static ID ID_DEBUG;
|
51
52
|
static ID ID_LEVEL;
|
52
53
|
static ID ID_TO_S;
|
54
|
+
static ID ID_RATIONAL;
|
53
55
|
|
54
56
|
static VALUE mDO;
|
55
57
|
static VALUE cDO_Quoting;
|
@@ -60,7 +62,6 @@ static VALUE cDO_Reader;
|
|
60
62
|
|
61
63
|
static VALUE rb_cDate;
|
62
64
|
static VALUE rb_cDateTime;
|
63
|
-
static VALUE rb_cRational;
|
64
65
|
static VALUE rb_cBigDecimal;
|
65
66
|
|
66
67
|
static VALUE mPostgres;
|
@@ -148,7 +149,7 @@ static VALUE parse_date(const char *date) {
|
|
148
149
|
|
149
150
|
// Math from Date.jd_to_ajd
|
150
151
|
ajd = jd * 2 - 1;
|
151
|
-
rational = rb_funcall(
|
152
|
+
rational = rb_funcall(rb_mKernel, ID_RATIONAL, 2, INT2NUM(ajd), INT2NUM(2));
|
152
153
|
|
153
154
|
return rb_funcall(rb_cDate, ID_NEW_DATE, 3, rational, INT2NUM(0), INT2NUM(2299161));
|
154
155
|
}
|
@@ -157,7 +158,7 @@ static VALUE parse_date(const char *date) {
|
|
157
158
|
static VALUE seconds_to_offset(do_int64 num) {
|
158
159
|
do_int64 den = 86400;
|
159
160
|
reduce(&num, &den);
|
160
|
-
return rb_funcall(
|
161
|
+
return rb_funcall(rb_mKernel, ID_RATIONAL, 2, rb_ll2inum(num), rb_ll2inum(den));
|
161
162
|
}
|
162
163
|
|
163
164
|
static VALUE timezone_to_offset(int hour_offset, int minute_offset) {
|
@@ -251,7 +252,7 @@ static VALUE parse_date_time(const char *date) {
|
|
251
252
|
|
252
253
|
reduce(&num, &den);
|
253
254
|
|
254
|
-
ajd = rb_funcall(
|
255
|
+
ajd = rb_funcall(rb_mKernel, ID_RATIONAL, 2, rb_ull2inum(num), rb_ull2inum(den));
|
255
256
|
offset = timezone_to_offset(hour_offset, minute_offset);
|
256
257
|
|
257
258
|
return rb_funcall(rb_cDateTime, ID_NEW_DATE, 3, ajd, offset, INT2NUM(2299161));
|
@@ -315,10 +316,10 @@ static VALUE infer_ruby_type(Oid type) {
|
|
315
316
|
return rb_str_new2(ruby_type);
|
316
317
|
}
|
317
318
|
|
318
|
-
static VALUE typecast(char *value, long length, char *type) {
|
319
|
+
static VALUE typecast(char *value, long length, const char *type) {
|
319
320
|
|
320
321
|
if ( strcmp(type, "Class") == 0) {
|
321
|
-
return rb_funcall(
|
322
|
+
return rb_funcall(rb_cObject, rb_intern("full_const_get"), 1, TAINTED_STRING(value, length));
|
322
323
|
} else if ( strcmp(type, "Integer") == 0 || strcmp(type, "Fixnum") == 0 || strcmp(type, "Bignum") == 0 ) {
|
323
324
|
return rb_cstr2inum(value, 10);
|
324
325
|
} else if ( strcmp(type, "Float") == 0 ) {
|
@@ -458,7 +459,7 @@ static VALUE cConnection_initialize(VALUE self, VALUE uri) {
|
|
458
459
|
PGconn *db;
|
459
460
|
|
460
461
|
r_host = rb_funcall(uri, rb_intern("host"), 0);
|
461
|
-
if ( Qnil != r_host
|
462
|
+
if ( Qnil != r_host ) {
|
462
463
|
host = StringValuePtr(r_host);
|
463
464
|
}
|
464
465
|
|
@@ -632,7 +633,7 @@ static VALUE cCommand_execute_reader(int argc, VALUE *argv[], VALUE self) {
|
|
632
633
|
field_names = rb_ary_new();
|
633
634
|
field_types = rb_iv_get(self, "@field_types");
|
634
635
|
|
635
|
-
if ( field_types == Qnil ||
|
636
|
+
if ( field_types == Qnil || RARRAY_LEN(field_types) == 0 ) {
|
636
637
|
field_types = rb_ary_new();
|
637
638
|
infer_types = 1;
|
638
639
|
}
|
@@ -677,7 +678,7 @@ static VALUE cReader_next(VALUE self) {
|
|
677
678
|
int i;
|
678
679
|
int position;
|
679
680
|
|
680
|
-
char *type
|
681
|
+
const char *type;
|
681
682
|
|
682
683
|
VALUE array = rb_ary_new();
|
683
684
|
VALUE field_types, ruby_type;
|
@@ -693,7 +694,7 @@ static VALUE cReader_next(VALUE self) {
|
|
693
694
|
}
|
694
695
|
|
695
696
|
for ( i = 0; i < field_count; i++ ) {
|
696
|
-
ruby_type =
|
697
|
+
ruby_type = RARRAY_PTR(field_types)[i];
|
697
698
|
|
698
699
|
if ( TYPE(ruby_type) == T_STRING ) {
|
699
700
|
type = StringValuePtr(ruby_type);
|
@@ -735,6 +736,13 @@ static VALUE cReader_fields(VALUE self) {
|
|
735
736
|
return rb_iv_get(self, "@fields");
|
736
737
|
}
|
737
738
|
|
739
|
+
static VALUE cReader_field_count(VALUE self) {
|
740
|
+
return rb_iv_get(self, "@field_count");
|
741
|
+
}
|
742
|
+
static VALUE cReader_row_count(VALUE self) {
|
743
|
+
return rb_iv_get(self, "@row_count");
|
744
|
+
}
|
745
|
+
|
738
746
|
void Init_do_postgres_ext() {
|
739
747
|
rb_require("date");
|
740
748
|
rb_require("bigdecimal");
|
@@ -743,16 +751,20 @@ void Init_do_postgres_ext() {
|
|
743
751
|
rb_cDate = CONST_GET(rb_mKernel, "Date");
|
744
752
|
rb_cDateTime = CONST_GET(rb_mKernel, "DateTime");
|
745
753
|
rb_cTime = CONST_GET(rb_mKernel, "Time");
|
746
|
-
rb_cRational = CONST_GET(rb_mKernel, "Rational");
|
747
754
|
rb_cBigDecimal = CONST_GET(rb_mKernel, "BigDecimal");
|
748
755
|
|
749
756
|
rb_funcall(rb_mKernel, rb_intern("require"), 1, rb_str_new2("data_objects"));
|
750
757
|
|
751
|
-
|
758
|
+
#ifdef RUBY_LESS_THAN_186
|
759
|
+
ID_NEW_DATE = rb_intern("new0");
|
760
|
+
#else
|
761
|
+
ID_NEW_DATE = rb_intern("new!");
|
762
|
+
#endif
|
752
763
|
ID_LOGGER = rb_intern("logger");
|
753
764
|
ID_DEBUG = rb_intern("debug");
|
754
765
|
ID_LEVEL = rb_intern("level");
|
755
766
|
ID_TO_S = rb_intern("to_s");
|
767
|
+
ID_RATIONAL = rb_intern("Rational");
|
756
768
|
|
757
769
|
// Get references to the DataObjects module and its classes
|
758
770
|
mDO = CONST_GET(rb_mKernel, "DataObjects");
|
@@ -784,5 +796,7 @@ void Init_do_postgres_ext() {
|
|
784
796
|
rb_define_method(cReader, "next!", cReader_next, 0);
|
785
797
|
rb_define_method(cReader, "values", cReader_values, 0);
|
786
798
|
rb_define_method(cReader, "fields", cReader_fields, 0);
|
799
|
+
rb_define_method(cReader, "row_count", cReader_row_count, 0);
|
800
|
+
rb_define_method(cReader, "field_count", cReader_field_count, 0);
|
787
801
|
|
788
802
|
}
|
@@ -28,8 +28,8 @@ def have_build_env
|
|
28
28
|
have_header('catalog/pg_type.h')
|
29
29
|
end
|
30
30
|
|
31
|
-
dir_config('pgsql', config_value('includedir-server'), config_value('libdir'))
|
32
|
-
dir_config('pgsql', config_value('includedir'), config_value('libdir'))
|
31
|
+
dir_config('pgsql-server', config_value('includedir-server'), config_value('libdir'))
|
32
|
+
dir_config('pgsql-client', config_value('includedir'), config_value('libdir'))
|
33
33
|
|
34
34
|
required_libraries = []
|
35
35
|
desired_functions = %w(PQsetClientEncoding pg_encoding_to_char PQfreemem)
|
@@ -39,6 +39,11 @@ if have_build_env
|
|
39
39
|
required_libraries.each(&method(:have_library))
|
40
40
|
desired_functions.each(&method(:have_func))
|
41
41
|
$CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/
|
42
|
+
|
43
|
+
if RUBY_VERSION < '1.8.6'
|
44
|
+
$CFLAGS << ' -DRUBY_LESS_THAN_186'
|
45
|
+
end
|
46
|
+
|
42
47
|
create_makefile("do_postgres_ext")
|
43
48
|
else
|
44
49
|
puts 'Could not find PostgreSQL build environment (libraries & headers): Makefile not created'
|
data/lib/do_postgres.rb
CHANGED
@@ -7,7 +7,7 @@ if RUBY_PLATFORM =~ /java/
|
|
7
7
|
require 'jdbc/postgres' # the JDBC driver, packaged as a gem
|
8
8
|
end
|
9
9
|
|
10
|
-
require
|
10
|
+
require 'do_postgres_ext'
|
11
11
|
require File.expand_path(File.join(File.dirname(__FILE__), 'do_postgres', 'version'))
|
12
12
|
require File.expand_path(File.join(File.dirname(__FILE__), 'do_postgres', 'transaction'))
|
13
13
|
|
@@ -23,6 +23,13 @@ if RUBY_PLATFORM =~ /java/
|
|
23
23
|
def self.pool_size
|
24
24
|
20
|
25
25
|
end
|
26
|
+
|
27
|
+
def character_set
|
28
|
+
# JDBC API does not provide an easy way to get the current character set
|
29
|
+
# For now, we code the character_set used as utf8
|
30
|
+
"utf8"
|
31
|
+
end
|
32
|
+
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
data/lib/do_postgres/version.rb
CHANGED
@@ -25,6 +25,7 @@ describe "DataObjects::Postgres::Connection" do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should be able to send queries asynchronously in parallel" do
|
28
|
+
pending "Asynchronous queries behaving oddly in JRuby" if JRUBY
|
28
29
|
threads = []
|
29
30
|
|
30
31
|
start = Time.now
|
@@ -129,18 +130,38 @@ describe "DataObjects::Postgres::Reader" do
|
|
129
130
|
lambda { command.execute_reader }.should raise_error
|
130
131
|
end
|
131
132
|
|
132
|
-
it "should open and close a reader" do
|
133
|
+
it "should open and close a reader with given types of columns" do
|
134
|
+
command = @connection.create_command("SELECT id, name FROM users LIMIT 3")
|
135
|
+
command.set_types [Integer, String ]
|
136
|
+
reader = command.execute_reader
|
137
|
+
reader.close.should == true
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should open and close a reader without given types of columns" do
|
133
141
|
command = @connection.create_command("SELECT * FROM users LIMIT 3")
|
134
|
-
command.set_types [Integer, String]
|
135
142
|
reader = command.execute_reader
|
143
|
+
reader.close.should == true
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should raise error on wrong number of columns calling set_types" do
|
147
|
+
pending "C-extension does not raise an error on encountering wrong number of columns" unless JRUBY
|
148
|
+
command = @connection.create_command("SELECT * FROM users LIMIT 3")
|
149
|
+
command.set_types [Integer, String]
|
150
|
+
lambda { reader = command.execute_reader }.should raise_error
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should return proper number of rows and fields using row_count and field_count" do
|
154
|
+
pending "do_jdbc doesn't return correctly row_count at the moment" if JRUBY
|
155
|
+
command = @connection.create_command("SELECT id, name, registered, money FROM users ORDER BY id DESC LIMIT 3")
|
156
|
+
reader = command.execute_reader
|
157
|
+
reader.field_count.should == 4
|
158
|
+
reader.row_count.should == 3
|
136
159
|
reader.close
|
137
160
|
end
|
138
161
|
|
139
162
|
it "should typecast a value from the postgres type" do
|
140
163
|
command = @connection.create_command("SELECT id, name, registered, money FROM users ORDER BY id DESC LIMIT 3")
|
141
164
|
reader = command.execute_reader
|
142
|
-
reader.send(:instance_variable_get, "@field_count").should == 4
|
143
|
-
reader.send(:instance_variable_get, "@row_count").should == 3
|
144
165
|
while ( reader.next!)
|
145
166
|
reader.values[0].should be_a_kind_of(Integer)
|
146
167
|
reader.values[1].should be_a_kind_of(String)
|
@@ -167,6 +188,16 @@ describe "DataObjects::Postgres::Reader" do
|
|
167
188
|
end
|
168
189
|
end
|
169
190
|
|
191
|
+
it "should return nil when the time is 0" do
|
192
|
+
pending "We need to introduce something like Proxy for typeasting where each SQL type will have _rules_ of casting" if JRUBY
|
193
|
+
pending "Fix zero representation of Time in PostgreSQL" unless JRUBY
|
194
|
+
id = insert("INSERT INTO users (name, fired_at) VALUES ('James', '0000-00-00')")
|
195
|
+
select("SELECT fired_at FROM users WHERE id = ?", [Time], id) do |reader|
|
196
|
+
reader.values.last.should be_nil
|
197
|
+
end
|
198
|
+
exec("DELETE FROM users WHERE id = ?", id)
|
199
|
+
end
|
200
|
+
|
170
201
|
it "should not convert empty strings to null" do
|
171
202
|
id = insert("INSERT INTO users (name) VALUES ('')")
|
172
203
|
select("SELECT name FROM users WHERE id = ?", [String], id) do |reader|
|
@@ -191,11 +222,19 @@ describe "DataObjects::Postgres::Reader" do
|
|
191
222
|
end
|
192
223
|
end
|
193
224
|
|
225
|
+
it "should return DateTimes using the current locale's Time Zone" do
|
226
|
+
date = DateTime.now
|
227
|
+
id = insert("INSERT INTO users (name, created_at) VALUES (?, ?)", 'Sam', date)
|
228
|
+
select("SELECT created_at FROM users WHERE id = ?", [DateTime], id) do |reader|
|
229
|
+
reader.values.last.to_s.should == date.to_s
|
230
|
+
end
|
231
|
+
exec("DELETE FROM users WHERE id = ?", id)
|
232
|
+
end
|
233
|
+
|
194
234
|
it "should typecast a timestamp field" do
|
195
235
|
command = @connection.create_command("SELECT created_at FROM users WHERE created_at is not null LIMIT 1")
|
196
236
|
reader = command.execute_reader
|
197
237
|
reader.next!
|
198
|
-
dt = reader.values[0]
|
199
238
|
reader.values[0].should be_a_kind_of(DateTime)
|
200
239
|
|
201
240
|
command = @connection.create_command("SELECT created_at::date as date FROM users WHERE created_at is not null LIMIT 1")
|
@@ -18,7 +18,7 @@ describe DataObjects::Postgres::Command do
|
|
18
18
|
@mock_logger = mock('MockLogger', :level => 0)
|
19
19
|
DataObjects::Postgres.should_receive(:logger).and_return(@mock_logger)
|
20
20
|
@mock_logger.should_receive(:debug).with(/\([\d.]+\) SELECT \* FROM users/)
|
21
|
-
command.execute_reader
|
21
|
+
command.execute_reader.close
|
22
22
|
end
|
23
23
|
|
24
24
|
it "shouldn't log reader queries when the level isn't Debug (0)" do
|
@@ -26,7 +26,7 @@ describe DataObjects::Postgres::Command do
|
|
26
26
|
@mock_logger = mock('MockLogger', :level => 1)
|
27
27
|
DataObjects::Postgres.should_receive(:logger).and_return(@mock_logger)
|
28
28
|
@mock_logger.should_not_receive(:debug)
|
29
|
-
command.execute_reader
|
29
|
+
command.execute_reader.close
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -35,7 +35,9 @@ describe DataObjects::Postgres::Command do
|
|
35
35
|
command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
|
36
36
|
@mock_logger = mock('MockLogger', :level => 0)
|
37
37
|
DataObjects::Postgres.should_receive(:logger).and_return(@mock_logger)
|
38
|
-
|
38
|
+
# NOTE: debug string on JRuby does not insert quotation marks
|
39
|
+
# on MRI, value is quoted
|
40
|
+
@mock_logger.should_receive(:debug).with(/\([\d.]+\) INSERT INTO users \(name\) VALUES \((\'?)Blah(\'?)\)/)
|
39
41
|
command.execute_non_query('Blah')
|
40
42
|
end
|
41
43
|
|
@@ -1,23 +1,25 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
3
3
|
|
4
|
-
|
4
|
+
unless JRUBY
|
5
|
+
describe DataObjects::Postgres::Command do
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
before(:each) do
|
8
|
+
@connection = DataObjects::Connection.new(DO_POSTGRES_SPEC_URI)
|
9
|
+
@command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
after(:each) do
|
13
|
+
@connection.close
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
it "should properly quote a string" do
|
17
|
+
@command.quote_string("O'Hare").should == "'O''Hare'"
|
18
|
+
@command.quote_string("Willy O'Hare & Johnny O'Toole").should == "'Willy O''Hare & Johnny O''Toole'"
|
19
|
+
@command.quote_string("Billy\\Bob").should == "'Billy\\Bob'"
|
20
|
+
@command.quote_string("The\\Backslasher\\Rises\\Again").should == "'The\\Backslasher\\Rises\\Again'"
|
21
|
+
@command.quote_string("Scott \"The Rage\" Bauer").should == "'Scott \"The Rage\" Bauer'"
|
22
|
+
end
|
22
23
|
|
24
|
+
end
|
23
25
|
end
|
@@ -6,7 +6,7 @@ describe "DataObjects::Postgres::Reader" do
|
|
6
6
|
|
7
7
|
before :all do
|
8
8
|
@connection = ensure_users_table_and_return_connection
|
9
|
-
Time.now.to_s.match(
|
9
|
+
Time.now.to_s.match(/([-+]\d{2})(\d{2})/)
|
10
10
|
@connection.create_command("SET SESSION TIME ZONE INTERVAL '#{$1}:#{$2}' HOUR TO MINUTE").execute_non_query
|
11
11
|
@connection.create_command("INSERT INTO users (name) VALUES ('Test')").execute_non_query
|
12
12
|
@connection.create_command("INSERT INTO users (name) VALUES ('Test')").execute_non_query
|
@@ -20,22 +20,27 @@ describe "DataObjects::Postgres::Reader" do
|
|
20
20
|
it "should return DateTimes using the current locale's Time Zone for TIMESTAMP WITHOUT TIME ZONE fields" do
|
21
21
|
date = DateTime.now
|
22
22
|
id = insert("INSERT INTO users (name, created_at) VALUES (?, ?)", 'Sam', date)
|
23
|
+
|
23
24
|
select("SELECT created_at FROM users WHERE id = ?", [DateTime], id) do |reader|
|
24
25
|
reader.values.last.to_s.should == date.to_s
|
25
26
|
end
|
27
|
+
|
26
28
|
exec("DELETE FROM users WHERE id = ?", id)
|
27
29
|
end
|
28
30
|
|
29
31
|
it "should return DateTimes using the current locale's Time Zone TIMESTAMP WITH TIME ZONE fields" do
|
30
32
|
date = DateTime.now
|
31
33
|
id = insert("INSERT INTO users (name, fired_at) VALUES (?, ?)", 'Sam', date)
|
34
|
+
|
32
35
|
select("SELECT fired_at FROM users WHERE id = ?", [DateTime], id) do |reader|
|
33
36
|
reader.values.last.to_s.should == date.to_s
|
34
37
|
end
|
38
|
+
|
35
39
|
exec("DELETE FROM users WHERE id = ?", id)
|
36
40
|
end
|
37
41
|
|
38
42
|
it "should return DateTimes using the current locale's Time Zone if they were inserted using a different timezone" do
|
43
|
+
pending "We don't support non-local date input yet"
|
39
44
|
now = DateTime.now
|
40
45
|
dates = [
|
41
46
|
now,
|
data/spec/spec_helper.rb
CHANGED
@@ -29,7 +29,7 @@ require 'do_postgres'
|
|
29
29
|
log_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log', 'do.log'))
|
30
30
|
FileUtils.mkdir_p(File.dirname(log_path))
|
31
31
|
|
32
|
-
DataObjects::Postgres.logger = DataObjects::Logger.new(log_path,
|
32
|
+
DataObjects::Postgres.logger = DataObjects::Logger.new(log_path, :debug)
|
33
33
|
|
34
34
|
POSTGRES = OpenStruct.new
|
35
35
|
POSTGRES.user = ENV['DO_PG_USER'] || 'postgres'
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: do_postgres
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Dirkjan Bussink
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-19 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.11
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
@@ -32,9 +32,9 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.8.2
|
34
34
|
version:
|
35
|
-
description: A DataObject.rb driver for
|
35
|
+
description: A DataObject.rb driver for PostgreSQL
|
36
36
|
email:
|
37
|
-
-
|
37
|
+
- d.bussink@gmail.com
|
38
38
|
executables: []
|
39
39
|
|
40
40
|
extensions:
|
@@ -51,7 +51,6 @@ files:
|
|
51
51
|
- Manifest.txt
|
52
52
|
- README.txt
|
53
53
|
- Rakefile
|
54
|
-
- TODO
|
55
54
|
- autobuild.rb
|
56
55
|
- buildfile
|
57
56
|
- ext-java/src/main/java/DoPostgresExtService.java
|
@@ -97,6 +96,6 @@ rubyforge_project: dorb
|
|
97
96
|
rubygems_version: 1.3.1
|
98
97
|
signing_key:
|
99
98
|
specification_version: 2
|
100
|
-
summary: A DataObject.rb driver for
|
99
|
+
summary: A DataObject.rb driver for PostgreSQL
|
101
100
|
test_files: []
|
102
101
|
|