pg 1.3.0.rc2-x64-mingw-ucrt
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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data/.appveyor.yml +36 -0
- data/.gems +6 -0
- data/.gemtest +0 -0
- data/.github/workflows/binary-gems.yml +85 -0
- data/.github/workflows/source-gem.yml +130 -0
- data/.gitignore +13 -0
- data/.hgsigs +34 -0
- data/.hgtags +41 -0
- data/.irbrc +23 -0
- data/.pryrc +23 -0
- data/.tm_properties +21 -0
- data/.travis.yml +49 -0
- data/BSDL +22 -0
- data/Contributors.rdoc +46 -0
- data/Gemfile +14 -0
- data/History.rdoc +648 -0
- data/LICENSE +56 -0
- data/Manifest.txt +72 -0
- data/POSTGRES +23 -0
- data/README-OS_X.rdoc +68 -0
- data/README-Windows.rdoc +56 -0
- data/README.ja.rdoc +13 -0
- data/README.rdoc +214 -0
- data/Rakefile +106 -0
- data/Rakefile.cross +300 -0
- data/certs/ged.pem +24 -0
- data/ext/errorcodes.def +1040 -0
- data/ext/errorcodes.rb +45 -0
- data/ext/errorcodes.txt +496 -0
- data/ext/extconf.rb +165 -0
- data/ext/gvl_wrappers.c +21 -0
- data/ext/gvl_wrappers.h +264 -0
- data/ext/pg.c +732 -0
- data/ext/pg.h +385 -0
- data/ext/pg_binary_decoder.c +229 -0
- data/ext/pg_binary_encoder.c +163 -0
- data/ext/pg_coder.c +615 -0
- data/ext/pg_connection.c +4415 -0
- data/ext/pg_copy_coder.c +628 -0
- data/ext/pg_errors.c +95 -0
- data/ext/pg_record_coder.c +519 -0
- data/ext/pg_result.c +1683 -0
- data/ext/pg_text_decoder.c +987 -0
- data/ext/pg_text_encoder.c +814 -0
- data/ext/pg_tuple.c +575 -0
- data/ext/pg_type_map.c +199 -0
- data/ext/pg_type_map_all_strings.c +129 -0
- data/ext/pg_type_map_by_class.c +269 -0
- data/ext/pg_type_map_by_column.c +349 -0
- data/ext/pg_type_map_by_mri_type.c +313 -0
- data/ext/pg_type_map_by_oid.c +385 -0
- data/ext/pg_type_map_in_ruby.c +330 -0
- data/ext/pg_util.c +149 -0
- data/ext/pg_util.h +65 -0
- data/ext/vc/pg.sln +26 -0
- data/ext/vc/pg_18/pg.vcproj +216 -0
- data/ext/vc/pg_19/pg_19.vcproj +209 -0
- data/lib/3.1/pg_ext.so +0 -0
- data/lib/pg/basic_type_map_based_on_result.rb +47 -0
- data/lib/pg/basic_type_map_for_queries.rb +193 -0
- data/lib/pg/basic_type_map_for_results.rb +81 -0
- data/lib/pg/basic_type_registry.rb +296 -0
- data/lib/pg/binary_decoder.rb +23 -0
- data/lib/pg/coder.rb +104 -0
- data/lib/pg/connection.rb +813 -0
- data/lib/pg/constants.rb +12 -0
- data/lib/pg/exceptions.rb +12 -0
- data/lib/pg/result.rb +43 -0
- data/lib/pg/text_decoder.rb +46 -0
- data/lib/pg/text_encoder.rb +59 -0
- data/lib/pg/tuple.rb +30 -0
- data/lib/pg/type_map_by_column.rb +16 -0
- data/lib/pg/version.rb +4 -0
- data/lib/pg.rb +87 -0
- data/lib/x64-mingw-ucrt/libpq.dll +0 -0
- data/misc/openssl-pg-segfault.rb +31 -0
- data/misc/postgres/History.txt +9 -0
- data/misc/postgres/Manifest.txt +5 -0
- data/misc/postgres/README.txt +21 -0
- data/misc/postgres/Rakefile +21 -0
- data/misc/postgres/lib/postgres.rb +16 -0
- data/misc/ruby-pg/History.txt +9 -0
- data/misc/ruby-pg/Manifest.txt +5 -0
- data/misc/ruby-pg/README.txt +21 -0
- data/misc/ruby-pg/Rakefile +21 -0
- data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
- data/pg.gemspec +32 -0
- data/sample/array_insert.rb +20 -0
- data/sample/async_api.rb +106 -0
- data/sample/async_copyto.rb +39 -0
- data/sample/async_mixed.rb +56 -0
- data/sample/check_conn.rb +21 -0
- data/sample/copydata.rb +71 -0
- data/sample/copyfrom.rb +81 -0
- data/sample/copyto.rb +19 -0
- data/sample/cursor.rb +21 -0
- data/sample/disk_usage_report.rb +177 -0
- data/sample/issue-119.rb +94 -0
- data/sample/losample.rb +69 -0
- data/sample/minimal-testcase.rb +17 -0
- data/sample/notify_wait.rb +72 -0
- data/sample/pg_statistics.rb +285 -0
- data/sample/replication_monitor.rb +222 -0
- data/sample/test_binary_values.rb +33 -0
- data/sample/wal_shipper.rb +434 -0
- data/sample/warehouse_partitions.rb +311 -0
- data.tar.gz.sig +0 -0
- metadata +188 -0
- metadata.gz.sig +0 -0
data/lib/pg/constants.rb
ADDED
data/lib/pg/result.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pg' unless defined?( PG )
|
5
|
+
|
6
|
+
|
7
|
+
class PG::Result
|
8
|
+
|
9
|
+
# Apply a type map for all value retrieving methods.
|
10
|
+
#
|
11
|
+
# +type_map+: a PG::TypeMap instance.
|
12
|
+
#
|
13
|
+
# This method is equal to #type_map= , but returns self, so that calls can be chained.
|
14
|
+
#
|
15
|
+
# See also PG::BasicTypeMapForResults
|
16
|
+
def map_types!(type_map)
|
17
|
+
self.type_map = type_map
|
18
|
+
return self
|
19
|
+
end
|
20
|
+
|
21
|
+
# Set the data type for all field name returning methods.
|
22
|
+
#
|
23
|
+
# +type+: a Symbol defining the field name type.
|
24
|
+
#
|
25
|
+
# This method is equal to #field_name_type= , but returns self, so that calls can be chained.
|
26
|
+
def field_names_as(type)
|
27
|
+
self.field_name_type = type
|
28
|
+
return self
|
29
|
+
end
|
30
|
+
|
31
|
+
### Return a String representation of the object suitable for debugging.
|
32
|
+
def inspect
|
33
|
+
str = self.to_s
|
34
|
+
str[-1,0] = if cleared?
|
35
|
+
" cleared"
|
36
|
+
else
|
37
|
+
" status=#{res_status(result_status)} ntuples=#{ntuples} nfields=#{nfields} cmd_tuples=#{cmd_tuples}"
|
38
|
+
end
|
39
|
+
return str
|
40
|
+
end
|
41
|
+
|
42
|
+
end # class PG::Result
|
43
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'date'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module PG
|
8
|
+
module TextDecoder
|
9
|
+
class Date < SimpleDecoder
|
10
|
+
def decode(string, tuple=nil, field=nil)
|
11
|
+
if string =~ /\A(\d{4})-(\d\d)-(\d\d)\z/
|
12
|
+
::Date.new $1.to_i, $2.to_i, $3.to_i
|
13
|
+
else
|
14
|
+
string
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class JSON < SimpleDecoder
|
20
|
+
def decode(string, tuple=nil, field=nil)
|
21
|
+
::JSON.parse(string, quirks_mode: true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Convenience classes for timezone options
|
26
|
+
class TimestampUtc < Timestamp
|
27
|
+
def initialize(params={})
|
28
|
+
super(params.merge(flags: PG::Coder::TIMESTAMP_DB_UTC | PG::Coder::TIMESTAMP_APP_UTC))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
class TimestampUtcToLocal < Timestamp
|
32
|
+
def initialize(params={})
|
33
|
+
super(params.merge(flags: PG::Coder::TIMESTAMP_DB_UTC | PG::Coder::TIMESTAMP_APP_LOCAL))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
class TimestampLocal < Timestamp
|
37
|
+
def initialize(params={})
|
38
|
+
super(params.merge(flags: PG::Coder::TIMESTAMP_DB_LOCAL | PG::Coder::TIMESTAMP_APP_LOCAL))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# For backward compatibility:
|
43
|
+
TimestampWithoutTimeZone = TimestampLocal
|
44
|
+
TimestampWithTimeZone = Timestamp
|
45
|
+
end
|
46
|
+
end # module PG
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require 'ipaddr'
|
6
|
+
|
7
|
+
module PG
|
8
|
+
module TextEncoder
|
9
|
+
class Date < SimpleEncoder
|
10
|
+
def encode(value)
|
11
|
+
value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d") : value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class TimestampWithoutTimeZone < SimpleEncoder
|
16
|
+
def encode(value)
|
17
|
+
value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d %H:%M:%S.%N") : value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class TimestampUtc < SimpleEncoder
|
22
|
+
def encode(value)
|
23
|
+
value.respond_to?(:utc) ? value.utc.strftime("%Y-%m-%d %H:%M:%S.%N") : value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class TimestampWithTimeZone < SimpleEncoder
|
28
|
+
def encode(value)
|
29
|
+
value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d %H:%M:%S.%N %:z") : value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class JSON < SimpleEncoder
|
34
|
+
def encode(value)
|
35
|
+
::JSON.generate(value, quirks_mode: true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Inet < SimpleEncoder
|
40
|
+
def encode(value)
|
41
|
+
case value
|
42
|
+
when IPAddr
|
43
|
+
default_prefix = (value.family == Socket::AF_INET ? 32 : 128)
|
44
|
+
s = value.to_s
|
45
|
+
if value.respond_to?(:prefix)
|
46
|
+
prefix = value.prefix
|
47
|
+
else
|
48
|
+
range = value.to_range
|
49
|
+
prefix = default_prefix - Math.log(((range.end.to_i - range.begin.to_i) + 1), 2).to_i
|
50
|
+
end
|
51
|
+
s << "/" << prefix.to_s if prefix != default_prefix
|
52
|
+
s
|
53
|
+
else
|
54
|
+
value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end # module PG
|
data/lib/pg/tuple.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pg' unless defined?( PG )
|
5
|
+
|
6
|
+
|
7
|
+
class PG::Tuple
|
8
|
+
|
9
|
+
### Return a String representation of the object suitable for debugging.
|
10
|
+
def inspect
|
11
|
+
"#<#{self.class} #{self.map{|k,v| "#{k}: #{v.inspect}" }.join(", ") }>"
|
12
|
+
end
|
13
|
+
|
14
|
+
def has_key?(key)
|
15
|
+
field_map.has_key?(key)
|
16
|
+
end
|
17
|
+
alias key? has_key?
|
18
|
+
|
19
|
+
def keys
|
20
|
+
field_names || field_map.keys.freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
def each_key(&block)
|
24
|
+
if fn=field_names
|
25
|
+
fn.each(&block)
|
26
|
+
else
|
27
|
+
field_map.each_key(&block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pg' unless defined?( PG )
|
5
|
+
|
6
|
+
class PG::TypeMapByColumn
|
7
|
+
# Returns the type oids of the assigned coders.
|
8
|
+
def oids
|
9
|
+
coders.map{|c| c.oid if c }
|
10
|
+
end
|
11
|
+
|
12
|
+
def inspect
|
13
|
+
type_strings = coders.map{|c| c ? c.inspect_short : 'nil' }
|
14
|
+
"#<#{self.class} #{type_strings.join(' ')}>"
|
15
|
+
end
|
16
|
+
end
|
data/lib/pg/version.rb
ADDED
data/lib/pg.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
|
2
|
+
# -*- ruby -*-
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
# The top-level PG namespace.
|
6
|
+
module PG
|
7
|
+
|
8
|
+
# Is this file part of a fat binary gem with bundled libpq?
|
9
|
+
bundled_libpq_path = File.join(__dir__, RUBY_PLATFORM.gsub(/^i386-/, "x86-"))
|
10
|
+
if File.exist?(bundled_libpq_path)
|
11
|
+
POSTGRESQL_LIB_PATH = bundled_libpq_path
|
12
|
+
else
|
13
|
+
bundled_libpq_path = nil
|
14
|
+
# Try to load libpq path as found by extconf.rb
|
15
|
+
begin
|
16
|
+
require "pg/postgresql_lib_path"
|
17
|
+
rescue LoadError
|
18
|
+
# rake-compiler doesn't use regular "make install", but uses it's own install tasks.
|
19
|
+
# It therefore doesn't copy pg/postgresql_lib_path.rb in case of "rake compile".
|
20
|
+
POSTGRESQL_LIB_PATH = false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
add_dll_path = proc do |path, &block|
|
25
|
+
if RUBY_PLATFORM =~/(mswin|mingw)/i && path && File.exist?(path)
|
26
|
+
begin
|
27
|
+
require 'ruby_installer/runtime'
|
28
|
+
RubyInstaller::Runtime.add_dll_directory(path, &block)
|
29
|
+
rescue LoadError
|
30
|
+
old_path = ENV['PATH']
|
31
|
+
ENV['PATH'] = "#{path};#{old_path}"
|
32
|
+
block.call
|
33
|
+
ENV['PATH'] = old_path
|
34
|
+
end
|
35
|
+
else
|
36
|
+
# No need to set a load path manually - it's set as library rpath.
|
37
|
+
block.call
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Add a load path to the one retrieved from pg_config
|
42
|
+
add_dll_path.call(POSTGRESQL_LIB_PATH) do
|
43
|
+
if bundled_libpq_path
|
44
|
+
# It's a Windows binary gem, try the <major>.<minor> subdirectory
|
45
|
+
major_minor = RUBY_VERSION[ /^(\d+\.\d+)/ ] or
|
46
|
+
raise "Oops, can't extract the major/minor version from #{RUBY_VERSION.dump}"
|
47
|
+
require "#{major_minor}/pg_ext"
|
48
|
+
else
|
49
|
+
require 'pg_ext'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
class NotAllCopyDataRetrieved < PG::Error
|
55
|
+
end
|
56
|
+
|
57
|
+
### Get the PG library version. If +include_buildnum+ is +true+, include the build ID.
|
58
|
+
def self::version_string( include_buildnum=false )
|
59
|
+
vstring = "%s %s" % [ self.name, VERSION ]
|
60
|
+
vstring << " (build %s)" % [ REVISION[/: ([[:xdigit:]]+)/, 1] || '0' ] if include_buildnum
|
61
|
+
return vstring
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
### Convenience alias for PG::Connection.new.
|
66
|
+
def self::connect( *args )
|
67
|
+
return PG::Connection.new( *args )
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
require 'pg/exceptions'
|
72
|
+
require 'pg/constants'
|
73
|
+
require 'pg/coder'
|
74
|
+
require 'pg/binary_decoder'
|
75
|
+
require 'pg/text_encoder'
|
76
|
+
require 'pg/text_decoder'
|
77
|
+
require 'pg/basic_type_registry'
|
78
|
+
require 'pg/basic_type_map_based_on_result'
|
79
|
+
require 'pg/basic_type_map_for_queries'
|
80
|
+
require 'pg/basic_type_map_for_results'
|
81
|
+
require 'pg/type_map_by_column'
|
82
|
+
require 'pg/connection'
|
83
|
+
require 'pg/result'
|
84
|
+
require 'pg/tuple'
|
85
|
+
require 'pg/version'
|
86
|
+
|
87
|
+
end # module PG
|
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
PGHOST = 'localhost'
|
4
|
+
PGDB = 'test'
|
5
|
+
#SOCKHOST = 'github.com'
|
6
|
+
SOCKHOST = 'it-trac.laika.com'
|
7
|
+
|
8
|
+
# Load pg first, so the libssl.so that libpq is linked against is loaded.
|
9
|
+
require 'pg'
|
10
|
+
$stderr.puts "connecting to postgres://#{PGHOST}/#{PGDB}"
|
11
|
+
conn = PG.connect( PGHOST, :dbname => PGDB )
|
12
|
+
|
13
|
+
# Now load OpenSSL, which might be linked against a different libssl.
|
14
|
+
require 'socket'
|
15
|
+
require 'openssl'
|
16
|
+
$stderr.puts "Connecting to #{SOCKHOST}"
|
17
|
+
sock = TCPSocket.open( SOCKHOST, 443 )
|
18
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
19
|
+
sock = OpenSSL::SSL::SSLSocket.new( sock, ctx )
|
20
|
+
sock.sync_close = true
|
21
|
+
|
22
|
+
# The moment of truth...
|
23
|
+
$stderr.puts "Attempting to connect..."
|
24
|
+
begin
|
25
|
+
sock.connect
|
26
|
+
rescue Errno
|
27
|
+
$stderr.puts "Got an error connecting, but no segfault."
|
28
|
+
else
|
29
|
+
$stderr.puts "Nope, no segfault!"
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
= postgres
|
2
|
+
|
3
|
+
* https://github.com/ged/ruby-pg
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
This is an old, deprecated version of the Ruby PostgreSQL driver that hasn't
|
8
|
+
been maintained or supported since early 2008.
|
9
|
+
|
10
|
+
You should install/require 'pg' instead.
|
11
|
+
|
12
|
+
If you need the 'postgres' gem for legacy code that can't be converted, you can
|
13
|
+
still install it using an explicit version, like so:
|
14
|
+
|
15
|
+
gem install postgres -v '0.7.9.2008.01.28'
|
16
|
+
gem uninstall postgres -v '>0.7.9.2008.01.28'
|
17
|
+
|
18
|
+
If you have any questions, the nice folks in the Google group can help:
|
19
|
+
|
20
|
+
http://goo.gl/OjOPP / ruby-pg@googlegroups.com
|
21
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'hoe'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
Hoe.spec 'postgres' do
|
9
|
+
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
10
|
+
self.dependency 'pg', '~> 0'
|
11
|
+
self.spec_extras[:date] = Date.parse( '2008/01/30' )
|
12
|
+
|
13
|
+
line = '-' * 75
|
14
|
+
msg = paragraphs_of( 'README.txt', 3..-1 )
|
15
|
+
msg.unshift( line )
|
16
|
+
msg.push( line )
|
17
|
+
|
18
|
+
self.spec_extras[:post_install_message] = msg.join( "\n\n" ) + "\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
# vim: syntax=ruby
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module Postgres
|
6
|
+
|
7
|
+
VERSION = '0.8.1'
|
8
|
+
|
9
|
+
gemdir = Pathname( __FILE__ ).dirname.parent
|
10
|
+
readme = gemdir + 'README.txt'
|
11
|
+
|
12
|
+
header, message = readme.read.split( /^== Description/m )
|
13
|
+
abort( message.strip )
|
14
|
+
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
= ruby-pg
|
2
|
+
|
3
|
+
* https://github.com/ged/ruby-pg
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
This is an old, deprecated version of the 'pg' gem that hasn't been
|
8
|
+
maintained or supported since early 2008.
|
9
|
+
|
10
|
+
You should install/require 'pg' instead.
|
11
|
+
|
12
|
+
If you need ruby-pg for legacy code that can't be converted, you can still
|
13
|
+
install it using an explicit version, like so:
|
14
|
+
|
15
|
+
gem install ruby-pg -v '0.7.9.2008.01.28'
|
16
|
+
gem uninstall ruby-pg -v '>0.7.9.2008.01.28'
|
17
|
+
|
18
|
+
If you have any questions, the nice folks in the Google group can help:
|
19
|
+
|
20
|
+
http://goo.gl/OjOPP / ruby-pg@googlegroups.com
|
21
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'hoe'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
Hoe.spec 'ruby-pg' do
|
9
|
+
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
10
|
+
self.dependency 'pg', '~> 0'
|
11
|
+
self.spec_extras[:date] = Date.parse( '2008/01/30' )
|
12
|
+
|
13
|
+
line = '-' * 75
|
14
|
+
msg = paragraphs_of( 'README.txt', 3..-1 )
|
15
|
+
msg.unshift( line )
|
16
|
+
msg.push( line )
|
17
|
+
|
18
|
+
self.spec_extras[:post_install_message] = msg.join( "\n\n" ) + "\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
# vim: syntax=ruby
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module Pg
|
6
|
+
|
7
|
+
VERSION = '0.8.0'
|
8
|
+
|
9
|
+
gemdir = Pathname( __FILE__ ).dirname.parent.parent
|
10
|
+
readme = gemdir + 'README.txt'
|
11
|
+
|
12
|
+
header, message = readme.read.split( /^== Description/m )
|
13
|
+
abort( message.strip )
|
14
|
+
|
15
|
+
end
|
16
|
+
|
data/pg.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
|
4
|
+
require_relative 'lib/pg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pg"
|
8
|
+
spec.version = PG::VERSION
|
9
|
+
spec.authors = ["Michael Granger", "Lars Kanis"]
|
10
|
+
spec.email = ["ged@FaerieMUD.org", "lars@greiz-reinsdorf.de"]
|
11
|
+
|
12
|
+
spec.summary = "Pg is the Ruby interface to the PostgreSQL RDBMS"
|
13
|
+
spec.description = "Pg is the Ruby interface to the PostgreSQL RDBMS. It works with PostgreSQL 9.3 and later."
|
14
|
+
spec.homepage = "https://github.com/ged/ruby-pg"
|
15
|
+
spec.license = "BSD-2-Clause"
|
16
|
+
spec.required_ruby_version = ">= 2.5"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/ged/ruby-pg"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/ged/ruby-pg/blob/master/History.rdoc"
|
21
|
+
spec.metadata["documentation_uri"] = "http://deveiate.org/code/pg"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.extensions = ["ext/extconf.rb"]
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
spec.cert_chain = ["certs/ged.pem"]
|
31
|
+
spec.rdoc_options = ["--main", "README.rdoc"]
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'pg'
|
4
|
+
|
5
|
+
c = PG.connect( dbname: 'test' )
|
6
|
+
|
7
|
+
# this one works:
|
8
|
+
c.exec( "DROP TABLE IF EXISTS foo" )
|
9
|
+
c.exec( "CREATE TABLE foo (strings character varying[]);" )
|
10
|
+
|
11
|
+
# But using a prepared statement works:
|
12
|
+
c.set_error_verbosity( PG::PQERRORS_VERBOSE )
|
13
|
+
c.prepare( 'stmt', "INSERT INTO foo VALUES ($1);" )
|
14
|
+
|
15
|
+
# This won't work
|
16
|
+
#c.exec_prepared( 'stmt', ["ARRAY['this','that']"] )
|
17
|
+
|
18
|
+
# but this will:
|
19
|
+
c.exec_prepared( 'stmt', ["{'this','that'}"] )
|
20
|
+
|
data/sample/async_api.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'pg'
|
4
|
+
|
5
|
+
# This is a example of how to use the asynchronous API to query the
|
6
|
+
# server without blocking other threads. It's intentionally low-level;
|
7
|
+
# if you hooked up the PG::Connection#socket to some kind of reactor, you
|
8
|
+
# could make this much nicer.
|
9
|
+
|
10
|
+
TIMEOUT = 5.0 # seconds to wait for an async operation to complete
|
11
|
+
|
12
|
+
# Print 'x' continuously to demonstrate that other threads aren't
|
13
|
+
# blocked while waiting for the connection, for the query to be sent,
|
14
|
+
# for results, etc. You might want to sleep inside the loop or
|
15
|
+
# comment this out entirely for cleaner output.
|
16
|
+
progress_thread = Thread.new { loop { print 'x' } }
|
17
|
+
|
18
|
+
# Output progress messages
|
19
|
+
def output_progress( msg )
|
20
|
+
puts "\n>>> #{msg}\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Start the connection
|
24
|
+
output_progress "Starting connection..."
|
25
|
+
conn = PG::Connection.connect_start( :dbname => 'test' ) or
|
26
|
+
abort "Unable to create a new connection!"
|
27
|
+
abort "Connection failed: %s" % [ conn.error_message ] if
|
28
|
+
conn.status == PG::CONNECTION_BAD
|
29
|
+
|
30
|
+
# Now grab a reference to the underlying socket so we know when the
|
31
|
+
# connection is established
|
32
|
+
socket = conn.socket_io
|
33
|
+
|
34
|
+
# Track the progress of the connection, waiting for the socket to become readable/writable
|
35
|
+
# before polling it
|
36
|
+
poll_status = PG::PGRES_POLLING_WRITING
|
37
|
+
until poll_status == PG::PGRES_POLLING_OK ||
|
38
|
+
poll_status == PG::PGRES_POLLING_FAILED
|
39
|
+
|
40
|
+
# If the socket needs to read, wait 'til it becomes readable to poll again
|
41
|
+
case poll_status
|
42
|
+
when PG::PGRES_POLLING_READING
|
43
|
+
output_progress " waiting for socket to become readable"
|
44
|
+
select( [socket], nil, nil, TIMEOUT ) or
|
45
|
+
raise "Asynchronous connection timed out!"
|
46
|
+
|
47
|
+
# ...and the same for when the socket needs to write
|
48
|
+
when PG::PGRES_POLLING_WRITING
|
49
|
+
output_progress " waiting for socket to become writable"
|
50
|
+
select( nil, [socket], nil, TIMEOUT ) or
|
51
|
+
raise "Asynchronous connection timed out!"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Output a status message about the progress
|
55
|
+
case conn.status
|
56
|
+
when PG::CONNECTION_STARTED
|
57
|
+
output_progress " waiting for connection to be made."
|
58
|
+
when PG::CONNECTION_MADE
|
59
|
+
output_progress " connection OK; waiting to send."
|
60
|
+
when PG::CONNECTION_AWAITING_RESPONSE
|
61
|
+
output_progress " waiting for a response from the server."
|
62
|
+
when PG::CONNECTION_AUTH_OK
|
63
|
+
output_progress " received authentication; waiting for backend start-up to finish."
|
64
|
+
when PG::CONNECTION_SSL_STARTUP
|
65
|
+
output_progress " negotiating SSL encryption."
|
66
|
+
when PG::CONNECTION_SETENV
|
67
|
+
output_progress " negotiating environment-driven parameter settings."
|
68
|
+
when PG::CONNECTION_NEEDED
|
69
|
+
output_progress " internal state: connect() needed."
|
70
|
+
end
|
71
|
+
|
72
|
+
# Check to see if it's finished or failed yet
|
73
|
+
poll_status = conn.connect_poll
|
74
|
+
end
|
75
|
+
|
76
|
+
abort "Connect failed: %s" % [ conn.error_message ] unless conn.status == PG::CONNECTION_OK
|
77
|
+
|
78
|
+
output_progress "Sending query"
|
79
|
+
conn.send_query( "SELECT * FROM pg_stat_activity" )
|
80
|
+
|
81
|
+
# Fetch results until there aren't any more
|
82
|
+
loop do
|
83
|
+
output_progress " waiting for a response"
|
84
|
+
|
85
|
+
# Buffer any incoming data on the socket until a full result is ready.
|
86
|
+
conn.consume_input
|
87
|
+
while conn.is_busy
|
88
|
+
select( [socket], nil, nil, TIMEOUT ) or
|
89
|
+
raise "Timeout waiting for query response."
|
90
|
+
conn.consume_input
|
91
|
+
end
|
92
|
+
|
93
|
+
# Fetch the next result. If there isn't one, the query is finished
|
94
|
+
result = conn.get_result or break
|
95
|
+
|
96
|
+
puts "\n\nQuery result:\n%p\n" % [ result.values ]
|
97
|
+
end
|
98
|
+
|
99
|
+
output_progress "Done."
|
100
|
+
conn.finish
|
101
|
+
|
102
|
+
if defined?( progress_thread )
|
103
|
+
progress_thread.kill
|
104
|
+
progress_thread.join
|
105
|
+
end
|
106
|
+
|