Sybase Adaptor patch: User.find("1") will fail when numconvert set to false

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:

Patch: copy from connection_adapters/abstract/quoting.rb

--- 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

Environment activerecord-1.15.3


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

The same issue occurs with validates_uniqueness_of:

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

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

- jeremy

Need an active record expert to look into two tickets on the Sybase adapter (which is now a gem). Tickets are #8400 and #10629. Thanks in advance!

~ Anthony

Jeremy Burks wrote: