# ActiveRecord::StatementInvalid error

**URL:** <https://www.ruby-forum.com/t/activerecord-statementinvalid-error/106515>\
**Category:** Rails\
**Created:** [June 11, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-error/106515 "2007-06-11T14:51:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@simon1](https://www.ruby-forum.com/u/simon1)\
**Post date:** [June 11, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-error/106515/1 "2007-06-11T14:51:56Z")

</div>

Hi,

I have an application that is running fine on two different machines,  
but when I ported the code to a third machine, it doesn’t seem to  
work. More specifically, for users with a significant amount of info,  
it seems to stop working. All the functionality seems to be working  
properly on a small test set, but with a larger set I get the  
following error:

AssociatedAp Load (0.000000) SystemExit: exit: SELECT \* FROM  
associated\_aps WHERE (mac = ‘00:0D:67:00:62:D3’) ORDER BY date DESC  
LIMIT 1

ActiveRecord::StatementInvalid (SystemExit: exit: SELECT \* FROM  
associated\_aps WHERE (mac = ‘00:0D:67:00:62:D3’) ORDER BY date DESC  
LIMIT 1):  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/  
active\_record/connection\_adapters/abstract\_adapter.rb:128:in `log' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ active_record/connection_adapters/mysql_adapter.rb:243:in `execute’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/  
active\_record/connection\_adapters/mysql\_adapter.rb:399:in `select' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ active_record/connection_adapters/abstract/database_statements.rb:7:in `select\_all’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/  
active\_record/base.rb:427:in `find_by_sql' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ active_record/base.rb:997:in `find\_every’  
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/  
active\_record/base.rb:991:in `find_initial' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/ active_record/base.rb:417:in `find’  
/app/controllers/account\_controller.rb:674:in `ap_status_review' /app/controllers/account_controller.rb:655:in `ap\_status\_review’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/base.rb:1095:in `perform_action_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:632:in `call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/filters.rb:638:in `call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:438:in `call’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/filters.rb:637:in `call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:638:in `call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/filters.rb:438:in `call' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/filters.rb:637:in `call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/filters.rb:619:in `perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/rescue.rb:83:in `perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/base.rb:430:in `process\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/filters.rb:624:in  
`process_without_session_management_support' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/ action_controller/session_management.rb:114:in `process’  
/app/controllers/application.rb:16:in `process' /app/controllers/application.rb:15:in `process’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/base.rb:330:in `process' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/dispatcher.rb: 41:in `dispatch’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi\_handler.rb:  
168:in `process_request' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb: 143:in `process\_each\_request!’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi\_handler.rb:  
109:in `with_signal_handler' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb: 142:in `process\_each\_request!’  
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in  
`each_cgi' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each\_cgi’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi\_handler.rb:  
141:in `process_each_request!' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb: 55:in `process!’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi\_handler.rb:  
25:in `process!’  
/var/www/rails/434Wireless/public/dispatch.fcgi:24

Rendering /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/  
action\_controller/templates/rescues/layout.rhtml (500 Internal Error)

The only difference between the machine where I get the error and the  
others is that I’m running Rails through Apache on the one with the  
errors. Here is what I get in the apache log when the crash happens:

[Mon Jun 11 13:13:07 2007] [error] [client 64.230.66.6] Premature end  
of script headers: dispatch.fcgi, referer: [http://209.87.xxx.xxx/](http://209.87.xxx.xxx/)

The strange thing is that the SQL query that it crashes on executes  
several times on the same request before it crashes. Has anybody had  
a similar experience, or have any ideas as to what the issue might be?

Thanks,

Simon

---

<div class="post-metadata">

**Author:** ![simon1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@simon1](https://www.ruby-forum.com/u/simon1)\
**Post date:** [June 11, 2007, 4:13pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-error/106515/2 "2007-06-11T16:13:22Z")

</div>

Forgot to mention that I am storing user info in session hashes.  
Could the issue be related to this at all?

Thanks again,

Simon

---

<div class="post-metadata">

**Author:** ![simon1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@simon1](https://www.ruby-forum.com/u/simon1)\
**Post date:** [June 11, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-error/106515/3 "2007-06-11T20:07:04Z")

</div>

Upon further investigation, the issue appears to have to do with  
running through Apache. I changed to Webrick, and everything works  
properly. However, I do need to get it running through Apache as  
well. Does anybody have any insight into the differences in the  
execution environment between Webrick and Apache? Any help here would  
be greatly appreciated.

Thanks,

SImon

---

<div class="post-metadata">

**Author:** ![simon1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@simon1](https://www.ruby-forum.com/u/simon1)\
**Post date:** [June 15, 2007, 10:41pm UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-error/106515/4 "2007-06-15T22:41:55Z")

</div>

Simon,

I am having the same problem in an Apache/Linux environment. Did you  
ever get anywhere with this?

Cheers,

Brad

Simon wrote:

> Upon further investigation, the issue appears to have to do with  
> running through Apache. I changed to Webrick, and everything works  
> properly. However, I do need to get it running through Apache as  
> well. Does anybody have any insight into the differences in the  
> execution environment between Webrick and Apache? Any help here would  
> be greatly appreciated.
> 
> Thanks,
> 
> SImon
