I'm trying to convert some JSON data and get it inserted into a sqlite3 db using Ruby. The JSON is coming from githubarchive.com I followed the advice on this question: Escaping Strings For Ruby SQLite Insert and my code looks like this:
Yajl::Parser.parse(open(input).read) do |event|
r = CSV::Row.new(headers, [])
flatmap({}, event).each do |k,v|
v = (Time.parse(v).utc.strftime('%Y-%m-%d %T') rescue '') if k =~ /_at$/
if r.include? k
r[k] = v
else
puts "Unknown field: #{k}, value: #{v}"
end
end
# tmp << r.to_s
db = SQLite3::Database.open( "../github.sqlite" )
val = (['?'] * 186).join(',')
ins = db.prepare("insert into Sheet1_copy values (#{val})")
ins.execute(r.to_s)
The top part of this is taken from their git project. Now, when I try to run this with any of the data, I get
gems/sqlite3-1.3.5/lib/sqlite3/statement.rb:67:in `step': constraint failed (SQLite3::ConstraintException)
Any thoughts? Thanks!