Please help me solve the following error message:
syntax error, unexpected tINTEGER, expecting $end
I have this model:
Code:
1. class GeoDatum < ActiveRecord::Base
2. end
The database contains the table geo_data, which contains the zip_code
column, filled with zip codes. I get the above error when searching
for a zip code and the zip code exists in the table. Here is the
console output:
>> GeoDatum.find_by_zip_code(95035)
SyntaxError: compile error
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:2203: syntax error, unexpected tINTEGER,
expecting $end
"95036
^
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:2203:in `compute_type''
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/
active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:2200:in `compute_type''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:1640:in `instantiate''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:661:in `find_by_sql''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:661:in `collect!''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:661:in `find_by_sql''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:1553:in `find_every''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:1510:in `find_initial''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:613:in `find''
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:1905:in `find_by_zip_code''
from (irb):3
I notice that the zip code 95035 is mysteriously incremented by one to
become 95036 in the error message. Interestingly, when the zip code
does not exist, no error is produced:
>> GeoDatum.find_by_zip_code(11111)
=> nil
>>
I am following the examples in "RailsSpace" by Hartl. I am using Ruby
1.8.7 and Rails 2.3.2. Not sure if this is a Ruby bug. See
http://redmine.ruby-lang.org/issues/show/386.
Below is the code that creates the geo_data table. db:migrate went
fine. Please help. Thanks.
Code
1. class CreateGeoData < ActiveRecord::Migration
2. def self.up
3. create_table :geo_data do |t|
4. t.column :zip_code, :string
5. t.column :latitude, :float
6. t.column :longitude, :float
7. t.column :city, :string
8. t.column :state, :string
9. t.column :county, :string
10. t.column :type, :string
11. end
12. add_index "geo_data", ["zip_code"], :name =>
"zip_code_optimization"
13.
14. csv_file = "#{RAILS_ROOT}/db/migrate/geo_data.csv"
15. fields = ''(zip_code, latitude, longitude, city, state,
county, type)''
16.
17. # execute "LOAD DATA INFILE ''#{csv_file}''
INTO TABLE
geo_data FIELDS " +
18. # "TERMINATED BY '','' OPTIONALLY ENCLOSED BY
\"\"\"\" " +
19. # "LINES TERMINATED BY ''\n'' " + fields
20.
21. execute "LOAD DATA LOCAL INFILE ''#{csv_file}''
INTO TABLE
geo_data FIELDS " +
22. "TERMINATED BY '','' OPTIONALLY ENCLOSED BY
''\"'' " +
23. "LINES TERMINATED BY ''\n'' " + fields
24.
25. end
26.
27. def self.down
28. drop_table :geo_data
29. end
30. end
Hassan Schroeder
2009-Jun-23 14:05 UTC
Re: syntax error, unexpected tINTEGER, expecting $end
On Tue, Jun 23, 2009 at 1:52 AM, LearnByDoing <easebus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> >> GeoDatum.find_by_zip_code(95035) > SyntaxError: compile error> 1. class CreateGeoData < ActiveRecord::Migration > 2. def self.up > 3. create_table :geo_data do |t| > 4. t.column :zip_code, :stringYou might want to try this passing a string as an argument, as you''ve defined the column in your table :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Frederick Cheung
2009-Jun-23 15:23 UTC
Re: syntax error, unexpected tINTEGER, expecting $end
On Jun 23, 9:52 am, LearnByDoing <ease...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Please help me solve the following error message: > > syntax error, unexpected tINTEGER, expecting $end >Looks like you have a type column (which activerecord uses for single table inheritance) but you''re actually storing data (such as 95036) in that column You can set which column AR uses for this with set_inheritance_column Fred> I have this model: > > Code: > > 1. class GeoDatum < ActiveRecord::Base > 2. end > > The database contains the table geo_data, which contains the zip_code > column, filled with zip codes. I get the above error when searching > for a zip code and the zip code exists in the table. Here is the > console output: > > >> GeoDatum.find_by_zip_code(95035) > SyntaxError: compile error > /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:2203: syntax error, unexpected tINTEGER, > expecting $end > "95036 > ^ > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:2203:in `compute_type'' > from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/ > active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:2200:in `compute_type'' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:1640:in `instantiate'' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:661:in `find_by_sql'' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:661:in `collect!'' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:661:in `find_by_sql'' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:1553:in `find_every'' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:1510:in `find_initial'' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:613:in `find'' > from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ > active_record/base.rb:1905:in `find_by_zip_code'' > from (irb):3 > > I notice that the zip code 95035 is mysteriously incremented by one to > become 95036 in the error message. Interestingly, when the zip code > does not exist, no error is produced: > > >> GeoDatum.find_by_zip_code(11111) > => nil > >> > > I am following the examples in "RailsSpace" by Hartl. I am using Ruby > 1.8.7 and Rails 2.3.2. Not sure if this is a Ruby bug. Seehttp://redmine.ruby-lang.org/issues/show/386. > > Below is the code that creates the geo_data table. db:migrate went > fine. Please help. Thanks. > > Code > > 1. class CreateGeoData < ActiveRecord::Migration > 2. def self.up > 3. create_table :geo_data do |t| > 4. t.column :zip_code, :string > 5. t.column :latitude, :float > 6. t.column :longitude, :float > 7. t.column :city, :string > 8. t.column :state, :string > 9. t.column :county, :string > 10. t.column :type, :string > 11. end > 12. add_index "geo_data", ["zip_code"], :name => > "zip_code_optimization" > 13. > 14. csv_file = "#{RAILS_ROOT}/db/migrate/geo_data.csv" > 15. fields = ''(zip_code, latitude, longitude, city, state, > county, type)'' > 16. > 17. # execute "LOAD DATA INFILE ''#{csv_file}'' INTO TABLE > geo_data FIELDS " + > 18. # "TERMINATED BY '','' OPTIONALLY ENCLOSED BY \"\"\"\" " + > 19. # "LINES TERMINATED BY ''\n'' " + fields > 20. > 21. execute "LOAD DATA LOCAL INFILE ''#{csv_file}'' INTO TABLE > geo_data FIELDS " + > 22. "TERMINATED BY '','' OPTIONALLY ENCLOSED BY ''\"'' " + > 23. "LINES TERMINATED BY ''\n'' " + fields > 24. > 25. end > 26. > 27. def self.down > 28. drop_table :geo_data > 29. end > 30. end