pg_conn 0.55.0 → 0.56.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7a478850b588c635e78fd50cac46e52665ece96fc538eb467eb2bf88fe6d6d7
4
- data.tar.gz: 8882d70f0289f8b3cdec8c9e3135513788eb09416a0ceb5ad763849f71324d95
3
+ metadata.gz: 071d157c556ff70c14231ebf8dc42e86acb85fdda7cf1c99ec1e3188f7d2c339
4
+ data.tar.gz: 23ac40bccd0bfc8e535414ff104d998aa257a879ae52164b5aedf6c421bbb4a8
5
5
  SHA512:
6
- metadata.gz: 5c3709874689cbfadf194fde8e4dd1d956ab0456ab205fd70064b680aa5dcebc161e11e5f3441237f502bf2c4df7cafa5a9a9b6608df42cd21ddc75848062c64
7
- data.tar.gz: b791c4afaefddc8286abf836abdbb6e92657bb5139bc377be032f174a6d2888dc774c8f8fd3c8643c6ca9f98f920d3f747d3163380c2fa85569a373ac30e45f0
6
+ metadata.gz: 7f8b56cc58d3e721b5bd2cf3efd88d4b478d6900e3654a311f5b0f99ab85c341ddcd406ac694c2d307c0a93e789fcfb0f458934e58cd6810267cee5e68fc5a6a
7
+ data.tar.gz: 32d1e368f8a02e3bd33a15cdb1d29b7dc55f8d3a96ccda39eef51ff737112945bcba3320a03b74b5045423f075e3fecdef89131b8338a1fd5104f5d1ba2696af
@@ -1,3 +1,3 @@
1
1
  module PgConn
2
- VERSION = "0.55.0"
2
+ VERSION = "0.56.0"
3
3
  end
data/lib/pg_conn.rb CHANGED
@@ -206,8 +206,8 @@ module PgConn
206
206
  def logger() = @logger
207
207
 
208
208
  # Controls error messages. It can be assigned true, false, nil, or a Proc
209
- # object that recieves the message. True causes the message to be printed
210
- # to standard error, false ignores it, and nil resets the state to the
209
+ # object that recieves the message. True causes the message to be ignored,
210
+ # false prints it to standard error, and nil resets the state to the
211
211
  # default given when the connection was initialized. #silent? returns true
212
212
  # if #silent is false or a Proc object and should be used instead #silent
213
213
  # to check the state because #silent returns truish when output is
@@ -1066,6 +1066,66 @@ module PgConn
1066
1066
  end
1067
1067
  end
1068
1068
 
1069
+ # Execute SQL og pgsql file. The file must be pure SQL or pgsql statements,
1070
+ # not psql meta commands. Any output from the file is ignored
1071
+ def sqlexec(file, **opts)
1072
+ source = IO.read(file) or error "Can't read #{file}"
1073
+ exec(source, **opts)
1074
+ end
1075
+
1076
+ # Execute file using psql(1) so that special psql meta commands (eg. \gset)
1077
+ # can be used. Return the output from the SQL file. The file is executed
1078
+ # with ON_ERROR_STOP on
1079
+ def psqlexec(file, fail: true, silent: self.silent)
1080
+ begin
1081
+ output, errors, status = Open3.capture3 %(
1082
+ psql -U #{username} -d #{database} --no-psqlrc -c '\\set ON_ERROR_STOP on' -f #{file}
1083
+ )
1084
+
1085
+ status.success? or raise PG::Error.new(errors)
1086
+
1087
+ output
1088
+
1089
+ rescue PG::Error => ex
1090
+ if @error.nil?
1091
+ @error = ex
1092
+ @err = nil
1093
+ end
1094
+
1095
+ # Process message
1096
+ if !silent
1097
+ $stderr.puts errors
1098
+ end
1099
+
1100
+ # puts "-------------------"
1101
+ # puts "ERRORS"
1102
+ # puts errors
1103
+ # puts "OUTPUT"
1104
+ # puts output
1105
+ # puts "EXCEPTION"
1106
+ # puts ex.message
1107
+ # puts "-------------------"
1108
+ #
1109
+ # if @error.message =~ /^\S* (ERROR.*)/
1110
+ # puts "BING #{silent}"
1111
+ # message = $1
1112
+ # puts "MESSAGE: #{message}"
1113
+ # saved_silent = self.silent
1114
+ # self.silent = silent
1115
+ # message_processor(message, file)
1116
+ # self.silent = saved_silent
1117
+ # elsif !silent
1118
+ # puts "BANG"
1119
+ # $stderr.puts errors
1120
+ # else
1121
+ # puts "NOTHING"
1122
+ # end
1123
+
1124
+ raise if fail
1125
+ nil
1126
+ end
1127
+ end
1128
+
1069
1129
  # Execute block with the given set of global or local options and reset
1070
1130
  # them afterwards
1071
1131
  #
@@ -1542,11 +1602,12 @@ module PgConn
1542
1602
  @err = nil
1543
1603
  end
1544
1604
 
1545
- # Process message before resetting silent state
1605
+ # Process message
1546
1606
  message_processor(@error.message, arg)
1547
- self.silent = saved_silent
1548
1607
 
1549
1608
  raise
1609
+ ensure
1610
+ self.silent = saved_silent
1550
1611
  end
1551
1612
 
1552
1613
  # For dump of SQL statements
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.55.0
4
+ version: 0.56.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen