pg 0.18.3 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.appveyor.yml +36 -0
  4. data/.gems +6 -0
  5. data/.github/workflows/binary-gems.yml +86 -0
  6. data/.github/workflows/source-gem.yml +129 -0
  7. data/.gitignore +13 -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/BSDL +2 -2
  15. data/Gemfile +14 -0
  16. data/History.rdoc +448 -4
  17. data/Manifest.txt +8 -21
  18. data/README-Windows.rdoc +4 -4
  19. data/README.ja.rdoc +1 -2
  20. data/README.rdoc +69 -17
  21. data/Rakefile +33 -135
  22. data/Rakefile.cross +70 -69
  23. data/certs/ged.pem +24 -0
  24. data/certs/larskanis-2022.pem +26 -0
  25. data/ext/errorcodes.def +109 -0
  26. data/ext/errorcodes.rb +1 -1
  27. data/ext/errorcodes.txt +35 -2
  28. data/ext/extconf.rb +120 -54
  29. data/ext/gvl_wrappers.c +8 -0
  30. data/ext/gvl_wrappers.h +44 -33
  31. data/ext/pg.c +213 -171
  32. data/ext/pg.h +92 -98
  33. data/ext/pg_binary_decoder.c +84 -15
  34. data/ext/pg_binary_encoder.c +24 -21
  35. data/ext/pg_coder.c +175 -39
  36. data/ext/pg_connection.c +1730 -1135
  37. data/ext/pg_copy_coder.c +94 -27
  38. data/ext/pg_record_coder.c +521 -0
  39. data/ext/pg_result.c +640 -221
  40. data/ext/pg_text_decoder.c +608 -40
  41. data/ext/pg_text_encoder.c +253 -99
  42. data/ext/pg_tuple.c +569 -0
  43. data/ext/pg_type_map.c +61 -21
  44. data/ext/pg_type_map_all_strings.c +19 -5
  45. data/ext/pg_type_map_by_class.c +54 -24
  46. data/ext/pg_type_map_by_column.c +79 -40
  47. data/ext/pg_type_map_by_mri_type.c +48 -19
  48. data/ext/pg_type_map_by_oid.c +55 -25
  49. data/ext/pg_type_map_in_ruby.c +51 -20
  50. data/ext/{util.c → pg_util.c} +12 -12
  51. data/ext/{util.h → pg_util.h} +2 -2
  52. data/lib/pg/basic_type_map_based_on_result.rb +47 -0
  53. data/lib/pg/basic_type_map_for_queries.rb +193 -0
  54. data/lib/pg/basic_type_map_for_results.rb +81 -0
  55. data/lib/pg/basic_type_registry.rb +301 -0
  56. data/lib/pg/binary_decoder.rb +23 -0
  57. data/lib/pg/coder.rb +24 -3
  58. data/lib/pg/connection.rb +723 -65
  59. data/lib/pg/constants.rb +2 -1
  60. data/lib/pg/exceptions.rb +9 -2
  61. data/lib/pg/result.rb +24 -7
  62. data/lib/pg/text_decoder.rb +24 -22
  63. data/lib/pg/text_encoder.rb +40 -8
  64. data/lib/pg/tuple.rb +30 -0
  65. data/lib/pg/type_map_by_column.rb +3 -2
  66. data/lib/pg/version.rb +4 -0
  67. data/lib/pg.rb +61 -36
  68. data/misc/openssl-pg-segfault.rb +31 -0
  69. data/misc/postgres/History.txt +9 -0
  70. data/misc/postgres/Manifest.txt +5 -0
  71. data/misc/postgres/README.txt +21 -0
  72. data/misc/postgres/Rakefile +21 -0
  73. data/misc/postgres/lib/postgres.rb +16 -0
  74. data/misc/ruby-pg/History.txt +9 -0
  75. data/misc/ruby-pg/Manifest.txt +5 -0
  76. data/misc/ruby-pg/README.txt +21 -0
  77. data/misc/ruby-pg/Rakefile +21 -0
  78. data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
  79. data/pg.gemspec +32 -0
  80. data/rakelib/task_extension.rb +46 -0
  81. data/sample/array_insert.rb +1 -1
  82. data/sample/async_api.rb +4 -8
  83. data/sample/async_copyto.rb +1 -1
  84. data/sample/async_mixed.rb +1 -1
  85. data/sample/check_conn.rb +1 -1
  86. data/sample/copydata.rb +71 -0
  87. data/sample/copyfrom.rb +1 -1
  88. data/sample/copyto.rb +1 -1
  89. data/sample/cursor.rb +1 -1
  90. data/sample/disk_usage_report.rb +6 -15
  91. data/sample/issue-119.rb +2 -2
  92. data/sample/losample.rb +1 -1
  93. data/sample/minimal-testcase.rb +2 -2
  94. data/sample/notify_wait.rb +1 -1
  95. data/sample/pg_statistics.rb +6 -15
  96. data/sample/replication_monitor.rb +9 -18
  97. data/sample/test_binary_values.rb +1 -1
  98. data/sample/wal_shipper.rb +2 -2
  99. data/sample/warehouse_partitions.rb +8 -17
  100. data.tar.gz.sig +0 -0
  101. metadata +80 -230
  102. metadata.gz.sig +0 -0
  103. data/ChangeLog +0 -5804
  104. data/lib/pg/basic_type_mapping.rb +0 -399
  105. data/spec/data/expected_trace.out +0 -26
  106. data/spec/data/random_binary_data +0 -0
  107. data/spec/helpers.rb +0 -355
  108. data/spec/pg/basic_type_mapping_spec.rb +0 -251
  109. data/spec/pg/connection_spec.rb +0 -1538
  110. data/spec/pg/result_spec.rb +0 -449
  111. data/spec/pg/type_map_by_class_spec.rb +0 -138
  112. data/spec/pg/type_map_by_column_spec.rb +0 -222
  113. data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
  114. data/spec/pg/type_map_by_oid_spec.rb +0 -149
  115. data/spec/pg/type_map_in_ruby_spec.rb +0 -164
  116. data/spec/pg/type_map_spec.rb +0 -22
  117. data/spec/pg/type_spec.rb +0 -690
  118. data/spec/pg_spec.rb +0 -50
