ActiveRecord::StatementInvalid error

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/

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

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

Thanks again,

Simon

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