do_postgres 0.9.11 → 0.9.12

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 (47) hide show
  1. data/LICENSE +1 -1
  2. data/Manifest.txt +15 -5
  3. data/Rakefile +7 -121
  4. data/ext/do_postgres_ext/do_postgres_ext.c +245 -108
  5. data/ext/do_postgres_ext/extconf.rb +3 -1
  6. data/lib/do_postgres.rb +5 -2
  7. data/lib/do_postgres/version.rb +1 -1
  8. data/spec/command_spec.rb +9 -0
  9. data/spec/connection_spec.rb +19 -0
  10. data/spec/encoding_spec.rb +8 -0
  11. data/spec/lib/rspec_immediate_feedback_formatter.rb +3 -0
  12. data/spec/reader_spec.rb +8 -0
  13. data/spec/result_spec.rb +86 -0
  14. data/spec/spec_helper.rb +90 -57
  15. data/spec/typecast/array_spec.rb +8 -0
  16. data/spec/typecast/bigdecimal_spec.rb +9 -0
  17. data/spec/typecast/boolean_spec.rb +9 -0
  18. data/spec/typecast/byte_array_spec.rb +8 -0
  19. data/spec/typecast/class_spec.rb +8 -0
  20. data/spec/typecast/date_spec.rb +9 -0
  21. data/spec/typecast/datetime_spec.rb +9 -0
  22. data/spec/typecast/float_spec.rb +9 -0
  23. data/spec/typecast/integer_spec.rb +8 -0
  24. data/spec/typecast/nil_spec.rb +10 -0
  25. data/spec/typecast/range_spec.rb +8 -0
  26. data/spec/typecast/string_spec.rb +8 -0
  27. data/spec/typecast/time_spec.rb +8 -0
  28. data/tasks/gem.rake +61 -0
  29. data/tasks/install.rake +15 -0
  30. data/tasks/native.rake +35 -0
  31. data/tasks/release.rake +75 -0
  32. data/tasks/retrieve.rake +79 -0
  33. data/tasks/spec.rake +18 -0
  34. metadata +72 -44
  35. data/.gitignore +0 -0
  36. data/autobuild.rb +0 -90
  37. data/buildfile +0 -27
  38. data/ext-java/src/main/java/DoPostgresExtService.java +0 -23
  39. data/ext-java/src/main/java/do_postgres/PostgresDriverDefinition.java +0 -12
  40. data/script/timezone_spec_runner.rb +0 -28
  41. data/script/timezones.txt +0 -562
  42. data/spec/integration/do_postgres_spec.rb +0 -312
  43. data/spec/integration/logging_spec.rb +0 -53
  44. data/spec/integration/quoting_spec.rb +0 -25
  45. data/spec/integration/timezone_spec.rb +0 -66
  46. data/spec/spec.opts +0 -2
  47. data/spec/unit/transaction_spec.rb +0 -28
@@ -28,8 +28,11 @@ def have_build_env
28
28
  have_header('catalog/pg_type.h')
29
29
  end
30
30
 
31
+ $CFLAGS << '-UENABLE_NLS -DHAVE_GETTIMEOFDAY -DHAVE_CRYPT' if RUBY_PLATFORM =~ /mswin|mingw/
32
+
31
33
  dir_config('pgsql-server', config_value('includedir-server'), config_value('libdir'))
32
34
  dir_config('pgsql-client', config_value('includedir'), config_value('libdir'))
35
+ dir_config('pgsql-win32') if RUBY_PLATFORM =~ /mswin|mingw/
33
36
 
34
37
  required_libraries = []
35
38
  desired_functions = %w(PQsetClientEncoding pg_encoding_to_char PQfreemem)
@@ -39,7 +42,6 @@ if have_build_env
39
42
  required_libraries.each(&method(:have_library))
40
43
  desired_functions.each(&method(:have_func))
41
44
  $CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/
42
-
43
45
  if RUBY_VERSION < '1.8.6'
44
46
  $CFLAGS << ' -DRUBY_LESS_THAN_186'
45
47
  end
data/lib/do_postgres.rb CHANGED
@@ -26,8 +26,11 @@ if RUBY_PLATFORM =~ /java/
26
26
 
27
27
  def character_set
28
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"
29
+ reader = self.create_command("SELECT pg_client_encoding()").execute_reader
30
+ reader.next!
31
+ char_set = reader.values.to_s
32
+ reader.close
33
+ char_set.downcase
31
34
  end
32
35
 
33
36
  end
@@ -1,5 +1,5 @@
1
1
  module DataObjects
2
2
  module Postgres
