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

Changeset 8185

Show
Ignore:
Timestamp:
11/22/07 01:29:19 (10 months ago)
Author:
bitsweat
Message:

PostgreSQL: correct binary escaping. References #8049, closes #10176 [jbasdf, tmacedo]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb

    r8113 r8185  
    7676            self.class.module_eval do 
    7777              define_method(:binary_to_string) do |value| 
    78                 if value =~ /\\\\\d{3}/ 
     78                if value =~ /\\\d{3}/ 
    7979                  PGconn.unescape_bytea(value) 
    8080                else 
     
    8686            self.class.module_eval do 
    8787              define_method(:binary_to_string) do |value| 
    88                 if value =~ /\\\\\d{3}/ 
     88                if value =~ /\\\d{3}/ 
    8989                  result = '' 
    9090                  i, max = 0, value.size 
  • trunk/activerecord/test/binary_test.rb

    r6859 r8185  
    11require 'abstract_unit' 
    2 require 'fixtures/binary' 
    32 
    4 class BinaryTest < Test::Unit::TestCase 
    5   BINARY_FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures/flowers.jpg' 
     3# Without using prepared statements, it makes no sense to test 
     4# BLOB data with SQL Server, because the length of a statement is 
     5# limited to 8KB. 
     6
     7# Without using prepared statements, it makes no sense to test 
     8# BLOB data with DB2 or Firebird, because the length of a statement 
     9# is limited to 32KB. 
     10unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter) 
     11  require 'fixtures/binary' 
    612 
    7   def setup 
    8     Binary.connection.execute 'DELETE FROM binaries' 
    9     @data = File.read(BINARY_FIXTURE_PATH).freeze 
    10   end 
    11    
    12   def test_truth 
    13     assert true 
    14   end 
     13  class BinaryTest < Test::Unit::TestCase 
     14    FIXTURES = %w(flowers.jpg example.log) 
    1515 
    16   # Without using prepared statements, it makes no sense to test 
    17   # BLOB data with SQL Server, because the length of a statement is 
    18   # limited to 8KB. 
    19   # 
    20   # Without using prepared statements, it makes no sense to test 
    21   # BLOB data with DB2 or Firebird, because the length of a statement 
    22   # is limited to 32KB. 
    23   unless current_adapter?(:SQLServerAdapter, :SybaseAdapter, :DB2Adapter, :FirebirdAdapter) 
    2416    def test_load_save 
    25       bin = Binary.new 
    26       bin.data = @data 
     17      Binary.delete_all 
    2718 
    28       assert @data == bin.data, 'Newly assigned data differs from original' 
    29            
    30       bin.save 
    31       assert @data == bin.data, 'Data differs from original after save' 
     19      FIXTURES.each do |filename| 
     20        data = File.read("#{File.dirname(__FILE__)}/fixtures/#{filename}").freeze 
    3221 
    33       db_bin = Binary.find(bin.id) 
    34       assert @data == db_bin.data, 'Reloaded data differs from original' 
     22        bin = Binary.new(:data => data) 
     23        assert_equal data, bin.data, 'Newly assigned data differs from original' 
     24 
     25        bin.save! 
     26        assert_equal data, bin.data, 'Data differs from original after save' 
     27 
     28        assert_equal data, bin.reload.data, 'Reloaded data differs from original' 
     29      end 
    3530    end 
    3631  end