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.
- checksums.yaml +4 -4
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +44 -27
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca254f7c17749713f46f07448221683e5975c570407aff61ee440f82a37466ca
|
4
|
+
data.tar.gz: 86486e52477bbf36009d69f9322061077b5860582e4fc7ced67e2d88bad5ee0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0981561372e9039eda5c8eb85948c63559e1875f4764dfaa3b32d52fa501b62522b2acde9a58036aa6978bb9b454cb66bec788e9d141dbc50b3ce5e14ee9941
|
7
|
+
data.tar.gz: 70a3927ceec9d61962002e301c817479e043878ec122ed1d265c9ed9372fb0abc744eaaf266e983b6352179f42e983752c030a12e878699c24b37fde8c6c663e
|
data/lib/pg_conn/version.rb
CHANGED
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?
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
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
|
-
|
713
|
+
@savepoints = nil
|
714
|
+
pg_exec(commit ? "commit" : "rollback")
|
706
715
|
end
|
707
716
|
else
|
708
|
-
|
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
|
-
#
|
728
|
-
#
|
729
|
-
#
|
730
|
-
#
|
731
|
-
#
|
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
|
-
|
734
|
-
|
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
|
-
|
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
|