3
- VERSION = "0.9.11"
3
+ VERSION = "0.9.12"
4
4
  end
5
5
  end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
+ require 'data_objects/spec/command_spec'
5
+
6
+ describe DataObjects::Postgres::Command do
7
+ it_should_behave_like 'a Command'
8
+ it_should_behave_like 'a Command with async'
9
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
+ require 'data_objects/spec/connection_spec'
5
+
6
+ describe DataObjects::Postgres::Connection do
7
+
8
+ before :all do
9
+ @driver = CONFIG.scheme
10
+ @user = CONFIG.user
11
+ @password = CONFIG.pass
12
+ @host = CONFIG.host
13
+ @port = CONFIG.port
14
+ @database = CONFIG.database
15
+ end
16
+
17
+ it_should_behave_like 'a Connection'
18
+ it_should_behave_like 'a Connection with authentication support'
19
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
+ require 'data_objects/spec/encoding_spec'
5
+
6
+ describe DataObjects::Postgres::Connection do
7
+ it_should_behave_like 'a driver supporting encodings'
8
+ end
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'data_objects', 'spec', 'lib', 'rspec_immediate_feedback_formatter'))
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
+ require 'data_objects/spec/reader_spec'
5
+
6
+ describe DataObjects::Postgres::Reader do
7
+ it_should_behave_like 'a Reader'
8
+ end
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
+ require 'data_objects/spec/result_spec'
5
+
6
+ describe DataObjects::Postgres::Result do
7
+ it_should_behave_like 'a Result'
8
+
9
+ before :all do
10
+ setup_test_environment
11
+ end
12
+
13
+ describe 'without using RETURNING' do
14
+
15
+ before :each do
16
+ @connection = DataObjects::Connection.new(CONFIG.uri)
17
+ @result = @connection.create_command("INSERT INTO users (name) VALUES (?)").execute_non_query("monkey")
18
+ end
19
+
20
+ after :each do
21
+ @connection.close
22
+ end
23
+
24
+ it { @result.should respond_to(:affected_rows) }
25
+
26
+ describe 'affected_rows' do
27
+
28
+ it 'should return the number of created rows' do
29
+ @result.affected_rows.should == 1
30
+ end
31
+
32
+ end
33
+
34
+ it { @result.should respond_to(:insert_id) }
35
+
36
+ describe 'insert_id' do
37
+
38
+ it 'should return nil' do
39
+ @result.insert_id.should be_nil
40
+ end
41
+
42
+ it 'should be retrievable through curr_val' do
43
+ # This is actually the 4th record inserted
44
+ reader = @connection.create_command("SELECT currval('users_id_seq')").execute_reader
45
+ reader.next!
46
+ reader.values.first.should == 4
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ describe 'when using RETURNING' do
54
+
55
+ before :each do
56
+ @connection = DataObjects::Connection.new(CONFIG.uri)
57
+ @result = @connection.create_command("INSERT INTO users (name) VALUES (?) RETURNING id").execute_non_query("monkey")
58
+ end
59
+
60
+ after :each do
61
+ @connection.close
62
+ end
63
+
64
+ it { @result.should respond_to(:affected_rows) }
65
+
66
+ describe 'affected_rows' do
67
+
68
+ it 'should return the number of created rows' do
69
+ @result.affected_rows.should == 1
70
+ end
71
+
72
+ end
73
+
74
+ it { @result.should respond_to(:insert_id) }
75
+
76
+ describe 'insert_id' do
77
+
78
+ it 'should return the generated key value' do
79
+ @result.insert_id.should == 2
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,20 +3,22 @@ JRUBY = RUBY_PLATFORM =~ /java/
3
3
 
4
4
  require 'rubygems'
5
5
 
6
- gem 'rspec', '>=1.1.3'
6
+ gem 'rspec', '>1.1.12'
7
7
  require 'spec'
8
8
 
9
9
  require 'date'
10
10
  require 'ostruct'
11
11
  require 'pathname'
12
12
  require 'fileutils'
13
- require 'bigdecimal'
14
13
 
15
14
  # put data_objects from repository in the load path
16
15
  # DO NOT USE installed gem of data_objects!
17
16
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_objects', 'lib'))
18
17
  require 'data_objects'
19
18
 
19
+ DATAOBJECTS_SPEC_ROOT = Pathname(__FILE__).dirname.parent.parent + 'data_objects' + 'spec'
20
+ Pathname.glob((DATAOBJECTS_SPEC_ROOT + 'lib/**/*.rb').to_s).each { |f| require f }
21
+
20
22
  if JRUBY
21
23
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'do_jdbc', 'lib'))
22
24
  require 'do_jdbc'
