rails-sqlserver / tiny_tds

TinyTDS - Simple and fast FreeTDS bindings for Ruby using DB-Library.
Other
606 stars 189 forks source link

Similar to Issue #35: TinyTds::Error: Incorrect syntax near the keyword 'and' #51

Closed parkerl closed 12 years ago

parkerl commented 12 years ago

Rails 3.1.0 TinyTDS 0.5.0rc1 activerecord-sqlserver-adapter 3.1.0 FreeTDS 0.91

I get the following when trying to save

 c.save
  EXECUTE (74.4ms)  BEGIN TRANSACTION
   (94.7ms)  EXEC sp_executesql N'UPDATE [Contacts] SET [IsRetired] = 0 WHERE [Contacts].[ContactId] = 1; SELECT @@ROWCOUNT AS AffectedRows'
TinyTds::Error: Incorrect syntax near the keyword 'and'.: EXEC sp_executesql N'UPDATE [Contacts] SET [IsRetired] = 0 WHERE [Contacts].[ContactId] = 847; SELECT @@ROWCOUNT AS AffectedRows'
ActiveRecord::StatementInvalid: TinyTds::Error: Incorrect syntax near the keyword 'and'.: EXEC sp_executesql N'UPDATE [Contacts] SET [IsRetired] = 0 WHERE [Contacts].[ContactId] = 1; SELECT @@ROWCOUNT AS AffectedRows'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-sqlserver-adapter-3.1.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:317:in `each'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-sqlserver-adapter-3.1.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:317:in `handle_to_names_and_values_dblib'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-sqlserver-adapter-3.1.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:306:in `handle_to_names_and_values'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-sqlserver-adapter-3.1.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:277:in `block in raw_select'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-sqlserver-adapter-3.1.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:274:in `raw_select'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-sqlserver-adapter-3.1.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:257:in `do_exec_query'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-sqlserver-adapter-3.1.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:22:in `exec_query'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:77:in `exec_update'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-sqlserver-adapter-3.1.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:37:in `exec_update'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:96:in `update'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `update'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/persistence.rb:305:in `update'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/locking/optimistic.rb:84:in `update'
... 12 levels...
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/validations.rb:50:in `save'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/attribute_methods/dirty.rb:22:in `save'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/transactions.rb:241:in `block (2 levels) in save'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/transactions.rb:208:in `transaction'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/transactions.rb:241:in `block in save'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0/lib/active_record/transactions.rb:240:in `save'
        from (irb):3
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
        from /Users/parker/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>

Running the statement in SMS works fine.

metaskills commented 12 years ago

I don't see the keyword "and" in the statement? Is this an error from a trigger or something?

parkerl commented 12 years ago

Oh man do I feel bad for submitting that. Good call. Now I have to figure out why the trigger works in SMS and not from rails. D'oh.