pg_conn 0.7.0 → 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: 410aa55b50b2d9c16aa9ab8a220475b83b91aa78e5ecb1a012e1a3524b2bcedb
4
- data.tar.gz: '037319c6f45a570caedbcbb1ba1a725c738fa17771a1379ccab530d541d3270d'
3
+ metadata.gz: 240a2b6bb03ef6c0ffa37ae12c2610e185c69b873ccebda32a6ef0bfd0626b06
4
+ data.tar.gz: 6fcf77b84a14ddf55640a8b359b5843a5fa565b2db849d649df856626220dec6
5
5
  SHA512:
6
- metadata.gz: 6d1b677fbefbffd5189c29be2a185f76d5a85227c27f8e3a2883fe8db2a5b4c6054525975a93c5b3b4c0439009a70fe41d5a762493046090fa85d18dc381f87e
7
- data.tar.gz: 03b617328dd1acd4bcfc1069c3d47b7bfc80771b924c39e7b91ad0c310f72577e6da3106e818769052f5fff7ee80ec43f2df6d127d76615b0278c353594ab70d
6
+ metadata.gz: 8d14ccc934203b706bc32b65f2678cd2db9f1ed32b7b0268ad32d22a76d7255d66c0b9d5e3f639fe6553fe174817304519926d9f5d66861f8d9c7999e32d798a
7
+ data.tar.gz: 4d21fe7896ec5fa5b9d02e675265c68a4a1460658ddaf0508627c0430032f69dfef3608cf65c90b4cb8d1e13951f4ce871b74370fa5fc93bf9971ac737dcceba
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.2"
3
3
  end
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 :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 && err.message.sub(/\n.*/m, "")
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
- @err = ex
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
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.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen