cipherstash-pg 1.0.0.beta.1-x86_64-darwin-22 → 1.0.0.beta.4-x86_64-darwin-22

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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/.appveyor.yml +42 -0
  3. data/.gems +6 -0
  4. data/.gemtest +0 -0
  5. data/.github/workflows/binary-gems.yml +117 -0
  6. data/.github/workflows/source-gem.yml +137 -0
  7. data/.gitignore +19 -0
  8. data/.hgsigs +34 -0
  9. data/.hgtags +41 -0
  10. data/.irbrc +23 -0
  11. data/.pryrc +23 -0
  12. data/.tm_properties +21 -0
  13. data/.travis.yml +49 -0
  14. data/Gemfile +3 -3
  15. data/Gemfile.lock +45 -0
  16. data/{History.rdoc → History.md} +168 -153
  17. data/README.ja.md +266 -0
  18. data/README.md +272 -0
  19. data/Rakefile +65 -104
  20. data/Rakefile.cross +298 -0
  21. data/certs/larskanis-2023.pem +24 -0
  22. data/cipherstash-pg.gemspec +0 -0
  23. data/lib/2.7/pg_ext.bundle +0 -0
  24. data/lib/3.0/pg_ext.bundle +0 -0
  25. data/lib/3.1/pg_ext.bundle +0 -0
  26. data/lib/3.2/pg_ext.bundle +0 -0
  27. data/lib/cipherstash-pg/basic_type_map_based_on_result.rb +11 -0
  28. data/lib/cipherstash-pg/basic_type_map_for_queries.rb +113 -0
  29. data/lib/cipherstash-pg/basic_type_map_for_results.rb +30 -0
  30. data/lib/cipherstash-pg/basic_type_registry.rb +206 -0
  31. data/lib/cipherstash-pg/binary_decoder.rb +21 -0
  32. data/lib/cipherstash-pg/coder.rb +82 -0
  33. data/lib/cipherstash-pg/connection.rb +467 -0
  34. data/lib/cipherstash-pg/constants.rb +3 -0
  35. data/lib/cipherstash-pg/exceptions.rb +19 -0
  36. data/lib/cipherstash-pg/result.rb +22 -0
  37. data/lib/cipherstash-pg/text_decoder.rb +43 -0
  38. data/lib/cipherstash-pg/text_encoder.rb +67 -0
  39. data/lib/cipherstash-pg/tuple.rb +24 -0
  40. data/lib/cipherstash-pg/type_map_by_column.rb +11 -0
  41. data/lib/cipherstash-pg/version.rb +3 -0
  42. data/lib/cipherstash-pg.rb +56 -11
  43. data/lib/libpq.5.dylib +0 -0
  44. data/misc/openssl-pg-segfault.rb +15 -25
  45. data/misc/postgres/Rakefile +13 -20
  46. data/misc/postgres/lib/postgres.rb +10 -14
  47. data/misc/ruby-pg/Rakefile +13 -20
  48. data/misc/ruby-pg/lib/ruby/pg.rb +10 -14
  49. data/rakelib/task_extension.rb +17 -31
  50. data/sample/array_insert.rb +7 -20
  51. data/sample/async_api.rb +54 -96
  52. data/sample/async_copyto.rb +20 -35
  53. data/sample/async_mixed.rb +22 -50
  54. data/sample/check_conn.rb +8 -20
  55. data/sample/copydata.rb +18 -68
  56. data/sample/copyfrom.rb +26 -78
  57. data/sample/copyto.rb +10 -16
  58. data/sample/cursor.rb +9 -19
  59. data/sample/disk_usage_report.rb +89 -174
  60. data/sample/issue-119.rb +45 -93
  61. data/sample/losample.rb +48 -66
  62. data/sample/minimal-testcase.rb +6 -17
  63. data/sample/notify_wait.rb +21 -67
  64. data/sample/pg_statistics.rb +100 -281
  65. data/sample/replication_monitor.rb +119 -218
  66. data/sample/test_binary_values.rb +14 -30
  67. data/sample/wal_shipper.rb +199 -431
  68. data/sample/warehouse_partitions.rb +157 -307
  69. data/translation/.po4a-version +7 -0
  70. data/translation/po/all.pot +875 -0
  71. data/translation/po/ja.po +868 -0
  72. data/translation/po4a.cfg +9 -0
  73. metadata +50 -28
  74. data/README.ja.rdoc +0 -13
  75. data/README.rdoc +0 -233
  76. data/lib/pg/basic_type_map_based_on_result.rb +0 -47
  77. data/lib/pg/basic_type_map_for_queries.rb +0 -193
  78. data/lib/pg/basic_type_map_for_results.rb +0 -81
  79. data/lib/pg/basic_type_registry.rb +0 -301
  80. data/lib/pg/binary_decoder.rb +0 -23
  81. data/lib/pg/coder.rb +0 -104
  82. data/lib/pg/connection.rb +0 -878
  83. data/lib/pg/constants.rb +0 -12
  84. data/lib/pg/exceptions.rb +0 -18
  85. data/lib/pg/result.rb +0 -43
  86. data/lib/pg/text_decoder.rb +0 -46
  87. data/lib/pg/text_encoder.rb +0 -59
  88. data/lib/pg/tuple.rb +0 -30
  89. data/lib/pg/type_map_by_column.rb +0 -16
  90. data/lib/pg/version.rb +0 -4
  91. data/lib/pg.rb +0 -55
