pg 0.18.0 → 1.1.4

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 (80) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/BSDL +2 -2
  4. data/ChangeLog +1221 -4
  5. data/History.rdoc +200 -0
  6. data/Manifest.txt +5 -18
  7. data/README-Windows.rdoc +15 -26
  8. data/README.rdoc +27 -10
  9. data/Rakefile +33 -24
  10. data/Rakefile.cross +57 -39
  11. data/ext/errorcodes.def +37 -0
  12. data/ext/errorcodes.rb +1 -1
  13. data/ext/errorcodes.txt +16 -1
  14. data/ext/extconf.rb +29 -35
  15. data/ext/gvl_wrappers.c +4 -0
  16. data/ext/gvl_wrappers.h +27 -39
  17. data/ext/pg.c +27 -53
  18. data/ext/pg.h +66 -83
  19. data/ext/pg_binary_decoder.c +75 -6
  20. data/ext/pg_binary_encoder.c +14 -12
  21. data/ext/pg_coder.c +83 -13
  22. data/ext/pg_connection.c +627 -351
  23. data/ext/pg_copy_coder.c +44 -9
  24. data/ext/pg_result.c +364 -134
  25. data/ext/pg_text_decoder.c +605 -46
  26. data/ext/pg_text_encoder.c +95 -76
  27. data/ext/pg_tuple.c +541 -0
  28. data/ext/pg_type_map.c +20 -13
  29. data/ext/pg_type_map_by_column.c +7 -7
  30. data/ext/pg_type_map_by_mri_type.c +2 -2
  31. data/ext/pg_type_map_in_ruby.c +4 -7
  32. data/ext/util.c +7 -7
  33. data/ext/util.h +3 -3
  34. data/lib/pg/basic_type_mapping.rb +105 -45
  35. data/lib/pg/binary_decoder.rb +22 -0
  36. data/lib/pg/coder.rb +1 -1
  37. data/lib/pg/connection.rb +109 -39
  38. data/lib/pg/constants.rb +1 -1
  39. data/lib/pg/exceptions.rb +1 -1
  40. data/lib/pg/result.rb +11 -6
  41. data/lib/pg/text_decoder.rb +25 -20
  42. data/lib/pg/text_encoder.rb +43 -1
  43. data/lib/pg/tuple.rb +30 -0
  44. data/lib/pg/type_map_by_column.rb +1 -1
  45. data/lib/pg.rb +21 -11
  46. data/spec/helpers.rb +50 -25
  47. data/spec/pg/basic_type_mapping_spec.rb +287 -30
  48. data/spec/pg/connection_spec.rb +695 -282
  49. data/spec/pg/connection_sync_spec.rb +41 -0
  50. data/spec/pg/result_spec.rb +59 -17
  51. data/spec/pg/tuple_spec.rb +280 -0
  52. data/spec/pg/type_map_by_class_spec.rb +3 -3
  53. data/spec/pg/type_map_by_column_spec.rb +1 -1
  54. data/spec/pg/type_map_by_mri_type_spec.rb +2 -2
  55. data/spec/pg/type_map_by_oid_spec.rb +1 -1
  56. data/spec/pg/type_map_in_ruby_spec.rb +1 -1
  57. data/spec/pg/type_map_spec.rb +1 -1
  58. data/spec/pg/type_spec.rb +319 -35
  59. data/spec/pg_spec.rb +2 -2
  60. data.tar.gz.sig +0 -0
  61. metadata +68 -68
  62. metadata.gz.sig +0 -0
  63. data/sample/array_insert.rb +0 -20
  64. data/sample/async_api.rb +0 -106
  65. data/sample/async_copyto.rb +0 -39
  66. data/sample/async_mixed.rb +0 -56
  67. data/sample/check_conn.rb +0 -21
  68. data/sample/copyfrom.rb +0 -81
  69. data/sample/copyto.rb +0 -19
  70. data/sample/cursor.rb +0 -21
  71. data/sample/disk_usage_report.rb +0 -186
  72. data/sample/issue-119.rb +0 -94
  73. data/sample/losample.rb +0 -69
  74. data/sample/minimal-testcase.rb +0 -17
  75. data/sample/notify_wait.rb +0 -72
  76. data/sample/pg_statistics.rb +0 -294
  77. data/sample/replication_monitor.rb +0 -231
  78. data/sample/test_binary_values.rb +0 -33
  79. data/sample/wal_shipper.rb +0 -434
  80. data/sample/warehouse_partitions.rb +0 -320
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -11,27 +11,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SwMB0GA1UdDgQWBBRyjf55EbrHagiRLqt5YAd3yb8k4DAcBgNVHREE
27
+ FTATgRFnZWRARmFlcmllTVVELm9yZzAcBgNVHRIEFTATgRFnZWRARmFlcmllTVVE
28
+ Lm9yZzANBgkqhkiG9w0BAQsFAAOCAYEAP9Ffkvg4e8CjIWi8SykQ8oJSS8jbmbgF
29
+ abke3vXWLG6V9kFiObuJd5wZRBluJANu7bEtjgc3fFaGVP2XxVdCpVjNbmMDg4Qp
30
+ ovvczP53X6pQP2RSZgxF6Lblvy8y11RziUTVRG/Z2aJHsElo6gI7vQznE/OSDrhC
31
+ gEhr8uaIUt7D+HZWRbU0+MkKPpL5uMqaFuJbqXEvSwPTuUuYkDfNfsjQO7ruWBac
32
+ bxHCrvpZ6Tijc0nrlyXi6gPOCLeaqhau2xFnlvKgELwsGYSoKBJyDwqtQ5kwrOlU
33
+ tkSyLrfZ+RZcH535Hyvif7ZxB0v5OxXXoec+N2vrUsEUMRDL9dg4/WFdN8hIOixF
34
+ 3IPKpZ1ho0Ya5q7yhygtBK9/NBFHw+nbJjcltfPDBXleRe8u73gnQo8AZIhStYSP
35
+ v4qqqa27Bs468d6SoPxjSm8a2mM9HZ4OdWhq4tFsbTeXDVquCfi64OTEaTt2xQdR
36
+ JnC4lpJfCP6aCXa5h2XAQfPSH636cQap
33
37
  -----END CERTIFICATE-----
