pg 0.17.2.pre.546 → 0.18.0.pre20140820094244

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 637de7550ad54596f1d2296e620abf62627bfd15
4
- data.tar.gz: 7ddb6d5c72f909b0378360011aa13c020f0d88cf
3
+ metadata.gz: 767ac4aadc69aaf46db948f63ce84af28379d6cd
4
+ data.tar.gz: b91de92eda56d82dd3c0c5a7870a137955fa4591
5
5
  SHA512:
6
- metadata.gz: ce2fa474c1921e469990bdb6c99a2bd73a0568197946639850f6d1da126acb8d7e36137b78f156417fbc46f63f42e6d0cae61301127ce05954818a58be4e5d23
7
- data.tar.gz: 9525dd2c6a8805c0aaca253c3cf497533a7077e466bdf2ea0c25ecf1c0d47e4053639766d73cbfad548d5b8568453e82b83e73280f0f9dc552eee379a850c37b
6
+ metadata.gz: 1fb27aca7115cf8b3f3b7d34acd040725e8824cc3f9d7581568b89afafe2d87e76415d68709f54bae7acefe09b9e92e0556a47ce7bf98e7b015e18d40e900807
7
+ data.tar.gz: 791ea89b3739a63eccab2e5e8502cbc60ac394b464cf55180022ab4e4ffaca8b7e1d89b759e8d9994cc1353bc402819b03f794a44556e9fdd7e961c7a7c778db
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,17 @@
1
+ == v0.18.0 [2014-08-20] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ New:
4
+
5
+ - Add PG::Connection#conninfo
6
+ - Convert specs to expect syntax for RSpec 3
7
+ - Check connection status with a matcher in specs
8
+
9
+ Bugfixes:
10
+
11
+ - Fix some type mismatches for Oid return values. Thanks to Mina Naguib for the fix.
12
+ - Fix typo in documentation.
13
+
14
+
1
15
  == v0.17.1 [2013-12-18] Michael Granger <ged@FaerieMUD.org>
2
16
 
3
17
  Bugfixes:
@@ -9,7 +9,7 @@ docs :: http://deveiate.org/code/pg
9
9
 
10
10
  Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
11
11
 