data/sample/issue-119.rb CHANGED
@@ -1,94 +1,46 @@
1
- # -*- ruby -*-
2
-
3
- require 'pg'
4
-
5
- # This is another example of how to use COPY FROM, this time as a
6
- # minimal test case used to try to figure out what was going on in
7
- # an issue submitted from a user:
8
- #
9
- # https://bitbucket.org/ged/ruby-pg/issue/119
10
- #
11
-
12
- conn = PG.connect( dbname: 'test' )
13
- table_name = 'issue_119'
14
- field_list = %w[name body_weight brain_weight]
15
- method = 0
16
- options = { truncate: true }
17
- sql_parameters = ''
18
-
19
- conn.set_error_verbosity( PG::PQERRORS_VERBOSE )
20
- conn.exec( "DROP TABLE IF EXISTS #{table_name}" )
21
- conn.exec( "CREATE TABLE #{table_name} ( id SERIAL, name TEXT, body_weight REAL, brain_weight REAL )" )
22
-
23
- text = <<-END_DATA
24
- Mountain beaver 1.35 465
25
- Cow 465 423
26
- Grey wolf 36.33 119.5
27
- Goat 27.66 115
28
- Guinea pig 1.04 5.5
29
- Dipliodocus 11700 50
30
- Asian elephant 2547 4603
31
- Donkey 187.1 419
32
- Horse 521 655
33
- Potar monkey 10 115
34
- Cat 3.3 25.6
35
- Giraffe 529 680
36
- Gorilla 207 406
37
- Human 62 1320
38
- African elephant 6654 5712
39
- Triceratops 9400 70
40
- Rhesus monkey 6.8 179
41
- Kangaroo 35 56
42
- Golden hamster 0.12 1
43
- Mouse 0.023 0.4
44
- Rabbit 2.5 12.1
45
- Sheep 55.5 175
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
- # -*- ruby -*-
2
-
3
- require 'pg'
4
-
5
- SAMPLE_WRITE_DATA = 'some sample data'
6
- SAMPLE_EXPORT_NAME = 'lowrite.txt'
7
-
8
- conn = PG.connect( :dbname => 'test', :host => 'localhost', :port => 5432 )
9
- puts "dbname: " + conn.db + "\thost: " + conn.host + "\tuser: " + conn.user
10
-
11
- # Start a transaction, as all large object functions require one.
12
- puts "Beginning transaction"
13
- conn.exec( 'BEGIN' )
14
-
15
- # Test importing from a file
16
- puts "Import test:"
17
- puts " importing %s" % [ __FILE__ ]
18
- oid = conn.lo_import( __FILE__ )
19
- puts " imported as large object %d" % [ oid ]
20
-
21
- # Read back 50 bytes of the imported data
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
- bytes = conn.lo_write( fd, buf )
36
- buf.slice!( 0, bytes )
37
- totalbytes += bytes
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 " appended %d bytes" % [ totalbytes ]
40
-
41
- # Now export it
42
- puts "Export test:"
43
- File.unlink( SAMPLE_EXPORT_NAME ) if File.exist?( SAMPLE_EXPORT_NAME )
44
- conn.lo_export( oid, SAMPLE_EXPORT_NAME )
45
- puts " success!" if File.exist?( SAMPLE_EXPORT_NAME )
46
- puts " exported as %s (%d bytes)" % [ SAMPLE_EXPORT_NAME, File.size(SAMPLE_EXPORT_NAME) ]
47
-
48
- conn.exec( 'COMMIT' )
49
- puts "End of transaction."
50
-
51
-
52
- puts 'Testing read and delete from a new transaction:'
53
- puts ' starting a new transaction'
54
- conn.exec( 'BEGIN' )
55
-
56
- fd = conn.lo_open( oid, PG::INV_READ )
57
- puts ' reopened okay.'
58
- conn.lo_lseek( fd, 50, PG::SEEK_END )
59
- buf = conn.lo_read( fd, 50 )
60
- puts ' read okay.' if buf == SAMPLE_WRITE_DATA
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.")
@@ -1,17 +1,6 @@
1
- # -*- ruby -*-
2
-
3
- require 'pg'
4
-
5
- conn = PG.connect( :dbname => 'test' )
6
- $stderr.puts '---',
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"))
@@ -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
- require 'pathname'
8
- basedir = Pathname.new( __FILE__ ).expand_path.dirname.parent
9
- libdir = basedir + 'lib'
10
- $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
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
- require 'pg'
14
-
15
- TRIGGER_TABLE = %{
16
- CREATE TABLE IF NOT EXISTS test ( message text );
17
- }
18
-
19
- TRIGGER_FUNCTION = %{
20
- CREATE OR REPLACE FUNCTION notify_test()
21
- RETURNS TRIGGER
22
- LANGUAGE plpgsql
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 "Now switch to a different term and run:",
56
- '',
57
- %{ psql test -c "insert into test values ('A message.')"},
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
- puts "I got one from pid %d: %s" % notifications.first
25
+ puts(("I got one from pid %d: %s" % notifications.first))
69
26
  end
70
-
71
-
72
-