scraperwiki / code-scraper-in-browser-tool

Just like on ScraperWiki Classic; now a part of QuickCode.
https://quickcode.io
Other
38 stars 8 forks source link

problem with save_data in sqlite with ruby if pass unique key #112

Closed mlessev closed 11 years ago

mlessev commented 11 years ago

data2 = { id: 12, search_keyword: "test", country: "BG" }

ScraperWiki.save_sqlite(['country'], data2, 'test')

Return the following error:

Started run: 2013-07-30 18:59:17+00:00 /var/lib/gems/1.9.1/gems/sqlite_magic-0.0.2/lib/sqlite_magic.rb:83:in block in save_data': Data has nil value for unique key. Unique keys are ["country"]. Offending data: {:id=>12, :search_keyword=>"test", :country=>"BG"} (SqliteMagic::DatabaseError) from /var/lib/gems/1.9.1/gems/sqlite_magic-0.0.2/lib/sqlite_magic.rb:80:ineach' from /var/lib/gems/1.9.1/gems/sqlite_magic-0.0.2/lib/sqlite_magic.rb:80:in save_data' from /var/lib/gems/1.9.1/gems/scraperwiki-3.0.1/lib/scraperwiki.rb:89:insave_sqlite' from ./code/scraper:34:in `

' Finished run: 2013-07-30 18:59:18+00:00 Exit code: 1

henare commented 11 years ago

In ScraperWiki.save_sqlite(['country'], data2, 'test') your key is a String, in data2 your key is a Hash.

Try changing your save_sqlite call to ScraperWiki.save_sqlite([:country], data2, 'test')

mlessev commented 11 years ago

Hello,

Thank you for your replay but it doesn't work too.

Anyway I have already find the problem and it is not in ScraperWiki.save_sqlite(['country'], data2, 'test') but in data2 definitions.

When I change

data2 = { id: 12, search_keyword: "test", country: "BG" }

with

data2 = { id => 12, search_keyword => "test", country => "BG" }

It works as I expected.

p.s I'm not a ruby expert and the code was migrated from https://classic.scraperwiki.com where it works - so I suppose the problem is in different interpreters