pg_conn 0.7.0 → 0.7.2
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 +24 -7
- 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: 240a2b6bb03ef6c0ffa37ae12c2610e185c69b873ccebda32a6ef0bfd0626b06
|
4
|
+
data.tar.gz: 6fcf77b84a14ddf55640a8b359b5843a5fa565b2db849d649df856626220dec6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d14ccc934203b706bc32b65f2678cd2db9f1ed32b7b0268ad32d22a76d7255d66c0b9d5e3f639fe6553fe174817304519926d9f5d66861f8d9c7999e32d798a
|
7
|
+
data.tar.gz: 4d21fe7896ec5fa5b9d02e675265c68a4a1460658ddaf0508627c0430032f69dfef3608cf65c90b4cb8d1e13951f4ce871b74370fa5fc93bf9971ac737dcceba
|
data/lib/pg_conn/version.rb
CHANGED
data/lib/pg_conn.rb
CHANGED
@@ -64,16 +64,32 @@ module PgConn
|
|
64
64
|
attr_reader :timestamp
|
65
65
|
|
66
66
|
# PG::Error object if the last statement failed; otherwise nil
|
67
|
-
attr_reader :
|
67
|
+
attr_reader :error
|
68
|
+
|
69
|
+
# Tuple of error message, lineno, and charno of the error object where each
|
70
|
+
# element defaults to nil if not found
|
71
|
+
def err
|
72
|
+
@err ||=
|
73
|
+
if error&.message =~ /.*?ERROR:\s*(.*?)\n(?:.*?(\s*LINE\s+(\d+):\s*).*?\n(?:(\s+)\^\n)?)?/
|
74
|
+
[$1.capitalize, $3&.to_i, $4 && ($4.size - $2.size + 1)]
|
75
|
+
else
|
76
|
+
[nil, nil, nil]
|
77
|
+
end
|
78
|
+
end
|
68
79
|
|
69
80
|
# Last error message. The error message is the first line of the PG error
|
70
81
|
# message that may contain additional info. It doesn't contain a
|
71
82
|
# terminating newline
|
72
|
-
def errmsg = err
|
83
|
+
def errmsg = err[0]
|
84
|
+
|
85
|
+
# The one-based line number of the last error or nil if absent in the
|
86
|
+
# Postgres error message
|
87
|
+
def errline = err[1]
|
88
|
+
|
89
|
+
# The one-based character number of the error in the last PG::Error or nil
|
90
|
+
# if absent in the Postgres error message
|
91
|
+
def errchar = err[2]
|
73
92
|
|
74
|
-
# The line number of the last PG::Error. It is not always present
|
75
|
-
def errline() err && err.message =~ /\n\s*LINE\s+(\d+):/m and $1.to_i end
|
76
|
-
|
77
93
|
# :call-seq:
|
78
94
|
# initialize(dbname = nil, user = nil, field_name_class: Symbol)
|
79
95
|
# initialize(connection_hash, field_name_class: Symbol)
|
@@ -657,7 +673,7 @@ module PgConn
|
|
657
673
|
# TODO: Fix silent by not handling exceptions
|
658
674
|
def pg_exec(arg, fail: true, silent: false)
|
659
675
|
if @pg_connection
|
660
|
-
@err = nil
|
676
|
+
@error = @err = nil
|
661
677
|
begin
|
662
678
|
last_stmt = nil # To make the current SQL statement visible to the rescue clause. FIXME Not used?
|
663
679
|
if arg.is_a?(String)
|
@@ -672,10 +688,11 @@ module PgConn
|
|
672
688
|
end
|
673
689
|
|
674
690
|
rescue PG::Error => ex
|
675
|
-
@
|
691
|
+
@error = ex
|
676
692
|
if fail
|
677
693
|
if !silent # FIXME Why do we handle this?
|
678
694
|
$stderr.puts arg
|
695
|
+
$stderr.puts
|
679
696
|
$stderr.puts ex.message
|
680
697
|
$stderr.flush
|
681
698
|
end
|