12
- It works with {PostgreSQL 8.4 and later}[http://www.postgresql.org/support/versioning/].
12
+ It works with {PostgreSQL 9.0 and later}[http://www.postgresql.org/support/versioning/].
13
13
 
14
14
  A small example usage:
15
15
 
@@ -34,8 +34,8 @@ A small example usage:
34
34
 
35
35
  == Requirements
36
36
 
37
- * Ruby 1.9.3-p392, or 2.0.0-p0.
38
- * PostgreSQL 8.4.x or later (with headers, -dev packages, etc).
37
+ * Ruby 1.9.3 or later.
38
+ * PostgreSQL 9.0.x or later (with headers, -dev packages, etc).
39
39
 
40
40
  It may work with earlier versions of Ruby/PostgreSQL as well, but those are
41
41
  not regularly tested.
@@ -83,7 +83,7 @@ Lars Kanis <lars@greiz-reinsdorf.de>.
83
83
 
84
84
  == Copying
85
85
 
86
- Copyright (c) 1997-2013 by the authors.
86
+ Copyright (c) 1997-2014 by the authors.
87
87
 
88
88
  * Jeff Davis <ruby-pg@j-davis.com>
89
89
  * Guy Decoux (ts) <decoux@moulon.inra.fr>
data/Rakefile CHANGED
@@ -31,6 +31,8 @@ EXT = LIBDIR + "pg_ext.#{DLEXT}"
31
31
 
32
32
  TEST_DIRECTORY = BASEDIR + "tmp_test_specs"
33
33
 
34
+ GEMSPEC = 'pg.gemspec'
35
+
34
36
  CLOBBER.include( TEST_DIRECTORY.to_s )
35
37
  CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
36
38
 
@@ -67,7 +69,7 @@ $hoespec = Hoe.spec 'pg' do
67
69
  self.spec_extras[:licenses] = ['BSD', 'Ruby', 'GPL']
68
70
  self.spec_extras[:extensions] = [ 'ext/extconf.rb' ]
69
71
 
70
- self.require_ruby_version( '>= 1.8.7' )
72
+ self.require_ruby_version( '>= 1.9.3' )
71
73
 
72
74
  self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
73
75
  self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
@@ -180,3 +182,19 @@ file 'ext/pg_errors.c' => ['ext/errorcodes.def'] do
180
182
  # trigger compilation of changed errorcodes.def
181
183
  touch 'ext/pg_errors.c'
182
184
  end
185
+
186
+
187
+ task :gemspec => GEMSPEC
188
+ file GEMSPEC => __FILE__
189
+ task GEMSPEC do |task|
190
+ spec = $hoespec.spec
191
+ spec.files.delete( '.gemtest' )
192
+ spec.version = "#{spec.version}.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
193
+ File.open( task.name, 'w' ) do |fh|
194
+ fh.write( spec.to_ruby )
195
+ end
196
+ end
197
+
198
+ CLOBBER.include( GEMSPEC.to_s )
199
+ task :default => :gemspec
200
+
data/ext/pg.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * pg.c - Toplevel extension
3
- * $Id: pg.c,v 74aa9514a381 2013/05/18 17:29:19 lars $
3
+ * $Id: pg.c,v 8e95248e80f6 2014/08/20 16:42:14 ged $
4
4
  *
5
5
  * Author/s:
6
6
  *
@@ -15,7 +15,7 @@
15
15
  * See Contributors.rdoc for the many additional fine people that have contributed
16
16
  * to this library over the years.
17
17
  *
18
- * Copyright (c) 1997-2012 by the authors.
18
+ * Copyright (c) 1997-2014 by the authors.
19
19
  *
20
20
  * You may redistribute this software under the same terms as Ruby itself; see
21
21
  * http://www.ruby-lang.org/en/LICENSE.txt or the LICENSE file in the source
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * pg_connection.c - PG::Connection class extension
3
- * $Id: pg_connection.c,v 6c2444dc63e1 2013/12/30 16:49:29 lars $
3
+ * $Id: pg_connection.c,v affbd590e74e 2014/08/20 16:14:47 ged $
4
4
  *
5
5
  */
6
6
 
@@ -46,6 +46,8 @@ pg_get_pgconn( VALUE self )
46
46
  }
47
47
 
48
48
 
49
+
50
+
49
51
  /*
50
52
  * Close the associated socket IO object if there is one.
51
53
  */
@@ -68,6 +70,40 @@ pgconn_close_socket_io( VALUE self )
68
70
  }
69
71
 
70
72
 
73
+ /*
74
+ * Create a Ruby Array of Hashes out of a PGconninfoOptions array.
75
+ */
76
+ static VALUE
77
+ pgconn_make_conninfo_array( const PQconninfoOption *options )
78
+ {
79
+ VALUE ary = rb_ary_new();
80
+ VALUE hash;
81
+ int i = 0;
82
+
83
+ if (!options) return Qnil;
84
+
85
+ for(i = 0; options[i].keyword != NULL; i++) {
86
+ hash = rb_hash_new();
87
+ if(options[i].keyword)
88
+ rb_hash_aset(hash, ID2SYM(rb_intern("keyword")), rb_str_new2(options[i].keyword));
89
+ if(options[i].envvar)
90
+ rb_hash_aset(hash, ID2SYM(rb_intern("envvar")), rb_str_new2(options[i].envvar));
91
+ if(options[i].compiled)
92
+ rb_hash_aset(hash, ID2SYM(rb_intern("compiled")), rb_str_new2(options[i].compiled));
93
+ if(options[i].val)
94
+ rb_hash_aset(hash, ID2SYM(rb_intern("val")), rb_str_new2(options[i].val));
95
+ if(options[i].label)
96
+ rb_hash_aset(hash, ID2SYM(rb_intern("label")), rb_str_new2(options[i].label));
97
+ if(options[i].dispchar)
98
+ rb_hash_aset(hash, ID2SYM(rb_intern("dispchar")), rb_str_new2(options[i].dispchar));
99
+ rb_hash_aset(hash, ID2SYM(rb_intern("dispsize")), INT2NUM(options[i].dispsize));
100
+ rb_ary_push(ary, hash);
101
+ }
102
+
103
+ return ary;
104
+ }
105
+
106
+
71
107
  /*
72
108
  * Allocation/
73
109
  */
@@ -319,31 +355,13 @@ static VALUE
319
355
  pgconn_s_conndefaults(VALUE self)
