<?xml version="1.0" encoding="UTF-8"?>
<tickets type="array">
  <ticket>
    <assigned-user-id type="integer" nil="true"></assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-11-06T10:00:53-05:00</created-at>
    <creator-id type="integer">23964</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">40</number>
    <permalink>uniqueidentifier-column-error</permalink>
    <priority type="integer">175767</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag nil="true"></tag>
    <title>uniqueidentifier column error</title>
    <updated-at type="datetime">2009-12-04T18:07:51-05:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Sputz</creator-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/40</url>
    <original-body>Thank you for the SQL Server adapter.

I have a problem with an uniqueidentifier column.

Here is the error that i get:

DBI::DatabaseError: 37000 (8169) [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting from a character string to uniqueidentifier.: INSERT INTO [Users] ([salt], [updated_at], [UserName], [remember_token_expires_at], [Password], [Email], [EmailValidationStatus], [remember_token], [ConfirmationKey], [created_at]) VALUES(NULL, '2009-11-06 14:32:23.640', 's', NULL, 's', 's', 0, NULL, 'newid(', '2009-11-06 14:32:23.640')

The problem must be here: 'newid('. If edit the query and eliminate the quotes and close the parenthesis it runs perfectly in SQL Management</original-body>
    <latest-body>Thank you for the SQL Server adapter.

I have a problem with an uniqueidentifier column.

Here is the error that i get:

DBI::DatabaseError: 37000 (8169) [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting from a character string to uniqueidentifier.: INSERT INTO [Users] ([salt], [updated_at], [UserName], [remember_token_expires_at], [Password], [Email], [EmailValidationStatus], [remember_token], [ConfirmationKey], [created_at]) VALUES(NULL, '2009-11-06 14:32:23.640', 's', NULL, 's', 's', 0, NULL, 'newid(', '2009-11-06 14:32:23.640')

The problem must be here: 'newid('. If edit the query and eliminate the quotes and close the parenthesis it runs perfectly in SQL Management</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Thank you for the SQL Server adapter.&lt;/p&gt;
&lt;p&gt;I have a problem with an uniqueidentifier column.&lt;/p&gt;
&lt;p&gt;Here is the error that i get:&lt;/p&gt;
&lt;p&gt;DBI::DatabaseError: 37000 (8169) &lt;a href=
&quot;/projects/20277/changesets/Microsoft&quot; title=
&quot;Changeset [Microsoft]&quot;&gt;[Microsoft]&lt;/a&gt;[SQL Server Native Client
10.0][SQL Server]Conversion failed when converting from a character
string to uniqueidentifier.: INSERT INTO &lt;a href=
&quot;/projects/20277/changesets/Users&quot; title=
&quot;Changeset [Users]&quot;&gt;[Users]&lt;/a&gt; ([salt], [updated_at], &lt;a href=
&quot;/projects/20277/changesets/UserName&quot; title=
&quot;Changeset [UserName]&quot;&gt;[UserName]&lt;/a&gt;, [remember_token_expires_at],
&lt;a href=&quot;/projects/20277/changesets/Password&quot; title=
&quot;Changeset [Password]&quot;&gt;[Password]&lt;/a&gt;, &lt;a href=
&quot;/projects/20277/changesets/Email&quot; title=
&quot;Changeset [Email]&quot;&gt;[Email]&lt;/a&gt;, &lt;a href=
&quot;/projects/20277/changesets/EmailValidationStatus&quot; title=
&quot;Changeset [EmailValidationStatus]&quot;&gt;[EmailValidationStatus]&lt;/a&gt;,
[remember_token], &lt;a href=
&quot;/projects/20277/changesets/ConfirmationKey&quot; title=
&quot;Changeset [ConfirmationKey]&quot;&gt;[ConfirmationKey]&lt;/a&gt;, [created_at])
VALUES(NULL, '2009-11-06 14:32:23.640', 's', NULL, 's', 's', 0,
NULL, 'newid(', '2009-11-06 14:32:23.640')&lt;/p&gt;
&lt;p&gt;The problem must be here: 'newid('. If edit the query and
eliminate the quotes and close the parenthesis it runs perfectly in
SQL Management&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer" nil="true"></assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-09-13T12:09:46-04:00</created-at>
    <creator-id type="integer">69553</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">39</number>
    <permalink>timeusec-support</permalink>
    <priority type="integer">0</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag>time#usec</tag>
    <title>time#usec support?</title>
    <updated-at type="datetime">2009-09-14T08:28:06-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Julio Fern&#225;ndez</creator-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/39</url>
    <original-body>__activerecord-sqlserver-adapter-2.2.21 
Micro second support. Time#usec is automatically converted to SQL Server&#8217;s 3.33 millisecond limitation??  not running for me.__

Completed in 188ms (View: 79, DB: 78) | 200 OK [http://localhost/store]
/!\ FAILSAFE /!\  Sun Sep 13 17:46:58 +0200 2009
  Status: 500 Internal Server Error
  DBI::DatabaseError: 22008 (242) [Microsoft][ODBC SQL Server Driver][SQL Server
]La conversi&#190;n del tipo de datos varchar en datetime produjo un valor fuera de i
ntervalo.: UPDATE [sessions] SET [updated_at] = '2009-09-13 15:46:58.890', [data
] = 'BAh7CToJY2FydG86CUNhcnQGOgtAaXRlbXNbADoMdXNlcl9pZGkGOhBfY3Ny
Zl90b2tlbiIxaTkyZ3ZiQzhDb3ppN2w4TnM2UnlTRGQwWkpZcHNXWVdiV05E
cXVQY1hNbz0iCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpG
bGFzaEhhc2h7AAY6CkB1c2VkewA=
' WHERE [id] = 1
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connecti
on_adapters/abstract_adapter.rb:219:in `log'
    C:/Ruby/lib/ruby/gems/1.8/gems/__activerecord-sqlserver-adapter-2.2.21__/lib/act
ive_record/connection_adapters/sqlserver_adapter.rb:840:in `raw_execute'</original-body>
    <latest-body>__activerecord-sqlserver-adapter-2.2.21 
Micro second support. Time#usec is automatically converted to SQL Server&#8217;s 3.33 millisecond limitation??  not running for me.__

Completed in 188ms (View: 79, DB: 78) | 200 OK [http://localhost/store]
/!\ FAILSAFE /!\  Sun Sep 13 17:46:58 +0200 2009
  Status: 500 Internal Server Error
  DBI::DatabaseError: 22008 (242) [Microsoft][ODBC SQL Server Driver][SQL Server
]La conversi&#190;n del tipo de datos varchar en datetime produjo un valor fuera de i
ntervalo.: UPDATE [sessions] SET [updated_at] = '2009-09-13 15:46:58.890', [data
] = 'BAh7CToJY2FydG86CUNhcnQGOgtAaXRlbXNbADoMdXNlcl9pZGkGOhBfY3Ny
Zl90b2tlbiIxaTkyZ3ZiQzhDb3ppN2w4TnM2UnlTRGQwWkpZcHNXWVdiV05E
cXVQY1hNbz0iCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpG
bGFzaEhhc2h7AAY6CkB1c2VkewA=
' WHERE [id] = 1
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connecti
on_adapters/abstract_adapter.rb:219:in `log'
    C:/Ruby/lib/ruby/gems/1.8/gems/__activerecord-sqlserver-adapter-2.2.21__/lib/act
ive_record/connection_adapters/sqlserver_adapter.rb:840:in `raw_execute'</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;&lt;strong&gt;activerecord-sqlserver-adapter-2.2.21&lt;br&gt;
Micro second support. Time#usec is automatically converted to SQL
Server&amp;#8217;s 3.33 millisecond limitation?? not running for
me.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Completed in 188ms (View: 79, DB: 78) | 200 OK [&lt;a href=
&quot;http://localhost/store&quot;&gt;http://localhost/store&lt;/a&gt;]&lt;br&gt;
/!\ FAILSAFE /!\ Sun Sep 13 17:46:58 +0200 2009 Status: 500
Internal Server Error DBI::DatabaseError: 22008 (242) &lt;a href=
&quot;/projects/20277/changesets/Microsoft&quot; title=
&quot;Changeset [Microsoft]&quot;&gt;[Microsoft]&lt;/a&gt;[ODBC SQL Server Driver][SQL
Server ]La conversi&amp;frac34;n del tipo de datos varchar en datetime
produjo un valor fuera de i ntervalo.: UPDATE &lt;a href=
&quot;/projects/20277/changesets/sessions&quot; title=
&quot;Changeset [sessions]&quot;&gt;[sessions]&lt;/a&gt; SET [updated_at] =
'2009-09-13 15:46:58.890', [data&lt;br&gt;
] = 'BAh7CToJY2FydG86CUNhcnQGOgtAaXRlbXNbADoMdXNlcl9pZGkGOhBfY3Ny
Zl90b2tlbiIxaTkyZ3ZiQzhDb3ppN2w4TnM2UnlTRGQwWkpZcHNXWVdiV05E&lt;br&gt;
cXVQY1hNbz0iCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpG&lt;br&gt;
bGFzaEhhc2h7AAY6CkB1c2VkewA=&lt;br&gt;
' WHERE &lt;a href=&quot;/projects/20277/changesets/id&quot; title=
&quot;Changeset [id]&quot;&gt;[id]&lt;/a&gt; = 1&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connecti&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;on_adapters/abstract_adapter.rb:219:in
&lt;code&gt;log'&amp;lt;br/&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;C:/Ruby/lib/ruby/gems/1.8/gems/__activerecord-sqlserver-adapter-2.2.21__/lib/act&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;ive_record/connection_adapters/sqlserver_adapter.rb:840:in
&lt;code&gt;raw_execute'&lt;/code&gt;&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer" nil="true"></assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-09-03T05:01:58-04:00</created-at>
    <creator-id type="integer">54849</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">38</number>
    <permalink>remove-echoe-dep-when-running-rake-test_sqlserver</permalink>
    <priority type="integer">137103</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag nil="true"></tag>
    <title>Remove Echoe dep when running rake test_sqlserver</title>
    <updated-at type="datetime">2009-09-05T20:06:31-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Bob Jelica</creator-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/38</url>
    <original-body>Echoe is required to run tests. As I understand Echoe is similar to hoe, and should not be required to run tests.

Cheers, and keep up the good work!</original-body>
    <latest-body>Echoe is required to run tests. As I understand Echoe is similar to hoe, and should not be required to run tests.

Cheers, and keep up the good work!</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Echoe is required to run tests. As I understand Echoe is similar
to hoe, and should not be required to run tests.&lt;/p&gt;
&lt;p&gt;Cheers, and keep up the good work!&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-04-30T00:36:42-04:00</created-at>
    <creator-id type="integer">55672</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">29</number>
    <permalink>use-of-ntext-causing-nomemoryerror-exception-in-fetch</permalink>
    <priority type="integer">103762</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag nil="true"></tag>
    <title>Use of 'ntext' causing NoMemoryError, exception in 'fetch'</title>
    <updated-at type="datetime">2009-08-25T14:52:10-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>TimG</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/29</url>
    <original-body>Just beginning to work in Ruby and Rails for the first time and find that your adapter (Version 2.2.15) is failing when trying to read a record back from a SQL Server 2005 table that includes a column with the datatype  'ntext'. The exception thrown is as follows:

NoMemoryError in PackagesController#index
negative allocation size (or too big)

D:/ruby/lib/ruby/gems/1.8/gems/dbd-odbc-0.2.4/lib/dbd/odbc/statement.rb:41:in `fetch'

If I change the column type to 'text', the problem disappears.

It seems to make no difference if the ntext/text column contains a value, or is null. 

Release notes for 2.1.15 suggest that ntext is supported, but that's not what I'm seeing using Ruby 1.8.6, Rails 2.3.2, DBI 0.4.0, and adapter 2.2.15.

Anything I might be missing?

Thanks,
Tim</original-body>
    <latest-body>Just beginning to work in Ruby and Rails for the first time and find that your adapter (Version 2.2.15) is failing when trying to read a record back from a SQL Server 2005 table that includes a column with the datatype  'ntext'. The exception thrown is as follows:

NoMemoryError in PackagesController#index
negative allocation size (or too big)

D:/ruby/lib/ruby/gems/1.8/gems/dbd-odbc-0.2.4/lib/dbd/odbc/statement.rb:41:in `fetch'

If I change the column type to 'text', the problem disappears.

It seems to make no difference if the ntext/text column contains a value, or is null. 

Release notes for 2.1.15 suggest that ntext is supported, but that's not what I'm seeing using Ruby 1.8.6, Rails 2.3.2, DBI 0.4.0, and adapter 2.2.15.

Anything I might be missing?

Thanks,
Tim</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Just beginning to work in Ruby and Rails for the first time and
find that your adapter (Version 2.2.15) is failing when trying to
read a record back from a SQL Server 2005 table that includes a
column with the datatype 'ntext'. The exception thrown is as
follows:&lt;/p&gt;
&lt;p&gt;NoMemoryError in PackagesController#index negative allocation
size (or too big)&lt;/p&gt;
&lt;p&gt;
D:/ruby/lib/ruby/gems/1.8/gems/dbd-odbc-0.2.4/lib/dbd/odbc/statement.rb:41:in
&lt;code&gt;fetch'&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If I change the column type to 'text', the problem
disappears.&lt;/p&gt;
&lt;p&gt;It seems to make no difference if the ntext/text column contains
a value, or is null.&lt;/p&gt;
&lt;p&gt;Release notes for 2.1.15 suggest that ntext is supported, but
that's not what I'm seeing using Ruby 1.8.6, Rails 2.3.2, DBI
0.4.0, and adapter 2.2.15.&lt;/p&gt;
&lt;p&gt;Anything I might be missing?&lt;/p&gt;
&lt;p&gt;Thanks, Tim&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-01-04T22:44:07-05:00</created-at>
    <creator-id type="integer">15346</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">12</number>
    <permalink>ado-might-not-work-add-odbc-databaseyml-example</permalink>
    <priority type="integer">45356</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>ADO Might Not Work. Add ODBC database.yml Example</title>
    <updated-at type="datetime">2009-06-18T11:11:50-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Ken Collins</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/12</url>
    <original-body>I need some help in determining if ADO works anymore. Older version of DBI back to 0.023 are confirmed to work, but I'd like to know more. Also take a look at talking about this in the README and/or provide an example database.yml snippet.</original-body>
    <latest-body>I need some help in determining if ADO works anymore. Older version of DBI back to 0.023 are confirmed to work, but I'd like to know more. Also take a look at talking about this in the README and/or provide an example database.yml snippet.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;I need some help in determining if ADO works anymore. Older
version of DBI back to 0.023 are confirmed to work, but I'd like to
know more. Also take a look at talking about this in the README
and/or provide an example database.yml snippet.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-04-07T18:12:39-04:00</created-at>
    <creator-id type="integer">25048</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">24</number>
    <permalink>explicit-db-name-in-table-failsmultiple-databases</permalink>
    <priority type="integer">98453</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>Explicit DB name in table fails/Multiple databases</title>
    <updated-at type="datetime">2009-06-18T11:08:42-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>chagar</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/24</url>
    <original-body>When the model has set_table_name 'MYDATABASE.dbo.myTable', I get the following error, because the column_definitions method lacks a period in its query, or because unqualify_db_name is getting a database name that lacks a period.


Adding a single period in one place, makes it work.

The relevant line in column_definitions is:

FROM #{db_name}INFORMATION_SCHEMA.COLUMNS columns


Error message:

DBI::DatabaseError: S0002 (208) [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'MYDATABASEINFORMATION_SCHEMA.COLUMNS'.:  SELECT columns.TABLE_NAME as table_name, columns.COLUMN_NAME as name, columns.DATA_TYPE as type, columns.COLUMN_DEFAULT as default_value, columns.NUMERIC_SCALE as numeric_scale, columns.NUMERIC_PRECISION as numeric_precision, CASE WHEN columns.DATA_TYPE IN ('nchar','nvarchar') THEN columns.CHARACTER_MAXIMUM_LENGTH ELSE COL_LENGTH(columns.TABLE_NAME, columns.COLUMN_NAME) END as length, CASE WHEN columns.IS_NULLABLE = 'YES' THEN 1 ELSE NULL end as is_nullable, CASE WHEN COLUMNPROPERTY(OBJECT_ID(columns.TABLE_NAME), columns.COLUMN_NAME, 'IsIdentity') = 0 THEN NULL ELSE 1 END as is_identity FROM MYDATABASEINFORMATION_SCHEMA.COLUMNS columns WHERE columns.TABLE_NAME = 'myTable' ORDER BY columns.ordinal_position</original-body>
    <latest-body>When the model has set_table_name 'MYDATABASE.dbo.myTable', I get the following error, because the column_definitions method lacks a period in its query, or because unqualify_db_name is getting a database name that lacks a period.


Adding a single period in one place, makes it work.

The relevant line in column_definitions is:

FROM #{db_name}INFORMATION_SCHEMA.COLUMNS columns


Error message:

DBI::DatabaseError: S0002 (208) [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'MYDATABASEINFORMATION_SCHEMA.COLUMNS'.:  SELECT columns.TABLE_NAME as table_name, columns.COLUMN_NAME as name, columns.DATA_TYPE as type, columns.COLUMN_DEFAULT as default_value, columns.NUMERIC_SCALE as numeric_scale, columns.NUMERIC_PRECISION as numeric_precision, CASE WHEN columns.DATA_TYPE IN ('nchar','nvarchar') THEN columns.CHARACTER_MAXIMUM_LENGTH ELSE COL_LENGTH(columns.TABLE_NAME, columns.COLUMN_NAME) END as length, CASE WHEN columns.IS_NULLABLE = 'YES' THEN 1 ELSE NULL end as is_nullable, CASE WHEN COLUMNPROPERTY(OBJECT_ID(columns.TABLE_NAME), columns.COLUMN_NAME, 'IsIdentity') = 0 THEN NULL ELSE 1 END as is_identity FROM MYDATABASEINFORMATION_SCHEMA.COLUMNS columns WHERE columns.TABLE_NAME = 'myTable' ORDER BY columns.ordinal_position</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;When the model has set_table_name 'MYDATABASE.dbo.myTable', I
get the following error, because the column_definitions method
lacks a period in its query, or because unqualify_db_name is
getting a database name that lacks a period.&lt;/p&gt;
&lt;p&gt;Adding a single period in one place, makes it work.&lt;/p&gt;
&lt;p&gt;The relevant line in column_definitions is:&lt;/p&gt;
&lt;p&gt;FROM #{db_name}INFORMATION_SCHEMA.COLUMNS columns&lt;/p&gt;
&lt;p&gt;Error message:&lt;/p&gt;
&lt;p&gt;DBI::DatabaseError: S0002 (208) [Microsoft][ODBC SQL Server
Driver][SQL Server]Invalid object name
'MYDATABASEINFORMATION_SCHEMA.COLUMNS'.: SELECT columns.TABLE_NAME
as table_name, columns.COLUMN_NAME as name, columns.DATA_TYPE as
type, columns.COLUMN_DEFAULT as default_value,
columns.NUMERIC_SCALE as numeric_scale, columns.NUMERIC_PRECISION
as numeric_precision, CASE WHEN columns.DATA_TYPE IN
('nchar','nvarchar') THEN columns.CHARACTER_MAXIMUM_LENGTH ELSE
COL_LENGTH(columns.TABLE_NAME, columns.COLUMN_NAME) END as length,
CASE WHEN columns.IS_NULLABLE = 'YES' THEN 1 ELSE NULL end as
is_nullable, CASE WHEN
COLUMNPROPERTY(OBJECT_ID(columns.TABLE_NAME), columns.COLUMN_NAME,
'IsIdentity') = 0 THEN NULL ELSE 1 END as is_identity FROM
MYDATABASEINFORMATION_SCHEMA.COLUMNS columns WHERE
columns.TABLE_NAME = 'myTable' ORDER BY
columns.ordinal_position&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer" nil="true"></assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-04-29T20:04:35-04:00</created-at>
    <creator-id type="integer">20594</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">27</number>
    <permalink>better-add_limit_offset-for-sql-server-2005</permalink>
    <priority type="integer">103303</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag>pagination</tag>
    <title>Better add_limit_offset! for SQL Server 2005</title>
    <updated-at type="datetime">2009-06-18T11:06:01-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Seth Ladd</creator-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/27</url>
    <original-body>Thanks for maintaining a SQL Server adapter.

As you know, the current strategy for pagination in the adapter is pretty gnarly.  As you're also aware, SQL Server 2005 has a supported way to do efficient pagination.

Here's the code that we have been using for years:

      def add_limit_offset!(sql, options)
        if options[:limit] and options[:offset]
          sql.sub!(/ORDER BY.*$/i, '')
          sql.sub!(/SELECT/i,
                  &quot;SELECT row_number() over( order by #{options[:order]} ) as row_num, \n&quot;)
          sql.replace(&quot;select top #{options[:limit]} * from (#{sql}) as tmp_table1 \n&quot; +
                &quot;where row_num &gt; #{options[:offset]}&quot;)
        end
      end

I hope you can use it to enhance the adapter, if only for 2005 support.</original-body>
    <latest-body>Thanks for maintaining a SQL Server adapter.

As you know, the current strategy for pagination in the adapter is pretty gnarly.  As you're also aware, SQL Server 2005 has a supported way to do efficient pagination.

Here's the code that we have been using for years:

      def add_limit_offset!(sql, options)
        if options[:limit] and options[:offset]
          sql.sub!(/ORDER BY.*$/i, '')
          sql.sub!(/SELECT/i,
                  &quot;SELECT row_number() over( order by #{options[:order]} ) as row_num, \n&quot;)
          sql.replace(&quot;select top #{options[:limit]} * from (#{sql}) as tmp_table1 \n&quot; +
                &quot;where row_num &gt; #{options[:offset]}&quot;)
        end
      end

I hope you can use it to enhance the adapter, if only for 2005 support.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Thanks for maintaining a SQL Server adapter.&lt;/p&gt;
&lt;p&gt;As you know, the current strategy for pagination in the adapter
is pretty gnarly. As you're also aware, SQL Server 2005 has a
supported way to do efficient pagination.&lt;/p&gt;
&lt;p&gt;Here's the code that we have been using for years:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;  def add_limit_offset!(sql, options)
    if options[:limit] and options[:offset]
      sql.sub!(/ORDER BY.*$/i, '')
      sql.sub!(/SELECT/i,
              &quot;SELECT row_number() over( order by #{options[:order]} ) as row_num, \n&quot;)
      sql.replace(&quot;select top #{options[:limit]} * from (#{sql}) as tmp_table1 \n&quot; +
            &quot;where row_num &amp;gt; #{options[:offset]}&quot;)
    end
  end
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;I hope you can use it to enhance the adapter, if only for 2005
support.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-05-12T21:09:43-04:00</created-at>
    <creator-id type="integer">52369</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">31</number>
    <permalink>multiple-order-by-with-same-column-name-on-different-tables-fails</permalink>
    <priority type="integer">106715</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>Multiple order by with same column name on different tables fails</title>
    <updated-at type="datetime">2009-06-18T11:00:13-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Tomas Varsavsky</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/31</url>
    <original-body>A find that has multiple order bys on different tables but the same column name fails. The first order by is applied but the last one is removed. For example:

  Facility.find(:all, :include =&gt; [:duty_holder], :order =&gt; 'duty_holders.name ASC, facilities.name ASC')

The SQL generated only has the first order by.</original-body>
    <latest-body>A find that has multiple order bys on different tables but the same column name fails. The first order by is applied but the last one is removed. For example:

  Facility.find(:all, :include =&gt; [:duty_holder], :order =&gt; 'duty_holders.name ASC, facilities.name ASC')

The SQL generated only has the first order by.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;A find that has multiple order bys on different tables but the
same column name fails. The first order by is applied but the last
one is removed. For example:&lt;/p&gt;
&lt;p&gt;Facility.find(:all, :include =&amp;gt; [:duty_holder], :order =&amp;gt;
'duty_holders.name ASC, facilities.name ASC')&lt;/p&gt;
&lt;p&gt;The SQL generated only has the first order by.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-04-29T22:39:45-04:00</created-at>
    <creator-id type="integer">20594</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">28</number>
    <permalink>column_definitions-generates-invalid-sql</permalink>
    <priority type="integer">103645</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>column_definitions generates invalid sql</title>
    <updated-at type="datetime">2009-06-18T10:53:50-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Seth Ladd</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/28</url>
    <original-body>Hello,

This may be a configuration issue, as I can't believe the released version has this bug.  However, I'll include the diff for reference.  Notice the missing period between the db_name and the INFORMATION_SCHEMA

My configuration looks like this:

development:
  adapter: sqlserver
  mode: odbc
  dsn: DRIVER=/opt/local/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=10.0.6.20;DATABASE=dses_production;Port=1433;uid=pandora;pwd=XXXXXXX;

The diff:


Index: vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb
===================================================================
--- vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb	(revision 18159)
+++ vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb	(working copy)
@@ -1043,7 +1043,7 @@
             WHEN COLUMNPROPERTY(OBJECT_ID(columns.TABLE_NAME), columns.COLUMN_NAME, 'IsIdentity') = 0 THEN NULL
             ELSE 1
           END as is_identity
-          FROM #{db_name}INFORMATION_SCHEMA.COLUMNS columns
+          FROM #{db_name}.INFORMATION_SCHEMA.COLUMNS columns
           WHERE columns.TABLE_NAME = '#{table_name}'
           ORDER BY columns.ordinal_position
         }.gsub(/[ \t\r\n]+/,' ')

Any ideas?</original-body>
    <latest-body>Hello,

This may be a configuration issue, as I can't believe the released version has this bug.  However, I'll include the diff for reference.  Notice the missing period between the db_name and the INFORMATION_SCHEMA

My configuration looks like this:

development:
  adapter: sqlserver
  mode: odbc
  dsn: DRIVER=/opt/local/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=10.0.6.20;DATABASE=dses_production;Port=1433;uid=pandora;pwd=XXXXXXX;

The diff:


Index: vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb
===================================================================
--- vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb	(revision 18159)
+++ vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb	(working copy)
@@ -1043,7 +1043,7 @@
             WHEN COLUMNPROPERTY(OBJECT_ID(columns.TABLE_NAME), columns.COLUMN_NAME, 'IsIdentity') = 0 THEN NULL
             ELSE 1
           END as is_identity
-          FROM #{db_name}INFORMATION_SCHEMA.COLUMNS columns
+          FROM #{db_name}.INFORMATION_SCHEMA.COLUMNS columns
           WHERE columns.TABLE_NAME = '#{table_name}'
           ORDER BY columns.ordinal_position
         }.gsub(/[ \t\r\n]+/,' ')

Any ideas?</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;This may be a configuration issue, as I can't believe the
released version has this bug. However, I'll include the diff for
reference. Notice the missing period between the db_name and the
INFORMATION_SCHEMA&lt;/p&gt;
&lt;p&gt;My configuration looks like this:&lt;/p&gt;
&lt;p&gt;development: adapter: sqlserver mode: odbc dsn:
DRIVER=/opt/local/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=10.0.6.20;DATABASE=dses_production;Port=1433;uid=pandora;pwd=XXXXXXX;&lt;/p&gt;
&lt;p&gt;The diff:&lt;/p&gt;
&lt;h1&gt;Index:
vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb&lt;/h1&gt;
&lt;p&gt;---
vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb
(revision 18159) +++
vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb
(working copy) @@ -1043,7 +1043,7 @@&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;         WHEN COLUMNPROPERTY(OBJECT_ID(columns.TABLE_NAME), columns.COLUMN_NAME, 'IsIdentity') = 0 THEN NULL
         ELSE 1
       END as is_identity
&lt;/code&gt;
&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;pre&gt;
&lt;code&gt;   FROM #{db_name}INFORMATION_SCHEMA.COLUMNS columns
&lt;/code&gt;
&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;pre&gt;
&lt;code&gt;   FROM #{db_name}.INFORMATION_SCHEMA.COLUMNS columns
   WHERE columns.TABLE_NAME = '#{table_name}'
   ORDER BY columns.ordinal_position
 }.gsub(/[ \t\r\n]+/,' ')
&lt;/code&gt;
&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Any ideas?&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-06-10T05:51:21-04:00</created-at>
    <creator-id type="integer">59528</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">34</number>
    <permalink>no-memory-error-on-windows-odbc-with-nvarcharmax</permalink>
    <priority type="integer">113373</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>No Memory Error on Windows ODBC with nvarchar(max)</title>
    <updated-at type="datetime">2009-06-18T10:49:06-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Colin Stevens</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/34</url>
    <original-body>When using ODBC on the Windows plaform, the nvarchar(max) datatype causes rows to overflow. This is a similar ticket to that already posted, in that case the answer was to change the text field to something realistic in freetds.ini but this solution is not available when using native odbc drivers on windows.</original-body>
    <latest-body>When using ODBC on the Windows plaform, the nvarchar(max) datatype causes rows to overflow. This is a similar ticket to that already posted, in that case the answer was to change the text field to something realistic in freetds.ini but this solution is not available when using native odbc drivers on windows.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;When using ODBC on the Windows plaform, the nvarchar(max)
datatype causes rows to overflow. This is a similar ticket to that
already posted, in that case the answer was to change the text
field to something realistic in freetds.ini but this solution is
not available when using native odbc drivers on windows.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">1</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-06-12T17:28:21-04:00</created-at>
    <creator-id type="integer">38760</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">37</number>
    <permalink>pessimistic-locking-via-add_lock-adds-lock-clause-on-nested-selects-and-can-cause-deadlock</permalink>
    <priority type="integer">113375</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>Pessimistic locking via add_lock! adds lock clause on nested selects and can cause deadlock</title>
    <updated-at type="datetime">2009-06-18T10:47:17-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Joe Rafaniello</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/37</url>
    <original-body>I am using the 2.2.16 version of the adapter and noticed that I occasionally receive deadlocks while using the :lock option, like this:

        Account.find(:first,
          :conditions =&gt; [cond, *cond_param],
          :order =&gt; &quot;priority, id&quot;,
          :lock =&gt; &quot;WITH(UPDLOCK, ROWLOCK) &quot;)
      }

The error shows itself as a process being chosen as a deadlock victim.  Notice that we have nested selects and that each one has a WITH(UPDLOCK,ROWLOCK) and they are on the same table:

An error has occurred during work processing: DBI::DatabaseError: 37000 (1205) [unixODBC][FreeTDS][SQL Server]Transaction (Process ID 62) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.: SELECT TOP 1 * FROM [accounts] WITH(UPDLOCK, ROWLOCK)  WHERE (state = 'active' and acct_type = 'priority' and (created_on is null or created_on &lt;= '2009-06-04 23:06:27.404') and (task_id is NULL or task_id not in ( select task_id FROM accounts WITH(UPDLOCK, ROWLOCK)  where state = 'expired' and task_id is not NULL )) and (region = 'NorthEast' or region = '*' or region IS NULL) and (role in ('administrator','operator') or role = '*' or role IS NULL) ORDER BY priority, id
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:811:in `raw_execute'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:834:in `raw_select'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:787:in `select'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:787:in `select'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:635:in `find_by_sql'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:1490:in `find_every'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:1452:in `find_initial'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:587:in `find'

I found that the sql.gsub! line in the add_lock! method of the adapter is adding the LOCK phrase to each of the FROM clauses.  I have a hack to the adapter to only add the lock for the first select we find.  I'm not sure this is really the correct way of handling it.  I'm not sure how to handle the JOIN gsub! either.  Any ideas?

Attached is a svn diff of my local patch.</original-body>
    <latest-body>I am using the 2.2.16 version of the adapter and noticed that I occasionally receive deadlocks while using the :lock option, like this:

        Account.find(:first,
          :conditions =&gt; [cond, *cond_param],
          :order =&gt; &quot;priority, id&quot;,
          :lock =&gt; &quot;WITH(UPDLOCK, ROWLOCK) &quot;)
      }

The error shows itself as a process being chosen as a deadlock victim.  Notice that we have nested selects and that each one has a WITH(UPDLOCK,ROWLOCK) and they are on the same table:

An error has occurred during work processing: DBI::DatabaseError: 37000 (1205) [unixODBC][FreeTDS][SQL Server]Transaction (Process ID 62) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.: SELECT TOP 1 * FROM [accounts] WITH(UPDLOCK, ROWLOCK)  WHERE (state = 'active' and acct_type = 'priority' and (created_on is null or created_on &lt;= '2009-06-04 23:06:27.404') and (task_id is NULL or task_id not in ( select task_id FROM accounts WITH(UPDLOCK, ROWLOCK)  where state = 'expired' and task_id is not NULL )) and (region = 'NorthEast' or region = '*' or region IS NULL) and (role in ('administrator','operator') or role = '*' or role IS NULL) ORDER BY priority, id
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:811:in `raw_execute'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:834:in `raw_select'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:787:in `select'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:787:in `select'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:635:in `find_by_sql'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:1490:in `find_every'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:1452:in `find_initial'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:587:in `find'

I found that the sql.gsub! line in the add_lock! method of the adapter is adding the LOCK phrase to each of the FROM clauses.  I have a hack to the adapter to only add the lock for the first select we find.  I'm not sure this is really the correct way of handling it.  I'm not sure how to handle the JOIN gsub! either.  Any ideas?

Attached is a svn diff of my local patch.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;I am using the 2.2.16 version of the adapter and noticed that I
occasionally receive deadlocks while using the :lock option, like
this:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;    Account.find(:first,
      :conditions =&amp;gt; [cond, *cond_param],
      :order =&amp;gt; &quot;priority, id&quot;,
      :lock =&amp;gt; &quot;WITH(UPDLOCK, ROWLOCK) &quot;)
  }
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;The error shows itself as a process being chosen as a deadlock
victim. Notice that we have nested selects and that each one has a
WITH(UPDLOCK,ROWLOCK) and they are on the same table:&lt;/p&gt;
&lt;p&gt;An error has occurred during work processing:
DBI::DatabaseError: 37000 (1205) [unixODBC][FreeTDS][SQL
Server]Transaction (Process ID 62) was deadlocked on lock resources
with another process and has been chosen as the deadlock victim.
Rerun the transaction.: SELECT TOP 1 * FROM [accounts]
WITH(UPDLOCK, ROWLOCK) WHERE (state = 'active' and acct_type =
'priority' and (created_on is null or created_on &amp;lt;= '2009-06-04
23:06:27.404') and (task_id is NULL or task_id not in ( select
task_id FROM accounts WITH(UPDLOCK, ROWLOCK) where state =
'expired' and task_id is not NULL )) and (region = 'NorthEast' or
region = '&lt;em&gt;' or region IS NULL) and (role in
('administrator','operator') or role = '&lt;/em&gt;' or role IS NULL)
ORDER BY priority, id
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in
&lt;code&gt;log'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:811:in&lt;/code&gt;raw_execute'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:834:in
&lt;code&gt;raw_select'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:787:in&lt;/code&gt;select'
/var/www/miq/vmdb/vendor/gems/rails-sqlserver-2000-2005-adapter-2.2.16/lib/active_record/connection_adapters/sqlserver_adapter.rb:787:in
&lt;code&gt;select'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in&lt;/code&gt;select_all_without_query_cache'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in
&lt;code&gt;select_all'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:635:in&lt;/code&gt;find_by_sql'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:1490:in
&lt;code&gt;find_every'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:1452:in&lt;/code&gt;find_initial'
/var/www/miq/vmdb/config/../vendor/gems/activerecord-2.2.2/lib/active_record/base.rb:587:in
&lt;code&gt;find'&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I found that the sql.gsub! line in the add_lock! method of the
adapter is adding the LOCK phrase to each of the FROM clauses. I
have a hack to the adapter to only add the lock for the first
select we find. I'm not sure this is really the correct way of
handling it. I'm not sure how to handle the JOIN gsub! either. Any
ideas?&lt;/p&gt;
&lt;p&gt;Attached is a svn diff of my local patch.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer" nil="true"></assigned-user-id>
    <attachments-count type="integer">2</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-06-12T09:33:33-04:00</created-at>
    <creator-id type="integer">47358</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">36</number>
    <permalink>quote_column_name-messes-up-quoted-column-names</permalink>
    <priority type="integer">118816</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag>quotes quoting</tag>
    <title>#quote_column_name messes up quoted column names</title>
    <updated-at type="datetime">2009-06-18T10:23:31-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Vince Puzzella</creator-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/36</url>
    <original-body>Quick Fix:
@@@
      def quote_column_name(column_name)
        #column_name.to_s.split('.').map{ |name| &quot;[#{name}]&quot; }.join('.')
        column_name.to_s.split('.').map{ |name| name =~ /^\[.*\]$/ ? name : &quot;[#{name}]&quot; }.join('.')
      end
@@@</original-body>
    <latest-body>Quick Fix:
@@@
      def quote_column_name(column_name)
        #column_name.to_s.split('.').map{ |name| &quot;[#{name}]&quot; }.join('.')
        column_name.to_s.split('.').map{ |name| name =~ /^\[.*\]$/ ? name : &quot;[#{name}]&quot; }.join('.')
      end
@@@</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Quick Fix:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
      def quote_column_name(column_name)
        #column_name.to_s.split('.').map{ |name| &amp;quot;[#{name}]&amp;quot; }.join('.')
        column_name.to_s.split('.').map{ |name| name =~ /^\[.*\]$/ ? name : &amp;quot;[#{name}]&amp;quot; }.join('.')
      end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-04-01T13:10:08-04:00</created-at>
    <creator-id type="integer">20272</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">21</number>
    <permalink>active_scaffold-doesnt-work-properly</permalink>
    <priority type="integer">96864</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>Active_scaffold doesn't work properly</title>
    <updated-at type="datetime">2009-06-18T09:52:15-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Jordan Yeo</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/21</url>
    <original-body>Trying to use the active_scaffold plugin with the adapter doesn't work. Gives the error: 

DBI::DatabaseError: 42000 (102) [FreeTDS][SQL Server]Incorrect syntax near '\.'.: SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 10  [people].* FROM [people]   ORDER BY people.[id] ASC) AS tmp1 ORDER BY people\.\[[id]\] DESC) AS tmp2 ORDER BY people\.\[[id]\] ASC</original-body>
    <latest-body>Trying to use the active_scaffold plugin with the adapter doesn't work. Gives the error: 

DBI::DatabaseError: 42000 (102) [FreeTDS][SQL Server]Incorrect syntax near '\.'.: SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 10  [people].* FROM [people]   ORDER BY people.[id] ASC) AS tmp1 ORDER BY people\.\[[id]\] DESC) AS tmp2 ORDER BY people\.\[[id]\] ASC</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Trying to use the active_scaffold plugin with the adapter
doesn't work. Gives the error:&lt;/p&gt;
&lt;p&gt;DBI::DatabaseError: 42000 (102) [FreeTDS][SQL Server]Incorrect
syntax near '.'.: SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP
10 [people].* FROM [people] ORDER BY people.[id] ASC) AS tmp1 ORDER
BY people.[[id]] DESC) AS tmp2 ORDER BY people.[[id]] ASC&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-01-28T18:33:48-05:00</created-at>
    <creator-id type="integer">44451</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">17</number>
    <permalink>using-limit-and-offset-does-not-produce-correct-results-on-server-2005</permalink>
    <priority type="integer">67162</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag>limit offset pagination</tag>
    <title>Using limit and offset does not produce correct results on Server 2005</title>
    <updated-at type="datetime">2009-06-18T09:51:07-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Paul</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/17</url>
    <original-body>When querying against Server 2005 using both `:limit` and `:offset` simultaneously only the top limit results from the query are produced and the offset seems to be ignored.

Example:
@@@ ruby
Site.find(:all, :limit =&gt; 5, :offset =&gt; 10, :order =&gt; 'id ASC').each { |site| puts &quot;#{site.id}&quot; }

# Returns
# =&gt; 1
# =&gt; 2
# =&gt; 3
# =&gt; 4
# =&gt; 5

# Expected
# =&gt; 11
# =&gt; 12
# =&gt; 13
# =&gt; 14
# =&gt; 15
@@@

I have, however, found a way of obtaining the correct results using some 2005-specific functionality:

@@@ sql
WITH pagination AS (SELECT row_number() OVER (order by id) AS row_num, * FROM sites)
SELECT * FROM pagination WHERE row_num BETWEEN 10 AND 15 ORDER BY row_num
@@@

Considering that there is the `sqlserver_2005?` method would it be possible to use this type of query only when the adapter is connected to 2005?</original-body>
    <latest-body>When querying against Server 2005 using both `:limit` and `:offset` simultaneously only the top limit results from the query are produced and the offset seems to be ignored.

Example:
@@@ ruby
Site.find(:all, :limit =&gt; 5, :offset =&gt; 10, :order =&gt; 'id ASC').each { |site| puts &quot;#{site.id}&quot; }

# Returns
# =&gt; 1
# =&gt; 2
# =&gt; 3
# =&gt; 4
# =&gt; 5

# Expected
# =&gt; 11
# =&gt; 12
# =&gt; 13
# =&gt; 14
# =&gt; 15
@@@

I have, however, found a way of obtaining the correct results using some 2005-specific functionality:

@@@ sql
WITH pagination AS (SELECT row_number() OVER (order by id) AS row_num, * FROM sites)
SELECT * FROM pagination WHERE row_num BETWEEN 10 AND 15 ORDER BY row_num
@@@

Considering that there is the `sqlserver_2005?` method would it be possible to use this type of query only when the adapter is connected to 2005?</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;When querying against Server 2005 using both &lt;code&gt;:limit&lt;/code&gt;
and &lt;code&gt;:offset&lt;/code&gt; simultaneously only the top limit results
from the query are produced and the offset seems to be ignored.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
Site.find(:all, :limit =&amp;gt; 5, :offset =&amp;gt; 10, :order =&amp;gt; 'id ASC').each { |site| puts &amp;quot;#{site.id}&amp;quot; }

# Returns
# =&amp;gt; 1
# =&amp;gt; 2
# =&amp;gt; 3
# =&amp;gt; 4
# =&amp;gt; 5

# Expected
# =&amp;gt; 11
# =&amp;gt; 12
# =&amp;gt; 13
# =&amp;gt; 14
# =&amp;gt; 15
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I have, however, found a way of obtaining the correct results
using some 2005-specific functionality:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;sql&quot;&gt;
WITH pagination AS (SELECT row_number() OVER (order by id) AS row_num, * FROM sites)
SELECT * FROM pagination WHERE row_num BETWEEN 10 AND 15 ORDER BY row_num
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Considering that there is the &lt;code&gt;sqlserver_2005?&lt;/code&gt;
method would it be possible to use this type of query only when the
adapter is connected to 2005?&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">1</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-06-11T10:06:53-04:00</created-at>
    <creator-id type="integer">136</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">35</number>
    <permalink>add_limit_offset-doesnt-respect-orderings-from-scopes</permalink>
    <priority type="integer">113374</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag>limit named_scope offset pagination</tag>
    <title>add_limit_offset! doesn't respect orderings from scopes</title>
    <updated-at type="datetime">2009-06-18T09:50:31-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Murray Steele</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/35</url>
    <original-body>If we have a scope like:

@@@ ruby
class Donut &lt; ActiveRecord::Base
  named_scope :ordered, :order =&gt; 'sprinkles'
end
@@@

and then try to paginate results of that scope:

@@@ ruby

Donut.ordered.find(:all, :limit =&gt; 10, :offset =&gt; 10)

@@@

What we get, instead of the 2nd page of results, is the 1st page of results.  It doesn't matter what offset we put in, we're still gonna get the 1st page of results.

What's being generated is:

@@@ SQL
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 20 * FROM [donuts] ORDER BY [sprinkles]) AS tmp1) AS tmp2
@@@

What should be generated is:

@@@ SQL
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 20 * FROM [donuts] ORDER BY [sprinkles]) AS tmp1 ORDER BY [sprinkles] DESC) AS tmp2 ORDER BY [sprinkles]
@@@

The attached patch takes care of this.</original-body>
    <latest-body>If we have a scope like:

@@@ ruby
class Donut &lt; ActiveRecord::Base
  named_scope :ordered, :order =&gt; 'sprinkles'
end
@@@

and then try to paginate results of that scope:

@@@ ruby

Donut.ordered.find(:all, :limit =&gt; 10, :offset =&gt; 10)

@@@

What we get, instead of the 2nd page of results, is the 1st page of results.  It doesn't matter what offset we put in, we're still gonna get the 1st page of results.

What's being generated is:

@@@ SQL
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 20 * FROM [donuts] ORDER BY [sprinkles]) AS tmp1) AS tmp2
@@@

What should be generated is:

@@@ SQL
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 20 * FROM [donuts] ORDER BY [sprinkles]) AS tmp1 ORDER BY [sprinkles] DESC) AS tmp2 ORDER BY [sprinkles]
@@@

The attached patch takes care of this.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;If we have a scope like:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
class Donut &amp;lt; ActiveRecord::Base
  named_scope :ordered, :order =&amp;gt; 'sprinkles'
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then try to paginate results of that scope:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;

Donut.ordered.find(:all, :limit =&amp;gt; 10, :offset =&amp;gt; 10)

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What we get, instead of the 2nd page of results, is the 1st page
of results. It doesn't matter what offset we put in, we're still
gonna get the 1st page of results.&lt;/p&gt;
&lt;p&gt;What's being generated is:&lt;/p&gt;
&lt;p&gt;@@@ SQL SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 20 *
FROM [donuts] ORDER BY [sprinkles]) AS tmp1) AS tmp2&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;

What should be generated is:

@@@ SQL
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 20 * FROM [donuts] ORDER BY [sprinkles]) AS tmp1 ORDER BY [sprinkles] DESC) AS tmp2 ORDER BY [sprinkles]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The attached patch takes care of this.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-04-08T02:00:09-04:00</created-at>
    <creator-id type="integer">3914</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">25</number>
    <permalink>cant-have-a-table-called-applications</permalink>
    <priority type="integer">98500</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>Can't have a table called 'Applications'</title>
    <updated-at type="datetime">2009-06-08T18:24:09-04:00</updated-at>
    <user-id type="integer">3914</user-id>
    <user-name>Hugh</user-name>
    <creator-name>Hugh</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/25</url>
    <original-body>This is due to the calling of classify on the table_name in order to check if it has an ActiveRecord model.

I made a quick hack to get me out of this pickle:

http://github.com/artpop/2000-2005-adapter/commit/0925a1baeedef9acb9625d0a51b0ac293357dac4

However there has to be a better way than calling classify on table_name because there are bound to be other class name clashes.</original-body>
    <latest-body>This is due to the calling of classify on the table_name in order to check if it has an ActiveRecord model.

I made a quick hack to get me out of this pickle:

http://github.com/artpop/2000-2005-adapter/commit/0925a1baeedef9acb9625d0a51b0ac293357dac4

However there has to be a better way than calling classify on table_name because there are bound to be other class name clashes.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;This is due to the calling of classify on the table_name in
order to check if it has an ActiveRecord model.&lt;/p&gt;
&lt;p&gt;I made a quick hack to get me out of this pickle:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://github.com/artpop/2000-2005-adapter/commit/0925a1baeedef9acb9625d0a51b0ac293357dac4&quot;&gt;
http://github.com/artpop/2000-20...&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;However there has to be a better way than calling classify on
table_name because there are bound to be other class name
clashes.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-05-29T20:46:46-04:00</created-at>
    <creator-id type="integer">58377</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">33</number>
    <permalink>table_klass-doesnt-rescue-loaderror</permalink>
    <priority type="integer">1</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag>loaderror table_klass</tag>
    <title>table_klass doesn't rescue LoadError</title>
    <updated-at type="datetime">2009-06-08T13:48:27-04:00</updated-at>
    <user-id type="integer">58377</user-id>
    <user-name>Larry Kyrala</user-name>
    <creator-name>Larry Kyrala</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/33</url>
    <original-body>Under certain circumstances, constantize raises a LoadError which is not rescued by the method table_klass in around sqlserver_adapter.rb, line 100.

(This may solve the problem reported in #25, which I suspect is caused by the same underlying issue).


I've been troubleshooting a model for work that fails while using version 2.2.17 of the adapter. 

We have a model that is set up like this:

in &quot;foo.rb&quot;:
@@@
class Foo &lt; ActiveRecord::Base
  set_table_name :FOO     # this is a legacy database name we can't change
end
@@@

When we try to use this with rails-sqlserver-2000-2005-adapter (2.2.17), we get a stack trace similar to:

@@@
% ruby script/console
&gt;&gt; Foo.first
LoadError: Expected /local/gems/gems/foo/lib/foo.rb to define FOO
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:428:in `load_missing_constant'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in `const_missing'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:89:in `const_missing'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/inflector.rb:352:in `constantize'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `each'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `constantize'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
	from /local/gems/gems/rails-sqlserver-2000-2005-adapter-2.2.17/lib/active_record/connection_adapters/sqlserver_adapter.rb:100:in `table_klass'
@@@

We tracked this to the following code around sqlserver_adapter.rb, line 100 

@@@
      def table_klass
        @table_klass ||= table_name.classify.constantize rescue nil
        (@table_klass &amp;&amp; @table_klass &lt; ActiveRecord::Base) ? @table_klass : nil
      end
@@@

It seems like the intent of this method at is to find an existing class constant that matches the table name or return nil.  This would work in our situation if the rails method load_missing_constant only raised StandardError exceptions.  However, in one case (notably ours and I think #25), this method actually raises a LoadError exception.
(see activesupport-2.2.2/lib/active_support/dependencies.rb:428:in `load_missing_constant')

Since table_klass does not explicitly rescue LoadErrors, the exception bubbles up to the developer.

This seems to only happen if there is a likely file candidate for load_missing_constant in the file paths.  In our case, this is &quot;foo.rb&quot;.  In #25's case, this is &quot;application.rb&quot;.

This might be a potential fix:

@@@
      def table_klass
        begin
          @table_klass ||= table_name.classify.constantize 
        rescue StandardError, LoadError
           nil
        end
        (@table_klass &amp;&amp; @table_klass &lt; ActiveRecord::Base) ? @table_klass : nil
      end
@@@

but I wanted to check that this fix matches your original intent.

Thanks and hope this helps!</original-body>
    <latest-body>Under certain circumstances, constantize raises a LoadError which is not rescued by the method table_klass in around sqlserver_adapter.rb, line 100.

(This may solve the problem reported in #25, which I suspect is caused by the same underlying issue).


I've been troubleshooting a model for work that fails while using version 2.2.17 of the adapter. 

We have a model that is set up like this:

in &quot;foo.rb&quot;:
@@@
class Foo &lt; ActiveRecord::Base
  set_table_name :FOO     # this is a legacy database name we can't change
end
@@@

When we try to use this with rails-sqlserver-2000-2005-adapter (2.2.17), we get a stack trace similar to:

@@@
% ruby script/console
&gt;&gt; Foo.first
LoadError: Expected /local/gems/gems/foo/lib/foo.rb to define FOO
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:428:in `load_missing_constant'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in `const_missing'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:89:in `const_missing'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/inflector.rb:352:in `constantize'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `each'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `constantize'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
	from /local/gems/gems/rails-sqlserver-2000-2005-adapter-2.2.17/lib/active_record/connection_adapters/sqlserver_adapter.rb:100:in `table_klass'
@@@

We tracked this to the following code around sqlserver_adapter.rb, line 100 

@@@
      def table_klass
        @table_klass ||= table_name.classify.constantize rescue nil
        (@table_klass &amp;&amp; @table_klass &lt; ActiveRecord::Base) ? @table_klass : nil
      end
@@@

It seems like the intent of this method at is to find an existing class constant that matches the table name or return nil.  This would work in our situation if the rails method load_missing_constant only raised StandardError exceptions.  However, in one case (notably ours and I think #25), this method actually raises a LoadError exception.
(see activesupport-2.2.2/lib/active_support/dependencies.rb:428:in `load_missing_constant')

Since table_klass does not explicitly rescue LoadErrors, the exception bubbles up to the developer.

This seems to only happen if there is a likely file candidate for load_missing_constant in the file paths.  In our case, this is &quot;foo.rb&quot;.  In #25's case, this is &quot;application.rb&quot;.

This might be a potential fix:

@@@
      def table_klass
        begin
          @table_klass ||= table_name.classify.constantize 
        rescue StandardError, LoadError
           nil
        end
        (@table_klass &amp;&amp; @table_klass &lt; ActiveRecord::Base) ? @table_klass : nil
      end
@@@

but I wanted to check that this fix matches your original intent.

Thanks and hope this helps!</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Under certain circumstances, constantize raises a LoadError
which is not rescued by the method table_klass in around
sqlserver_adapter.rb, line 100.&lt;/p&gt;
&lt;p&gt;(This may solve the problem reported in &lt;a href=&quot;/projects/20277/tickets/25&quot; title=&quot;Ticket #25&quot;&gt;#25&lt;/a&gt;, which I
suspect is caused by the same underlying issue).&lt;/p&gt;
&lt;p&gt;I've been troubleshooting a model for work that fails while
using version 2.2.17 of the adapter.&lt;/p&gt;
&lt;p&gt;We have a model that is set up like this:&lt;/p&gt;
&lt;p&gt;in &quot;foo.rb&quot;:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
class Foo &amp;lt; ActiveRecord::Base
  set_table_name :FOO     # this is a legacy database name we can't change
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When we try to use this with rails-sqlserver-2000-2005-adapter
(2.2.17), we get a stack trace similar to:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
% ruby script/console
&amp;gt;&amp;gt; Foo.first
LoadError: Expected /local/gems/gems/foo/lib/foo.rb to define FOO
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:428:in `load_missing_constant'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in `const_missing'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:89:in `const_missing'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/inflector.rb:352:in `constantize'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `each'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `constantize'
	from /local/gems/gems/activesupport-2.2.2/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
	from /local/gems/gems/rails-sqlserver-2000-2005-adapter-2.2.17/lib/active_record/connection_adapters/sqlserver_adapter.rb:100:in `table_klass'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We tracked this to the following code around
sqlserver_adapter.rb, line 100&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
      def table_klass
        @table_klass ||= table_name.classify.constantize rescue nil
        (@table_klass &amp;amp;&amp;amp; @table_klass &amp;lt; ActiveRecord::Base) ? @table_klass : nil
      end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It seems like the intent of this method at is to find an
existing class constant that matches the table name or return nil.
This would work in our situation if the rails method
load_missing_constant only raised StandardError exceptions.
However, in one case (notably ours and I think &lt;a href=&quot;/projects/20277/tickets/25&quot; title=&quot;Ticket #25&quot;&gt;#25&lt;/a&gt;), this
method actually raises a LoadError exception. (see
activesupport-2.2.2/lib/active_support/dependencies.rb:428:in
&lt;code&gt;load_missing_constant')&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Since table_klass does not explicitly rescue LoadErrors, the
exception bubbles up to the developer.&lt;/p&gt;
&lt;p&gt;This seems to only happen if there is a likely file candidate
for load_missing_constant in the file paths. In our case, this is
&quot;foo.rb&quot;. In &lt;a href=&quot;/projects/20277/tickets/25&quot; title=&quot;Ticket #25&quot;&gt;#25&lt;/a&gt;'s case, this is &quot;application.rb&quot;.&lt;/p&gt;
&lt;p&gt;This might be a potential fix:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
      def table_klass
        begin
          @table_klass ||= table_name.classify.constantize 
        rescue StandardError, LoadError
           nil
        end
        (@table_klass &amp;amp;&amp;amp; @table_klass &amp;lt; ActiveRecord::Base) ? @table_klass : nil
      end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but I wanted to check that this fix matches your original
intent.&lt;/p&gt;
&lt;p&gt;Thanks and hope this helps!&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">1</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-05-27T16:19:06-04:00</created-at>
    <creator-id type="integer">58109</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">32</number>
    <permalink>sql-server-2008-not-supported</permalink>
    <priority type="integer">113372</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag>2008 connection</tag>
    <title>SQL Server 2008 not supported</title>
    <updated-at type="datetime">2009-06-05T19:22:42-04:00</updated-at>
    <user-id type="integer">58109</user-id>
    <user-name>howardk</user-name>
    <creator-name>howardk</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/32</url>
    <original-body>The adapter refuses to talk to SQL Server 2008 (hardcoded to reject anything other than 2000 or 2005), though it works fine it you lift the hardcoded restriction.

The patch is quite simple for 2.2.17, just recognize SQL Server 2008 and handle it same as 2005 is handled. Diff is attached, amounting to:

* Recognize version='2008'
* Add sqlserver_2008? test method, a la sqlserver_2005?
* Add sqlserver_2005_or_2008? test method
* Replace the 2 tests for 2005 to also accept 2008
* Update 1 comment noting also applicable to 2008

Tests and development to date confirm the adapter seems to work fine for SQL Server 2008, but we haven't done exhaustive testing of the adapter so I wouldn't swear it's flawless. Will be happy to report if we encounter any problems in the future, but so far it's looking quite good.

DISCLAIMER: I work for Microsoft, but I have no connection to the SQL Server team or any other data access team. Just trying to use ActiveRecord and SQL Server 2008 together, and stumbling face first into the brick wall here.</original-body>
    <latest-body>The adapter refuses to talk to SQL Server 2008 (hardcoded to reject anything other than 2000 or 2005), though it works fine it you lift the hardcoded restriction.

The patch is quite simple for 2.2.17, just recognize SQL Server 2008 and handle it same as 2005 is handled. Diff is attached, amounting to:

* Recognize version='2008'
* Add sqlserver_2008? test method, a la sqlserver_2005?
* Add sqlserver_2005_or_2008? test method
* Replace the 2 tests for 2005 to also accept 2008
* Update 1 comment noting also applicable to 2008

Tests and development to date confirm the adapter seems to work fine for SQL Server 2008, but we haven't done exhaustive testing of the adapter so I wouldn't swear it's flawless. Will be happy to report if we encounter any problems in the future, but so far it's looking quite good.

DISCLAIMER: I work for Microsoft, but I have no connection to the SQL Server team or any other data access team. Just trying to use ActiveRecord and SQL Server 2008 together, and stumbling face first into the brick wall here.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;The adapter refuses to talk to SQL Server 2008 (hardcoded to
reject anything other than 2000 or 2005), though it works fine it
you lift the hardcoded restriction.&lt;/p&gt;
&lt;p&gt;The patch is quite simple for 2.2.17, just recognize SQL Server
2008 and handle it same as 2005 is handled. Diff is attached,
amounting to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Recognize version='2008'&lt;/li&gt;
&lt;li&gt;Add sqlserver_2008? test method, a la sqlserver_2005?&lt;/li&gt;
&lt;li&gt;Add sqlserver_2005_or_2008? test method&lt;/li&gt;
&lt;li&gt;Replace the 2 tests for 2005 to also accept 2008&lt;/li&gt;
&lt;li&gt;Update 1 comment noting also applicable to 2008&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tests and development to date confirm the adapter seems to work
fine for SQL Server 2008, but we haven't done exhaustive testing of
the adapter so I wouldn't swear it's flawless. Will be happy to
report if we encounter any problems in the future, but so far it's
looking quite good.&lt;/p&gt;
&lt;p&gt;DISCLAIMER: I work for Microsoft, but I have no connection to
the SQL Server team or any other data access team. Just trying to
use ActiveRecord and SQL Server 2008 together, and stumbling face
first into the brick wall here.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-05-12T21:01:14-04:00</created-at>
    <creator-id type="integer">52369</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">30</number>
    <permalink>text-fields-are-created-as-strings-in-schemarb</permalink>
    <priority type="integer">106801</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag>schema text type</tag>
    <title>Text fields are created as strings in schema.rb </title>
    <updated-at type="datetime">2009-05-14T16:11:40-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Tomas Varsavsky</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/30</url>
    <original-body>When text fields are created in the SQLServer database 
as varchar(max) the type in schema.rb is changed to string! This makes 
my tests fail because the test database is created from schema.rb not 
migrations. 

In my migration I have: 
    create_table :audits, :force =&gt; true do |t| 
      t.text    :changes 
    end 

In the DB the changes column is created as varchar(max). 

In my schema.rb I have: 
  create_table &quot;audits&quot;, :force =&gt; true do |t| 
    t.string   &quot;changes&quot;,        :limit =&gt; nil 
  end</original-body>
    <latest-body>When text fields are created in the SQLServer database 
as varchar(max) the type in schema.rb is changed to string! This makes 
my tests fail because the test database is created from schema.rb not 
migrations. 

In my migration I have: 
    create_table :audits, :force =&gt; true do |t| 
      t.text    :changes 
    end 

In the DB the changes column is created as varchar(max). 

In my schema.rb I have: 
  create_table &quot;audits&quot;, :force =&gt; true do |t| 
    t.string   &quot;changes&quot;,        :limit =&gt; nil 
  end</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;When text fields are created in the SQLServer database as
varchar(max) the type in schema.rb is changed to string! This makes
my tests fail because the test database is created from schema.rb
not migrations.&lt;/p&gt;
&lt;p&gt;In my migration I have:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;create_table :audits, :force =&amp;gt; true do |t|
  t.text    :changes 
end 
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;In the DB the changes column is created as varchar(max).&lt;/p&gt;
&lt;p&gt;In my schema.rb I have: create_table &quot;audits&quot;, :force =&amp;gt; true
do |t|&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;t.string   &quot;changes&quot;,        :limit =&amp;gt; nil
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;end&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-04-01T15:30:32-04:00</created-at>
    <creator-id type="integer">20272</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">22</number>
    <permalink>exception-with-new-line-character</permalink>
    <priority type="integer">96890</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>Exception with new line character</title>
    <updated-at type="datetime">2009-04-21T16:07:20-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Jordan Yeo</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/22</url>
    <original-body>NoMethodError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.split):
    /Library/Ruby/Gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.13/lib/active_record/connection_adapters/sqlserver_adapter.rb:649:in `set_utf8_values!'
    /Library/Ruby/Gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.13/lib/active_record/connection_adapters/sqlserver_adapter.rb:311:in `insert_sql'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:44:in `insert_without_query_dirty'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:18:in `insert'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2733:in `create_without_callbacks'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/callbacks.rb:237:in `create_without_timestamps'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/timestamp.rb:29:in `create'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2699:in `create_or_update_without_callbacks'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/callbacks.rb:222:in `create_or_update'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2383:in `save_without_validation'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:1009:in `save_without_dirty'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/dirty.rb:79:in `save_without_transactions'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:179:in `send'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:179:in `with_transaction_returning_status'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:129:in `transaction'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:138:in `transaction'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:178:in `with_transaction_returning_status'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:146:in `save'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:158:in `rollback_active_record_state!'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:146:in `save'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:693:in `create'
    /app/controllers/apply_controller.rb:72:in `add_reference'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `send'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `perform_action_without_filters'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:617:in `call_filters'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:in `perform_action_without_caching'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:in `cache'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `send'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `process_without_filters'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session_management.rb:134:in `process'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in `process'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:183:in `handle_request'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:123:in `dispatch'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `synchronize'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `dispatch'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:39:in `dispatch'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:76:in `process'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in `synchronize'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in `process'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process_client'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process_client'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `each'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load_without_new_constant_marking'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load'
    /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/servers/mongrel.rb:64
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
    /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3</original-body>
    <latest-body>NoMethodError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.split):
    /Library/Ruby/Gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.13/lib/active_record/connection_adapters/sqlserver_adapter.rb:649:in `set_utf8_values!'
    /Library/Ruby/Gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.13/lib/active_record/connection_adapters/sqlserver_adapter.rb:311:in `insert_sql'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:44:in `insert_without_query_dirty'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:18:in `insert'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2733:in `create_without_callbacks'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/callbacks.rb:237:in `create_without_timestamps'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/timestamp.rb:29:in `create'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2699:in `create_or_update_without_callbacks'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/callbacks.rb:222:in `create_or_update'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2383:in `save_without_validation'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:1009:in `save_without_dirty'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/dirty.rb:79:in `save_without_transactions'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:179:in `send'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:179:in `with_transaction_returning_status'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:129:in `transaction'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:138:in `transaction'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:178:in `with_transaction_returning_status'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:146:in `save'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:158:in `rollback_active_record_state!'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:146:in `save'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:693:in `create'
    /app/controllers/apply_controller.rb:72:in `add_reference'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `send'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `perform_action_without_filters'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:617:in `call_filters'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:in `perform_action_without_caching'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:in `cache'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `send'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `process_without_filters'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session_management.rb:134:in `process'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in `process'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:183:in `handle_request'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:123:in `dispatch'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `synchronize'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `dispatch'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'
    /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:39:in `dispatch'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:76:in `process'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in `synchronize'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in `process'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process_client'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process_client'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `each'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in `run'
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load_without_new_constant_marking'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load'
    /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/servers/mongrel.rb:64
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
    /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
    /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;NoMethodError (You have a nil object when you didn't expect it!
You might have expected an instance of Array. The error occurred
while evaluating nil.split):&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;/Library/Ruby/Gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.13/lib/active_record/connection_adapters/sqlserver_adapter.rb:649:in `set_utf8_values!'
/Library/Ruby/Gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.13/lib/active_record/connection_adapters/sqlserver_adapter.rb:311:in `insert_sql'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:44:in `insert_without_query_dirty'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:18:in `insert'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2733:in `create_without_callbacks'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/callbacks.rb:237:in `create_without_timestamps'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/timestamp.rb:29:in `create'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2699:in `create_or_update_without_callbacks'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/callbacks.rb:222:in `create_or_update'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2383:in `save_without_validation'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:1009:in `save_without_dirty'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/dirty.rb:79:in `save_without_transactions'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:179:in `send'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:179:in `with_transaction_returning_status'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:129:in `transaction'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:138:in `transaction'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:178:in `with_transaction_returning_status'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:146:in `save'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:158:in `rollback_active_record_state!'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:146:in `save'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:693:in `create'
/app/controllers/apply_controller.rb:72:in `add_reference'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in `perform_action_without_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:617:in `call_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:in `perform_action_without_caching'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:in `cache'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in `process_without_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in `process_without_session_management_support'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session_management.rb:134:in `process'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in `process'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:183:in `handle_request'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:123:in `dispatch'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `synchronize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `dispatch'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:39:in `dispatch'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:76:in `process'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in `synchronize'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in `process'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process_client'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process_client'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load_without_new_constant_marking'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in `load'
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/servers/mongrel.rb:64
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in `require'
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3
&lt;/code&gt;
&lt;/pre&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-02-04T14:15:29-05:00</created-at>
    <creator-id type="integer">38760</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">18</number>
    <permalink>sql-server-adapter-doesnt-reconnect-on-lost-connection</permalink>
    <priority type="integer">1</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag>connection dbi::databaseerror</tag>
    <title>SQL Server adapter doesn't reconnect on lost connection</title>
    <updated-at type="datetime">2009-04-21T07:09:38-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Joe Rafaniello</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/18</url>
    <original-body>I noticed that mysql added the ability to reconnect on a lost connection, see 
[edge-rails](http://weblog.rubyonrails.com/2009/1/31/this-week-in-edge-rails, &quot;edge-rails&quot;).

It was added through this ticket: [#1293](http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1293 &quot;#1293&quot;)

This is also problem with the sql server adapter regardless if you lose connectivity, the DB loses connectivity, or if the DB kills the DB session.

In my custom sql server adapter based off of 1.2.3, I have to explicitly rescue the &quot;execute&quot; and retry after reconnecting.

Can this type of logic be added to the adapter?  It should also cover any time we explicitly connect via DBI.

The exception raised at &quot;execute&quot; time is ActiveRecord::StatementInvalid.

If using FreeTDS and DBI, lower level exceptions are:

if err.message =~ /^DBI::DatabaseError: 08S01 \((0|20004|20006)\)/
  reconnect!
  retry
  #FreeTDS exceptions:
  #08S01 (0)  Communication link failure
  #08S01 (20004) Read from the server failed
  #08S01 (20006) Write to the server failed
end

We currently establish the connection in sqlserver_connection in ActiveRecord::Base.  I would suggest we defer the connection to the initialize of the adapter.  In the initialize, the connect method would establish the @connection, and rescue and retry the connect on DBI::DatabaseError.  The current reconnect! method does not retry, will only raise the error.

In production, we cannot rely on the connection being always available and need an seemless retrying of queries.

If I can, I was going to port my changes to the latest adapter and post my changes.  Not sure if these changes are the best... only my suggestion.</original-body>
    <latest-body>I noticed that mysql added the ability to reconnect on a lost connection, see 
[edge-rails](http://weblog.rubyonrails.com/2009/1/31/this-week-in-edge-rails, &quot;edge-rails&quot;).

It was added through this ticket: [#1293](http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1293 &quot;#1293&quot;)

This is also problem with the sql server adapter regardless if you lose connectivity, the DB loses connectivity, or if the DB kills the DB session.

In my custom sql server adapter based off of 1.2.3, I have to explicitly rescue the &quot;execute&quot; and retry after reconnecting.

Can this type of logic be added to the adapter?  It should also cover any time we explicitly connect via DBI.

The exception raised at &quot;execute&quot; time is ActiveRecord::StatementInvalid.

If using FreeTDS and DBI, lower level exceptions are:

if err.message =~ /^DBI::DatabaseError: 08S01 \((0|20004|20006)\)/
  reconnect!
  retry
  #FreeTDS exceptions:
  #08S01 (0)  Communication link failure
  #08S01 (20004) Read from the server failed
  #08S01 (20006) Write to the server failed
end

We currently establish the connection in sqlserver_connection in ActiveRecord::Base.  I would suggest we defer the connection to the initialize of the adapter.  In the initialize, the connect method would establish the @connection, and rescue and retry the connect on DBI::DatabaseError.  The current reconnect! method does not retry, will only raise the error.

In production, we cannot rely on the connection being always available and need an seemless retrying of queries.

If I can, I was going to port my changes to the latest adapter and post my changes.  Not sure if these changes are the best... only my suggestion.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;I noticed that mysql added the ability to reconnect on a lost
connection, see &lt;a href=&quot;http://weblog.rubyonrails.com/2009/1/31/this-week-in-edge-rails%2C&quot; title=&quot;edge-rails&quot;&gt;edge-rails&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It was added through this ticket: &lt;a href=&quot;http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1293&quot; title=&quot;#1293&quot;&gt;#1293&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is also problem with the sql server adapter regardless if
you lose connectivity, the DB loses connectivity, or if the DB
kills the DB session.&lt;/p&gt;
&lt;p&gt;In my custom sql server adapter based off of 1.2.3, I have to
explicitly rescue the &quot;execute&quot; and retry after reconnecting.&lt;/p&gt;
&lt;p&gt;Can this type of logic be added to the adapter? It should also
cover any time we explicitly connect via DBI.&lt;/p&gt;
&lt;p&gt;The exception raised at &quot;execute&quot; time is
ActiveRecord::StatementInvalid.&lt;/p&gt;
&lt;p&gt;If using FreeTDS and DBI, lower level exceptions are:&lt;/p&gt;
&lt;p&gt;if err.message =~ /^DBI::DatabaseError: 08S01 ((0|20004|20006))/
reconnect! retry #FreeTDS exceptions: &lt;a href=&quot;/projects/20277/tickets/08&quot; title=&quot;Ticket #08&quot;&gt;#08&lt;/a&gt;S01 (0)
Communication link failure &lt;a href=&quot;/projects/20277/tickets/08&quot; title=&quot;Ticket #08&quot;&gt;#08&lt;/a&gt;S01 (20004) Read from the server failed
&lt;a href=&quot;/projects/20277/tickets/08&quot; title=&quot;Ticket #08&quot;&gt;#08&lt;/a&gt;S01
(20006) Write to the server failed end&lt;/p&gt;
&lt;p&gt;We currently establish the connection in sqlserver_connection in
ActiveRecord::Base. I would suggest we defer the connection to the
initialize of the adapter. In the initialize, the connect method
would establish the @connection, and rescue and retry the connect
on DBI::DatabaseError. The current reconnect! method does not
retry, will only raise the error.&lt;/p&gt;
&lt;p&gt;In production, we cannot rely on the connection being always
available and need an seemless retrying of queries.&lt;/p&gt;
&lt;p&gt;If I can, I was going to port my changes to the latest adapter
and post my changes. Not sure if these changes are the best... only
my suggestion.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-04-16T18:35:42-04:00</created-at>
    <creator-id type="integer">54330</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">26</number>
    <permalink>cant-have-a-description-column-and-sort-desc</permalink>
    <priority type="integer">100735</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>Can't have a 'description' column and sort DESC</title>
    <updated-at type="datetime">2009-04-20T13:54:57-04:00</updated-at>
    <user-id type="integer">54330</user-id>
    <user-name>pclowser</user-name>
    <creator-name>pclowser</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/26</url>
    <original-body>Given these two migrations:
@@@
class CreateStatuses &lt; ActiveRecord::Migration
  def self.up
    create_table :statuses do |t|
      t.string :description

      t.timestamps
    end
  end

  def self.down
  end
end

class AddDataToStatuses &lt; ActiveRecord::Migration
  def self.up
    Status.create(:description =&gt; 'Active')
    Status.create(:description =&gt; 'Inactive')
    Status.create(:description =&gt; 'Pending')
  end

  def self.down
  end
end
@@@

Results in the following:
@@@
testapp: script/console
Loading development environment (Rails 2.2.2)
&gt;&gt; statuses = Status.find(:all, :order =&gt; &quot;description&quot;)
=&gt; [#&lt;Status id: 1, description: &quot;Active&quot;, created_at: &quot;2009-04-16 22:11:43&quot;, updated_at: &quot;2009-04-16 22:11:43&quot;&gt;, #&lt;Status id: 2, description: &quot;Inactive&quot;, created_at: &quot;2009-04-16 22:11:43&quot;, updated_at: &quot;2009-04-16 22:11:43&quot;&gt;, #&lt;Status id: 3, description: &quot;Pending&quot;, created_at: &quot;2009-04-16 22:11:43&quot;, updated_at: &quot;2009-04-16 22:11:43&quot;&gt;]

&gt;&gt; statuses = Status.find(:all, :order =&gt; &quot;description desc&quot;)
ActiveRecord::StatementInvalid: DBI::DatabaseError: 42000 (156) [FreeTDS][SQL Server]Incorrect syntax near the keyword 'DESC'.: SELECT * FROM [statuses]  ORDER BY ription desc DESC
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
from /opt/local/lib/ruby/gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.15/lib/active_record/connection_adapters/sqlserver_adapter.rb:728:in `raw_execute'
from /opt/local/lib/ruby/gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.15/lib/active_record/connection_adapters/sqlserver_adapter.rb:751:in `raw_select'
from /opt/local/lib/ruby/gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.15/lib/active_record/connection_adapters/sqlserver_adapter.rb:704:in `select'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:635:in `find_by_sql'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1490:in `find_every'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:589:in `find'
from (irb):4
@@@</original-body>
    <latest-body>Given these two migrations:
@@@
class CreateStatuses &lt; ActiveRecord::Migration
  def self.up
    create_table :statuses do |t|
      t.string :description

      t.timestamps
    end
  end

  def self.down
  end
end

class AddDataToStatuses &lt; ActiveRecord::Migration
  def self.up
    Status.create(:description =&gt; 'Active')
    Status.create(:description =&gt; 'Inactive')
    Status.create(:description =&gt; 'Pending')
  end

  def self.down
  end
end
@@@

Results in the following:
@@@
testapp: script/console
Loading development environment (Rails 2.2.2)
&gt;&gt; statuses = Status.find(:all, :order =&gt; &quot;description&quot;)
=&gt; [#&lt;Status id: 1, description: &quot;Active&quot;, created_at: &quot;2009-04-16 22:11:43&quot;, updated_at: &quot;2009-04-16 22:11:43&quot;&gt;, #&lt;Status id: 2, description: &quot;Inactive&quot;, created_at: &quot;2009-04-16 22:11:43&quot;, updated_at: &quot;2009-04-16 22:11:43&quot;&gt;, #&lt;Status id: 3, description: &quot;Pending&quot;, created_at: &quot;2009-04-16 22:11:43&quot;, updated_at: &quot;2009-04-16 22:11:43&quot;&gt;]

&gt;&gt; statuses = Status.find(:all, :order =&gt; &quot;description desc&quot;)
ActiveRecord::StatementInvalid: DBI::DatabaseError: 42000 (156) [FreeTDS][SQL Server]Incorrect syntax near the keyword 'DESC'.: SELECT * FROM [statuses]  ORDER BY ription desc DESC
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
from /opt/local/lib/ruby/gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.15/lib/active_record/connection_adapters/sqlserver_adapter.rb:728:in `raw_execute'
from /opt/local/lib/ruby/gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.15/lib/active_record/connection_adapters/sqlserver_adapter.rb:751:in `raw_select'
from /opt/local/lib/ruby/gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.15/lib/active_record/connection_adapters/sqlserver_adapter.rb:704:in `select'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:635:in `find_by_sql'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1490:in `find_every'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:589:in `find'
from (irb):4
@@@</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Given these two migrations:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
class CreateStatuses &amp;lt; ActiveRecord::Migration
  def self.up
    create_table :statuses do |t|
      t.string :description

      t.timestamps
    end
  end

  def self.down
  end
end

class AddDataToStatuses &amp;lt; ActiveRecord::Migration
  def self.up
    Status.create(:description =&amp;gt; 'Active')
    Status.create(:description =&amp;gt; 'Inactive')
    Status.create(:description =&amp;gt; 'Pending')
  end

  def self.down
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Results in the following:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
testapp: script/console
Loading development environment (Rails 2.2.2)
&amp;gt;&amp;gt; statuses = Status.find(:all, :order =&amp;gt; &amp;quot;description&amp;quot;)
=&amp;gt; [#&amp;lt;Status id: 1, description: &amp;quot;Active&amp;quot;, created_at: &amp;quot;2009-04-16 22:11:43&amp;quot;, updated_at: &amp;quot;2009-04-16 22:11:43&amp;quot;&amp;gt;, #&amp;lt;Status id: 2, description: &amp;quot;Inactive&amp;quot;, created_at: &amp;quot;2009-04-16 22:11:43&amp;quot;, updated_at: &amp;quot;2009-04-16 22:11:43&amp;quot;&amp;gt;, #&amp;lt;Status id: 3, description: &amp;quot;Pending&amp;quot;, created_at: &amp;quot;2009-04-16 22:11:43&amp;quot;, updated_at: &amp;quot;2009-04-16 22:11:43&amp;quot;&amp;gt;]

&amp;gt;&amp;gt; statuses = Status.find(:all, :order =&amp;gt; &amp;quot;description desc&amp;quot;)
ActiveRecord::StatementInvalid: DBI::DatabaseError: 42000 (156) [FreeTDS][SQL Server]Incorrect syntax near the keyword 'DESC'.: SELECT * FROM [statuses]  ORDER BY ription desc DESC
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
from /opt/local/lib/ruby/gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.15/lib/active_record/connection_adapters/sqlserver_adapter.rb:728:in `raw_execute'
from /opt/local/lib/ruby/gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.15/lib/active_record/connection_adapters/sqlserver_adapter.rb:751:in `raw_select'
from /opt/local/lib/ruby/gems/1.8/gems/rails-sqlserver-2000-2005-adapter-2.2.15/lib/active_record/connection_adapters/sqlserver_adapter.rb:704:in `select'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:635:in `find_by_sql'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1490:in `find_every'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:589:in `find'
from (irb):4
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-04-07T13:43:06-04:00</created-at>
    <creator-id type="integer">53328</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">23</number>
    <permalink>cant-load-adapter-with-ruby-191-rails-232</permalink>
    <priority type="integer">98342</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag nil="true"></tag>
    <title>can't load adapter with Ruby 1.9.1 + Rails 2.3.2</title>
    <updated-at type="datetime">2009-04-20T12:05:01-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Erik DeBill</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/23</url>
    <original-body>Using rails-sqlserver-2000-2005-adapter (2.2.15) I can upgrade from rails 2.2.2 to 2.3.2 just fine as long as I stay on Ruby 1.8.5.  If I upgrade to ruby 1.9.1-p0 webrick will fail to start, complaining that it can't find the ActiveRecord adapter.  Is this a known incompatibility?

This is the exact error I'm getting:

[edebill@webdev auth]$ ruby script/server
=&gt; Booting WEBrick
=&gt; Rails 2.3.2 application starting on http://0.0.0.0:3000
/usr/lib/ruby/gems/1.9.1/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `rescue in rescue in establish_connection': Please install the sqlserver adapter: `gem install activerecord-sqlserver-adapter` (no such file to load -- parsedate) (RuntimeError)
        from /usr/lib/ruby/gems/1.9.1/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:73:in `rescue in establish_connection'

my database.yml looks like so:

development:
#  adapter: odbc
  adapter: sqlserver
  mode: ODBC
  dsn: devserver
  username: PLACEHOLDER\username
  password: PLACEHOLDER
  pool: 5
  timeout: 5000
  schema_search_path: dbo


I'm using the following versions of things:

[edebill@webdev auth]$ ruby -v
ruby 1.9.1p0 (2009-01-30 revision 21907) [x86_64-linux]
[edebill@webdev auth]$ gem list

*** LOCAL GEMS ***

actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activeresource (2.3.2)
activesupport (2.3.2)
builder (2.1.2)
daemons (1.0.10)
datacats4r (1.2.0.7)
dbd-odbc (0.2.4)
dbi (0.4.0)
deprecated (2.0.1)
httpclient (2.1.4)
odbc-rails (1.5)
rails (2.3.2)
rails-sqlserver-2000-2005-adapter (2.2.15)
rake (0.8.4)
soap4r (1.5.8)</original-body>
    <latest-body>Using rails-sqlserver-2000-2005-adapter (2.2.15) I can upgrade from rails 2.2.2 to 2.3.2 just fine as long as I stay on Ruby 1.8.5.  If I upgrade to ruby 1.9.1-p0 webrick will fail to start, complaining that it can't find the ActiveRecord adapter.  Is this a known incompatibility?

This is the exact error I'm getting:

[edebill@webdev auth]$ ruby script/server
=&gt; Booting WEBrick
=&gt; Rails 2.3.2 application starting on http://0.0.0.0:3000
/usr/lib/ruby/gems/1.9.1/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `rescue in rescue in establish_connection': Please install the sqlserver adapter: `gem install activerecord-sqlserver-adapter` (no such file to load -- parsedate) (RuntimeError)
        from /usr/lib/ruby/gems/1.9.1/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:73:in `rescue in establish_connection'

my database.yml looks like so:

development:
#  adapter: odbc
  adapter: sqlserver
  mode: ODBC
  dsn: devserver
  username: PLACEHOLDER\username
  password: PLACEHOLDER
  pool: 5
  timeout: 5000
  schema_search_path: dbo


I'm using the following versions of things:

[edebill@webdev auth]$ ruby -v
ruby 1.9.1p0 (2009-01-30 revision 21907) [x86_64-linux]
[edebill@webdev auth]$ gem list

*** LOCAL GEMS ***

actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activeresource (2.3.2)
activesupport (2.3.2)
builder (2.1.2)
daemons (1.0.10)
datacats4r (1.2.0.7)
dbd-odbc (0.2.4)
dbi (0.4.0)
deprecated (2.0.1)
httpclient (2.1.4)
odbc-rails (1.5)
rails (2.3.2)
rails-sqlserver-2000-2005-adapter (2.2.15)
rake (0.8.4)
soap4r (1.5.8)</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Using rails-sqlserver-2000-2005-adapter (2.2.15) I can upgrade
from rails 2.2.2 to 2.3.2 just fine as long as I stay on Ruby
1.8.5. If I upgrade to ruby 1.9.1-p0 webrick will fail to start,
complaining that it can't find the ActiveRecord adapter. Is this a
known incompatibility?&lt;/p&gt;
&lt;p&gt;This is the exact error I'm getting:&lt;/p&gt;
&lt;p&gt;[edebill@webdev auth]$ ruby script/server =&amp;gt; Booting WEBrick
=&amp;gt; Rails 2.3.2 application starting on &lt;a href=&quot;http://0.0.0.0:3000&quot;&gt;http://0.0.0.0:3000&lt;/a&gt;
/usr/lib/ruby/gems/1.9.1/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in
&lt;code&gt;rescue in rescue in establish_connection': Please install the
sqlserver adapter:&lt;/code&gt;gem install
activerecord-sqlserver-adapter&lt;code&gt;(no such file to load --
parsedate) (RuntimeError)&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;    from /usr/lib/ruby/gems/1.9.1/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:73:in `rescue in establish_connection'
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;my database.yml looks like so:&lt;/p&gt;
&lt;p&gt;development:&lt;/p&gt;
&lt;h1&gt;adapter: odbc&lt;/h1&gt;
&lt;p&gt;adapter: sqlserver mode: ODBC dsn: devserver username:
PLACEHOLDER\username password: PLACEHOLDER pool: 5 timeout: 5000
schema_search_path: dbo&lt;/p&gt;
&lt;p&gt;I'm using the following versions of things:&lt;/p&gt;
&lt;p&gt;[edebill@webdev auth]$ ruby -v ruby 1.9.1p0 (2009-01-30 revision
21907) [x86_64-linux] [edebill@webdev auth]$ gem list&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;LOCAL GEMS&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;actionmailer (2.3.2) actionpack (2.3.2) activerecord (2.3.2)
activeresource (2.3.2) activesupport (2.3.2) builder (2.1.2)
daemons (1.0.10) datacats4r (1.2.0.7) dbd-odbc (0.2.4) dbi (0.4.0)
deprecated (2.0.1) httpclient (2.1.4) odbc-rails (1.5) rails
(2.3.2) rails-sqlserver-2000-2005-adapter (2.2.15) rake (0.8.4)
soap4r (1.5.8)&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">1</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-02-09T05:19:26-05:00</created-at>
    <creator-id type="integer">136</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">20</number>
    <permalink>provide-support-for-running-queries-at-different-isolation-levels</permalink>
    <priority type="integer">69767</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>Provide support for running queries at different isolation levels</title>
    <updated-at type="datetime">2009-04-20T11:34:33-04:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Murray Steele</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/20</url>
    <original-body>In one of our apps we found that an external process was locking tables that we wanted to query to show the user status updates.  The external process was taking a long time and the sql queries from the server were blocking until the external process released the lock.  What we ended up doing was using SQL Servers Isolation Level stuff to allow our webserver queries to run regardless of the lock status of the tables they were querying.

This patch provides that functionality as a connection level method that takes a block.  All code within the block is run at the specified isolation level and the original isolation level is restored when the block completes.  

It's not super-clear to me if this sort of functionality is supposed to be catered for by the :lock option for sqlqueries or not, but I think this might be a bit more flexible.</original-body>
    <latest-body>In one of our apps we found that an external process was locking tables that we wanted to query to show the user status updates.  The external process was taking a long time and the sql queries from the server were blocking until the external process released the lock.  What we ended up doing was using SQL Servers Isolation Level stuff to allow our webserver queries to run regardless of the lock status of the tables they were querying.

This patch provides that functionality as a connection level method that takes a block.  All code within the block is run at the specified isolation level and the original isolation level is restored when the block completes.  

It's not super-clear to me if this sort of functionality is supposed to be catered for by the :lock option for sqlqueries or not, but I think this might be a bit more flexible.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;In one of our apps we found that an external process was locking
tables that we wanted to query to show the user status updates. The
external process was taking a long time and the sql queries from
the server were blocking until the external process released the
lock. What we ended up doing was using SQL Servers Isolation Level
stuff to allow our webserver queries to run regardless of the lock
status of the tables they were querying.&lt;/p&gt;
&lt;p&gt;This patch provides that functionality as a connection level
method that takes a block. All code within the block is run at the
specified isolation level and the original isolation level is
restored when the block completes.&lt;br&gt;&lt;/p&gt;
&lt;p&gt;It's not super-clear to me if this sort of functionality is
supposed to be catered for by the :lock option for sqlqueries or
not, but I think this might be a bit more flexible.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-02-06T10:33:46-05:00</created-at>
    <creator-id type="integer">18871</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">19</number>
    <permalink>schemaownership-prefix-on-table-names-in-generated-sql</permalink>
    <priority type="integer">69359</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag nil="true"></tag>
    <title>schema/ownership prefix on table names in generated sql</title>
    <updated-at type="datetime">2009-02-09T09:44:18-05:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>ChrisH</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/19</url>
    <original-body>does the adapter support this?

ie instead of generating:

select * from [table_name]

does it support:

select * from schema.[table_name]

Thanks.

Our sqlserver dba's are telling us it is more efficient to specify the owner/schema prefix and I'm not seeing that I can set that anywhere.

Thanks.</original-body>
    <latest-body>does the adapter support this?

ie instead of generating:

select * from [table_name]

does it support:

select * from schema.[table_name]

Thanks.

Our sqlserver dba's are telling us it is more efficient to specify the owner/schema prefix and I'm not seeing that I can set that anywhere.

Thanks.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;does the adapter support this?&lt;/p&gt;
&lt;p&gt;ie instead of generating:&lt;/p&gt;
&lt;p&gt;select * from [table_name]&lt;/p&gt;
&lt;p&gt;does it support:&lt;/p&gt;
&lt;p&gt;select * from schema.[table_name]&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;Our sqlserver dba's are telling us it is more efficient to
specify the owner/schema prefix and I'm not seeing that I can set
that anywhere.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-01-24T03:03:08-05:00</created-at>
    <creator-id type="integer">44835</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">16</number>
    <permalink>support-encoding-property-in-databaseyml</permalink>
    <priority type="integer">64316</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag nil="true"></tag>
    <title>support encoding property in database.yml</title>
    <updated-at type="datetime">2009-01-26T16:45:59-05:00</updated-at>
    <user-id type="integer">11371</user-id>
    <user-name>Adam Meehan</user-name>
    <creator-name>phoenix</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/16</url>
    <original-body>I had set &quot;encoding: utf8&quot; in my database.yml,but it seems not work.
All of the records I selected from my SqlServer2005 is encoding with gbk,and I have to convert evey record to utf8 by IConv.There is some way to set the encoding just like the database.yml of mysql?

There are my gems:
rails-sqlserver-2000-2005-adapter-2.2.4
dbi (0.4.1)
dbd-odbc (0.2.4)

I am using odbc to connect my sqlserver,because if I use native connection,I can't commit any change to my database,It will raise &quot; HRESULT error code:0x80020009: COMMIT TRANSACTION&quot;.</original-body>
    <latest-body>I had set &quot;encoding: utf8&quot; in my database.yml,but it seems not work.
All of the records I selected from my SqlServer2005 is encoding with gbk,and I have to convert evey record to utf8 by IConv.There is some way to set the encoding just like the database.yml of mysql?

There are my gems:
rails-sqlserver-2000-2005-adapter-2.2.4
dbi (0.4.1)
dbd-odbc (0.2.4)

I am using odbc to connect my sqlserver,because if I use native connection,I can't commit any change to my database,It will raise &quot; HRESULT error code:0x80020009: COMMIT TRANSACTION&quot;.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;I had set &quot;encoding: utf8&quot; in my database.yml,but it seems not
work. All of the records I selected from my SqlServer2005 is
encoding with gbk,and I have to convert evey record to utf8 by
IConv.There is some way to set the encoding just like the
database.yml of mysql?&lt;/p&gt;
&lt;p&gt;There are my gems: rails-sqlserver-2000-2005-adapter-2.2.4 dbi
(0.4.1) dbd-odbc (0.2.4)&lt;/p&gt;
&lt;p&gt;I am using odbc to connect my sqlserver,because if I use native
connection,I can't commit any change to my database,It will raise &quot;
HRESULT error code:0x80020009: COMMIT TRANSACTION&quot;.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-01-19T06:10:44-05:00</created-at>
    <creator-id type="integer">3299</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">14</number>
    <permalink>to_sqlserver_string-does-not-handle-leading-zeros-in-usec</permalink>
    <priority type="integer">62810</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>to_sqlserver_string does not handle leading zeros in usec</title>
    <updated-at type="datetime">2009-01-23T12:09:39-05:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Jonathan Lim</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/14</url>
    <original-body>to_sqlserver_string does not handle usecs with a leading 0.</original-body>
    <latest-body>to_sqlserver_string does not handle usecs with a leading 0.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;to_sqlserver_string does not handle usecs with a leading 0.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-01-20T09:00:31-05:00</created-at>
    <creator-id type="integer">15346</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">15</number>
    <permalink>information_schemaviews-definitions-are-4000-chars-long</permalink>
    <priority type="integer">63176</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>resolved</state>
    <tag nil="true"></tag>
    <title>INFORMATION_SCHEMA.VIEWS Definitions Are 4000 Chars Long</title>
    <updated-at type="datetime">2009-01-21T21:56:51-05:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>Ken Collins</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/15</url>
    <original-body>Note to self, I recently found this out when dealing with a long view definition.

http://joseph.randomnetworks.com/archives/2006/03/21/overcoming-the-limitation-of-information_schemaviews-in-sql-server-2000/

http://msdn.microsoft.com/en-us/library/aa933201.aspx

I would love to discuss if I should cope with this by just allow the code to cope with NULL and/or go about a different way.</original-body>
    <latest-body>Note to self, I recently found this out when dealing with a long view definition.

http://joseph.randomnetworks.com/archives/2006/03/21/overcoming-the-limitation-of-information_schemaviews-in-sql-server-2000/

http://msdn.microsoft.com/en-us/library/aa933201.aspx

I would love to discuss if I should cope with this by just allow the code to cope with NULL and/or go about a different way.</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;Note to self, I recently found this out when dealing with a long
view definition.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://joseph.randomnetworks.com/archives/2006/03/21/overcoming-the-limitation-of-information_schemaviews-in-sql-server-2000/&quot;&gt;
http://joseph.randomnetworks.com...&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa933201.aspx&quot;&gt;http://msdn.microsoft.com/en-us/...&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I would love to discuss if I should cope with this by just allow
the code to cope with NULL and/or go about a different way.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2009-01-11T02:21:15-05:00</created-at>
    <creator-id type="integer">38936</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">13</number>
    <permalink>possible-improvement-of-limitoffset-implementation-not-sure-how-to-patch</permalink>
    <priority type="integer">45357</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag>pagination</tag>
    <title>Possible improvement of limit/offset implementation (not sure how to patch)</title>
    <updated-at type="datetime">2009-01-12T08:56:14-05:00</updated-at>
    <user-id type="integer">15346</user-id>
    <user-name>Ken Collins</user-name>
    <creator-name>j2fly</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/13</url>
    <original-body>I think I found a better way to do the offset and limit handling but I'm not sure how to go about implementing it into the code as a patch. 

I can see the method I need to modify on line 357 of the current adapter (2.2.8) add_limit_offset!(sql, options) but I'm not enough of a ruby ninja to implement it. Here are my findings though... hopefully Ken can wire it up? 

The current adapter when used in conjunction with the will_paginate gem requires an order by to work at all. With no order by my page numbers change, but my record set spins out and stays at the first 10.

Here is the query the adapter generates without an order by:

&lt;code&gt;
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM [users]) AS tmp1) AS tmp2
&lt;/code&gt;

You run that in SQL Server Management Studio all day changing the inner query to get a different subset of data to select the top 10 from but with no order by you'll get the same 10 results every time.

With an order by it works... sort of... 

&lt;code&gt;
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM [users] ORDER BY updated_at DESC) AS tmp1 ORDER BY [updated_at] ASC) AS tmp2 ORDER BY [updated_at] desc
&lt;/code&gt;

The problem I ran into (the reason I say sort of above) was that not all of my updated_at columns were populated with a date. We did a historical load of user data and the engineer that wrote the SSIS script didn't put in the current date/time or anything to the updated_at so after the first 9 pages of my 18k rows or users (10 per page) I started seeing the same set of users over and over. I believe it was because all their updated_at columns were the same &quot;NULL&quot; value. However, I don't think this situation is unique to my NULL fields on the order by. What happens if there is an order by but it's a lot of repeated data, like say a state name or something. Would this possibly cause the same issue as my NULL field with the adapter's current implementation of the offset and limiting? I guess I don't know 100%, just raising the question. In either case, I think I may have found a solution. 

I did some research on other ways to achieve limits and offsets in SQL and I believe I have found a better way. It's 2 separate queries for the 2 different situations. The first if you know you have an order by specified in the options hash, and the 2nd if you have no order by. 


This query gets the first 10 records from my users table ordered by updated_at with the newest updated record at the top.

&lt;code&gt;
SELECT * FROM
(SELECT ROW_NUMBER() OVER (ORDER BY updated_at desc) AS rnum, * FROM users) AS user_with_rnum
where rnum &gt;= 1 and rnum &lt;= 10
&lt;/code&gt;

To see the next 10, simply add 10 to both numbers in there where, like so...

&lt;code&gt;
SELECT * FROM
(SELECT ROW_NUMBER() OVER (ORDER BY updated_at desc) AS rnum, * FROM users) AS user_with_rnum
where rnum &gt;= 11 and rnum &lt;= 20
&lt;/code&gt;

This seems to continue to work even when I reach my null fields (numbers 71 and 80 for me), providing the next set of them based on that row count, which I believe is the key. 


This second option would be if you know there is no order by, it would still allow you to page through the users (10 at a time in this case) ordered by ID in an ascending (ASC) fashion (the default when nothing is specified in SQL)

Again, this query gets the first 10 records....

&lt;code&gt;
select top 10 * from users usr
where usr.id not in (select top 0 usr2.id from users usr2)
&lt;/code&gt;

For this one, to see the next 10 just add 10 to the 0 like so... (this gets you records 11-20) even though the syntax seems weird.

&lt;code&gt;
select top 10 * from users usr
where usr.id not in (select top 10 usr2.id from users usr2)
&lt;/code&gt;

This gets you records 21-30 ... and so on (again, I know... sort of creepy syntax, but it does work!)

&lt;code&gt;
select top 10 * from users usr
where usr.id not in (select top 20 usr2.id from users usr2)
&lt;/code&gt;


Is there a way to have both of these options implemented to help shore up this limitation with the existing adapter? Again, I apologize that I can not provide a patch directly, but hopefully I've highlighted what I believe is a good fix with direct SQL anyway. 

Thanks,
-Jon</original-body>
    <latest-body>I think I found a better way to do the offset and limit handling but I'm not sure how to go about implementing it into the code as a patch. 

I can see the method I need to modify on line 357 of the current adapter (2.2.8) add_limit_offset!(sql, options) but I'm not enough of a ruby ninja to implement it. Here are my findings though... hopefully Ken can wire it up? 

The current adapter when used in conjunction with the will_paginate gem requires an order by to work at all. With no order by my page numbers change, but my record set spins out and stays at the first 10.

Here is the query the adapter generates without an order by:

&lt;code&gt;
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM [users]) AS tmp1) AS tmp2
&lt;/code&gt;

You run that in SQL Server Management Studio all day changing the inner query to get a different subset of data to select the top 10 from but with no order by you'll get the same 10 results every time.

With an order by it works... sort of... 

&lt;code&gt;
SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM [users] ORDER BY updated_at DESC) AS tmp1 ORDER BY [updated_at] ASC) AS tmp2 ORDER BY [updated_at] desc
&lt;/code&gt;

The problem I ran into (the reason I say sort of above) was that not all of my updated_at columns were populated with a date. We did a historical load of user data and the engineer that wrote the SSIS script didn't put in the current date/time or anything to the updated_at so after the first 9 pages of my 18k rows or users (10 per page) I started seeing the same set of users over and over. I believe it was because all their updated_at columns were the same &quot;NULL&quot; value. However, I don't think this situation is unique to my NULL fields on the order by. What happens if there is an order by but it's a lot of repeated data, like say a state name or something. Would this possibly cause the same issue as my NULL field with the adapter's current implementation of the offset and limiting? I guess I don't know 100%, just raising the question. In either case, I think I may have found a solution. 

I did some research on other ways to achieve limits and offsets in SQL and I believe I have found a better way. It's 2 separate queries for the 2 different situations. The first if you know you have an order by specified in the options hash, and the 2nd if you have no order by. 


This query gets the first 10 records from my users table ordered by updated_at with the newest updated record at the top.

&lt;code&gt;
SELECT * FROM
(SELECT ROW_NUMBER() OVER (ORDER BY updated_at desc) AS rnum, * FROM users) AS user_with_rnum
where rnum &gt;= 1 and rnum &lt;= 10
&lt;/code&gt;

To see the next 10, simply add 10 to both numbers in there where, like so...

&lt;code&gt;
SELECT * FROM
(SELECT ROW_NUMBER() OVER (ORDER BY updated_at desc) AS rnum, * FROM users) AS user_with_rnum
where rnum &gt;= 11 and rnum &lt;= 20
&lt;/code&gt;

This seems to continue to work even when I reach my null fields (numbers 71 and 80 for me), providing the next set of them based on that row count, which I believe is the key. 


This second option would be if you know there is no order by, it would still allow you to page through the users (10 at a time in this case) ordered by ID in an ascending (ASC) fashion (the default when nothing is specified in SQL)

Again, this query gets the first 10 records....

&lt;code&gt;
select top 10 * from users usr
where usr.id not in (select top 0 usr2.id from users usr2)
&lt;/code&gt;

For this one, to see the next 10 just add 10 to the 0 like so... (this gets you records 11-20) even though the syntax seems weird.

&lt;code&gt;
select top 10 * from users usr
where usr.id not in (select top 10 usr2.id from users usr2)
&lt;/code&gt;

This gets you records 21-30 ... and so on (again, I know... sort of creepy syntax, but it does work!)

&lt;code&gt;
select top 10 * from users usr
where usr.id not in (select top 20 usr2.id from users usr2)
&lt;/code&gt;


Is there a way to have both of these options implemented to help shore up this limitation with the existing adapter? Again, I apologize that I can not provide a patch directly, but hopefully I've highlighted what I believe is a good fix with direct SQL anyway. 

Thanks,
-Jon</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;I think I found a better way to do the offset and limit handling
but I'm not sure how to go about implementing it into the code as a
patch.&lt;/p&gt;
&lt;p&gt;I can see the method I need to modify on line 357 of the current
adapter (2.2.8) add_limit_offset!(sql, options) but I'm not enough
of a ruby ninja to implement it. Here are my findings though...
hopefully Ken can wire it up?&lt;/p&gt;
&lt;p&gt;The current adapter when used in conjunction with the
will_paginate gem requires an order by to work at all. With no
order by my page numbers change, but my record set spins out and
stays at the first 10.&lt;/p&gt;
&lt;p&gt;Here is the query the adapter generates without an order by:&lt;/p&gt;
&lt;p&gt;SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM
[users]) AS tmp1) AS tmp2&lt;/p&gt;
&lt;p&gt;You run that in SQL Server Management Studio all day changing
the inner query to get a different subset of data to select the top
10 from but with no order by you'll get the same 10 results every
time.&lt;/p&gt;
&lt;p&gt;With an order by it works... sort of...&lt;/p&gt;
&lt;p&gt;SELECT * FROM (SELECT TOP 10 * FROM (SELECT TOP 40 * FROM
[users] ORDER BY updated_at DESC) AS tmp1 ORDER BY [updated_at]
ASC) AS tmp2 ORDER BY [updated_at] desc&lt;/p&gt;
&lt;p&gt;The problem I ran into (the reason I say sort of above) was that
not all of my updated_at columns were populated with a date. We did
a historical load of user data and the engineer that wrote the SSIS
script didn't put in the current date/time or anything to the
updated_at so after the first 9 pages of my 18k rows or users (10
per page) I started seeing the same set of users over and over. I
believe it was because all their updated_at columns were the same
&quot;NULL&quot; value. However, I don't think this situation is unique to my
NULL fields on the order by. What happens if there is an order by
but it's a lot of repeated data, like say a state name or
something. Would this possibly cause the same issue as my NULL
field with the adapter's current implementation of the offset and
limiting? I guess I don't know 100%, just raising the question. In
either case, I think I may have found a solution.&lt;/p&gt;
&lt;p&gt;I did some research on other ways to achieve limits and offsets
in SQL and I believe I have found a better way. It's 2 separate
queries for the 2 different situations. The first if you know you
have an order by specified in the options hash, and the 2nd if you
have no order by.&lt;/p&gt;
&lt;p&gt;This query gets the first 10 records from my users table ordered
by updated_at with the newest updated record at the top.&lt;/p&gt;
&lt;p&gt;SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY updated_at
desc) AS rnum, * FROM users) AS user_with_rnum where rnum &amp;gt;= 1
and rnum &amp;lt;= 10&lt;/p&gt;
&lt;p&gt;To see the next 10, simply add 10 to both numbers in there
where, like so...&lt;/p&gt;
&lt;p&gt;SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY updated_at
desc) AS rnum, * FROM users) AS user_with_rnum where rnum &amp;gt;= 11
and rnum &amp;lt;= 20&lt;/p&gt;
&lt;p&gt;This seems to continue to work even when I reach my null fields
(numbers 71 and 80 for me), providing the next set of them based on
that row count, which I believe is the key.&lt;/p&gt;
&lt;p&gt;This second option would be if you know there is no order by, it
would still allow you to page through the users (10 at a time in
this case) ordered by ID in an ascending (ASC) fashion (the default
when nothing is specified in SQL)&lt;/p&gt;
&lt;p&gt;Again, this query gets the first 10 records....&lt;/p&gt;
&lt;p&gt;select top 10 * from users usr where usr.id not in (select top 0
usr2.id from users usr2)&lt;/p&gt;
&lt;p&gt;For this one, to see the next 10 just add 10 to the 0 like so...
(this gets you records 11-20) even though the syntax seems
weird.&lt;/p&gt;
&lt;p&gt;select top 10 * from users usr where usr.id not in (select top
10 usr2.id from users usr2)&lt;/p&gt;
&lt;p&gt;This gets you records 21-30 ... and so on (again, I know... sort
of creepy syntax, but it does work!)&lt;/p&gt;
&lt;p&gt;select top 10 * from users usr where usr.id not in (select top
20 usr2.id from users usr2)&lt;/p&gt;
&lt;p&gt;Is there a way to have both of these options implemented to help
shore up this limitation with the existing adapter? Again, I
apologize that I can not provide a patch directly, but hopefully
I've highlighted what I believe is a good fix with direct SQL
anyway.&lt;/p&gt;
&lt;p&gt;Thanks, -Jon&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
  <ticket>
    <assigned-user-id type="integer">15346</assigned-user-id>
    <attachments-count type="integer">0</attachments-count>
    <closed type="boolean">true</closed>
    <created-at type="datetime">2008-11-24T09:23:12-05:00</created-at>
    <creator-id type="integer">38704</creator-id>
    <milestone-due-on type="datetime" nil="true"></milestone-due-on>
    <milestone-id type="integer" nil="true"></milestone-id>
    <number type="integer">1</number>
    <permalink>problem-with-queries-from-will_paginate-plugin</permalink>
    <priority type="integer">1</priority>
    <project-id type="integer">20277</project-id>
    <raw-data type="binary" nil="true" encoding="base64"></raw-data>
    <state>invalid</state>
    <tag>pagination</tag>
    <title>Problem with queries from will_paginate plugin</title>
    <updated-at type="datetime">2009-01-10T17:32:11-05:00</updated-at>
    <user-id type="integer">38936</user-id>
    <user-name>j2fly</user-name>
    <creator-name>Juanma Cervera</creator-name>
    <assigned-user-name>Ken Collins</assigned-user-name>
    <url>http://rails-sqlserver.lighthouseapp.com/projects/20277/tickets/1</url>
    <original-body>I was having troubles with some queries, when I use the will_paginate plugin, and I have to specify the order for the result with the fields prefixed by table names.

This is a sample case.
@@@ ruby
class Author &lt; AvtiveRecord::Base
 #columns:(id, name)
  has_many :books
end

class Book &lt; ActiveRecord::Base
 #columns:(id, name, author_id)
 belongs_to :author
end .
@@@

This fails, but already failed with the old adapter:

@@@ ruby
  Author.paginate :all, :include =&gt; :books, :per_page =&gt; 10, :page =&gt; 2, :order =&gt; &quot;authors.name, books.name&quot;
@@@

I can see what is the problem, but I can't think a way to avoid it.

Juan M. Cervera</original-body>
    <latest-body>I was having troubles with some queries, when I use the will_paginate plugin, and I have to specify the order for the result with the fields prefixed by table names.

This is a sample case.
@@@ ruby
class Author &lt; AvtiveRecord::Base
 #columns:(id, name)
  has_many :books
end

class Book &lt; ActiveRecord::Base
 #columns:(id, name, author_id)
 belongs_to :author
end .
@@@

This fails, but already failed with the old adapter:

@@@ ruby
  Author.paginate :all, :include =&gt; :books, :per_page =&gt; 10, :page =&gt; 2, :order =&gt; &quot;authors.name, books.name&quot;
@@@

I can see what is the problem, but I can't think a way to avoid it.

Juan M. Cervera</latest-body>
    <original-body-html>&lt;div&gt;&lt;p&gt;I was having troubles with some queries, when I use the
will_paginate plugin, and I have to specify the order for the
result with the fields prefixed by table names.&lt;/p&gt;
&lt;p&gt;This is a sample case.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
class Author &amp;lt; AvtiveRecord::Base
 #columns:(id, name)
  has_many :books
end

class Book &amp;lt; ActiveRecord::Base
 #columns:(id, name, author_id)
 belongs_to :author
end .
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This fails, but already failed with the old adapter:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
  Author.paginate :all, :include =&amp;gt; :books, :per_page =&amp;gt; 10, :page =&amp;gt; 2, :order =&amp;gt; &amp;quot;authors.name, books.name&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I can see what is the problem, but I can't think a way to avoid
it.&lt;/p&gt;
&lt;p&gt;Juan M. Cervera&lt;/p&gt;&lt;/div&gt;</original-body-html>
  </ticket>
</tickets>
