Posts

Showing posts with the label sqlserver

Easy Way to Configure Rails ActiveRecord and SQL Server on Mac OS X

Thanks to How to Connect To Microsoft SQL Server From Rails On OSX , I found out a very easy way to configure the database connection. Assuming you have FreeTDS installed (easily through macports ) and iODBC (comes out of the box with Mac OS X) then this is all you need in your database.yml file: development: adapter: sqlserver mode: odbc dsn: DRIVER=/opt/local/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=10.0.6.20;DATABASE=awesome_development;Port=1433;uid=sa;pwd=password; No configuration of a DSN required, and no mucking about with freetds.conf! Now, if I could just use database.yml to get rid of SQL Server all together, I'd be a happy developer.

SQL Server Adapter for Rails 2.0

UPDATE: Everything works now. Turns out I had a plugin installed that monkey patched the SQL Server Adapter. This plugin was from an older version of Rails, and the Rails 2.0 adapters now extend from AbstractAdapter. Fixing the parent class in my plugin monkey patch (to extend from AbstractAdapter) fixed this up and now I no longer get the error. I just installed the SQL Server Adapter Gem from gems.rubyonrails.org for my new Rails 2.0 project: gem install activerecord-sqlserver-adapter --source=http://gems.rubyonrails.org When I attempt to use it, I receive this error message: TypeError: superclass mismatch for class SQLServerAdapter from /var/lib/gems/1.8/gems/activerecord-sqlserver-adapter-1.0.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:190 from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require' from /home/sladd/development/workspace/...

Fixing Rails Pagination for SQL Server

MS SQL Server certainly feels like the red headed step child of the Rails connection adapters. The core developers aren't interested in it, and I'd have to guess that most Rails developers deploy to MySQL or PostgreSQL . A good example of why the SQL Server support needs more love from the Rails community. The pagination code in the connection adapter is horribly ugly. SQL Server 2000 doesn't support a limit or offset, which makes pagination extremely difficult. For kicks, check out the SQL that the Rails connection adapter generates for a limit and offset query in SQL Server. There's enough sub queries and reverse sorts to make your head spin. Not to mention the awful performance killing select count(*) before every query. SQL Server 2005 makes our life a little easier in that it added row_number() support. With this, it's possible, however not straight forward, to perform pagination that doesn't make you want to puke so much. Unfortunately, Rails h...

Locking Rows in SQL Server 2005

There turns out to be a few different ways to lock rows in SQL Server 2005. The `SERIALIZABLE` tag is one of the options. Here are a few more: SQL Server Row Locking Strategies As an aside, Rails (and Hibernate ) support object locking with database locking semantics. In Rails 1.1.x, only optimistic locking was supported. Rails 1.2 added support for pesimistic locking . Hibernate accomplishes the row lock with: return tableName + " with (updlock, rowlock)"; AFAICT, Rails punts on this. I can't find the locking syntax in the connection adapter. There is an add_lock! But it expects the locking syntax string unless you can use the default (`FOR UPDATE`, which of course SQL Server doesn't support). That's pretty lame on Rails' part. But anyway...