@@ -31,68 +33,99 @@ FileUtils.mkdir_p(File.dirname(log_path))
31
33
 
32
34
  DataObjects::Postgres.logger = DataObjects::Logger.new(log_path, :debug)
33
35
 
34
- POSTGRES = OpenStruct.new
35
- POSTGRES.user = ENV['DO_PG_USER'] || 'postgres'
36
- POSTGRES.pass = ENV['DO_PG_PASS'] || ''
37
- POSTGRES.host = ENV['DO_PG_HOST'] || '127.0.0.1'
38
- POSTGRES.hostname = ENV['DO_PG_HOSTNAME'] || 'localhost'
39
- POSTGRES.port = ENV['DO_PG_PORT'] || '5432'
40
- POSTGRES.database = ENV['DO_PG_DATABASE'] || 'do_test'
41
-
42
- DO_POSTGRES_SPEC_URI = Addressable::URI::parse(ENV["DO_PG_SPEC_URI"] ||
43
- "postgres://#{POSTGRES.user}:#{POSTGRES.pass}@#{POSTGRES.hostname}:#{POSTGRES.port}/#{POSTGRES.database}")
44
-
45
- module PostgresSpecHelpers
46
-
47
- def ensure_users_table_and_return_connection
48
- connection = DataObjects::Connection.new(DO_POSTGRES_SPEC_URI)
49
- connection.create_command("DROP TABLE users").execute_non_query rescue nil
50
- connection.create_command("DROP TABLE companies").execute_non_query rescue nil
51
- connection.create_command(<<-EOF).execute_non_query
52
- CREATE TABLE users (
53
- id serial NOT NULL,
54
- "name" text,
55
- registered boolean DEFAULT false,
56
- money double precision DEFAULT 1908.56,
57
- created_on date DEFAULT ('now'::text)::date,
58
- created_at timestamp without time zone DEFAULT now(),
59
- born_at time without time zone DEFAULT now(),
60
- fired_at timestamp with time zone DEFAULT now(),
61
- amount numeric(10,2) DEFAULT 11.1,
62
- company_id integer DEFAULT 1
63
- )
64
- WITHOUT OIDS;
36
+ at_exit { DataObjects.logger.flush }
37
+
38
+ Spec::Runner.configure do |config|
39
+ config.include(DataObjects::Spec::PendingHelpers)
40
+ end
41
+
42
+ CONFIG = OpenStruct.new
43
+ CONFIG.scheme = 'postgres'
44
+ CONFIG.user = ENV['DO_POSTGRES_USER'] || 'postgres'
45
+ CONFIG.pass = ENV['DO_POSTGRES_PASS'] || ''
46
+ CONFIG.host = ENV['DO_POSTGRES_HOST'] || 'localhost'
47
+ CONFIG.port = ENV['DO_POSTGRES_PORT'] || '5432'
48
+ CONFIG.database = ENV['DO_POSTGRES_DATABASE'] || '/do_test'
49
+
50
+ CONFIG.uri = ENV["DO_POSTGRES_SPEC_URI"] ||"#{CONFIG.scheme}://#{CONFIG.user}:#{CONFIG.pass}@#{CONFIG.host}:#{CONFIG.port}#{CONFIG.database}"
51
+ CONFIG.sleep = "SELECT pg_sleep(1)"
52
+
53
+ module DataObjectsSpecHelpers
54
+
55
+ def setup_test_environment
56
+ conn = DataObjects::Connection.new(CONFIG.uri)
57
+
58
+ conn.create_command(<<-EOF).execute_non_query
59
+ DROP TABLE IF EXISTS "invoices"
65
60
  EOF
66
61
 
67
- connection.create_command(<<-EOF).execute_non_query
68
- CREATE TABLE companies (
69
- id serial NOT NULL,
70
- "name" character varying
71
- )
72
- WITHOUT OIDS;
62
+ conn.create_command(<<-EOF).execute_non_query
63
+ DROP TABLE IF EXISTS "users"
73
64
  EOF
74
65
 
75
- return connection
76
- end
66
+ conn.create_command(<<-EOF).execute_non_query
67
+ DROP TABLE IF EXISTS "widgets"
68
+ EOF
77
69
 
78
- def insert(query, *args)
79
- result = @connection.create_command(query[/\) RETURNING.*/i] ? query : "#{query} RETURNING id").execute_non_query(*args)
80
- result.insert_id
81
- end
70
+ conn.create_command(<<-EOF).execute_non_query
71
+ CREATE TABLE "users" (
72
+ "id" SERIAL,
73
+ "name" VARCHAR(200) default 'Billy' NULL,
74
+ "fired_at" timestamp,
75
+ PRIMARY KEY ("id")
76
+ );
77
+ EOF
82
78
 