data/sample/async_api.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  require 'pg'
4
4
 
@@ -27,10 +27,6 @@ conn = PG::Connection.connect_start( :dbname => 'test' ) or
27
27
  abort "Connection failed: %s" % [ conn.error_message ] if
28
28
  conn.status == PG::CONNECTION_BAD
29
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
30
  # Track the progress of the connection, waiting for the socket to become readable/writable
35
31
  # before polling it
36
32
  poll_status = PG::PGRES_POLLING_WRITING
@@ -41,13 +37,13 @@ until poll_status == PG::PGRES_POLLING_OK ||
41
37
  case poll_status
42
38
  when PG::PGRES_POLLING_READING
43
39
  output_progress " waiting for socket to become readable"
44
- select( [socket], nil, nil, TIMEOUT ) or
40
+ select( [conn.socket_io], nil, nil, TIMEOUT ) or
45
41
  raise "Asynchronous connection timed out!"
46
42
 
47
43
  # ...and the same for when the socket needs to write
48
44
  when PG::PGRES_POLLING_WRITING
49
45
  output_progress " waiting for socket to become writable"
50
- select( nil, [socket], nil, TIMEOUT ) or
46
+ select( nil, [conn.socket_io], nil, TIMEOUT ) or
51
47
  raise "Asynchronous connection timed out!"
52
48
  end
53
49
 
@@ -85,7 +81,7 @@ loop do
85
81
  # Buffer any incoming data on the socket until a full result is ready.
86
82
  conn.consume_input
87
83
  while conn.is_busy
88
- select( [socket], nil, nil, TIMEOUT ) or
84
+ select( [conn.socket_io], nil, nil, TIMEOUT ) or
89
85
  raise "Timeout waiting for query response."