320
356
  {
321
357
  PQconninfoOption *options = PQconndefaults();
322
- VALUE ary = rb_ary_new();
323
- VALUE hash;
324
- int i = 0;
358
+ VALUE array = pgconn_make_conninfo_array( options );
359
+
360
+ PQconninfoFree(options);
325
361
 
326
362
  UNUSED( self );
327
363
 
328
- for(i = 0; options[i].keyword != NULL; i++) {
329
- hash = rb_hash_new();
330
- if(options[i].keyword)
331
- rb_hash_aset(hash, ID2SYM(rb_intern("keyword")), rb_str_new2(options[i].keyword));
332
- if(options[i].envvar)
333
- rb_hash_aset(hash, ID2SYM(rb_intern("envvar")), rb_str_new2(options[i].envvar));
334
- if(options[i].compiled)
335
- rb_hash_aset(hash, ID2SYM(rb_intern("compiled")), rb_str_new2(options[i].compiled));
336
- if(options[i].val)
337
- rb_hash_aset(hash, ID2SYM(rb_intern("val")), rb_str_new2(options[i].val));
338
- if(options[i].label)
339
- rb_hash_aset(hash, ID2SYM(rb_intern("label")), rb_str_new2(options[i].label));
340
- if(options[i].dispchar)
341
- rb_hash_aset(hash, ID2SYM(rb_intern("dispchar")), rb_str_new2(options[i].dispchar));
342
- rb_hash_aset(hash, ID2SYM(rb_intern("dispsize")), INT2NUM(options[i].dispsize));
343
- rb_ary_push(ary, hash);
344
- }
345
- PQconninfoFree(options);
346
- return ary;
364
+ return array;
347
365
  }
348
366
 
349
367
 
@@ -604,6 +622,28 @@ pgconn_options(VALUE self)
604
622
  return rb_tainted_str_new2(options);
605
623
  }
606
624
 
