Any feedback appreciated on the following. My most recent attempt to identify the issue is a minimal Ruby/SQLite/ActiveRecord script, Pastied here: http://pastie.textmate.org/492514 which brings up the following when run from the command line (an empty database file already exists): $ ./simple_db.rbx [SNIP]/active_record/connection_adapters/sqlite3_adapter.rb:29:in `table_structure'': Could not find table ''users'' (ActiveRecord::StatementInvalid) from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/ lib/active_support/core_ext/object/misc.rb:39:in `returning'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/ lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `table_structure'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/ lib/active_record/connection_adapters/sqlite_adapter.rb:213:in `columns'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/ lib/active_record/base.rb:1276:in `columns'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/ lib/active_record/base.rb:3008:in `attributes_from_column_definition_without_lock'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/ lib/active_record/locking/optimistic.rb:66:in `attributes_from_column_definition'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/ lib/active_record/base.rb:2435:in `initialize'' from ./simple_db.rbx:10:in `new'' from ./simple_db.rbx:10 The adapted blog example code I want to run for my students as an example is Pastied at: http://pastie.org/492517 so I''d appreciate the identification of any glaring errors (currently Camping 1.5 under plain CGI): The errors in the server log read: [SNIP]/activerecord-2.3.2/lib/active_record/connection_adapters/ abstract_adapter.rb:212:in `log'': SQLite3::SQLException: unable to open database file: CREATE TABLE "blogtiny_schema_infos" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "version" float) (ActiveRecord::StatementInvalid) from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/connection_adapters/sqlite_adapter.rb:157:in `execute'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/connection_adapters/sqlite_adapter.rb:402:in `catch_schema_changes'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/connection_adapters/sqlite_adapter.rb:157:in `execute'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/connection_adapters/abstract/schema_statements.rb: 114:in `create_table'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/migration.rb:352:in `send'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/migration.rb:352:in `method_missing'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/migration.rb:328:in `say_with_time'' from /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/migration.rb:328:in `say_with_time'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/migration.rb:348:in `method_missing'' from (eval):71:in `create_schema'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/schema.rb:43:in `instance_eval'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/schema.rb:43:in `define'' from (eval):70:in `create_schema'' from /Users/deveritt/Sites/cgi-bin/camping/blogtiny.rbx:71:in `create'' from /Users/deveritt/Sites/cgi-bin/camping/blogtiny.rbx:77 [Thu May 28 12:18:13 2009] [error] [client 127.0.0.1] malformed header from script. Bad header=-- create_table("blogtiny_sche: /Users/ deveritt/Sites/cgi-bin/camping/blogtiny.rbx Note the odd truncation of ''blogtiny_sche'' in the final line. And one dumb question: I don''t have to ''require sqlite3-ruby'', right? Dave
Are the permissions on the file set right? What happens if you try to access the file with rhe sqlite3 command line tool and run the query yourself? -- Eric On Tue, Jun 9, 2009 at 6:35 AM, Dave Everitt<deveritt at innotts.co.uk> wrote:> Any feedback appreciated on the following. My most recent attempt to > identify the issue is a minimal Ruby/SQLite/ActiveRecord script, Pastied > here: http://pastie.textmate.org/492514 which brings up the following when > run from the command line (an empty database file already exists): > > $ ./simple_db.rbx > [SNIP]/active_record/connection_adapters/sqlite3_adapter.rb:29:in > `table_structure'': Could not find table ''users'' > (ActiveRecord::StatementInvalid) > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/object/misc.rb:39:in > `returning'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in > `table_structure'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:213:in > `columns'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1276:in > `columns'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:3008:in > `attributes_from_column_definition_without_lock'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/locking/optimistic.rb:66:in > `attributes_from_column_definition'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2435:in > `initialize'' > ? ? ? ?from ./simple_db.rbx:10:in `new'' > ? ? ? ?from ./simple_db.rbx:10 > > The adapted blog example code I want to run for my students as an example is > Pastied at: http://pastie.org/492517 so I''d appreciate the identification of > any glaring errors (currently Camping 1.5 under plain CGI): > > The errors in the server log read: > [SNIP]/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in > `log'': SQLite3::SQLException: unable to open database file: CREATE TABLE > "blogtiny_schema_infos" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, > "version" float) ?(ActiveRecord::StatementInvalid) > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in > `execute'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:402:in > `catch_schema_changes'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in > `execute'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:114:in > `create_table'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:352:in > `send'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:352:in > `method_missing'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:328:in > `say_with_time'' > ? ? ? ?from /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:328:in > `say_with_time'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:348:in > `method_missing'' > ? ? ? ?from (eval):71:in `create_schema'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema.rb:43:in > `instance_eval'' > ? ? ? ?from > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema.rb:43:in > `define'' > ? ? ? ?from (eval):70:in `create_schema'' > ? ? ? ?from /Users/deveritt/Sites/cgi-bin/camping/blogtiny.rbx:71:in > `create'' > ? ? ? ?from /Users/deveritt/Sites/cgi-bin/camping/blogtiny.rbx:77 > [Thu May 28 12:18:13 2009] [error] [client 127.0.0.1] malformed header from > script. Bad header=-- create_table("blogtiny_sche: > /Users/deveritt/Sites/cgi-bin/camping/blogtiny.rbx > > Note the odd truncation of ''blogtiny_sche'' in the final line. > > And one dumb question: > I don''t have to ''require sqlite3-ruby'', right? > > Dave > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >
What version of the gem are you using? 1.2.4? I''m assuming you compiled ruby yourself based off of its location, did you compile sqlite as well or get it through your OS package manager? In either case, I''ve found you''ll need the sqlite header files for the gem to work correctly. In your package manager they''re probably called sqlite-devel or something like that. Dave On Tue, Jun 9, 2009 at 8:26 AM, Eric Mill<kprojection at gmail.com> wrote:> Are the permissions on the file set right? What happens if you try to > access the file with rhe sqlite3 command line tool and run the query > yourself? > > -- Eric > > On Tue, Jun 9, 2009 at 6:35 AM, Dave Everitt<deveritt at innotts.co.uk> wrote: >> Any feedback appreciated on the following. My most recent attempt to >> identify the issue is a minimal Ruby/SQLite/ActiveRecord script, Pastied >> here: http://pastie.textmate.org/492514 which brings up the following when >> run from the command line (an empty database file already exists): >> >> $ ./simple_db.rbx >> [SNIP]/active_record/connection_adapters/sqlite3_adapter.rb:29:in >> `table_structure'': Could not find table ''users'' >> (ActiveRecord::StatementInvalid) >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/object/misc.rb:39:in >> `returning'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in >> `table_structure'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:213:in >> `columns'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1276:in >> `columns'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:3008:in >> `attributes_from_column_definition_without_lock'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/locking/optimistic.rb:66:in >> `attributes_from_column_definition'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2435:in >> `initialize'' >> ? ? ? ?from ./simple_db.rbx:10:in `new'' >> ? ? ? ?from ./simple_db.rbx:10 >> >> The adapted blog example code I want to run for my students as an example is >> Pastied at: http://pastie.org/492517 so I''d appreciate the identification of >> any glaring errors (currently Camping 1.5 under plain CGI): >> >> The errors in the server log read: >> [SNIP]/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in >> `log'': SQLite3::SQLException: unable to open database file: CREATE TABLE >> "blogtiny_schema_infos" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, >> "version" float) ?(ActiveRecord::StatementInvalid) >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in >> `execute'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:402:in >> `catch_schema_changes'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:157:in >> `execute'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:114:in >> `create_table'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:352:in >> `send'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:352:in >> `method_missing'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:328:in >> `say_with_time'' >> ? ? ? ?from /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:328:in >> `say_with_time'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:348:in >> `method_missing'' >> ? ? ? ?from (eval):71:in `create_schema'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema.rb:43:in >> `instance_eval'' >> ? ? ? ?from >> /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema.rb:43:in >> `define'' >> ? ? ? ?from (eval):70:in `create_schema'' >> ? ? ? ?from /Users/deveritt/Sites/cgi-bin/camping/blogtiny.rbx:71:in >> `create'' >> ? ? ? ?from /Users/deveritt/Sites/cgi-bin/camping/blogtiny.rbx:77 >> [Thu May 28 12:18:13 2009] [error] [client 127.0.0.1] malformed header from >> script. Bad header=-- create_table("blogtiny_sche: >> /Users/deveritt/Sites/cgi-bin/camping/blogtiny.rbx >> >> Note the odd truncation of ''blogtiny_sche'' in the final line. >> >> And one dumb question: >> I don''t have to ''require sqlite3-ruby'', right? >> >> Dave >> >> _______________________________________________ >> Camping-list mailing list >> Camping-list at rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list >> > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >-- Dave
Increasing permissions (currently 755) makes no difference. I can use the DB fine from the sqlite3 cl tool - Dave> On 9 Jun 2009, at 13:26, Eric Mill wrote: > >> > Are the permissions on the file set right? What happens if you try > to access the file with rhe sqlite3 command line tool and run the > query yourself?
Dave - to answer: 1. sqlite3-ruby (1.2.4), 2. I installed an updated Ruby (1.8.6) some time ago (can''t recall how!), 3. sqlite3 (3.1.3) is already on OS X 10.4.11, 4. I don''t use a package manager (or ports or fink), and know nothing about sqlite header files. I was thinking of installing a newer sqlite3 (keeping the existing), which might do the trick? Although using the OS X version lowers the entry bar, and I''m trying to make this easy for students. Dave> What version of the gem are you using? 1.2.4? > I''m assuming you compiled ruby yourself based off of its location, > did you compile sqlite as well or get it through your OS package > manager? > In either case, I''ve found you''ll need the sqlite header files for > the gem to work correctly. In your package manager they''re probably > called sqlite-devel or something like that.
On Tue, Jun 09, 2009 at 11:35:26AM +0100, Dave Everitt wrote:> Any feedback appreciated on the following. My most recent attempt to > identify the issue is a minimal Ruby/SQLite/ActiveRecord script, Pastied > here: http://pastie.textmate.org/492514 which brings up the following > when run from the command line (an empty database file already exists): > > $ ./simple_db.rbx > [SNIP]/active_record/connection_adapters/sqlite3_adapter.rb:29:in > `table_structure'': Could not find table ''users''(1) Not really a ''camping'' related pastie. See (3) for the same thing done the ''camping way''. (2) There seems to be nothing in the code above telling activerecord to create your database schema unless you''re doing seperate rake db:migrate scripts outside of this script. My suspicion, therefore is that the ''users'' table simply does not exist in your database. (3) This is a full working solution for camping 1.5: #!/usr/bin/env ruby $:.unshift File.dirname(__FILE__) + "/../../lib" require ''camping'' Camping.goes :Dave module Dave::Models class User < Base end class CreateTables < V 1.0 def self.up create_table :dave_users, :force => true do |t| t.column :id, :integer, :null => false t.column :name, :string, :limit => 255 t.column :password, :string, :limit => 255 end def self.down drop_table :dave_users end end end end module Dave::Controllers class Index < R ''/'' def get user = User.new() user.id = "dave" user.name = "Dave Everitt" user.password = "davepass" user.save # user = User.find("dave") # user.destroy() render :fin end end end module Dave::Views def fin "Finished, no errors" end end def Dave.create Dave::Models.create_schema :assume => (Dave::Models::User.table_exists? ? 1.0 : 0.0) end *************************** Save this file as dave.rb. Note the Dave::Models.create_schema call (as per point 2 above) To get this to work I have the following gems installed: $ gem list *** LOCAL GEMS *** activerecord (2.3.2) activesupport (2.3.2) builder (2.1.2) camping (1.5.180) markaby (0.5) metaid (1.0) sqlite3-ruby (1.2.4) I run it with: camping dave.rb I then visited http://localhost:3301/ with my browser (which showed "Finished, no errors"). To confirm that there is a table in the sqlite database with the correct fields and with one record: $ sqlite3 ~/.camping.db SQLite version 3.6.10 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .tables dave_schema_infos dave_users sessions sqlite> .header on sqlite> select * from dave_users; id|name|password 0|Dave Everitt|davepass Hope some of the above points you in the ''right'' direction. Cheers, Jonathan.
Thanks Jonathan - that''s done the trick. (BTW my previous fumble was an attempt to pinpoint my problem by connecting without Camping.) With the idea of using this as the simplest possible ''Camping with SQLite'' example for beginners (or testing new setups), I''ve adjusted and pastied it: http://pastie.textmate.org/509724 Comments welcome - Dave