34
- date: 2015-01-03 00:00:00.000000000 Z
38
+ date: 2019-01-09 00:00:00.000000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: hoe-mercurial
@@ -53,14 +57,14 @@ dependencies:
53
57
  requirements:
54
58
  - - "~>"
55
59
  - !ruby/object:Gem::Version
56
- version: '0.6'
60
+ version: '0.10'
57
61
  type: :development
58
62
  prerelease: false
59
63
  version_requirements: !ruby/object:Gem::Requirement
60
64
  requirements:
61
65
  - - "~>"
62
66
  - !ruby/object:Gem::Version
63
- version: '0.6'
67
+ version: '0.10'
64
68
  - !ruby/object:Gem::Dependency
65
69
  name: hoe-highline
66
70
  requirement: !ruby/object:Gem::Requirement
@@ -76,79 +80,93 @@ dependencies:
76
80
  - !ruby/object:Gem::Version
77
81
  version: '0.2'
78
82
  - !ruby/object:Gem::Dependency
79
- name: rdoc
83
+ name: rake-compiler
80
84
  requirement: !ruby/object:Gem::Requirement
81
85
  requirements:
82
86
  - - "~>"
83
87
  - !ruby/object:Gem::Version
84
- version: '4.0'
88
+ version: '1.0'
85
89
  type: :development
86
90
  prerelease: false
87
91
  version_requirements: !ruby/object:Gem::Requirement
88
92
  requirements:
89
93
  - - "~>"
90
94
  - !ruby/object:Gem::Version
91
- version: '4.0'
95
+ version: '1.0'
92
96
  - !ruby/object:Gem::Dependency
93
- name: rake-compiler
97
+ name: rake-compiler-dock
94
98
  requirement: !ruby/object:Gem::Requirement
95
99
  requirements:
96
100
  - - "~>"
97
101
  - !ruby/object:Gem::Version
98
- version: '0.9'
102
+ version: 0.7.0
99
103
  type: :development
100
104
  prerelease: false
101
105
  version_requirements: !ruby/object:Gem::Requirement
102
106
  requirements:
103
107
  - - "~>"
