pg_conn 0.34.0 → 0.35.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 +4 -4
- data/lib/pg_conn/version.rb +1 -1
- data/lib/pg_conn.rb +47 -26
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a4c942ce055688931946e0d5a71ddc89a722b2dd98ea6d9d0edc150b39421dd9
         | 
| 4 | 
            +
              data.tar.gz: 3fea9a99e361c86b3b413845d5f319562051347afe025a27006c80548f822ff4
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: aa391cc15005c51ca01503e33096dacecec5743fa3bf6f28c22d7fd2ad7e14d2e23f48dc2cc0e3e9cade6d77bc359d3b56ebb871015e2db9d08cffcedcf8988f
         | 
| 7 | 
            +
              data.tar.gz: 6fd5537fe417a8dac42ad2ac3af16c75a329bcafc93118ae2a375a3ec3368d0dc088163f8dbd87d5b56a8cb357b3bc5c76c6f9ec49618d4d4c6099bee472b423
         | 
    
        data/lib/pg_conn/version.rb
    CHANGED
    
    
    
        data/lib/pg_conn.rb
    CHANGED
    
    | @@ -155,19 +155,27 @@ module PgConn | |
| 155 155 | 
             
                # #exec or #transaction block. The timestamp includes the current time zone
         | 
| 156 156 | 
             
                attr_reader :timestamptz
         | 
| 157 157 |  | 
| 158 | 
            -
                # Controls  | 
| 159 | 
            -
                #  | 
| 160 | 
            -
                #  | 
| 161 | 
            -
                #  | 
| 162 | 
            -
                 | 
| 158 | 
            +
                # Controls error messages. It can be assigned true, false, nil. True causes
         | 
| 159 | 
            +
                # the error message to be printed to standard error, false ignores it, and
         | 
| 160 | 
            +
                # nil resets the state to the default given when the connection was
         | 
| 161 | 
            +
                # initialized or false if absent. Note that #silent only controls the error
         | 
| 162 | 
            +
                # message, the exception is not affected
         | 
| 163 | 
            +
                def silent() @options[:silent] end
         | 
| 164 | 
            +
                def silent=(value) set_option(:silent, value) end
         | 
| 165 | 
            +
             | 
| 166 | 
            +
                # Controls notices. It can be assigned true, false, nil, or a Proc object
         | 
| 167 | 
            +
                # that recieves the message. True causes the message to be printed to
         | 
| 168 | 
            +
                # standard output, false ignores it, and nil resets the state to the
         | 
| 169 | 
            +
                # default given when the connection was initialized or false if absent
         | 
| 163 170 | 
             
                def notice() @options[:notice] end
         | 
| 171 | 
            +
                def notice=(value) set_option(:notice, value) end
         | 
| 164 172 |  | 
| 165 | 
            -
                # Controls warnings.  | 
| 166 | 
            -
                #  | 
| 167 | 
            -
                #  | 
| 168 | 
            -
                #  | 
| 169 | 
            -
                def warning=(value) set_option(:warning, value) end
         | 
| 173 | 
            +
                # Controls warnings. It can be assigned true, false, nil, or a Proc object
         | 
| 174 | 
            +
                # that recieves the message. True causes the message to be printed to
         | 
| 175 | 
            +
                # standard error, false ignores it, and nil resets the state to the default
         | 
| 176 | 
            +
                # given when the connection was initialized or false if absent
         | 
| 170 177 | 
             
                def warning() @options[:warning] end
         | 
| 178 | 
            +
                def warning=(value) set_option(:warning, value) end
         | 
| 171 179 |  | 
| 172 180 | 
             
                # TODO: Move error message handling into the same framework as notice and
         | 
| 173 181 | 
             
                # warning but we have a name collision just below that would need to be
         | 
| @@ -206,7 +214,7 @@ module PgConn | |
| 206 214 | 
             
                # if absent in the Postgres error message
         | 
| 207 215 | 
             
                def errchar = err[2]
         | 
| 208 216 |  | 
| 209 | 
            -
                DEFAULT_OPTIONS = { notice: false, warning: false }
         | 
| 217 | 
            +
                DEFAULT_OPTIONS = { silent: false, notice: false, warning: false }
         | 
| 210 218 |  | 
| 211 219 | 
             
                # :call-seq:
         | 
| 212 220 | 
             
                #     initialize(dbname = nil, user = nil, **options)
         | 