90
86
  conn.consume_input
91
87
  end
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  require 'pg'
4
4
  require 'stringio'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  require 'pg'
4
4
 
data/sample/check_conn.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
  # encoding: utf-8
4
4
 
@@ -0,0 +1,71 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'pg'
4
+ require 'stringio'
5
+
6
+ $stderr.puts "Opening database connection ..."
7
+ conn = PG.connect( dbname: 'test' )
8
+
9
+ conn.exec( <<END_SQL )
10
+ DROP TABLE IF EXISTS logs;
11
+ CREATE TABLE logs (
12
+ client_ip inet,
13
+ username text,
14
+ ts timestamp,
15
+ request text,
16
+ status smallint,
17
+ bytes int
18
+ );
19
+ END_SQL
20
+
21
+ csv_io = StringIO.new( <<"END_DATA" )
22
+ "127.0.0.1","","30/Aug/2010:08:21:24 -0700","GET /manual/ HTTP/1.1",404,205
23
+ "127.0.0.1","","30/Aug/2010:08:21:24 -0700","GET /favicon.ico HTTP/1.1",404,209
24
+ "127.0.0.1","","30/Aug/2010:08:21:24 -0700","GET /favicon.ico HTTP/1.1",404,209
25
+ "127.0.0.1","","30/Aug/2010:08:22:29 -0700","GET /manual/ HTTP/1.1",200,11094
26
+ "127.0.0.1","","30/Aug/2010:08:22:38 -0700","GET /manual/index.html HTTP/1.1",200,725
27
+ "127.0.0.1","","30/Aug/2010:08:27:56 -0700","GET /manual/ HTTP/1.1",200,11094
28
+ "127.0.0.1","","30/Aug/2010:08:27:57 -0700","GET /manual/ HTTP/1.1",200,11094
29
+ "127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/index.html HTTP/1.1",200,7709
30
+ "127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/images/feather.gif HTTP/1.1",200,6471
31
+ "127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/images/left.gif HTTP/1.1",200,60
32
+ "127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/style/css/manual.css HTTP/1.1",200,18674
33
+ "127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/style/css/manual-print.css HTTP/1.1",200,13200
34
+ "127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/images/favicon.ico HTTP/1.1",200,1078
35
+ "127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/style/css/manual-loose-100pc.css HTTP/1.1",200,3065
36
+ "127.0.0.1","","30/Aug/2010:08:28:14 -0700","OPTIONS * HTTP/1.0",200,0
37
+ "127.0.0.1","","30/Aug/2010:08:28:15 -0700","OPTIONS * HTTP/1.0",200,0
38
+ "127.0.0.1","","30/Aug/2010:08:28:47 -0700","GET /manual/mod/directives.html HTTP/1.1",200,33561
39
+ "127.0.0.1","","30/Aug/2010:08:28:53 -0700","GET /manual/mod/mpm_common.html HTTP/1.1",200,67683
40
+ "127.0.0.1","","30/Aug/2010:08:28:53 -0700","GET /manual/images/down.gif HTTP/1.1",200,56
41
+ "127.0.0.1","","30/Aug/2010:08:28:53 -0700","GET /manual/images/up.gif HTTP/1.1",200,57
42
+ "127.0.0.1","","30/Aug/2010:09:19:58 -0700","GET /manual/mod/mod_log_config.html HTTP/1.1",200,28307
43
+ "127.0.0.1","","30/Aug/2010:09:20:19 -0700","GET /manual/mod/core.html HTTP/1.1",200,194144
44
+ "127.0.0.1","","30/Aug/2010:16:02:56 -0700","GET /manual/ HTTP/1.1",200,11094
45
+ "127.0.0.1","","30/Aug/2010:16:03:00 -0700","GET /manual/ HTTP/1.1",200,11094
46
+ "127.0.0.1","","30/Aug/2010:16:06:16 -0700","GET /manual/mod/mod_dir.html HTTP/1.1",200,10583
47
+ "127.0.0.1","","30/Aug/2010:16:06:44 -0700","GET /manual/ HTTP/1.1",200,7709
48
+ END_DATA
49
+
50
+ ### You can test the error case from the database side easily by
51
+ ### changing one of the numbers at the end of one of the above rows to
52
+ ### something non-numeric like "-".
53
+
54
+ $stderr.puts "Running COPY command with data ..."
55
+ buf = ''
56
+ conn.transaction do
57
+ res = conn.copy_data( "COPY logs FROM STDIN WITH csv" ) do
58
+ $stderr.print "Sending lines... "
59
+ csv_io.each_line.with_index do |buf, i|
60
+ $stderr.print "#{i + 1} "
61
+ conn.put_copy_data( buf )
62
+ end
63
+ $stderr.puts "done."
64
+ end
65
+ $stderr.puts "Result of COPY is: %s" % [ res.res_status(res.result_status) ]
66
+ $stderr.puts " tuples copied: %p" % [ res.cmd_tuples ]
67
+ end
68
+
69
+
70
+ conn.finish
71
+
data/sample/copyfrom.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  require 'pg'
4
4
  require 'stringio'