104
108
  - !ruby/object:Gem::Version
105
- version: '0.9'
109
+ version: 0.7.0
106
110
  - !ruby/object:Gem::Dependency
107
- name: hoe
111
+ name: hoe-bundler
108
112
  requirement: !ruby/object:Gem::Requirement
109
113
  requirements:
110
114
  - - "~>"
111
115
  - !ruby/object:Gem::Version
112
- version: '3.12'
116
+ version: '1.0'
113
117
  type: :development
114
118
  prerelease: false
115
119
  version_requirements: !ruby/object:Gem::Requirement
116
120
  requirements:
117
121
  - - "~>"
118
122
  - !ruby/object:Gem::Version
119
- version: '3.12'
123
+ version: '1.0'
120
124
  - !ruby/object:Gem::Dependency
121
- name: hoe-bundler
125
+ name: rspec
122
126
  requirement: !ruby/object:Gem::Requirement
123
127
  requirements:
124
128
  - - "~>"
125
129
  - !ruby/object:Gem::Version
126
- version: '1.0'
130
+ version: '3.5'
127
131
  type: :development
128
132
  prerelease: false
129
133
  version_requirements: !ruby/object:Gem::Requirement
130
134
  requirements:
131
135
  - - "~>"
132
136
  - !ruby/object:Gem::Version
133
- version: '1.0'
137
+ version: '3.5'
134
138
  - !ruby/object:Gem::Dependency
135
- name: rspec
139
+ name: rdoc
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '5.1'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '5.1'
152
+ - !ruby/object:Gem::Dependency
153
+ name: hoe
136
154
  requirement: !ruby/object:Gem::Requirement
137
155
  requirements:
138
156
  - - "~>"
139
157
  - !ruby/object:Gem::Version
140
- version: '3.0'
158
+ version: '3.16'
141
159
  type: :development
142
160
  prerelease: false
143
161
  version_requirements: !ruby/object:Gem::Requirement
144
162
  requirements:
145
163
  - - "~>"
146
164
  - !ruby/object:Gem::Version
147
- version: '3.0'
165
+ version: '3.16'
148
166
  description: |-
149
167
  Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
150
168
 
