MSSQL: Strings that starts or ends with parenthesis are choped by unquote
-------------------------------------------------------------------------

                 Key: JRUBY-2011
                 URL: http://jira.codehaus.org/browse/JRUBY-2011
             Project: JRuby
          Issue Type: Bug
          Components: ActiveRecord-JDBC
    Affects Versions: JRuby 1.0.2, JRuby 1.1RC2
         Environment: Windows 2000 / Built-in JRuby/ActiveRecord-JDBC on 
Netbeans 6.0.
            Reporter: Silvio Fonseca


The 'unquote' method at jdbc_mssql.rb strips parenthesis on beginning and end 
of strings.

Test (at script/console, Test is an ActiveRecord subclass)
>> m=Test.find(1).column_for_attribute(:name)
>> => #<ActiveRecord::ConnectionAdapters::JdbcColumn:0x1acee78 @precision=nil, 
>> @name="name", @default=nil, @scale=nil, @type=
:string, @limit=8000, @primary=false, @null=true, @sql_type="varchar(8000)">
>> m.type_cast("Test2")
=> "Test2"
>> m.type_cast("Test2)")
=> "Test2"
>> m.type_cast("(Test2")
=> "Test2"
>> m.type_cast("(Test2)")
=> "Test2"

Workaround for the issue is to unquote only the apostrophes to cover the actual 
reason it was created for (http://www.mail-archive.com/[EMAIL 
PROTECTED]/msg00655.html)

      def type_cast(value)
        return nil if value.nil? || value == "(NULL)"
        case type
-        when :string then unquote value
+        when :string then unquote_string value
        when :integer then unquote(value).to_i rescue value ? 1 : 0
        when :primary_key then value == true || value == false ? value == true 
? 1 : 0 : value.to_i 
        when :decimal   then self.class.value_to_decimal(value)
        when :datetime  then cast_to_datetime(value)
        when :timestamp then cast_to_time(value)
        when :time      then cast_to_time(value)
        when :date      then cast_to_datetime(value)
        when :boolean   then value == true or (value =~ /^t(rue)?$/i) == 0 or 
unquote(value)=="1"
        when :binary    then unquote value
        else value
        end
      end
      
+      def unquote_string(value)
+        value.to_s.sub(/^\'/, "").sub(/\'$/, "")
+      end


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to