pg_conn 0.7.1 → 0.7.2
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 +18 -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,20 +64,31 @@ 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]
|
73
84
|
|
74
|
-
# The one-based line number of the last
|
85
|
+
# The one-based line number of the last error or nil if absent in the
|
75
86
|
# Postgres error message
|
76
|
-
def errline = err
|
87
|
+
def errline = err[1]
|
77
88
|
|
78
89
|
# The one-based character number of the error in the last PG::Error or nil
|
79
90
|
# if absent in the Postgres error message
|
80
|
-
def errchar = err
|
91
|
+
def errchar = err[2]
|
81
92
|
|
82
93
|
# :call-seq:
|
83
94
|
# initialize(dbname = nil, user = nil, field_name_class: Symbol)
|
@@ -662,7 +673,7 @@ module PgConn
|
|
662
673
|
# TODO: Fix silent by not handling exceptions
|
663
674
|
def pg_exec(arg, fail: true, silent: false)
|
664
675
|
if @pg_connection
|
665
|
-
@err = nil
|
676
|
+
@error = @err = nil
|
666
677
|
begin
|
667
678
|
last_stmt = nil # To make the current SQL statement visible to the rescue clause. FIXME Not used?
|
668
679
|
if arg.is_a?(String)
|
@@ -677,7 +688,7 @@ module PgConn
|
|
677
688
|
end
|
678
689
|
|
679
690
|
rescue PG::Error => ex
|
680
|
-
@
|
691
|
+
@error = ex
|
681
692
|
if fail
|
682
693
|
if !silent # FIXME Why do we handle this?
|
683
694
|
$stderr.puts arg
|