Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby + ActiveRecord: Can't write to database
    primarykey
    data
    text
    <p>I'm writing a script in Ruby for work. Our company uses FileMaker Pro for its database, and as far as I can tell, the most painless way to get information from the FileMaker database into a sqlite3 database is to export from FileMaker into a tab-delimited text file, then parse the file with Ruby.</p> <p>The code sorts the tab-delimited text file and places each individual database listing into a position in an array. Then, it goes through each array position and breaks it down further into another array, such that in all the arrays, position 1 is the part number, 2 is the location, and so on and so forth. That part of the code works just great.</p> <p>The part that's giving me fits is the part that uses ActiveRecord to write the sub-array to a sqlite3 table. Here's the offending code:</p> <pre><code>Partsdb.create( :item_number =&gt; record_array[1], :location =&gt; record_array[2], :quantity =&gt; record_array[3], :make =&gt; record_array[4], :year =&gt; record_array[5], :model =&gt; record_array[6], :serial =&gt; record_array[7], :volt =&gt; record_array[8], :phase =&gt; record_array[9], :weight =&gt; record_array[10], :list_price =&gt; record_array[11], :sold =&gt; record_array[12], :image_path =&gt; record_array[13], :short_desc =&gt; record_array[14], :long_desc =&gt; record_array[15], :junk =&gt; record_array[16] ) </code></pre> <p>I've required 'rubygems' and 'active_record', so it's not that. Here's the table declaration that I did in the sqlite3 terminal:</p> <pre><code>CREATE TABLE parts_info(item_number INTEGER PRIMARY KEY ASC, location TEXT, quantity INTEGER, make TEXT, year INTEGER, model TEXT, serial TEXT, volt INTEGER, phase INTEGER, weight INTEGER, list_price REAL, sold INTEGER, image_path TEXT, short_desc TEXT, long_desc TEXT, junk TEXT); </code></pre> <p>... and lastly, here's the error message that I get in my terminal when I try to run the script:</p> <pre><code>john@ubuntu:~/Desktop/idealm_db_parser$ ruby test.rb /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.4/lib/active_record/connection_adapters/sqlite_adapter.rb:295:in `table_structure': Could not find table 'partsdbs' (ActiveRecord::StatementInvalid) from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.4/lib/active_record/connection_adapters/sqlite_adapter.rb:186:in `columns' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.4/lib/active_record/base.rb:679:in `columns' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.4/lib/active_record/persistence.rb:284:in `attributes_from_column_definition' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.4/lib/active_record/locking/optimistic.rb:62:in `attributes_from_column_definition' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.4/lib/active_record/base.rb:1394:in `initialize' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.4/lib/active_record/base.rb:496:in `new' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.4/lib/active_record/base.rb:496:in `create' from test.rb:36:in `block (2 levels) in &lt;main&gt;' from test.rb:30:in `each' from test.rb:30:in `block in &lt;main&gt;' from test.rb:25:in `glob' from test.rb:25:in `&lt;main&gt;' </code></pre> <p>TRWTF is the 4th line in the error output - 'Could not find table 'partsdbs' (ActiveRecord::StatementInvalid). I've tried calling the table several different things, but it appends an 's' to the end of the table's name every time in the error output.</p> <p>Any and all help would be greatly appreciated. I'm relatively new to programming, I've only been using Ruby for about two weeks, and I've been messing with ActiveRecord for about 3 days, so I'm still a little wet behind the ears.</p> <p>Thanks for reading.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload