Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4156

Show
Ignore:
Timestamp:
04/04/06 18:53:40 (2 years ago)
Author:
xal
Message:

Multiple fixes and optimizations in PostgreSQL adapter, allowing ruby-postgres gem to work properly. Closes #4461

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r4144 r4156  
    11*SVN* 
     2 
     3* Multiple fixes and optimizations in PostgreSQL adapter, allowing ruby-postgres gem to work properly. [ruben.nine@gmail.com] 
    24 
    35* Fixed that AssociationCollection#delete_all should work even if the records of the association are not loaded yet. [Florian Weber] 
  • trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

    r3916 r4156  
    2424        PGconn.connect(host, port, "", "", database, username, password), logger, config 
    2525      ) 
     26 
     27      PGconn.translate_results = false if PGconn.respond_to? :translate_results= 
    2628 
    2729      pga.schema_search_path = config[:schema_search_path] || config[:schema_order] 
     
    6466          true 
    6567        end 
    66       rescue PGError 
    67         false 
     68      # postgres-pr raises a NoMethodError when querying if no conn is available 
     69      rescue PGError, NoMethodError 
     70        false       
    6871      end 
    6972 
     
    340343      private 
    341344        BYTEA_COLUMN_TYPE_OID = 17 
     345        TIMESTAMPOID = 1114 
     346        TIMESTAMPTZOID = 1184 
    342347 
    343348        def configure_connection 
     
    356361        def select(sql, name = nil) 
    357362          res = execute(sql, name) 
    358           results = res.result            
     363          results = res.result 
    359364          rows = [] 
    360365          if results.length > 0 
     
    364369              row.each_index do |cel_index| 
    365370                column = row[cel_index] 
    366                 if res.type(cel_index) == BYTEA_COLUMN_TYPE_OID 
    367                   column = unescape_bytea(column) 
     371                 
     372                case res.type(cel_index) 
     373                  when BYTEA_COLUMN_TYPE_OID 
     374                    column = unescape_bytea(column) 
     375                  when TIMESTAMPTZOID, TIMESTAMPOID 
     376                    column = cast_to_time(column) 
    368377                end 
     378 
    369379                hashed_row[fields[cel_index]] = column 
    370380              end 
     
    473483          return "f" if value =~ /false/i 
    474484           
    475           # Char/String type values 
    476           return $1 if value =~ /^'(.*)'::(bpchar|text|character varying)$/ 
     485          # Char/String/Bytea type values 
     486          return $1 if value =~ /^'(.*)'::(bpchar|text|character varying|bytea)$/ 
    477487           
    478488          # Numeric values 
     
    486496          return nil 
    487497        end 
     498 
     499        # Only needed for DateTime instances 
     500        def cast_to_time(value) 
     501          return value unless value.class == DateTime 
     502          v = value 
     503          time_array = [v.year, v.month, v.day, v.hour, v.min, v.sec] 
     504          Time.send(Base.default_timezone, *time_array) rescue nil 
     505        end 
    488506    end 
    489507  end