cipherstash-pg 1.0.0.beta.1-x86_64-darwin-22 → 1.0.0.beta.3-x86_64-darwin-22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.appveyor.yml +42 -0
- data/.gems +6 -0
- data/.gemtest +0 -0
- data/.github/workflows/binary-gems.yml +117 -0
- data/.github/workflows/source-gem.yml +137 -0
- data/.gitignore +19 -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/Gemfile +3 -3
- data/Gemfile.lock +45 -0
- data/{History.rdoc → History.md} +168 -153
- data/README.ja.md +266 -0
- data/README.md +272 -0
- data/Rakefile +65 -104
- data/Rakefile.cross +298 -0
- data/certs/larskanis-2023.pem +24 -0
- data/cipherstash-pg.gemspec +0 -0
- data/lib/2.7/pg_ext.bundle +0 -0
- data/lib/3.0/pg_ext.bundle +0 -0
- data/lib/3.1/pg_ext.bundle +0 -0
- data/lib/3.2/pg_ext.bundle +0 -0
- data/lib/cipherstash-pg/basic_type_map_based_on_result.rb +11 -0
- data/lib/cipherstash-pg/basic_type_map_for_queries.rb +113 -0
- data/lib/cipherstash-pg/basic_type_map_for_results.rb +30 -0
- data/lib/cipherstash-pg/basic_type_registry.rb +206 -0
- data/lib/cipherstash-pg/binary_decoder.rb +21 -0
- data/lib/cipherstash-pg/coder.rb +82 -0
- data/lib/cipherstash-pg/connection.rb +467 -0
- data/lib/cipherstash-pg/constants.rb +3 -0
- data/lib/cipherstash-pg/exceptions.rb +19 -0
- data/lib/cipherstash-pg/result.rb +22 -0
- data/lib/cipherstash-pg/text_decoder.rb +43 -0
- data/lib/cipherstash-pg/text_encoder.rb +67 -0
- data/lib/cipherstash-pg/tuple.rb +24 -0
- data/lib/cipherstash-pg/type_map_by_column.rb +11 -0
- data/lib/cipherstash-pg/version.rb +3 -0
- data/lib/cipherstash-pg.rb +56 -11
- data/lib/libpq.5.dylib +0 -0
- data/misc/openssl-pg-segfault.rb +15 -25
- data/misc/postgres/Rakefile +13 -20
- data/misc/postgres/lib/postgres.rb +10 -14
- data/misc/ruby-pg/Rakefile +13 -20
- data/misc/ruby-pg/lib/ruby/pg.rb +10 -14
- data/rakelib/task_extension.rb +17 -31
- data/sample/array_insert.rb +7 -20
- data/sample/async_api.rb +54 -96
- data/sample/async_copyto.rb +20 -35
- data/sample/async_mixed.rb +22 -50
- data/sample/check_conn.rb +8 -20
- data/sample/copydata.rb +18 -68
- data/sample/copyfrom.rb +26 -78
- data/sample/copyto.rb +10 -16
- data/sample/cursor.rb +9 -19
- data/sample/disk_usage_report.rb +89 -174
- data/sample/issue-119.rb +45 -93
- data/sample/losample.rb +48 -66
- data/sample/minimal-testcase.rb +6 -17
- data/sample/notify_wait.rb +21 -67
- data/sample/pg_statistics.rb +100 -281
- data/sample/replication_monitor.rb +119 -218
- data/sample/test_binary_values.rb +14 -30
- data/sample/wal_shipper.rb +199 -431
- data/sample/warehouse_partitions.rb +157 -307
- data/translation/.po4a-version +7 -0
- data/translation/po/all.pot +875 -0
- data/translation/po/ja.po +868 -0
- data/translation/po4a.cfg +9 -0
- metadata +50 -28
- data/README.ja.rdoc +0 -13
- data/README.rdoc +0 -233
- data/lib/pg/basic_type_map_based_on_result.rb +0 -47
- data/lib/pg/basic_type_map_for_queries.rb +0 -193
- data/lib/pg/basic_type_map_for_results.rb +0 -81
- data/lib/pg/basic_type_registry.rb +0 -301
- data/lib/pg/binary_decoder.rb +0 -23
- data/lib/pg/coder.rb +0 -104
- data/lib/pg/connection.rb +0 -878
- data/lib/pg/constants.rb +0 -12
- data/lib/pg/exceptions.rb +0 -18
- data/lib/pg/result.rb +0 -43
- data/lib/pg/text_decoder.rb +0 -46
- data/lib/pg/text_encoder.rb +0 -59
- data/lib/pg/tuple.rb +0 -30
- data/lib/pg/type_map_by_column.rb +0 -16
- data/lib/pg/version.rb +0 -4
- data/lib/pg.rb +0 -55
data/lib/cipherstash-pg.rb
CHANGED
@@ -1,15 +1,60 @@
|
|
1
|
-
|
1
|
+
# -*- ruby -*-
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
4
|
+
module CipherStashPG
|
5
|
+
# cipherstash-pg *always* ships a "fat" gem with precompiled libs for
|
6
|
+
# each popular major.minor version of Ruby that is still in use.
|
7
|
+
major_minor = RUBY_VERSION[ /^(\d+\.\d+)/ ] or
|
8
|
+
raise "Oops, can't extract the major/minor version from #{RUBY_VERSION.dump}"
|
9
|
+
begin
|
10
|
+
require "#{major_minor}/pg_ext"
|
11
|
+
rescue => e
|
12
|
+
STDERR.puts "Failed to load pg_ext for #{RUBY_VERSION.dump}"
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
# Provide a means to read the extension installation scripts
|
17
|
+
DB_EXT_DIR = File.join(__dir__, '../vendor/database-extensions')
|
18
|
+
def self.install_script
|
19
|
+
File.read(File.join(DB_EXT_DIR, "install.sql"))
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.uninstall_script
|
23
|
+
File.read(File.join(DB_EXT_DIR, "uninstall.sql"))
|
24
|
+
end
|
25
|
+
|
26
|
+
class NotAllCopyDataRetrieved < CipherStashPG::Error
|
27
|
+
end
|
28
|
+
|
29
|
+
class NotInBlockingMode < CipherStashPG::Error
|
30
|
+
end
|
6
31
|
|
7
|
-
|
8
|
-
|
9
|
-
|
32
|
+
# Get the CipherStashPG library version.
|
33
|
+
#
|
34
|
+
# +include_buildnum+ is no longer used and any value passed will be ignored.
|
35
|
+
def self.version_string( include_buildnum=nil )
|
36
|
+
"%s %s" % [ self.name, VERSION ]
|
37
|
+
end
|
10
38
|
|
11
|
-
|
12
|
-
|
13
|
-
|
39
|
+
### Convenience alias for CipherStashPG::Connection.new.
|
40
|
+
def self.connect( *args, &block )
|
41
|
+
Connection.new( *args, &block )
|
14
42
|
end
|
15
|
-
|
43
|
+
|
44
|
+
require 'cipherstash-pg/exceptions'
|
45
|
+
require 'cipherstash-pg/constants'
|
46
|
+
require 'cipherstash-pg/coder'
|
47
|
+
require 'cipherstash-pg/binary_decoder'
|
48
|
+
require 'cipherstash-pg/text_encoder'
|
49
|
+
require 'cipherstash-pg/text_decoder'
|
50
|
+
require 'cipherstash-pg/basic_type_registry'
|
51
|
+
require 'cipherstash-pg/basic_type_map_based_on_result'
|
52
|
+
require 'cipherstash-pg/basic_type_map_for_queries'
|
53
|
+
require 'cipherstash-pg/basic_type_map_for_results'
|
54
|
+
require 'cipherstash-pg/type_map_by_column'
|
55
|
+
require 'cipherstash-pg/connection'
|
56
|
+
require 'cipherstash-pg/result'
|
57
|
+
require 'cipherstash-pg/tuple'
|
58
|
+
require 'cipherstash-pg/version'
|
59
|
+
|
60
|
+
end # module CipherStashPG
|
data/lib/libpq.5.dylib
CHANGED
Binary file
|
data/misc/openssl-pg-segfault.rb
CHANGED
@@ -1,31 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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 )
|
1
|
+
PGHOST = "localhost"
|
2
|
+
PGDB = "test"
|
3
|
+
SOCKHOST = "it-trac.laika.com"
|
4
|
+
require("cipherstash-pg")
|
5
|
+
$stderr.puts("connecting to postgres://#{PGHOST}/#{PGDB}")
|
6
|
+
conn = CipherStashPG.connect(PGHOST, :dbname => (PGDB))
|
7
|
+
require("socket")
|
8
|
+
require("openssl")
|
9
|
+
$stderr.puts("Connecting to #{SOCKHOST}")
|
10
|
+
sock = TCPSocket.open(SOCKHOST, 443)
|
18
11
|
ctx = OpenSSL::SSL::SSLContext.new
|
19
|
-
sock = OpenSSL::SSL::SSLSocket.new(
|
12
|
+
sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
|
20
13
|
sock.sync_close = true
|
21
|
-
|
22
|
-
# The moment of truth...
|
23
|
-
$stderr.puts "Attempting to connect..."
|
14
|
+
$stderr.puts("Attempting to connect...")
|
24
15
|
begin
|
25
|
-
|
16
|
+
sock.connect
|
26
17
|
rescue Errno
|
27
|
-
|
18
|
+
$stderr.puts("Got an error connecting, but no segfault.")
|
28
19
|
else
|
29
|
-
|
20
|
+
$stderr.puts("Nope, no segfault!")
|
30
21
|
end
|
31
|
-
|
data/misc/postgres/Rakefile
CHANGED
@@ -1,21 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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"
|
1
|
+
require("date")
|
2
|
+
require("rubygems")
|
3
|
+
require("hoe")
|
4
|
+
require("pp")
|
5
|
+
Hoe.spec("postgres") do
|
6
|
+
self.developer("Michael Granger", "ged@FaerieMUD.org")
|
7
|
+
self.dependency("pg", "~> 0")
|
8
|
+
self.spec_extras[:date] = Date.parse("2008/01/30")
|
9
|
+
line = ("-" * 75)
|
10
|
+
msg = paragraphs_of("README.txt", (3..-1))
|
11
|
+
msg.unshift(line)
|
12
|
+
msg.push(line)
|
13
|
+
self.spec_extras[:post_install_message] = (msg.join("\n\n") + "\n")
|
19
14
|
end
|
20
|
-
|
21
|
-
# vim: syntax=ruby
|
@@ -1,16 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'pathname'
|
4
|
-
|
1
|
+
require("pathname")
|
5
2
|
module Postgres
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
VERSION = "0.8.1"
|
4
|
+
|
5
|
+
gemdir = Pathname("(string)").dirname.parent
|
6
|
+
|
7
|
+
readme = (gemdir + "README.txt")
|
8
|
+
|
9
|
+
header, message = readme.read.split(/^== Description/m)
|
10
|
+
|
11
|
+
abort(message.strip)
|
15
12
|
end
|
16
|
-
|
data/misc/ruby-pg/Rakefile
CHANGED
@@ -1,21 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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"
|
1
|
+
require("date")
|
2
|
+
require("rubygems")
|
3
|
+
require("hoe")
|
4
|
+
require("pp")
|
5
|
+
Hoe.spec("ruby-pg") do
|
6
|
+
self.developer("Michael Granger", "ged@FaerieMUD.org")
|
7
|
+
self.dependency("pg", "~> 0")
|
8
|
+
self.spec_extras[:date] = Date.parse("2008/01/30")
|
9
|
+
line = ("-" * 75)
|
10
|
+
msg = paragraphs_of("README.txt", (3..-1))
|
11
|
+
msg.unshift(line)
|
12
|
+
msg.push(line)
|
13
|
+
self.spec_extras[:post_install_message] = (msg.join("\n\n") + "\n")
|
19
14
|
end
|
20
|
-
|
21
|
-
# vim: syntax=ruby
|
data/misc/ruby-pg/lib/ruby/pg.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'pathname'
|
4
|
-
|
1
|
+
require("pathname")
|
5
2
|
module Pg
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
VERSION = "0.8.0"
|
4
|
+
|
5
|
+
gemdir = Pathname("(string)").dirname.parent.parent
|
6
|
+
|
7
|
+
readme = (gemdir + "README.txt")
|
8
|
+
|
9
|
+
header, message = readme.read.split(/^== Description/m)
|
10
|
+
|
11
|
+
abort(message.strip)
|
15
12
|
end
|
16
|
-
|
data/rakelib/task_extension.rb
CHANGED
@@ -1,46 +1,32 @@
|
|
1
|
-
# This source code is borrowed from:
|
2
|
-
# https://github.com/oneclick/rubyinstaller2/blob/b3dcbf69f131e44c78ea3a1c5e0041c223f266ce/lib/ruby_installer/build/utils.rb#L104-L144
|
3
|
-
|
4
1
|
module TaskExtension
|
5
|
-
# Extend rake's file task to be defined only once and to check the expected file is indeed generated
|
6
|
-
#
|
7
|
-
# The same as #task, but for #file.
|
8
|
-
# In addition this file task raises an error, if the file that is expected to be generated is not present after the block was executed.
|
9
2
|
def file(name, *args, &block)
|
10
3
|
task_once(name, block) do
|
11
4
|
super(name, *args) do |ta|
|
12
5
|
block&.call(ta).tap do
|
13
|
-
|
6
|
+
unless File.exist?(ta.name) then
|
7
|
+
raise("file #{ta.name} is missing after task executed")
|
8
|
+
end
|
14
9
|
end
|
15
10
|
end
|
16
11
|
end
|
17
12
|
end
|
18
|
-
|
19
|
-
# Extend rake's task definition to be defined only once, even if called several times
|
20
|
-
#
|
21
|
-
# This allows to define common tasks next to specific tasks.
|
22
|
-
# It is expected that any variation of the task's block is reflected in the task name or namespace.
|
23
|
-
# If the task name is identical, the task block is executed only once, even if the file task definition is executed twice.
|
13
|
+
|
24
14
|
def task(name, *args, &block)
|
25
|
-
task_once(name, block)
|
26
|
-
super
|
27
|
-
end
|
15
|
+
task_once(name, block) { super }
|
28
16
|
end
|
29
|
-
|
30
|
-
private
|
17
|
+
|
18
|
+
private(def task_once(name, block)
|
31
19
|
name = name.keys.first if name.is_a?(Hash)
|
32
|
-
if block
|
33
|
-
Rake::Task.task_defined?(name) &&
|
34
|
-
Rake::Task[name].instance_variable_get('@task_block_location') == block.source_location
|
35
|
-
# task is already defined for this target and the same block
|
36
|
-
# So skip double definition of the same action
|
20
|
+
if block and (Rake::Task.task_defined?(name) and (Rake::Task[name].instance_variable_get("@task_block_location") == block.source_location)) then
|
37
21
|
Rake::Task[name]
|
38
|
-
elsif block
|
39
|
-
yield.tap do
|
40
|
-
Rake::Task[name].instance_variable_set('@task_block_location', block.source_location)
|
41
|
-
end
|
42
22
|
else
|
43
|
-
|
23
|
+
if block then
|
24
|
+
yield.tap do
|
25
|
+
Rake::Task[name].instance_variable_set("@task_block_location", block.source_location)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
yield
|
29
|
+
end
|
44
30
|
end
|
45
|
-
end
|
46
|
-
end
|
31
|
+
end)
|
32
|
+
end
|
data/sample/array_insert.rb
CHANGED
@@ -1,20 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
c
|
6
|
-
|
7
|
-
|
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
|
-
|
1
|
+
require("cipherstash-pg")
|
2
|
+
c = CipherStashPG.connect(:dbname => "test")
|
3
|
+
c.exec("DROP TABLE IF EXISTS foo")
|
4
|
+
c.exec("CREATE TABLE foo (strings character varying[]);")
|
5
|
+
c.set_error_verbosity(CipherStashPG::PQERRORS_VERBOSE)
|
6
|
+
c.prepare("stmt", "INSERT INTO foo VALUES ($1);")
|
7
|
+
c.exec_prepared("stmt", ["{'this','that'}"])
|
data/sample/async_api.rb
CHANGED
@@ -1,102 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
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"
|
1
|
+
require("cipherstash-pg")
|
2
|
+
TIMEOUT = 5.0
|
3
|
+
progress_thread = Thread.new { loop { print("x") } }
|
4
|
+
def output_progress(msg)
|
5
|
+
puts("\n>>> #{msg}\n")
|
21
6
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
# Track the progress of the connection, waiting for the socket to become readable/writable
|
31
|
-
# before polling it
|
32
|
-
poll_status = PG::PGRES_POLLING_WRITING
|
33
|
-
until poll_status == PG::PGRES_POLLING_OK ||
|
34
|
-
poll_status == PG::PGRES_POLLING_FAILED
|
35
|
-
|
36
|
-
# If the socket needs to read, wait 'til it becomes readable to poll again
|
37
|
-
case poll_status
|
38
|
-
when PG::PGRES_POLLING_READING
|
39
|
-
output_progress " waiting for socket to become readable"
|
40
|
-
select( [conn.socket_io], nil, nil, TIMEOUT ) or
|
41
|
-
raise "Asynchronous connection timed out!"
|
42
|
-
|
43
|
-
# ...and the same for when the socket needs to write
|
44
|
-
when PG::PGRES_POLLING_WRITING
|
45
|
-
output_progress " waiting for socket to become writable"
|
46
|
-
select( nil, [conn.socket_io], nil, TIMEOUT ) or
|
47
|
-
raise "Asynchronous connection timed out!"
|
48
|
-
end
|
49
|
-
|
50
|
-
# Output a status message about the progress
|
51
|
-
case conn.status
|
52
|
-
when PG::CONNECTION_STARTED
|
53
|
-
output_progress " waiting for connection to be made."
|
54
|
-
when PG::CONNECTION_MADE
|
55
|
-
output_progress " connection OK; waiting to send."
|
56
|
-
when PG::CONNECTION_AWAITING_RESPONSE
|
57
|
-
output_progress " waiting for a response from the server."
|
58
|
-
when PG::CONNECTION_AUTH_OK
|
59
|
-
output_progress " received authentication; waiting for backend start-up to finish."
|
60
|
-
when PG::CONNECTION_SSL_STARTUP
|
61
|
-
output_progress " negotiating SSL encryption."
|
62
|
-
when PG::CONNECTION_SETENV
|
63
|
-
output_progress " negotiating environment-driven parameter settings."
|
64
|
-
when PG::CONNECTION_NEEDED
|
65
|
-
output_progress " internal state: connect() needed."
|
66
|
-
end
|
67
|
-
|
68
|
-
# Check to see if it's finished or failed yet
|
69
|
-
poll_status = conn.connect_poll
|
7
|
+
output_progress("Starting connection...")
|
8
|
+
(conn = CipherStashPG::Connection.connect_start(:dbname => "test") or abort("Unable to create a new connection!"))
|
9
|
+
if (conn.status == CipherStashPG::CONNECTION_BAD) then
|
10
|
+
abort(("Connection failed: %s" % [conn.error_message]))
|
70
11
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
12
|
+
poll_status = CipherStashPG::PGRES_POLLING_WRITING
|
13
|
+
until ((poll_status == CipherStashPG::PGRES_POLLING_OK) or (poll_status == CipherStashPG::PGRES_POLLING_FAILED)) do
|
14
|
+
(case poll_status
|
15
|
+
when CipherStashPG::PGRES_POLLING_READING then
|
16
|
+
output_progress(" waiting for socket to become readable")
|
17
|
+
(select([conn.socket_io], nil, nil, TIMEOUT) or raise("Asynchronous connection timed out!"))
|
18
|
+
when CipherStashPG::PGRES_POLLING_WRITING then
|
19
|
+
output_progress(" waiting for socket to become writable")
|
20
|
+
(select(nil, [conn.socket_io], nil, TIMEOUT) or raise("Asynchronous connection timed out!"))
|
21
|
+
end
|
22
|
+
case conn.status
|
23
|
+
when CipherStashPG::CONNECTION_STARTED then
|
24
|
+
output_progress(" waiting for connection to be made.")
|
25
|
+
when CipherStashPG::CONNECTION_MADE then
|
26
|
+
output_progress(" connection OK; waiting to send.")
|
27
|
+
when CipherStashPG::CONNECTION_AWAITING_RESPONSE then
|
28
|
+
output_progress(" waiting for a response from the server.")
|
29
|
+
when CipherStashPG::CONNECTION_AUTH_OK then
|
30
|
+
output_progress(" received authentication; waiting for backend start-up to finish.")
|
31
|
+
when CipherStashPG::CONNECTION_SSL_STARTUP then
|
32
|
+
output_progress(" negotiating SSL encryption.")
|
33
|
+
when CipherStashPG::CONNECTION_SETENV then
|
34
|
+
output_progress(" negotiating environment-driven parameter settings.")
|
35
|
+
when CipherStashPG::CONNECTION_NEEDED then
|
36
|
+
output_progress(" internal state: connect() needed.")
|
37
|
+
end
|
38
|
+
poll_status = conn.connect_poll)
|
39
|
+
end
|
40
|
+
unless (conn.status == CipherStashPG::CONNECTION_OK) then
|
41
|
+
abort(("Connect failed: %s" % [conn.error_message]))
|
42
|
+
end
|
43
|
+
output_progress("Sending query")
|
44
|
+
conn.send_query("SELECT * FROM pg_stat_activity")
|
78
45
|
loop do
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
# Fetch the next result. If there isn't one, the query is finished
|
90
|
-
result = conn.get_result or break
|
91
|
-
|
92
|
-
puts "\n\nQuery result:\n%p\n" % [ result.values ]
|
46
|
+
output_progress(" waiting for a response")
|
47
|
+
conn.consume_input
|
48
|
+
while conn.is_busy do
|
49
|
+
(select([conn.socket_io], nil, nil, TIMEOUT) or raise("Timeout waiting for query response."))
|
50
|
+
conn.consume_input
|
51
|
+
end
|
52
|
+
(result = conn.get_result or break)
|
53
|
+
puts(("\n\nQuery result:\n%p\n" % [result.values]))
|
93
54
|
end
|
94
|
-
|
95
|
-
output_progress "Done."
|
55
|
+
output_progress("Done.")
|
96
56
|
conn.finish
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
progress_thread.join
|
57
|
+
if defined? progress_thread then
|
58
|
+
progress_thread.kill
|
59
|
+
progress_thread.join
|
101
60
|
end
|
102
|
-
|
data/sample/async_copyto.rb
CHANGED
@@ -1,39 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# Using COPY asynchronously
|
7
|
-
|
8
|
-
$stderr.puts "Opening database connection ..."
|
9
|
-
conn = PG.connect( :dbname => 'test' )
|
10
|
-
conn.setnonblocking( true )
|
11
|
-
|
1
|
+
require("cipherstash-pg")
|
2
|
+
require("stringio")
|
3
|
+
$stderr.puts("Opening database connection ...")
|
4
|
+
conn = CipherStashPG.connect(:dbname => "test")
|
5
|
+
conn.setnonblocking(true)
|
12
6
|
socket = conn.socket_io
|
13
|
-
|
14
|
-
|
15
|
-
buf = ''
|
7
|
+
$stderr.puts("Running COPY command ...")
|
8
|
+
buf = ""
|
16
9
|
conn.transaction do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
conn.consume_input
|
31
|
-
end
|
32
|
-
|
33
|
-
buf = conn.get_copy_data
|
34
|
-
$stdout.puts( buf ) if buf
|
35
|
-
end until buf.nil?
|
10
|
+
conn.send_query("COPY logs TO STDOUT WITH csv")
|
11
|
+
buf = nil
|
12
|
+
begin
|
13
|
+
($stderr.puts("COPY loop")
|
14
|
+
conn.consume_input
|
15
|
+
while conn.is_busy do
|
16
|
+
$stderr.puts(" ready loop")
|
17
|
+
(select([socket], nil, nil, 5.0) or raise("Timeout (5s) waiting for query response."))
|
18
|
+
conn.consume_input
|
19
|
+
end
|
20
|
+
buf = conn.get_copy_data
|
21
|
+
$stdout.puts(buf) if buf)
|
22
|
+
end until buf.nil?
|
36
23
|
end
|
37
|
-
|
38
24
|
conn.finish
|
39
|
-
|
data/sample/async_mixed.rb
CHANGED
@@ -1,56 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'pg'
|
4
|
-
|
1
|
+
require("cipherstash-pg")
|
5
2
|
$stdout.sync = true
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
16
|
-
|
17
|
-
# Output progress messages
|
18
|
-
def output_progress( msg )
|
19
|
-
puts ">>> #{msg}\n"
|
3
|
+
TIMEOUT = 5.0
|
4
|
+
CONN_OPTS = { :host => "localhost", :dbname => "test" }
|
5
|
+
def output_progress(msg)
|
6
|
+
puts(">>> #{msg}\n")
|
7
|
+
end
|
8
|
+
output_progress("Starting connection...")
|
9
|
+
(conn = CipherStashPG.connect(CONN_OPTS) or abort("Unable to create a new connection!"))
|
10
|
+
unless (conn.status == CipherStashPG::CONNECTION_OK) then
|
11
|
+
abort(("Connect failed: %s" % [conn.error_message]))
|
20
12
|
end
|
21
|
-
|
22
|
-
# Start the (synchronous) connection
|
23
|
-
output_progress "Starting connection..."
|
24
|
-
conn = PG.connect( CONN_OPTS ) or abort "Unable to create a new connection!"
|
25
|
-
|
26
|
-
abort "Connect failed: %s" % [ conn.error_message ] unless conn.status == PG::CONNECTION_OK
|
27
|
-
|
28
|
-
# Now grab a reference to the underlying socket to select() on while the query is running
|
29
13
|
socket = conn.socket_io
|
30
|
-
|
31
|
-
|
32
|
-
output_progress "Sending query"
|
33
|
-
conn.send_query( "SELECT * FROM pg_stat_activity" )
|
34
|
-
|
35
|
-
# Fetch results until there aren't any more
|
14
|
+
output_progress("Sending query")
|
15
|
+
conn.send_query("SELECT * FROM pg_stat_activity")
|
36
16
|
loop do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
# Fetch the next result. If there isn't one, the query is finished
|
49
|
-
result = conn.get_result or break
|
50
|
-
|
51
|
-
output_progress "Query result:\n%p\n" % [ result.values ]
|
17
|
+
output_progress(" waiting for a response")
|
18
|
+
conn.consume_input
|
19
|
+
while conn.is_busy do
|
20
|
+
output_progress((" waiting for data to be available on %p..." % [socket]))
|
21
|
+
(select([socket], nil, nil, TIMEOUT) or raise("Timeout waiting for query response."))
|
22
|
+
conn.consume_input
|
23
|
+
end
|
24
|
+
(result = conn.get_result or break)
|
25
|
+
output_progress(("Query result:\n%p\n" % [result.values]))
|
52
26
|
end
|
53
|
-
|
54
|
-
output_progress "Done."
|
27
|
+
output_progress("Done.")
|
55
28
|
conn.finish
|
56
|
-
|