| @@ -314,7 +322,8 @@ module PgConn | |
| 314 322 | 
             
                    # type "uuid" with oid 2950..' warnings
         | 
| 315 323 | 
             
                    type_map.default_type_map = PG::TypeMapAllStrings.new
         | 
| 316 324 |  | 
| 317 | 
            -
                    # Timestamp decoder. FIXME What is this?
         | 
| 325 | 
            +
                    # Timestamp decoder. FIXME What is this? Why only Timestamp and not
         | 
| 326 | 
            +
                    # Timestamptz?
         | 
| 318 327 | 
             
                    type_map.add_coder PG::TextDecoder::Timestamp.new( # Timestamp without time zone
         | 
| 319 328 | 
             
                        oid: 1114,
         | 
| 320 329 | 
             
                        flags: PG::Coder::TIMESTAMP_DB_UTC | PG::Coder::TIMESTAMP_APP_UTC)
         | 
| @@ -329,12 +338,13 @@ module PgConn | |
| 329 338 |  | 
| 330 339 | 
             
                    @pg_connection.type_map_for_results = type_map
         | 
| 331 340 | 
             
                    @pg_connection.field_name_type = @field_name_class.to_s.downcase.to_sym # Use symbol field names
         | 
| 332 | 
            -
             | 
| 333 | 
            -
                    @options, @default_options = {}, DEFAULT_OPTIONS
         | 
| 334 | 
            -
                    set_options(options) # require @default_options
         | 
| 335 | 
            -
                    @default_options = @options.dup
         | 
| 336 341 | 
             
                  end
         | 
| 337 342 |  | 
| 343 | 
            +
                  # Set options even if there is no connection to avoid special casing
         | 
| 344 | 
            +
                  # absent options
         | 
| 345 | 
            +
                  @options, @default_options = {}, DEFAULT_OPTIONS.merge(options)
         | 
| 346 | 
            +
                  set_options(options) if @pg_connection
         | 
| 347 | 
            +
             | 
| 338 348 | 
             
                  @schema = SchemaMethods.new(self)
         | 
| 339 349 | 
             
                  @role = RoleMethods.new(self)
         | 
| 340 350 | 
             
                  @rdbms = RdbmsMethods.new(self)
         | 
| @@ -685,7 +695,7 @@ module PgConn | |
| 685 695 | 
             
                # of the function.  If the :proc option is true the "function" is assumed
         | 
| 686 696 | 
             
                # to be a procedure
         | 
| 687 697 | 
             
                #
         | 
| 688 | 
            -
                def call(name, *args, elem_type: nil, silent:  | 
| 698 | 
            +
                def call(name, *args, elem_type: nil, silent: self.silent, proc: false) # :proc may interfere with hashes
         | 
| 689 699 | 
             
                  args_seq = quote_values(args, elem_type: elem_type)
         | 
| 690 700 | 
             
                  if proc
         | 
| 691 701 | 
             
                    pg_exec "call #{name}(#{args_seq})", silent: silent
         | 
| @@ -709,7 +719,7 @@ module PgConn | |
| 709 719 | 
             
                end
         | 
| 710 720 |  | 
| 711 721 | 
             
                # Like #call with :proc set to true
         | 
| 712 | 
            -
                def proc(name, *args, silent:  | 
| 722 | 
            +
                def proc(name, *args, silent: self.silent)
         | 
| 713 723 | 
             
                  call(name, *args, silent: silent, proc: true)
         | 
| 714 724 | 
             
                end
         | 
| 715 725 |  | 
| @@ -818,7 +828,7 @@ module PgConn | |
| 818 828 | 
             
                end
         | 
| 819 829 |  | 
| 820 830 | 
             
                # Execute block with global options and resets afterwards. Currently only
         | 
| 821 | 
            -
                # :notice and :warning is supported. Very useful in RSpec tests
         | 
| 831 | 
            +
                # :silent, :notice and :warning is supported. Very useful in RSpec tests
         | 
| 822 832 | 
             
                #
         | 
| 823 833 | 
             
                # TODO: :error, :fail, :symbol, :schema, :search_path
         | 
| 824 834 | 
             
                #
         | 
| @@ -848,14 +858,14 @@ module PgConn | |
| 848 858 | 
             
                # transaction stack has collapsed
         | 
| 849 859 | 
             
                #
         | 
| 850 860 | 
             
                # TODO: Make sure the transaction stack is emptied on postgres errors
         | 
| 851 | 
            -
                def exec(sql, commit: true, fail: true, silent:  | 
| 861 | 
            +
                def exec(sql, commit: true, fail: true, silent: self.silent)
         | 
| 852 862 | 
             
                  transaction(commit: commit) { execute(sql, fail: fail, silent: silent) }
         | 
| 853 863 | 
             
                end
         | 
| 854 864 |  | 
| 855 | 
            -
                # Like #exec but returns true/false depending on if the command succeeded | 
| 856 | 
            -
                #  | 
| 857 | 
            -
                #  | 
| 858 | 
            -
                # should be captured
         | 
| 865 | 
            +
                # Like #exec but returns true/false depending on if the command succeeded,
         | 
| 866 | 
            +
                # error messages are suppressed by default.  There is no corresponding
         | 
| 867 | 
            +
                # #execute? method because any failure rolls back the whole transaction
         | 
| 868 | 
            +
                # stack. TODO: Check which exceptions that should be captured
         | 
| 859 869 | 
             
                def exec?(sql, commit: true, silent: true)
         | 
| 860 870 | 
             
                  begin
         | 
| 861 871 | 
             
                    exec(sql, commit: commit, fail: true, silent: silent)
         | 
| @@ -873,7 +883,7 @@ module PgConn | |
| 873 883 | 
             
                # unless :fail is false in which case it returns nil
         | 
| 874 884 | 
             
                #
         | 
| 875 885 | 
             
                # TODO: Handle postgres exceptions wrt transaction state and stack
         | 
| 876 | 
            -
                def execute(sql, fail: true, silent:  | 
| 886 | 
            +
                def execute(sql, fail: true, silent: self.silent)
         | 
| 877 887 | 
             
                  if @pg_connection
         | 
| 878 888 | 
             
                    begin
         | 
| 879 889 | 
             
                      pg_exec(sql, silent: silent)&.cmd_tuples
         | 
| @@ -994,6 +1004,9 @@ module PgConn | |
| 994 1004 | 
             
                # PgConn::Rollback exception in which case #transaction returns nil. Note
         | 
| 995 1005 | 
             
                # that the transaction timestamp is set to the start of the first
         | 
| 996 1006 | 
             
                # transaction even if transactions are nested
         | 
| 1007 | 
            +
                #
         | 
| 1008 | 
            +
                # FIXME: There is some strange problem in rspec where an #insert handles
         | 
| 1009 | 
            +
                # an exception correctly while #exec, #execute, and #transaction does not
         | 
| 997 1010 | 
             
                def transaction(commit: true, &block)
         | 
| 998 1011 | 
             
                  if block_given?
         | 
| 999 1012 | 
             
                    result = nil
         | 
| @@ -1165,6 +1178,14 @@ module PgConn | |
| 1165 1178 | 
             
                # that is shared between all connection copies
         | 
| 1166 1179 | 
             
                def set_option(option, value)
         | 
| 1167 1180 | 
             
                  case option
         | 
| 1181 | 
            +
                    when :silent
         | 
| 1182 | 
            +
                      @options[:silent] =
         | 
| 1183 | 
            +
                          case value
         | 
| 1184 | 
            +
                            when true, false; value
         | 
| 1185 | 
            +
                            when nil; @default_options[:silent]
         | 
| 1186 | 
            +
                          else
         | 
| 1187 | 
            +
                            raise ArgumentError, "Illegal value #{value.inspect}"
         | 
| 1188 | 
            +
                          end
         | 
| 1168 1189 | 
             
                    when :notice, :warning
         | 
| 1169 1190 | 
             
                      @options[option] =
         | 
| 1170 1191 | 
             
                          case value
         | 
| @@ -1231,7 +1252,7 @@ module PgConn | |
| 1231 1252 | 
             
                # though
         | 
| 1232 1253 | 
             
                #
         | 
| 1233 1254 | 
             
                # TODO: Fix silent by not handling exceptions
         | 
| 1234 | 
            -
                def pg_exec(arg, silent:  | 
| 1255 | 
            +
                def pg_exec(arg, silent: self.silent)
         | 
| 1235 1256 | 
             
                  if @pg_connection
         | 
| 1236 1257 | 
             
                    begin
         | 
| 1237 1258 | 
             
                      last_stmt = nil # To make the current SQL statement visible to the rescue clause. FIXME Not used?
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: pg_conn
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.35.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Claus Rasmussen
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2025-03- | 
| 11 | 
            +
            date: 2025-03-11 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: pg
         |