pg_conn 0.13.5 → 0.15.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 +44 -27
  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: ca254f7c17749713f46f07448221683e5975c570407aff61ee440f82a37466ca
4
+ data.tar.gz: 86486e52477bbf36009d69f9322061077b5860582e4fc7ced67e2d88bad5ee0b
5
5
  SHA512:
6
- metadata.gz: 69d9cc2e6a70fec98890b53381c294a51d6476c5e888f2d7eb4ed7b73268d216fa89423830c255a9b8ce9677a1bf3553eec1a793395801150d464863d3fe5d7b
7
- data.tar.gz: 6939ecd7182397e23fcf2eb901627dc479a97c5aa6a80f0a90eacc6a3665763407236da8ae54f747c8ad3060f815796ca3588fdcc128bce448c0ceabc3fb805b
6
+ metadata.gz: b0981561372e9039eda5c8eb85948c63559e1875f4764dfaa3b32d52fa501b62522b2acde9a58036aa6978bb9b454cb66bec788e9d141dbc50b3ce5e14ee9941
7
+ data.tar.gz: 70a3927ceec9d61962002e301c817479e043878ec122ed1d265c9ed9372fb0abc744eaaf266e983b6352179f42e983752c030a12e878699c24b37fde8c6c663e
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.13.5"
2
+ VERSION = "0.15.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
@@ -695,18 +700,21 @@ module PgConn
695
700
  end
696
701
  end
697
702
 
698
- def pop_transaction(commit: true)
699
- transaction? or raise Error, "No transaction in progress"
700
- if savepoint = @savepoints.pop
701
- if !commit
702
- pg_exec("rollback to savepoint #{savepoint}")
703
- pg_exec("release savepoint #{savepoint}")
703
+ def pop_transaction(commit: true, fail: true)
704
+ if transaction?
705
+ if savepoint = @savepoints.pop
706
+ if !commit
707
+ pg_exec("rollback to savepoint #{savepoint}")
708
+ pg_exec("release savepoint #{savepoint}")
709
+ else
710
+ pg_exec("release savepoint #{savepoint}")
711
+ end
704
712
  else
705
- pg_exec("release savepoint #{savepoint}")
713
+ @savepoints = nil
714
+ pg_exec(commit ? "commit" : "rollback")
706
715
  end
707
716
  else
708
- @savepoints = nil
709
- pg_exec(commit ? "commit" : "rollback")
717
+ fail and raise Error, "No transaction in progress"
710
718
  end
711
719
  end
712
720
 
@@ -715,7 +723,7 @@ module PgConn
715
723
  # invalid and the server is in an invalid state
716
724
  #
717
725
  # It is not an error to call #cancel_transaction when no transaction is in
718
- # progress
726
+ # progress, the method always succeeds
719
727
  def cancel_transaction
720
728
  begin
721
729
  pg_exec("rollback")
@@ -724,25 +732,34 @@ module PgConn
724
732
  @savepoints = nil
725
733
  end
726
734
 
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
735
+ # Start a transaction. If called with a block, the block is executed within
736
+ # a transaction that is auto-committed if the commit option is true (the
737
+ # default). #transaction returns the result of the block or nil if no block
738
+ # was given
739
+ #
740
+ # The transaction can be rolled back inside the block by raising a
741
+ # PgConn::Rollback exception in which case #transaction returns nil. Note
742
+ # that the transaction timestamp is set to the start of the first
743
+ # transaction even if transactions are nested
732
744
  def transaction(commit: true, &block)
733
- result = nil
734
- begin
745
+ if block_given?
746
+ result = nil
747
+ begin
748
+ push_transaction
749
+ result = yield
750
+ rescue PgConn::Rollback
751
+ pop_transaction(commit: false)
752
+ return nil
753
+ rescue PG::Error
754
+ @savepoints = nil
755
+ raise
756
+ end
757
+ pop_transaction(commit: commit)
758
+ result
759
+ else
735
760
  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
761
+ nil
743
762
  end
744
- pop_transaction(commit: commit)
745
- result
746
763
  end
747
764
 
748
765
  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.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen