cipherstash-pg 1.0.0.beta.1-x86_64-linux → 1.0.0.beta.3-x86_64-linux
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.so +0 -0
- data/lib/3.0/pg_ext.so +0 -0
- data/lib/3.1/pg_ext.so +0 -0
- data/lib/3.2/pg_ext.so +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.so.5 +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 -30
- 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/vendor/database-extensions/install.sql +0 -317
- data/vendor/database-extensions/uninstall.sql +0 -20
data/sample/issue-119.rb
CHANGED
@@ -1,94 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
conn
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
text
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
Jaguar 100 157
|
47
|
-
Chimpanzee 52.16 440
|
48
|
-
Brachiosaurus 87000 154.5
|
49
|
-
Mole 0.122 3
|
50
|
-
Pig 192 18
|
51
|
-
END_DATA
|
52
|
-
|
53
|
-
#ActiveRecord::Base.connection_pool.with_connection do |conn|
|
54
|
-
conn.transaction do
|
55
|
-
rc = conn #.raw_connection
|
56
|
-
rc.exec "TRUNCATE TABLE #{table_name};" if options[:truncate]
|
57
|
-
sql = "COPY #{table_name} (#{field_list.join(',')}) FROM STDIN #{sql_parameters} "
|
58
|
-
p sql
|
59
|
-
rc.exec(sql)
|
60
|
-
errmsg = nil # scope this outside of the rescue below so it's visible later
|
61
|
-
begin
|
62
|
-
if method == 1
|
63
|
-
rc.put_copy_data text + "\\.\n"
|
64
|
-
else
|
65
|
-
text.each_line { |line| rc.put_copy_data(line) }
|
66
|
-
end
|
67
|
-
rescue Errno => err
|
68
|
-
errmsg = "%s while reading copy data: %s" % [err.class.name, err.message]
|
69
|
-
puts "an error occurred"
|
70
|
-
end
|
71
|
-
|
72
|
-
if errmsg
|
73
|
-
rc.put_copy_end(errmsg)
|
74
|
-
puts "ERROR #{errmsg}"
|
75
|
-
else
|
76
|
-
rc.put_copy_end
|
77
|
-
end
|
78
|
-
|
79
|
-
while res = rc.get_result
|
80
|
-
st = res.res_status( res.result_status )
|
81
|
-
puts "Result of COPY is: %s" % [ st ]
|
82
|
-
if res.result_status != PG::PGRES_COPY_IN
|
83
|
-
puts res.error_message
|
84
|
-
end
|
85
|
-
end
|
86
|
-
puts "end"
|
87
|
-
end #transaction
|
88
|
-
#end #connection
|
89
|
-
|
90
|
-
conn.exec( "SELECT name, brain_weight FROM #{table_name}" ) do |res|
|
91
|
-
p res.values
|
1
|
+
require("cipherstash-pg")
|
2
|
+
conn = CipherStashPG.connect(:dbname => "test")
|
3
|
+
table_name = "issue_119"
|
4
|
+
field_list = ["name", "body_weight", "brain_weight"]
|
5
|
+
method = 0
|
6
|
+
options = { :truncate => true }
|
7
|
+
sql_parameters = ""
|
8
|
+
conn.set_error_verbosity(CipherStashPG::PQERRORS_VERBOSE)
|
9
|
+
conn.exec("DROP TABLE IF EXISTS #{table_name}")
|
10
|
+
conn.exec("CREATE TABLE #{table_name} ( id SERIAL, name TEXT, body_weight REAL, brain_weight REAL )")
|
11
|
+
text = "Mountain beaver\t1.35\t465\nCow\t465\t423\nGrey wolf\t36.33\t119.5\nGoat\t27.66\t115\nGuinea pig\t1.04\t5.5\nDipliodocus\t11700\t50\nAsian elephant\t2547\t4603\nDonkey\t187.1\t419\nHorse\t521\t655\nPotar monkey\t10\t115\nCat\t3.3\t25.6\nGiraffe\t529\t680\nGorilla\t207\t406\nHuman\t62\t1320\nAfrican elephant\t6654\t5712\nTriceratops\t9400\t70\nRhesus monkey\t6.8\t179\nKangaroo\t35\t56\nGolden hamster\t0.12\t1\nMouse\t0.023\t0.4\nRabbit\t2.5\t12.1\nSheep\t55.5\t175\nJaguar\t100\t157\nChimpanzee\t52.16\t440\nBrachiosaurus\t87000\t154.5\nMole\t0.122\t3\nPig\t192\t18\n"
|
12
|
+
conn.transaction do
|
13
|
+
rc = conn
|
14
|
+
rc.exec("TRUNCATE TABLE #{table_name};") if options[:truncate]
|
15
|
+
sql = "COPY #{table_name} (#{field_list.join(",")}) FROM STDIN #{sql_parameters} "
|
16
|
+
p(sql)
|
17
|
+
rc.exec(sql)
|
18
|
+
errmsg = nil
|
19
|
+
begin
|
20
|
+
if (method == 1) then
|
21
|
+
rc.put_copy_data((text + "\\.\n"))
|
22
|
+
else
|
23
|
+
text.each_line { |line| rc.put_copy_data(line) }
|
24
|
+
end
|
25
|
+
rescue Errno => err
|
26
|
+
errmsg = ("%s while reading copy data: %s" % [err.class.name, err.message])
|
27
|
+
puts("an error occurred")
|
28
|
+
end
|
29
|
+
if errmsg then
|
30
|
+
rc.put_copy_end(errmsg)
|
31
|
+
puts("ERROR #{errmsg}")
|
32
|
+
else
|
33
|
+
rc.put_copy_end
|
34
|
+
end
|
35
|
+
while res = rc.get_result do
|
36
|
+
st = res.res_status(res.result_status)
|
37
|
+
puts(("Result of COPY is: %s" % [st]))
|
38
|
+
if (res.result_status != CipherStashPG::PGRES_COPY_IN) then
|
39
|
+
puts(res.error_message)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
puts("end")
|
43
|
+
end
|
44
|
+
conn.exec("SELECT name, brain_weight FROM #{table_name}") do |res|
|
45
|
+
p(res.values)
|
92
46
|
end
|
93
|
-
|
94
|
-
|
data/sample/losample.rb
CHANGED
@@ -1,69 +1,51 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
puts
|
10
|
-
|
11
|
-
|
12
|
-
puts
|
13
|
-
conn.
|
14
|
-
|
15
|
-
|
16
|
-
puts "
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
puts "Read test:"
|
23
|
-
fd = conn.lo_open( oid, PG::INV_READ|PG::INV_WRITE )
|
24
|
-
conn.lo_lseek( fd, 0, PG::SEEK_SET )
|
25
|
-
buf = conn.lo_read( fd, 50 )
|
26
|
-
puts " read: %p" % [ buf ]
|
27
|
-
puts " read was ok!" if buf =~ /require 'pg'/
|
28
|
-
|
29
|
-
# Append some test data onto the end of the object
|
30
|
-
puts "Write test:"
|
31
|
-
conn.lo_lseek( fd, 0, PG::SEEK_END )
|
1
|
+
require("cipherstash-pg")
|
2
|
+
SAMPLE_WRITE_DATA = "some sample data"
|
3
|
+
SAMPLE_EXPORT_NAME = "lowrite.txt"
|
4
|
+
conn = CipherStashPG.connect(:dbname => "test", :host => "localhost", :port => 5432)
|
5
|
+
puts(((((("dbname: " + conn.db) + "\thost: ") + conn.host) + "\tuser: ") + conn.user))
|
6
|
+
puts("Beginning transaction")
|
7
|
+
conn.exec("BEGIN")
|
8
|
+
puts("Import test:")
|
9
|
+
puts((" importing %s" % ["(string)"]))
|
10
|
+
oid = conn.lo_import("(string)")
|
11
|
+
puts((" imported as large object %d" % [oid]))
|
12
|
+
puts("Read test:")
|
13
|
+
fd = conn.lo_open(oid, (CipherStashPG::INV_READ | CipherStashPG::INV_WRITE))
|
14
|
+
conn.lo_lseek(fd, 0, CipherStashPG::SEEK_SET)
|
15
|
+
buf = conn.lo_read(fd, 50)
|
16
|
+
puts((" read: %p" % [buf]))
|
17
|
+
if buf =~ /require 'pg'/ then
|
18
|
+
puts(" read was ok!")
|
19
|
+
end
|
20
|
+
puts("Write test:")
|
21
|
+
conn.lo_lseek(fd, 0, CipherStashPG::SEEK_END)
|
32
22
|
buf = SAMPLE_WRITE_DATA.dup
|
33
23
|
totalbytes = 0
|
34
|
-
until buf.empty?
|
35
|
-
|
36
|
-
|
37
|
-
|
24
|
+
until buf.empty? do
|
25
|
+
(bytes = conn.lo_write(fd, buf)
|
26
|
+
buf.slice!(0, bytes)
|
27
|
+
totalbytes = (totalbytes + bytes))
|
38
28
|
end
|
39
|
-
puts
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
puts
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
puts
|
58
|
-
conn.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
puts 'Closing and unlinking:'
|
63
|
-
conn.lo_close( fd )
|
64
|
-
puts ' closed.'
|
65
|
-
conn.lo_unlink( oid )
|
66
|
-
puts ' unlinked.'
|
67
|
-
conn.exec( 'COMMIT' )
|
68
|
-
puts 'Done.'
|
69
|
-
|
29
|
+
puts((" appended %d bytes" % [totalbytes]))
|
30
|
+
puts("Export test:")
|
31
|
+
File.unlink(SAMPLE_EXPORT_NAME) if File.exist?(SAMPLE_EXPORT_NAME)
|
32
|
+
conn.lo_export(oid, SAMPLE_EXPORT_NAME)
|
33
|
+
puts(" success!") if File.exist?(SAMPLE_EXPORT_NAME)
|
34
|
+
puts((" exported as %s (%d bytes)" % [SAMPLE_EXPORT_NAME, File.size(SAMPLE_EXPORT_NAME)]))
|
35
|
+
conn.exec("COMMIT")
|
36
|
+
puts("End of transaction.")
|
37
|
+
puts("Testing read and delete from a new transaction:")
|
38
|
+
puts(" starting a new transaction")
|
39
|
+
conn.exec("BEGIN")
|
40
|
+
fd = conn.lo_open(oid, CipherStashPG::INV_READ)
|
41
|
+
puts(" reopened okay.")
|
42
|
+
conn.lo_lseek(fd, 50, CipherStashPG::SEEK_END)
|
43
|
+
buf = conn.lo_read(fd, 50)
|
44
|
+
puts(" read okay.") if (buf == SAMPLE_WRITE_DATA)
|
45
|
+
puts("Closing and unlinking:")
|
46
|
+
conn.lo_close(fd)
|
47
|
+
puts(" closed.")
|
48
|
+
conn.lo_unlink(oid)
|
49
|
+
puts(" unlinked.")
|
50
|
+
conn.exec("COMMIT")
|
51
|
+
puts("Done.")
|
data/sample/minimal-testcase.rb
CHANGED
@@ -1,17 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
RUBY_DESCRIPTION,
|
8
|
-
PG.version_string( true ),
|
9
|
-
"Server version: #{conn.server_version}",
|
10
|
-
"Client version: #{PG.library_version}",
|
11
|
-
'---'
|
12
|
-
|
13
|
-
result = conn.exec( "SELECT * from pg_stat_activity" )
|
14
|
-
|
15
|
-
$stderr.puts %Q{Expected this to return: ["select * from pg_stat_activity"]}
|
16
|
-
p result.field_values( 'current_query' )
|
17
|
-
|
1
|
+
require("cipherstash-pg")
|
2
|
+
conn = CipherStashPG.connect(:dbname => "test")
|
3
|
+
$stderr.puts("---", RUBY_DESCRIPTION, CipherStashPG.version_string(true), "Server version: #{conn.server_version}", "Client version: #{CipherStashPG.library_version}", "---")
|
4
|
+
result = conn.exec("SELECT * from pg_stat_activity")
|
5
|
+
$stderr.puts("Expected this to return: [\"select * from pg_stat_activity\"]")
|
6
|
+
p(result.field_values("current_query"))
|
data/sample/notify_wait.rb
CHANGED
@@ -1,72 +1,26 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
#
|
3
|
-
# Test script, demonstrating a non-poll notification for a table event.
|
4
|
-
#
|
5
|
-
|
6
1
|
BEGIN {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
require("pathname")
|
3
|
+
basedir = Pathname.new("(string)").expand_path.dirname.parent
|
4
|
+
libdir = (basedir + "lib")
|
5
|
+
$LOAD_PATH.unshift(libdir.to_s) unless $LOAD_PATH.include?(libdir.to_s)
|
11
6
|
}
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
TRIGGER_FUNCTION
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
AS $$
|
24
|
-
BEGIN
|
25
|
-
NOTIFY woo;
|
26
|
-
RETURN NULL;
|
27
|
-
END
|
28
|
-
$$
|
29
|
-
}
|
30
|
-
|
31
|
-
DROP_TRIGGER = %{
|
32
|
-
DROP TRIGGER IF EXISTS notify_trigger ON test
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
TRIGGER = %{
|
37
|
-
CREATE TRIGGER notify_trigger
|
38
|
-
AFTER UPDATE OR INSERT OR DELETE
|
39
|
-
ON test
|
40
|
-
FOR EACH STATEMENT
|
41
|
-
EXECUTE PROCEDURE notify_test();
|
42
|
-
}
|
43
|
-
|
44
|
-
conn = PG.connect( :dbname => 'test' )
|
45
|
-
|
46
|
-
conn.exec( TRIGGER_TABLE )
|
47
|
-
conn.exec( TRIGGER_FUNCTION )
|
48
|
-
conn.exec( DROP_TRIGGER )
|
49
|
-
conn.exec( TRIGGER )
|
50
|
-
|
51
|
-
conn.exec( 'LISTEN woo' ) # register interest in the 'woo' event
|
52
|
-
|
7
|
+
require("cipherstash-pg")
|
8
|
+
TRIGGER_TABLE = "\n\tCREATE TABLE IF NOT EXISTS test ( message text );\n"
|
9
|
+
TRIGGER_FUNCTION = "\nCREATE OR REPLACE FUNCTION notify_test()\nRETURNS TRIGGER\nLANGUAGE plpgsql\nAS $$\n BEGIN\n NOTIFY woo;\n RETURN NULL;\n END\n$$\n"
|
10
|
+
DROP_TRIGGER = "\nDROP TRIGGER IF EXISTS notify_trigger ON test\n"
|
11
|
+
TRIGGER = "\nCREATE TRIGGER notify_trigger\nAFTER UPDATE OR INSERT OR DELETE\nON test\nFOR EACH STATEMENT\nEXECUTE PROCEDURE notify_test();\n"
|
12
|
+
conn = CipherStashPG.connect(:dbname => "test")
|
13
|
+
conn.exec(TRIGGER_TABLE)
|
14
|
+
conn.exec(TRIGGER_FUNCTION)
|
15
|
+
conn.exec(DROP_TRIGGER)
|
16
|
+
conn.exec(TRIGGER)
|
17
|
+
conn.exec("LISTEN woo")
|
53
18
|
notifications = []
|
54
|
-
|
55
|
-
puts
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
puts "Waiting up to 30 seconds for for an event!"
|
61
|
-
conn.wait_for_notify( 30 ) do |notify, pid|
|
62
|
-
notifications << [ pid, notify ]
|
63
|
-
end
|
64
|
-
|
65
|
-
if notifications.empty?
|
66
|
-
puts "Awww, I didn't see any events."
|
19
|
+
puts("Now switch to a different term and run:", "", " psql test -c \"insert into test values ('A message.')\"", "")
|
20
|
+
puts("Waiting up to 30 seconds for for an event!")
|
21
|
+
conn.wait_for_notify(30) { |notify, pid| (notifications << [pid, notify]) }
|
22
|
+
if notifications.empty? then
|
23
|
+
puts("Awww, I didn't see any events.")
|
67
24
|
else
|
68
|
-
|
25
|
+
puts(("I got one from pid %d: %s" % notifications.first))
|
69
26
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|