{"id":129,"date":"2009-09-23T14:36:14","date_gmt":"2009-09-23T14:36:14","guid":{"rendered":"http:\/\/nicholshayes.myzen.co.uk\/blog\/?p=129"},"modified":"2010-01-15T11:37:44","modified_gmt":"2010-01-15T11:37:44","slug":"bug-in-the-activerecord-sqlserver-adapter-2-2-21-gem","status":"publish","type":"post","link":"http:\/\/nicholshayes.co.uk\/blog\/?p=129","title":{"rendered":"Bug in the activerecord-sqlserver-adapter-2.2.21 gem"},"content":{"rendered":"<p>There is a bug in the activerecord-sqlserver-adapter-2.2.21 gem.<\/p>\n<p>The error is in the file:<\/p>\n<pre>\r\n\\lib\\active_record\\connection_adapters\\sqlserver_adapter.rb\r\n<\/pre>\n<p>Line 1058 reads:<\/p>\n<pre>\r\nFROM #{db_name}INFORMATION_SCHEMA.COLUMNS columns\r\n<\/pre>\n<p>But should read<\/p>\n<pre>\r\nFROM #{db_name}.INFORMATION_SCHEMA.COLUMNS columns\r\n<\/pre>\n<p>The lack of a full stop between the db_name and INFORMATION_SCHEMA causes an error because the database name gets appended to INFORMATION_SCHEMA and you get an error. For example, if the database was &#8216;db_one&#8217; you&#8217;d get the error:<\/p>\n<pre>\r\nInvalid object name 'db_oneINFORMATION_SCHEMA.COLUMNS'\r\n<\/pre>\n<p>When you try a connection.select (e.g. connection.select_all(sql))<\/p>\n<p><em>An update<\/em><br \/>\nThere could be an issue with the simple solution of just adding a period. The issue is that if a db_name isn&#8217;t speciftied  the SQL code could need to be just:<\/p>\n<p>FROM INFORMATION_SCHEMA.COLUMNS columns<\/p>\n<p>Therefore add a private method to sqlserver_adapter.rb:<\/p>\n<pre>\r\ndef db_name_with_period(db_name)\r\n  \"#{db_name}.\"\r\nend\r\n<\/pre>\n<p>And then update the problem line to:<\/p>\n<pre>\r\nFROM #{db_name_with_period(db_name) if db_name}INFORMATION_SCHEMA.COLUMNS columns\r\n<\/pre>\n<p>The problem has been posted to github:<\/p>\n<p><a href=\"http:\/\/github.com\/rails-sqlserver\/2000-2005-adapter\/issues\/closed\/#issue\/3\">http:\/\/github.com\/rails-sqlserver\/2000-2005-adapter\/issues\/closed\/#issue\/3<\/a><\/p>\n<p><strong>update 15-Jan-10<\/strong><br \/>\nThe problem is still present in the latest version of the adapter and therefore I have added a <a href=\"http:\/\/github.com\/rails-sqlserver\/2000-2005-adapter\/issues\/#issue\/24\">new issue<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Error causes INFORMATION_SCHEMA.COLUMNS to be appended to database name when using connection.select. <a href=\"http:\/\/nicholshayes.co.uk\/blog\/?p=129\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/129"}],"collection":[{"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=129"}],"version-history":[{"count":10,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/129\/revisions"}],"predecessor-version":[{"id":135,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/129\/revisions\/135"}],"wp:attachment":[{"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}