83
- def exec(query, *args)
84
- @connection.create_command(query).execute_non_query(*args)
85
- end
79
+ conn.create_command(<<-EOF).execute_non_query
80
+ CREATE TABLE "invoices" (
81
+ "id" SERIAL,
82
+ "invoice_number" varchar(50) NOT NULL,
83
+ PRIMARY KEY ("id")
84
+ );
85
+ EOF
86
+
87
+ conn.create_command(<<-EOF).execute_non_query
88
+ CREATE TABLE "widgets" (
89
+ "id" SERIAL,
90
+ "code" char(8) default 'A14' NULL,
91
+ "name" varchar(200) default 'Super Widget' NULL,
92
+ "shelf_location" text NULL,
93
+ "description" text NULL,
94
+ "image_data" bytea NULL,
95
+ "ad_description" text NULL,
96
+ "ad_image" bytea NULL,
97
+ "whitepaper_text" text NULL,
98
+ "cad_drawing" bytea NULL,
99
+ "flags" boolean default false,
100
+ "number_in_stock" smallint default 500,
101
+ "number_sold" integer default 0,
102
+ "super_number" bigint default 9223372036854775807,
103
+ "weight" float default 1.23,
104
+ "cost1" double precision default 10.23,
105
+ "cost2" decimal(8,2) default 50.23,
106
+ "release_date" date default '2008-02-14',
107
+ "release_datetime" timestamp default '2008-02-14 00:31:12',
108
+ "release_timestamp" timestamp with time zone default '2008-02-14 00:31:31',
109
+ PRIMARY KEY ("id")
110
+ );
111
+ EOF
86
112
 
87
- def select(query, types = nil, *args)
88
- begin
89
- command = @connection.create_command(query)
90
- command.set_types types unless types.nil?
91
- reader = command.execute_reader(*args)
92
- reader.next!
93
- yield reader
94
- ensure
95
- reader.close
113
+ 1.upto(16) do |n|
114
+ conn.create_command(<<-EOF).execute_non_query
115
+ insert into widgets(code, name, shelf_location, description, image_data, ad_description, ad_image, whitepaper_text, cad_drawing, super_number, weight) VALUES ('W#{n.to_s.rjust(7,"0")}', 'Widget #{n}', 'A14', 'This is a description', 'IMAGE DATA', 'Buy this product now!', 'AD IMAGE DATA', 'String', 'CAD \\001 \\000 DRAWING'::bytea, 1234, 13.4);
116
+ EOF
96
117
  end
118
+
119
+ conn.create_command(<<-EOF).execute_non_query
120
+ update widgets set flags = true where id = 2
121
+ EOF
122
+
123
+ conn.create_command(<<-EOF).execute_non_query
124
+ update widgets set ad_description = NULL where id = 3
125
+ EOF
126
+
127
+ conn.close
128
+
97
129
  end
130
+
98
131
  end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/array_spec'
5
+
6
+ describe 'DataObjects::Postgres with Array' do
7
+ it_should_behave_like 'supporting Array'
8
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/bigdecimal_spec'
5
+
6
+ describe 'DataObjects::Postgres with BigDecimal' do
7
+ it_should_behave_like 'supporting BigDecimal'
8
+ it_should_behave_like 'supporting BigDecimal autocasting'
9
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/boolean_spec'
5
+
6
+ describe 'DataObjects::Postgres with Boolean' do
7
+ it_should_behave_like 'supporting Boolean'
8
+ it_should_behave_like 'supporting Boolean autocasting'
9
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/byte_array_spec'
5
+
6
+ describe 'DataObjects::Postgres with ByteArray' do
7
+ it_should_behave_like 'supporting ByteArray'
8
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/class_spec'
5
+
6
+ describe 'DataObjects::Postgres with Class' do
7
+ it_should_behave_like 'supporting Class'
8
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/date_spec'
5
+
6
+ describe 'DataObjects::Postgres with Date' do
7
+ it_should_behave_like 'supporting Date'
8
+ it_should_behave_like 'supporting Date autocasting'
9
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/datetime_spec'
5
+
6
+ describe 'DataObjects::Postgres with DateTime' do
7
+ it_should_behave_like 'supporting DateTime'
8
+ it_should_behave_like 'supporting DateTime autocasting'
9
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/float_spec'
5
+
6
+ describe 'DataObjects::Postgres with Float' do
7
+ it_should_behave_like 'supporting Float'
8
+ it_should_behave_like 'supporting Float autocasting'
9
+ end