These are chat archives for rails-sqlserver/activerecord-sqlserver-adapter

13th
Jul 2016
Michael R. Cook
@mrcook
Jul 13 2016 10:29

Hi, would anyone have insight into the following odd behaviour?

I'm using a new Rails app to test this issue, so I create a migration:

  create_table :users do |t|
    t.string :code, unique: true, limit: 5
  end

After this I can User.create(code: 'ABCDE'). Now, if I then run User.find_by(code: 'ABCDEF'), I would expect nil to be returned (as is the case with MySQL), however, it is returning that user I just created.

Note: with this limit in place, a code with more than 5 characters is truncated on saving, so '1234567' would be saved as '12345'.

I'm running OSX 10.11.5, Rails 4.2.6, freetds 1.00, tiny_tds 1.0.4, and activerecord-sqlserver-adapter 4.2.15. Connecting to SQL Server 2012.

Ken Collins
@metaskills
Jul 13 2016 13:11
Can you post what User.where(code:'ABCDEF').to_sql yields?
Michael R. Cook
@mrcook
Jul 13 2016 13:14
Hi, "SELECT [users].* FROM [users] WHERE [users].[code] = N'ABCDEF'"
Ken Collins
@metaskills
Jul 13 2016 13:15
Is that the same as the find_by too?
Cause that select does look like it would return nil right?
Michael R. Cook
@mrcook
Jul 13 2016 13:16
Where returns, #<ActiveRecord::Relation [#<User id: 2, code: "ABCDE">]>
Ken Collins
@metaskills
Jul 13 2016 13:17
Even when the select has the "F" in the code string?
If so, this sounds like a SQL Server feature that you might want to tweak. Nothing adapter/tinytds related.
Michael R. Cook
@mrcook
Jul 13 2016 13:17
Yes, when I execute User.where(code:'ABCDEF') that was the result
Ken Collins
@metaskills
Jul 13 2016 13:17
Some things that come to mind are some of the ANSI settings?
Can you look into that?
Michael R. Cook
@mrcook
Jul 13 2016 13:18
Okay, do you have any idea what setting might be causing it?
Ken Collins
@metaskills
Jul 13 2016 13:18
I wold have to Google around.
I can share this...
Michael R. Cook
@mrcook
Jul 13 2016 13:18
Okay, I go and have a route around to see what I can find
We set those to be principal of least surprise and pass some AR tests.
But I feel you are hitting something that is not DB agnostic behavior.
Lemme know what you find.
Michael R. Cook
@mrcook
Jul 13 2016 13:21
Thanks Ken, that should be helpful. And yes, I'll let you know how I get on.
Ryan Condron
@rebelweb
Jul 13 2016 15:07
I am trying to compile tiny_tds into a chef omnibus package, I am havine a problem where defncopy exists as binstub in tiny_tds and as a binary from freetds. Not sure how to resolve the issue. I can't have a binstub and the executable in the same folder.
Ryan Condron
@rebelweb
Jul 13 2016 16:01
I have a work around by temporarily change the GEM_HOME env var I will keep everyone updated.
Ken Collins
@metaskills
Jul 13 2016 16:40
OK... naming the binstubs after the bin they wrapped felt like a good idea and I did consider that this could have negative outcomes.
But Windows needed them... and they felt not-so-evil for the POSIX systems too. Open to more thoughts.
Ryan Condron
@rebelweb
Jul 13 2016 17:54
i have moved them to a different gem home for now seeing how that works, in a chef omnibus setup you typically have 1 bin directory for everything because it packages up all the dependencies along with the app. If you're interested in more info on how it works gitlab uses this to deploy their rails app. I will let you know how everything works out.
Ryan Condron
@rebelweb
Jul 13 2016 21:16
Changing the GEM_HOME for tiny_tds's binstubs worked my app boots and works inside the omnibus package. Thanks for the insight.
Ken Collins
@metaskills
Jul 13 2016 22:25
LOVE IT!