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

Ticket #7987: sqlserver_binary.patch

File sqlserver_binary.patch, 1.3 kB (added by lawrence, 1 year ago)
  • lib/active_record/connection_adapters/sqlserver_adapter.rb

    old new  
    122122 
    123123      # These methods will only allow the adapter to insert binary data with a length of 7K or less 
    124124      # because of a SQL Server statement length policy. 
    125       def self.string_to_binary(value) 
    126         value.gsub(/(\r|\n|\0|\x1a)/) do 
    127           case $1 
    128             when "\r"   then  "%00" 
    129             when "\n"   then  "%01" 
    130             when "\0"   then  "%02" 
    131             when "\x1a" then  "%03" 
    132           end 
    133         end 
    134       end 
    135  
    136       def self.binary_to_string(value) 
    137         value.gsub(/(%00|%01|%02|%03)/) do 
    138           case $1 
    139             when "%00"    then  "\r" 
    140             when "%01"    then  "\n" 
    141             when "%02\0"  then  "\0" 
    142             when "%03"    then  "\x1a" 
    143           end 
    144         end 
    145       end 
     125      def self.string_to_binary(value)  
     126              Base64.encode64(value)  
     127      end  
     128                
     129            def self.binary_to_string(value)  
     130              Base64.decode64(value)  
     131            end  
    146132    end 
    147133 
    148134    # In ADO mode, this adapter will ONLY work on Windows systems,