data/sample/copyto.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  require 'pg'
4
4
  require 'stringio'
data/sample/cursor.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  require 'pg'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
  # vim: set noet nosta sw=4 ts=4 :
3
3
  #
4
4
  # Quickly dump size information for a given database.
@@ -10,21 +10,12 @@
10
10
  #
11
11
 
12
12
 
13
- begin
14
- require 'ostruct'
15
- require 'optparse'
16
- require 'etc'
17
- require 'pg'
13
+ require 'ostruct'
14
+ require 'optparse'
15
+ require 'etc'
16
+ require 'pg'
18
17
 
19
- rescue LoadError # 1.8 support
20
- unless Object.const_defined?( :Gem )
21
- require 'rubygems'
22
- retry
23
- end
24
- raise
25
- end
26
-
27
- SCRIPT_VERSION = %q$Id: disk_usage_report.rb,v 76ebae01c937 2013/03/26 17:50:02 ged $
18
+ SCRIPT_VERSION = %q$Id$
28
19
 
29
20
 
30
21
  ### Gather data and output it to $stdout.
data/sample/issue-119.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  require 'pg'
4
4
 
@@ -66,7 +66,7 @@ END_DATA
66
66
  end
67
67
  rescue Errno => err
68
68
  errmsg = "%s while reading copy data: %s" % [err.class.name, err.message]
69
- puts "an error occured"
69
+ puts "an error occurred"
70
70
  end
71
71
 
72
72
  if errmsg
data/sample/losample.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  require 'pg'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
 
3
3
  require 'pg'
4
4
 
@@ -7,7 +7,7 @@ $stderr.puts '---',
7
7
  RUBY_DESCRIPTION,
8
8
  PG.version_string( true ),
9
9
  "Server version: #{conn.server_version}",
10
- "Client version: #{PG.respond_to?( :library_version ) ? PG.library_version : 'unknown'}",
10
+ "Client version: #{PG.library_version}",
11
11
  '---'
12
12
 
13
13
  result = conn.exec( "SELECT * from pg_stat_activity" )
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
  #
3
3
  # Test script, demonstrating a non-poll notification for a table event.
4
4
  #
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
  # vim: set noet nosta sw=4 ts=4 :
3
3
  #
4
4
  # PostgreSQL statistic gatherer.
@@ -13,26 +13,17 @@
13
13
  # some nice performance charts.
14
14
  #
15
15
 
16
- begin
17
- require 'ostruct'
18
- require 'optparse'
19
- require 'etc'
20
- require 'pg'
21
-
22
- rescue LoadError # 1.8 support
23
- unless Object.const_defined?( :Gem )
24
- require 'rubygems'
25
- retry
26
- end
27
- raise
28
- end
16
+ require 'ostruct'
17
+ require 'optparse'
18
+ require 'etc'
19
+ require 'pg'
29
20
 
30
21
 
31
22
  ### PostgreSQL Stats. Fetch information from pg_stat_* tables.
