The same issue occurs with validates_uniqueness_of:
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/234451e0339d5872/11a2cf0ffba79260

Based on the tables linked below (in the Remarks section) MS SQL
Server 2000 and 2005 both implicitly convert between string and number
fields.

http://msdn2.microsoft.com/en-US/library/aa226054(SQL.80).aspx
http://msdn2.microsoft.com/en-us/library/ms187928.aspx

i am interested in helping solve this problem but i don't have any
bright ideas.

- jeremy

On Aug 3, 3:01 pm, "John Sheets" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Sorry I'm so late getting to this.  It's a bit of a stumper!
>
> I'm trying to figure out how to entirely remove the :numconvert hack from
> the Sybase adapter, but I'm not sure how to do it.  The "problem" is that
> the Sybase database does not auto-convert char SQL parameters to numeric
> like MySQL does.  For example if you call User.exist?("1") in MySQL, it'll
> pass the "1" straight out to the SQL.  MySQL implicitly converts it to an
> INT if necessary and the query succeeds.
>
> However, with Sybase, you have to explicitly convert CHAR to INT.  Passing
> the "1" to a numeric column results in a fatal SQL error.  (Incidentally,
> does anyone know if SQLServer does this too?)
>
> If the quote() method has column info like it does with User.find("1"),
> quote() can use that to skip quoting on INT columns.  So the patch below
> fixes find().  Unfortunately, User.exist?("1") is still broken...exist?
> calls #quote_bound_value (base.rb:1589) which does *not* pass along any
> column data.  There's no way to figure out how it should quote the value.
> And if it guesses wrong, Sybase throws an exception.
>
> To work around this, :numconvert used a sledgehammer regexp to convert *all*
> numeric-looking strings to int (thus the config option to turn it off!).
> That's pretty ugly, and causes problems with actual string data that looks
> like a number.
>
> Does anyone have suggestions or comments on what I can do here?  Is there
> any hope of fixing this in the Sybase adapter?
>
> Thanks,
> John
>
> On 4/8/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Dear sybase_adaptor.rb developers.
>
> > Please check this patch.
>
> > Problem:
> > User.find("1") will fail when numconvert set to false.
>
> > * At least above code work find with MySQL
>
> > * User is a ActiveRecord Object. "1" is primary key(id column).
>
> > * It is need to use the following case
>
> > class UsersController < ApplicationController
> >    ....
> >    def show
> >      @user = User.find(params[:id])
> >    end
>
> > About numconvert:
> >http://wiki.rubyonrails.org/rails/pages/HowToSetupSybaseAdapterOnRails
>
> > Patch:
> > copy from connection_adapters/abstract/quoting.rb
>
> > --- sybase_adapter.rb.org       2007-04-09 12:20:06.000000000 +0900
> > +++ sybase_adapter.rb   2007-04-09 12:39:29.000000000 +0900
> > @@ -283,6 +283,9 @@
> >            when String
> >              if column && column.type == :binary &&
> > column.class.respond_to?(:string_to_binary)
> >                "#{quote_string(column.class.string_to_binary(value))}"
> > +            elsif column && [:integer, :float].include?(column.type)
> > +              value = column.type == :integer ? value.to_i :
> > value.to_f
> > +              value.to_s
> >              elsif @numconvert && force_numeric?(column) && value =~ /
> > ^[+-]?[0-9]+$/o
> >                value
> >              else
>
> --
> "The Internet is not something you just dump something
> on.  It's not a big truck.  It's a series of tubes."
> --Senator Ted Stevens, R-AK
>
> John R. Sheetshttp://bark.metacasa.net


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to