625
+
626
+ /*
627
+ * call-seq:
628
+ * conn.conninfo -> hash
629
+ *
630
+ * Returns the connection options used by a live connection.
631
+ *
632
+ */
633
+ static VALUE
634
+ pgconn_conninfo( VALUE self )
635
+ {
636
+ PGconn *conn = pg_get_pgconn(self);
637
+ PQconninfoOption *options = PQconninfo( conn );
638
+ VALUE array = pgconn_make_conninfo_array( options );
639
+
640
+ PQconninfoFree(options);
641
+
642
+ return array;
643
+ }
644
+
645
+
646
+
607
647
  /*
608
648
  * call-seq:
609
649
  * conn.status()
@@ -3518,6 +3558,7 @@ init_pg_connection()
3518
3558
  rb_define_method(rb_cPGconn, "host", pgconn_host, 0);
3519
3559
  rb_define_method(rb_cPGconn, "port", pgconn_port, 0);
3520
3560
  rb_define_method(rb_cPGconn, "tty", pgconn_tty, 0);
3561
+ rb_define_method(rb_cPGconn, "conninfo", pgconn_conninfo, 0);
3521
3562
  rb_define_method(rb_cPGconn, "options", pgconn_options, 0);
3522
3563
  rb_define_method(rb_cPGconn, "status", pgconn_status, 0);
3523
3564
  rb_define_method(rb_cPGconn, "transaction_status", pgconn_transaction_status, 0);
data/lib/pg.rb CHANGED
@@ -19,10 +19,10 @@ end
19
19
  module PG
20
20
 
21
21
  # Library version
22
- VERSION = '0.17.2.pre.546'
22
+ VERSION = '0.18.0'
23
23
 
24
24
  # VCS revision
25
- REVISION = %q$Revision: 22d57e3a2b37 $
25
+ REVISION = %q$Revision: 8e95248e80f6 $
26
26
 
27
27
  class NotAllCopyDataRetrieved < PG::Error
28
28
  end
@@ -172,6 +172,15 @@ class PG::Connection
172
172
  return self.class.conndefaults
173
173
  end
174
174
 
175
+
176
+ ### Return the Postgres connection info structure as a Hash keyed by option
177
+ ### keyword (as a Symbol).
178
+ def conninfo_hash
179
+ return self.conninfo.each_with_object({}) do |info, hash|
180
+ hash[ info[:keyword].to_sym ] = info[:val]
181
+ end
182
+ end
183
+
175
184
  end # class PG::Connection
176
185
 
177
186
  # Backward-compatible alias
@@ -261,6 +261,55 @@ module PG::TestingHelpers
261
261
  end
262
262
  end
263
263
 
264
+
265
+ # A matcher for checking the status of a PG::Connection to ensure it's still
266
+ # usable.
267
+ class ConnStillUsableMatcher
268
+
269
+ def initialize
270
+ @conn = nil
271
+ @problem = nil
272
+ end
273
+
274
+ def matches?( conn )
275
+ @conn = conn
276
+ @problem = self.check_for_problems
277
+ return @problem.nil?
278
+ end
279
+
280
+ def check_for_problems
281
+ return "is finished" if @conn.finished?
282
+ return "has bad status" unless @conn.status == PG::CONNECTION_OK
283
+ return "has bad transaction status (%d)" % [ @conn.transaction_status ] unless
284
+ @conn.transaction_status.between?( PG::PQTRANS_IDLE, PG::PQTRANS_INTRANS )
285
+ return "is not usable." unless self.can_exec_query?
286
+ return nil
287
+ end
288
+
289
+ def can_exec_query?
290
+ @conn.send_query( "VALUES (1)" )
291
+ @conn.get_last_result.values == [["1"]]
292
+ end
293
+
294
+ def failure_message
295
+ return "expected %p to be usable, but it %s" % [ @conn, @problem ]
296
+ end
297
+
298
+ def failure_message_when_negated
299
+ "expected %p not to be usable, but it still is" % [ @conn ]
300
+ end
301
+
302
+ end
303
+
304
+
305
+ ### Return a ConnStillUsableMatcher to be used like:
306
+ ###
307
+ ### expect( pg_conn ).to still_be_usable
308
+ ###
309
+ def still_be_usable
310
+ return ConnStillUsableMatcher.new
311
+ end
312
+
264
313
  end
265
314
 
266
315
 
@@ -457,8 +457,7 @@ describe PG::Connection do
457
457
  end
458
458
  expect( rows ).to eq( ["1\n", "2\n"] )
459
459
  expect( res2.result_status ).to eq( PG::PGRES_COMMAND_OK )
460
- @conn.send_query( "VALUES (1)" )
461
- expect( @conn.get_last_result.values ).to eq( [["1"]] )
460
+ expect( @conn ).to still_be_usable
462
461
  end
463
462
 
464
463
  it "can handle incomplete #copy_data output queries" do
@@ -467,8 +466,7 @@ describe PG::Connection do
467
466
  @conn.get_copy_data
468
467
  end
469
468
  }.to raise_error(PG::NotAllCopyDataRetrieved, /Not all/)
470
- @conn.send_query( "VALUES (1)" )
471
- expect( @conn.get_last_result.values ).to eq( [["1"]] )
469
+ expect( @conn ).to still_be_usable
472
470
  end
473
471
 
474
472
  it "can handle client errors in #copy_data for output" do
@@ -477,8 +475,7 @@ describe PG::Connection do
477
475
  raise "boom"
478
476
  end
479
477
  }.to raise_error(RuntimeError, "boom")
480
- @conn.send_query( "VALUES (1)" )
481
- expect( @conn.get_last_result.values ).to eq( [["1"]] )
478
+ expect( @conn ).to still_be_usable
482
479
  end
483
480
 
484
481
  it "can handle server errors in #copy_data for output" do
@@ -492,8 +489,7 @@ describe PG::Connection do
492
489
  end
493
490
  }.to raise_error(PG::Error, /test-error/)
494
491
  end
495
- @conn.send_query( "VALUES (1)" )
496
- expect( @conn.get_last_result.values ).to eq( [["1"]] )
492
+ expect( @conn ).to still_be_usable
497
493
  end
498
494
 
499
495
  it "can process #copy_data input queries" do
@@ -506,8 +502,7 @@ describe PG::Connection do
506
502
  end
507
503
  expect( res2.result_status ).to eq( PG::PGRES_COMMAND_OK )
508
504
 
509
- @conn.send_query( "VALUES (1)" )
510
- expect( @conn.get_last_result.values ).to eq( [["1"]] )
505
+ expect( @conn ).to still_be_usable
511
506
 
512
507
  res = @conn.exec( "SELECT * FROM copytable ORDER BY col1" )
513
508
  expect( res.values ).to eq( [["1"], ["2"]] )
@@ -523,8 +518,8 @@ describe PG::Connection do
523
518
  end
524
519
  }.to raise_error(RuntimeError, "boom")
525
520
  end
526
- @conn.send_query( "VALUES (1)" )
527
- expect( @conn.get_last_result.values ).to eq( [["1"]] )
521
+
522
+ expect( @conn ).to still_be_usable
528
523
  end
529
524
 
530
525
  it "can handle server errors in #copy_data for input" do
@@ -537,8 +532,7 @@ describe PG::Connection do
537
532
  end
538
533
  }.to raise_error(PG::Error, /invalid input syntax for integer/)
539
534
  end
540
- @conn.send_query( "VALUES (1)" )
541
- expect( @conn.get_last_result.values ).to eq( [["1"]] )
535
+ expect( @conn ).to still_be_usable
542
536
  end
543
537
 
544
538
  it "should raise an error for non copy statements in #copy_data" do
@@ -546,8 +540,7 @@ describe PG::Connection do
546
540
  @conn.copy_data( "SELECT 1" ){}
547
541
  }.to raise_error(ArgumentError, /no COPY/)
548
542
 
549
- @conn.send_query( "VALUES (1)" )
550
- expect( @conn.get_last_result.values ).to eq( [["1"]] )
543
+ expect( @conn ).to still_be_usable
551
544
  end
552
545
 
553
546
  it "correctly finishes COPY queries passed to #async_exec" do
@@ -598,6 +591,30 @@ describe PG::Connection do
598
591
  end
599
592
 
600
593
 
594
+ it "can return the connection's connection options" do
595
+ expect( @conn.conninfo ).to be_a( Array )
596
+ expect( @conn.conninfo ).to all( be_a(Hash) )
597
+ expect( @conn.conninfo[0] ).to include( :keyword, :label, :dispchar, :dispsize )
598
+ end
599
+
600
+
601
+ it "can return the connection's connection options as a Hash" do
602
+ expect( @conn.conninfo_hash ).to be_a( Hash )
603
+ expect( @conn.conninfo_hash ).to include( :user, :password, :connect_timeout, :dbname, :host )
604
+ expect( @conn.conninfo_hash[:dbname] ).to eq( 'test' )
605
+ end
606
+
607
+
608
+ it "honors the connect_timeout connection parameter" do
609
+ conn = PG.connect( port: @port, dbname: 'test', connect_timeout: 11 )
610
+ begin
611
+ expect( conn.conninfo_hash[:connect_timeout] ).to eq( "11" )
612
+ ensure
613
+ conn.finish
614
+ end
615
+ end
616
+
617
+
601
618
  it "raises an appropriate error if either of the required arguments for encrypt_password " +
602
619
  "is not valid" do
603
620
  expect {
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.17.2.pre.546
4
+ version: 0.18.0.pre20140820094244
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -31,7 +31,7 @@ cert_chain:
31
31
  c7ZKPJcWBv0sm81+FCZXNACn2f9jfF8OQinxVs0O052KbGuEQaaiGIYeuuwQE2q6
32
32
  ggcrPfcYeTwWlfZPu2LrBg==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-07-25 00:00:00.000000000 Z
34
+ date: 2014-08-20 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hoe-mercurial
@@ -148,7 +148,7 @@ dependencies:
148
148
  description: |-
149
149
  Pg is the Ruby interface to the {PostgreSQL RDBMS}[http://www.postgresql.org/].
150
150
 
151
- It works with {PostgreSQL 8.4 and later}[http://www.postgresql.org/support/versioning/].
151
+ It works with {PostgreSQL 9.0 and later}[http://www.postgresql.org/support/versioning/].
152
152
 
153
153
  A small example usage:
154
154
 
@@ -188,7 +188,6 @@ extra_rdoc_files:
188
188
  - ext/pg_errors.c
189
189
  - ext/pg_result.c
190
190
  files:
191
- - ".gemtest"
192
191
  - BSDL
193
192
  - ChangeLog
194
193
  - Contributors.rdoc
@@ -265,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
265
264
  requirements:
266
265
  - - ">="
267
266
  - !ruby/object:Gem::Version
268
- version: 1.8.7
267
+ version: 1.9.3
269
268
  required_rubygems_version: !ruby/object:Gem::Requirement
270
269
  requirements:
271
270
  - - ">"
metadata.gz.sig CHANGED
Binary file
data/.gemtest DELETED
File without changes