32
23
  ### Optionally run in a continuous loop, displaying deltas.
33
24
  ###
34
25
  class Stats
35
- VERSION = %q$Id: pg_statistics.rb,v 36ca5b412583 2012/04/17 23:32:25 mahlon $
26
+ VERSION = %q$Id$
36
27
 
37
28
  def initialize( opts )
38
29
  @opts = opts
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
  # vim: set noet nosta sw=4 ts=4 :
3
3
  #
4
4
  # Get the current WAL segment and offset from a master postgresql
@@ -15,28 +15,19 @@
15
15
  # db_replication.monitor db-master.example.com ...
16
16
  #
17
17
 
18
- begin
19
- require 'ostruct'
20
- require 'optparse'
21
- require 'pathname'
22
- require 'etc'
23
- require 'pg'
24
- require 'pp'
25
-
26
- rescue LoadError # 1.8 support
27
- unless Object.const_defined?( :Gem )
28
- require 'rubygems'
29
- retry
30
- end
31
- raise
32
- end
18
+ require 'ostruct'
19
+ require 'optparse'
20
+ require 'pathname'
21
+ require 'etc'
22
+ require 'pg'
23
+ require 'pp'
33
24
 
34
25
 
35
26
  ### A class to encapsulate the PG handles.
36
27
  ###
37
28
  class PGMonitor
38
29
 
39
- VERSION = %q$Id: replication_monitor.rb,v 36ca5b412583 2012/04/17 23:32:25 mahlon $
30
+ VERSION = %q$Id$
40
31
 
41
32
  # When to consider a slave as 'behind', measured in WAL segments.
42
33
  # The default WAL segment size is 16, so we'll alert after
@@ -96,7 +87,7 @@ class PGMonitor
96
87
  #########
97
88
 
98
89
  ### Ask the master for the current xlog information, to compare
99
- ### to slaves. Returns true on succcess. On failure, populates
90
+ ### to slaves. Returns true on success. On failure, populates
100
91
  ### the failures array and returns false.
101
92
  ###
102
93
  def get_current_wal
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby1.9.1
1
+ # -*- ruby -*-1.9.1
2
2
 
3
3
  require 'pg'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
  #
3
3
  # A script to wrap ssh and rsync for PostgreSQL WAL files shipping.
4
4
  # Mahlon E. Smith <mahlon@martini.nu>
@@ -350,7 +350,7 @@ module WalShipper
350
350
  ###
351
351
  def dispatch_dest( dest )
352
352
  if ! dest.enabled.nil? && ! dest.enabled
353
- self.log "Skipping explicity disabled destination %p, WAL is queued." % [ dest.label ]
353
+ self.log "Skipping explicitly disabled destination %p, WAL is queued." % [ dest.label ]
354
354
  return
355
355
  end
356
356
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # -*- ruby -*-
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
  #
4
4
  # Script to automatically move partitioned tables and their indexes
@@ -36,21 +36,12 @@
36
36
  #
37
37
 
38
38
 
39
- begin
40
- require 'date'
41
- require 'ostruct'
42
- require 'optparse'
43
- require 'pathname'
44
- require 'etc'
45
- require 'pg'
46
-
47
- rescue LoadError # 1.8 support
48
- unless Object.const_defined?( :Gem )
49
- require 'rubygems'
50
- retry
51
- end
52
- raise
53
- end
39
+ require 'date'
40
+ require 'ostruct'
41
+ require 'optparse'
42
+ require 'pathname'
43
+ require 'etc'
44
+ require 'pg'
54
45
 
55
46
 
56
47
  ### A tablespace migration class.
@@ -159,7 +150,7 @@ class PGWarehouse
159
150
  end
160
151
  end
161
152
 
162
- # Add table inheritence information.
153
+ # Add table inheritance information.
163
154
  #
164
155
  db.exec 'SELECT inhrelid AS oid, inhparent AS parent FROM pg_inherits' do |res|
165
156
  res.each do |row|
data.tar.gz.sig CHANGED
Binary file