sqlite ruby inserting row where not exists error

I am writing a script (cron job) that is reading my S3 folder and getting infos of the files uploaded in it to insert them in a sqlite DB. To make sure the files infos are not inserted twice (duplicated) i use the INSERT INTO ... WHERE NOT EXISTS on the date and file name but i am getting an error:

/usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `initialize': near ",": syntax error (SQLite3::SQLException) from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `new' from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:91:in `prepare' from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.10/lib/sqlite3/database.rb:134:in `execute' from metadatacron.rb:70:in `block in <main>' from metadatacron.rb:37:in `each' from metadatacron.rb:37:in `<main>'    

Here is the line 70:

db.execute( 'INSERT INTO uploads (name, origin, remote_link, created_at, updated_at, file_type, site_id, s3bucket_id)  SELECT (?, ?, ?, ?, ?, ?, ?, ?) WHERE NOT EXISTS(SELECT 1 FROM uploads WHERE created_at = #{created_at} AND remote_link = #{remote_link})', name, origin, remote_link, created_at, created_at, image, 1, 2)     

Line 37 is the beginning of the loop: files.each do |object|

What I am missing?

Replay

Category: insert Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.126 (s). 12 q(s)