Hi everybody,
I’m experiencing trouble when trying to use ruby-postgres with a legacy
database I need access to. To me it seems the problem is the VARCHAR
columns used there as primary keys. On a simple
me = User.find(‘PS12345’)
I get a type error exception with the message ‘can’t convert String into
Integer’. The trace is:
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/postgresql_adapter.rb:24:in
connect' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/postgresql_adapter.rb:24:in
postgresql_connection’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in
connection_without_query_cache=' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/query_cache.rb:54:in
connection=’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:106:in
retrieve_connection' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:20:in
connection’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:801:in
sanitize' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:409:in
find’
./script/…/config/…/app/controllers/database_frontend_controller.rb:68:in
show_overview' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in
perform_action_without_filters’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in
perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69: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.11.2/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in
perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in
process_without_session_management_support’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in
process' /usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in
dispatch’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in
handle_dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in
service’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in
run’
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in
start_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in
start’
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in
start’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in
dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require’
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
require' /usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require’
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
`require’
script/server:3
My second app-specific database designed from scratch for Rails works
just fine. I’m on PPC OS X 10.4.5 with Ruby 1.8.4, Rails 1.0.0, Postgres
8.1.2 (on Linux) and have tried ruby-postgres 0.7.1 and 20051221, either
built from source or installed as gem.
Any help, hints, debug tips etc would be greatly appreciated. As I
haven’t had too much luck with postgres-pr as well, I’m now somewhat out
of options…
BTW, the problem I ran into when using postgres-pr was timestamps (with
or without timezones) being casted to nil. For example object.lastlogin
being nil, but object.lastlogin_before_type_cast containing the expected
data.
I tried at first to work around this by adding this to my model:
def after_find
self[:lastlogin] = self.lastlogin_before_type_cast
end
which seemed to work; unfortunately, when saving modified objects back
all timestamp fields where set to nil.
So again, thanks in advance for your help in either case …
Cheers,
Jan