pg_conn 0.13.5 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pg_conn/version.rb +1 -1
  3. data/lib/pg_conn.rb +32 -18
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e52454dd0c67763cbc1ea40cf63f17f7dfbf81eaf7b90aecf60f3874ac12ffd1
4
- data.tar.gz: bf895b59d9d6ed78f407b2260e5156e700c6dba66bde36c68e470e8311c20593
3
+ metadata.gz: d29017a92f97bb843ada8a10d00ab0a130e0e572e9775f21ddacb9f6d9ca4e66
4
+ data.tar.gz: e56a31694ec01c3ef15ae35b1f5a28304dad179a918c69a687e08fb267f1b30e
5
5
  SHA512:
6
- metadata.gz: 69d9cc2e6a70fec98890b53381c294a51d6476c5e888f2d7eb4ed7b73268d216fa89423830c255a9b8ce9677a1bf3553eec1a793395801150d464863d3fe5d7b
7
- data.tar.gz: 6939ecd7182397e23fcf2eb901627dc479a97c5aa6a80f0a90eacc6a3665763407236da8ae54f747c8ad3060f815796ca3588fdcc128bce448c0ceabc3fb805b
6
+ metadata.gz: a920f75a6d118bdc44e5442adbe38e6ecbc6872ac010f3c29390a25db4e95605541d4bc1dd67a0f7ac1332611119d983211aaff1acda885aca07ed1a464705a7
7
+ data.tar.gz: 4339f922abbdeb6db692a8906a5c5fea4aa21a645be69df90a39473cc2453c9f79c684b8b2e69996a343cc368dcaeaecc960154dbcc78003ec230bd3605363ad
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.13.5"
2
+ VERSION = "0.14.0"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -175,6 +175,9 @@ module PgConn
175
175
  end
176
176
 
177
177
  if @pg_connection && !using_existing_connection
178
+ # Set a dummy notice processor to avoid warnings on stderr
179
+ @pg_connection.set_notice_processor { |message| ; } # Intentionally a nop
180
+
178
181
  # Auto-convert to ruby types
179
182
  type_map = PG::BasicTypeMapForResults.new(@pg_connection)
180
183
 
@@ -677,7 +680,9 @@ module PgConn
677
680
 
678
681
  def rollback() raise Rollback end
679
682
 
680
- # True if a transaction is in progress
683
+ # True if a transaction is in progress. Note that this requires all
684
+ # transactions to be started using PgConn's transaction methods;
685
+ # transactions started using raw SQL are not registered
681
686
  def transaction?() !@savepoints.nil? end
682
687
 
683
688
  # Returns number of transaction or savepoint levels
@@ -715,7 +720,7 @@ module PgConn
715
720
  # invalid and the server is in an invalid state
716
721
  #
717
722
  # It is not an error to call #cancel_transaction when no transaction is in
718
- # progress
723
+ # progress, the method always succeeds
719
724
  def cancel_transaction
720
725
  begin
721
726
  pg_exec("rollback")
@@ -724,25 +729,34 @@ module PgConn
724
729
  @savepoints = nil
725
730
  end
726
731
 
727
- # Execute block within a transaction and return the result of the block.
728
- # The transaction can be rolled back by raising a PgConn::Rollback
729
- # exception in which case #transaction returns nil. Note that the
730
- # transaction timestamp is set to the start of the first transaction even
731
- # if transactions are nested
732
+ # Start a transaction. If called with a block, the block is executed within
733
+ # a transaction that is auto-committed if the commit option is true (the
734
+ # default). #transaction returns the result of the block or nil if no block
735
+ # was given
736
+ #
737
+ # The transaction can be rolled back inside the block by raising a
738
+ # PgConn::Rollback exception in which case #transaction returns nil. Note
739
+ # that the transaction timestamp is set to the start of the first
740
+ # transaction even if transactions are nested
732
741
  def transaction(commit: true, &block)
733
- result = nil
734
- begin
742
+ if block_given?
743
+ result = nil
744
+ begin
745
+ push_transaction
746
+ result = yield
747
+ rescue PgConn::Rollback
748
+ pop_transaction(commit: false)
749
+ return nil
750
+ rescue PG::Error
751
+ @savepoints = nil
752
+ raise
753
+ end
754
+ pop_transaction(commit: commit)
755
+ result
756
+ else
735
757
  push_transaction
736
- result = yield
737
- rescue PgConn::Rollback
738
- pop_transaction(commit: false)
739
- return nil
740
- rescue PG::Error
741
- @savepoints = nil
742
- raise
758
+ nil
743
759
  end
744
- pop_transaction(commit: commit)
745
- result
746
760
  end
747
761
 
748
762
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_conn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.5
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen