I have a simple project created around a very, very simple database: one
main table packs with just three rows
Column | Type |
Modifiers
--------±----------------------------±---------------------------------------------------
id | integer | not null default
nextval(‘packs_id_seq’::regclass)
nombre | character varying(40) |
path | character varying(250) |
in a method I have :
id = params[:album].to_i @album = Pack.find id
That is the sentence located using debugger. The answer in the browser:
ActiveRecord::StatementInvalid in FotosController#inic
PGError: ERROR: zero-length delimited identifier at or near “”""
LINE 1: SELECT “packs”.* FROM “packs” WHERE “packs”."" = $1 LIMIT …
^
: SELECT “packs”.* FROM “packs” WHERE “packs”."" = $1 LIMIT 1
"irb(main):001:0> Pack.find 1
Could not log “sql.active_record” event. NoMethodError: undefined method name' for nil:NilClass PGError: ERROR: zero-length delimited identifier at or near """" LINE 1: SELECT "packs".* FROM "packs" WHERE "packs"."" = $1 LIMIT ... ^ : SELECT "packs".* FROM "packs" WHERE "packs"."" = $1 LIMIT 1 ActiveRecord::StatementInvalid: PGError: ERROR: zero-length delimited identifier at or near """" LINE 1: SELECT "packs".* FROM "packs" WHERE "packs"."" = $1 LIMIT ... ^ : SELECT "packs".* FROM "packs" WHERE "packs"."" = $1 LIMIT 1 from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:968:inprepare’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:968:in exec_cache' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:552:inexec_query’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:244:in log' from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.0/lib/active_support/notifications/instrumenter.rb:21:ininstrument’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract_adapter.rb:239:in log' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:550:inexec_query’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1031:in select' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:18:inselect_all’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in select_all' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/base.rb:470:infind_by_sql’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/relation.rb:111:in to_a' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/relation/finder_methods.rb:370:infind_first’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/relation/finder_methods.rb:122:in first' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/relation/finder_methods.rb:328:infind_one’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/relation/finder_methods.rb:304:in find_with_ids' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/relation/finder_methods.rb:107:infind’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/base.rb:441:in __send__' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/base.rb:441:infind’
"
2.- I do not have a file db/schema.rb.
I am just using my database through config/database.yml.
from find' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/base.rb:441:in send’
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.0/lib/active_record/base.rb:441:in
`find’
"
2.- I do not have a file db/schema.rb.
I am just using my database through config/database.yml.
Well you should have, you should have used rails migrations to create
the db, unless this is a legacy database. Create schema.rb by running
rake db:schema:dump
and post it here, though whether this is anything to do with the
problem is unlikely.
I am just using my database through config/database.yml.
Well you should have, you should have used rails migrations to create
the db, unless this is a legacy database. Create schema.rb by running
rake db:schema:dump
and post it here, though whether this is anything to do with the
problem is unlikely.
Well you should have, you should have used rails migrations to create
the db, unless this is a legacy database. Create schema.rb by running
rake db:schema:dump
and post it here, though whether this is anything to do with the
problem is unlikely.
Also post model/pack.rb please.
Colin
Thanks Colin for your fast answer and your care.
I just created schema.rb. Here I send its content:
create_table “sessions”, :force => true do |t|
end
2.- The content of model/pack.rb
class Pack < ActiveRecord::Base
def self.lisapp
res = self.find :all
ar = []
res.each { |arap| ar << [arap[1], arap[0]] }
ar.sort
end
end
The method lisapp is not used any more. Instead I use, before the error
is
generated @albums = Pack.find :all
and it works. Problem is with :
Pack.find 1 ( or id)
Colin
ActiveRecord::Schema.define(:version => 20110110162357) do
t.datetime “created_at”
t.datetime “updated_at”
end
Notice how the spec for id is different between the two tables, I
suppose that is due to the fact that you are providing your own
nextval for id (there is no spec for it in sessions so rails will
assume the default id column). I suspect this may be the cause of the
problem. First I suggest reverting id to a normal id column as you
have for sessions and see if this removes the problem. If it does
then either don’t use the nextval feature or you will have to ask
others whether it is possible to do this and if so whether you are
doing it correctly. I strongly advise against doing this, life will
be much simpler if you stick to the rails conventions. Possibly you
can find another way to achieve what you want, maybe by adding another
column for your alternative id.
be much simpler if you stick to the rails conventions. Possibly you
can find another way to achieve what you want, maybe by adding another
column for your alternative id.
Colin
Thanks a lot Colin:
I did, literarily as you suggested, and I do not have that ugly error
with
“Packfind id” any more.
I do have another problem, that comes from changes in rails version,
but
I’ll Google before starting any new thread.
Thanks, once again.
Gato Pardo
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.