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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 515c790d7c2850a3d679f3b56601a8cd7311eeeb7c8875f23e7e24a9b1d3389a
4
- data.tar.gz: '08b7e60560b80649d613e7469c7d544b136c5cff789d9f107eeb83a56e4449ff'
3
+ metadata.gz: 240a2b6bb03ef6c0ffa37ae12c2610e185c69b873ccebda32a6ef0bfd0626b06
4
+ data.tar.gz: 6fcf77b84a14ddf55640a8b359b5843a5fa565b2db849d649df856626220dec6
5
5
  SHA512:
6
- metadata.gz: aee7f2323e2bd7cb4893780210161c7839dd985e33dec5d1c93b6318c4f3c03494ef2108031fe0aff0e83352c94bb6c5a421830ac7e8972cd23d830159a61f08
7
- data.tar.gz: c4ad3b31c34a19ce3c697ab9cdb318f9aee9752c7eb3bc598588da48923d488908b26c324fd29cf6381d60d08e249920a99671324b84434776fbdedeb85ad5f1
6
+ metadata.gz: 8d14ccc934203b706bc32b65f2678cd2db9f1ed32b7b0268ad32d22a76d7255d66c0b9d5e3f639fe6553fe174817304519926d9f5d66861f8d9c7999e32d798a
7
+ data.tar.gz: 4d21fe7896ec5fa5b9d02e675265c68a4a1460658ddaf0508627c0430032f69dfef3608cf65c90b4cb8d1e13951f4ce871b74370fa5fc93bf9971ac737dcceba
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
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 :err
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&.message =~ /^ERROR:\s*(.*?)\n/m && $1.capitalize
83
+ def errmsg = err[0]
73
84
 
74
- # The one-based line number of the last PG::Error or nil if absent in the
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&.message =~ /\n\s*LINE\s+(\d+):/m && $1.to_i
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&.message =~ /\n(\s*LINE\s+\d+: ).*?\n(\s+)\^\n/m && ($2.size - $1.size + 1)
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
- @err = ex
691
+ @error = ex
681
692
  if fail
682
693
  if !silent # FIXME Why do we handle this?
683
694
  $stderr.puts arg
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.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen