0

Im trying to insert into the database but sinatra throws this error

DataObjects::ConnectionError at / database is locked

at line Name.create(babyname: name ,year1900: results[0] ,year1910: results[1] ,year1920: results[2] ,year1930: results[3],year1940: results[4],year1950: results[5] ,year1960: results[6],year1970: results[7] ,year1980: results[8] ,year1990: results[9] ,year2000: results[10])

This is how im reading the text file and creating the name

File.open("names-data.txt", "r") do |f|
f.each_line do |line|
  item = line.split(/\n/)
  array = item[0].split(/\s+/)
  name = array[0]
  array.shift
  pop = array
  results = pop.map { |number| if number =~ /0/ then 1001 else number.to_i end }
 Name.create(babyname: name ,year1900: results[0] ,year1910: results[1] ,year1920: results[2] ,year1930: results[3],year1940: results[4],year1950: results[5] ,year1960: results[6],year1970: results[7] ,year1980: results[8] ,year1990: results[9] ,year2000: results[10])
end

end

Here are a few lines in the text file that i am reading

Abbigail 0 0 0 0 0 0 0 0 0 953 562

Abby 0 0 0 0 0 906 782 548 233 211 209

Abdiel 0 0 0 0 0 0 0 0 0 925 721

There are over 4000 lines

msc
  • 67
  • 8
  • Any suggestions would be great – msc Dec 06 '17 at 20:03
  • I'm not very familiar with DataMapper, but the standard way to do this would be as a one-to-many relationship where each name has many rows in a Popularity table. So you need another model. – Max Dec 06 '17 at 20:27
  • okay, but wouldnt all the numbers get seperated, then I wouldnt know which set of numbers are for which person – msc Dec 06 '17 at 21:12
  • You need a foreign key from popularity to name. – Max Dec 06 '17 at 21:26
  • okay, i guess ill try to figure that out...aside from that. the code i have above doesnt work when i do User.create()..its causing an internal server error and idk why – msc Dec 06 '17 at 21:44
  • nevermind fixed it – msc Dec 06 '17 at 22:08

0 Answers0