pg_conn 0.13.5 → 0.14.0
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.
- checksums.yaml +4 -4
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +32 -18
- 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: d29017a92f97bb843ada8a10d00ab0a130e0e572e9775f21ddacb9f6d9ca4e66
|
4
|
+
data.tar.gz: e56a31694ec01c3ef15ae35b1f5a28304dad179a918c69a687e08fb267f1b30e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a920f75a6d118bdc44e5442adbe38e6ecbc6872ac010f3c29390a25db4e95605541d4bc1dd67a0f7ac1332611119d983211aaff1acda885aca07ed1a464705a7
|
7
|
+
data.tar.gz: 4339f922abbdeb6db692a8906a5c5fea4aa21a645be69df90a39473cc2453c9f79c684b8b2e69996a343cc368dcaeaecc960154dbcc78003ec230bd3605363ad
|
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
|
@@ -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
|
-
#
|
728
|
-
#
|
729
|
-
#
|
730
|
-
#
|
731
|
-
#
|
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
|
-
|
734
|
-
|
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
|
-
|
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
|