151
- It works with {PostgreSQL 8.4 and later}[http://www.postgresql.org/support/versioning/].
169
+ It works with {PostgreSQL 9.2 and later}[http://www.postgresql.org/support/versioning/].
152
170
 
153
171
  A small example usage:
154
172
 
@@ -160,7 +178,7 @@ description: |-
160
178
  conn = PG.connect( dbname: 'sales' )
161
179
  conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
162
180
  puts " PID | User | Query"
163
- result.each do |row|
181
+ result.each do |row|
164
182
  puts " %7d | %-16s | %s " %
165
183
  row.values_at('procpid', 'usename', 'current_query')
166
184
  end
@@ -193,6 +211,7 @@ extra_rdoc_files:
193
211
  - ext/pg_result.c
194
212
  - ext/pg_text_decoder.c
195
213
  - ext/pg_text_encoder.c
214
+ - ext/pg_tuple.c
196
215
  - ext/pg_type_map.c
197
216
  - ext/pg_type_map_all_strings.c
198
217
  - ext/pg_type_map_by_class.c
@@ -233,6 +252,7 @@ files:
233
252
  - ext/pg_result.c
234
253
  - ext/pg_text_decoder.c
235
254
  - ext/pg_text_encoder.c
255
+ - ext/pg_tuple.c
236
256
  - ext/pg_type_map.c
237
257
  - ext/pg_type_map_all_strings.c
238
258
  - ext/pg_type_map_by_class.c
@@ -247,6 +267,7 @@ files:
247
267
  - ext/vc/pg_19/pg_19.vcproj
248
268
  - lib/pg.rb
249
269
  - lib/pg/basic_type_mapping.rb
270
+ - lib/pg/binary_decoder.rb
250
271
  - lib/pg/coder.rb
251
272
  - lib/pg/connection.rb
252
273
  - lib/pg/constants.rb
@@ -254,31 +275,16 @@ files:
254
275
  - lib/pg/result.rb
255
276
  - lib/pg/text_decoder.rb
256
277
  - lib/pg/text_encoder.rb
278
+ - lib/pg/tuple.rb
257
279
  - lib/pg/type_map_by_column.rb
258
- - sample/array_insert.rb
259
- - sample/async_api.rb
260
- - sample/async_copyto.rb
261
- - sample/async_mixed.rb
262
- - sample/check_conn.rb
263
- - sample/copyfrom.rb
264
- - sample/copyto.rb
265
- - sample/cursor.rb
266
- - sample/disk_usage_report.rb
267
- - sample/issue-119.rb
268
- - sample/losample.rb
269
- - sample/minimal-testcase.rb
270
- - sample/notify_wait.rb
271
- - sample/pg_statistics.rb
272
- - sample/replication_monitor.rb
273
- - sample/test_binary_values.rb
274
- - sample/wal_shipper.rb
275
- - sample/warehouse_partitions.rb
276
280
  - spec/data/expected_trace.out
277
281
  - spec/data/random_binary_data
278
282
  - spec/helpers.rb
279
283
  - spec/pg/basic_type_mapping_spec.rb
280
284
  - spec/pg/connection_spec.rb
285
+ - spec/pg/connection_sync_spec.rb
281
286
  - spec/pg/result_spec.rb
287
+ - spec/pg/tuple_spec.rb
282
288
  - spec/pg/type_map_by_class_spec.rb
283
289
  - spec/pg/type_map_by_column_spec.rb
284
290
  - spec/pg/type_map_by_mri_type_spec.rb
@@ -289,17 +295,11 @@ files:
289
295
  - spec/pg_spec.rb
290
296
  homepage: https://bitbucket.org/ged/ruby-pg
291
297
  licenses:
292
- - BSD
293
- - Ruby
294
- - GPL
298
+ - BSD-3-Clause
295
299
  metadata: {}
296
300
  post_install_message:
297
301
  rdoc_options:
298
- - "-f"
299
- - fivefish
300
- - "-t"
301
- - 'pg: The Ruby Interface to PostgreSQL'
302
- - "-m"
302
+ - "--main"
303
303
  - README.rdoc
304
304
  require_paths:
305
305
  - lib
@@ -307,7 +307,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
307
307
  requirements:
308
308
  - - ">="
309
309
  - !ruby/object:Gem::Version
310
- version: 1.8.7
310
+ version: 2.0.0
311
311
  required_rubygems_version: !ruby/object:Gem::Requirement
312
312
  requirements:
313
313
  - - ">="
@@ -315,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
315
  version: '0'
316
316
  requirements: []
317
317
  rubyforge_project:
318
- rubygems_version: 2.4.5
318
+ rubygems_version: 2.7.8
319
319
  signing_key:
320
320
  specification_version: 4
321
321
  summary: Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/]
metadata.gz.sig CHANGED
Binary file
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env 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 DELETED
@@ -1,106 +0,0 @@
1
- #!/usr/bin/env 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
-
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pg'
4
- require 'stringio'
5
-
6
- # Using COPY asynchronously
7
-
8
- $stderr.puts "Opening database connection ..."
9
- conn = PG.connect( :dbname => 'test' )
10
- conn.setnonblocking( true )
11
-
12
- socket = conn.socket_io
13
-
14
- $stderr.puts "Running COPY command ..."
15
- buf = ''
16
- conn.transaction do
17
- conn.send_query( "COPY logs TO STDOUT WITH csv" )
18
- buf = nil
19
-
20
- # #get_copy_data returns a row if there's a whole one to return, false
21
- # if there isn't one but the COPY is still running, or nil when it's
22
- # finished.
23
- begin
24
- $stderr.puts "COPY loop"
25
- conn.consume_input
26
- while conn.is_busy
27
- $stderr.puts " ready loop"
28
- select( [socket], nil, nil, 5.0 ) or
29
- raise "Timeout (5s) waiting for query response."
30
- conn.consume_input
31
- end
32
-
33
- buf = conn.get_copy_data
34
- $stdout.puts( buf ) if buf
35
- end until buf.nil?
36
- end
37
-
38
- conn.finish
39
-
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pg'
4
-
5
- $stdout.sync = true
6
-
7
- # This is a example of how to mix and match synchronous and async APIs. In this case,
8
- # the connection to the server is made syncrhonously, and then queries are
9
- # asynchronous.
10
-
11
- TIMEOUT = 5.0 # seconds to wait for an async operation to complete
12
- CONN_OPTS = {
13
- :host => 'localhost',
14
- :dbname => 'test',
15
- }
16
-
17
- # Output progress messages
18
- def output_progress( msg )
19
- puts ">>> #{msg}\n"
20
- 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
- socket = conn.socket_io
30
-
31
- # Send the (asynchronous) query
32
- output_progress "Sending query"
33
- conn.send_query( "SELECT * FROM pg_stat_activity" )
34
-
35
- # Fetch results until there aren't any more
36
- loop do
37
- output_progress " waiting for a response"
38
-
39
- # Buffer any incoming data on the socket until a full result is ready.
40
- conn.consume_input
41
- while conn.is_busy
42
- output_progress " waiting for data to be available on %p..." % [ socket ]
43
- select( [socket], nil, nil, TIMEOUT ) or
44
- raise "Timeout waiting for query response."
45
- conn.consume_input
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 ]
52
- end
53
-
54
- output_progress "Done."
55
- conn.finish
56
-
data/sample/check_conn.rb DELETED
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # vim: set nosta noet ts=4 sw=4:
3
- # encoding: utf-8
4
-
5
- require 'pg'
6
-
7
- # This is a minimal example of a function that can test an existing PG::Connection and
8
- # reset it if necessary.
9
-
10
- def check_connection( conn )
11
- begin
12
- conn.exec( "SELECT 1" )
13
- rescue PG::Error => err
14
- $stderr.puts "%p while testing connection: %s" % [ err.class, err.message ]
15
- conn.reset
16
- end
17
- end
18
-
19
- conn = PG.connect( dbname: 'test' )
20
- check_connection( conn )
21
-
data/sample/copyfrom.rb DELETED
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env 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
- copy_data = 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
- conn.exec( "COPY logs FROM STDIN WITH csv" )
58
- begin
59
- while copy_data.read( 256, buf )
60
- ### Uncomment this to test error-handling for exceptions from the reader side:
61
- # raise Errno::ECONNRESET, "socket closed while reading"
62
- $stderr.puts " sending %d bytes of data..." % [ buf.length ]
63
- until conn.put_copy_data( buf )
64
- $stderr.puts " waiting for connection to be writable..."
65
- sleep 0.1
66
- end
67
- end
68
- rescue Errno => err
69
- errmsg = "%s while reading copy data: %s" % [ err.class.name, err.message ]
70
- conn.put_copy_end( errmsg )
71
- else
72
- conn.put_copy_end
73
- while res = conn.get_result
74
- $stderr.puts "Result of COPY is: %s" % [ res.res_status(res.result_status) ]
75
- end
76
- end
77
- end
78
-
79
-
80
- conn.finish
81
-
data/sample/copyto.rb DELETED
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pg'
4
- require 'stringio'
5
-
6
- # An example of how to stream data to your local host from the database as CSV.
7
-
8
- $stderr.puts "Opening database connection ..."
9
- conn = PG.connect( :dbname => 'test' )
10
-
11
- $stderr.puts "Running COPY command ..."
12
- buf = ''
13
- conn.transaction do
14
- conn.exec( "COPY logs TO STDOUT WITH csv" )
15
- $stdout.puts( buf ) while buf = conn.get_copy_data
16
- end
17
-
18
- conn.finish
19
-
data/sample/cursor.rb DELETED
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pg'
4
-
5
- # An example of how to use SQL cursors. This is mostly a straight port of
6
- # the cursor portion of testlibpq.c from src/test/examples.
7
-
8
- $stderr.puts "Opening database connection ..."
9
- conn = PG.connect( :dbname => 'test' )
10
-
11
- #
12
- conn.transaction do
13
- conn.exec( "DECLARE myportal CURSOR FOR select * from pg_database" )
14
- res = conn.exec( "FETCH ALL IN myportal" )
15
-
16
- puts res.fields.collect {|fname| "%-15s" % [fname] }.join( '' )
17
- res.values.collect do |row|
18
- puts row.collect {|col| "%-15s" % [col] }.join( '' )
19
- end
20
- end
21
-