do_postgres 0.9.12-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ if RUBY_PLATFORM =~ /darwin/
2
+ ENV["RC_ARCHS"] = `uname -m`.chomp if `uname -sr` =~ /^Darwin/
3
+
4
+ # On PowerPC the defaults are fine
5
+ ENV["RC_ARCHS"] = '' if `uname -m` =~ /^Power Macintosh/
6
+ end
7
+
8
+ require 'mkmf'
9
+
10
+ # be polite: you can't force existance of uname functionality on all
11
+ # platforms.
12
+ if RUBY_PLATFORM =~ /darwin/
13
+ ENV["RC_ARCHS"] = `uname -m`.chomp if `uname -sr` =~ /^Darwin/
14
+ end
15
+
16
+ def config_value(type)
17
+ ENV["POSTGRES_#{type.upcase}"] || pg_config(type)
18
+ end
19
+
20
+ def pg_config(type)
21
+ IO.popen("pg_config --#{type}").readline.chomp rescue nil
22
+ end
23
+
24
+ def have_build_env
25
+ (have_library('pq') || have_library('libpq')) &&
26
+ have_header('libpq-fe.h') && have_header('libpq/libpq-fs.h') &&
27
+ have_header('postgres.h') && have_header('mb/pg_wchar.h') &&
28
+ have_header('catalog/pg_type.h')
29
+ end
30
+
31
+ $CFLAGS << '-UENABLE_NLS -DHAVE_GETTIMEOFDAY -DHAVE_CRYPT' if RUBY_PLATFORM =~ /mswin|mingw/
32
+
33
+ dir_config('pgsql-server', config_value('includedir-server'), config_value('libdir'))
34
+ dir_config('pgsql-client', config_value('includedir'), config_value('libdir'))
35
+ dir_config('pgsql-win32') if RUBY_PLATFORM =~ /mswin|mingw/
36
+
37
+ required_libraries = []
38
+ desired_functions = %w(PQsetClientEncoding pg_encoding_to_char PQfreemem)
39
+ compat_functions = %w(PQescapeString PQexecParams)
40
+
41
+ if have_build_env
42
+ required_libraries.each(&method(:have_library))
43
+ desired_functions.each(&method(:have_func))
44
+ $CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/
45
+ if RUBY_VERSION < '1.8.6'
46
+ $CFLAGS << ' -DRUBY_LESS_THAN_186'
47
+ end
48
+
49
+ create_makefile("do_postgres_ext")
50
+ else
51
+ puts 'Could not find PostgreSQL build environment (libraries & headers): Makefile not created'
52
+ exit(1)
53
+ end
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'data_objects'
3
+ if RUBY_PLATFORM =~ /java/
4
+ require 'do_jdbc'
5
+ require 'java'
6
+ gem 'jdbc-postgres'
7
+ require 'jdbc/postgres' # the JDBC driver, packaged as a gem
8
+ end
9
+
10
+ require 'do_postgres_ext'
11
+ require File.expand_path(File.join(File.dirname(__FILE__), 'do_postgres', 'version'))
12
+ require File.expand_path(File.join(File.dirname(__FILE__), 'do_postgres', 'transaction'))
13
+
14
+ if RUBY_PLATFORM =~ /java/
15
+ # Another way of loading the JDBC Class. This seems to be more reliable
16
+ # than Class.forName() within the data_objects.Connection Java class,
17
+ # which is currently not working as expected.
18
+ import 'org.postgresql.Driver'
19
+
20
+ module DataObjects
21
+ module Postgres
22
+ class Connection
23
+ def self.pool_size
24
+ 20
25
+ end
26
+
27
+ def character_set
28
+ # JDBC API does not provide an easy way to get the current character set
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
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,37 @@
1
+
2
+ module DataObjects
3
+
4
+ module Postgres
5
+
6
+ class Transaction < DataObjects::Transaction
7
+
8
+ def begin
9
+ cmd = "BEGIN"
10
+ connection.create_command(cmd).execute_non_query
11
+ end
12
+
13
+ def commit
14
+ cmd = "COMMIT PREPARED '#{id}'"
15
+ connection.create_command(cmd).execute_non_query
16
+ end
17
+
18
+ def rollback
19
+ cmd = "ROLLBACK"
20
+ connection.create_command(cmd).execute_non_query
21
+ end
22
+
23
+ def rollback_prepared
24
+ cmd = "ROLLBACK PREPARED '#{id}'"
25
+ connection.create_command(cmd).execute_non_query
26
+ end
27
+
28
+ def prepare
29
+ cmd = "PREPARE TRANSACTION '#{id}'"
30
+ connection.create_command(cmd).execute_non_query
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,5 @@
1
+ module DataObjects
2
+ module Postgres
3
+ VERSION = "0.9.12"
4
+ end
5
+ end
Binary file
@@ -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
@@ -0,0 +1,131 @@
1
+ $TESTING=true
2
+ JRUBY = RUBY_PLATFORM =~ /java/
3
+
4
+ require 'rubygems'
5
+
6
+ gem 'rspec', '>1.1.12'
7
+ require 'spec'
8
+
9
+ require 'date'
10
+ require 'ostruct'
11
+ require 'pathname'
12
+ require 'fileutils'
13
+
14
+ # put data_objects from repository in the load path
15
+ # DO NOT USE installed gem of data_objects!
16
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data_objects', 'lib'))
17
+ require 'data_objects'
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
+
22
+ if JRUBY
23
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'do_jdbc', 'lib'))
24
+ require 'do_jdbc'
25
+ end
26
+
27
+ # put the pre-compiled extension in the path to be found
28
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
29
+ require 'do_postgres'
30
+
31
+ log_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log', 'do.log'))
32
+ FileUtils.mkdir_p(File.dirname(log_path))
33
+
34
+ DataObjects::Postgres.logger = DataObjects::Logger.new(log_path, :debug)
35
+
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"
60
+ EOF
61
+
62
+ conn.create_command(<<-EOF).execute_non_query
63
+ DROP TABLE IF EXISTS "users"
64
+ EOF
65
+
66
+ conn.create_command(<<-EOF).execute_non_query
67
+ DROP TABLE IF EXISTS "widgets"
68
+ EOF
69
+
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
78
+
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
112
+
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
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
+
129
+ end
130
+
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