Skip to content

Conversation

@simondean
Copy link

Hi. I get the following error when using the :odbc mode with a table that has a primary key but no IDENTITY column.

IDENTITY_INSERT could not be turned OFF for table [TheTableName] (ActiveRecord::ActiveRecordError)

is_identity? seems to return a Fixnum with a value of 0 or 1. The issue seems to be caused both values evaluating as true. is_identity?.nil? is always false regardless of whether is_identity? returns 0 or 1. The issue was observed on Ruby 1.9.3 running on Windows 7 64bit connecting to a local SQL Server 2008 R2 database using the adapter's odbc mode (needed to get integrated security working using the Windows user account the ruby process was running under).

@metaskills
Copy link
Member

Thanks, but I suggest we open an issue and communicate a bit more before doing a pull request. FIrst, I think this issue i first related to RubyODBC since it is not doing native casting of boolean values like TinyTDS would. So can you confirm that this issue does not show up when using TinyTDS?

Second, even if this was not an issue with casting, then the fix is not putting extra code in leaf node methods, but to make sure that we put proper true and false values into the data returned by the column_definitions method, the source for said data.

https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver/schema_statements.rb#L152-240

So perhaps that line where we pull the identity should be something like CAST(c.is_identity, big) AS [is_identity]? Thoughts?

@metaskills
Copy link
Member

The regression is in this commit. 5d2b384

@metaskills metaskills closed this in 798f84d May 1, 2012
@metaskills
Copy link
Member

Just published 3.2.4 which fixes this issue. Thanks for reporting the problem. BTW, I highly suggest TinyTDS, we even distribute native Windows gems.

@simondean
Copy link
Author

Thanks very much for the fix and the new release. I'm using the ActiveRecord with activerecord-sqlserver-adapter in some Cucumber acceptance tests. The one advantage the odbc mode is offering is connecting via integrated security, with the connection picking up the identity of the process owner without having to specify the user name and password. If it were product code I'd definitely go with the tds mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants