sql - Inserting SQLite rows via Ruby iteration -
inserting 5 rows of 4-column data existing sqlite db, , these errors...
/users/sam/.rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize': near "tagline": syntax error (sqlite3::sqlexception) /users/sam/.rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `new' /users/sam/.rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `prepare' /users/sam/.rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:134:in `execute' insert_code_sam.rb:60:in `block in <main>' insert_code_sam.rb:59:in `times' insert_code_sam.rb:59:in `<main>'
here last lines (59-61) .rb file:
5.times db.execute('insert index1 (name tagline blurb photo_url) values (?, ?, ?, ?)', ["name", "tagline", "blurb", "photo"]) end
any suggestions?
you have small syntax error in sql. column list insert should comma delimited:
insert index1 (name, tagline, blurb, photo_url) ... ^ ^ ^
so ruby should this:
5.times db.execute('insert index1 (name, tagline, blurb, photo_url) values (?, ?, ?, ?)', ["name", "tagline", "blurb", "photo"]) end
see "column-name" loop in sqlite insert syntax diagram:
Comments
Post a Comment