Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. sql = 'SELECT id FROM publishers WHERE name = ?';
  2. sth = db.prepare(sql)
  3. row = sth.execute(result['publisher'])
  4.  
  5. puts "publisher: #{result['publisher']}--"
  6.  
  7. publisher_id = nil
  8. if (row.num_rows() > 0)
  9. row.each do |row|
  10. publisher_id = row[0]
  11. end
  12. else
  13. sql = 'INSERT INTO publishers (name) VALUES(?)'
  14. sth = db.prepare(sql)
  15. row = sth.execute(result['publisher'])
  16.  
  17. sql = 'SELECT id FROM publishers WHERE name = ?';
  18. sth = db.prepare(sql)
  19. row = sth.execute(result['publisher'])
  20.  
  21. row.each do |row|
  22. publisher_id = row[0]
  23. end
  24.  
  25.  
  26.  
  27. ## Go through the if above to get publisher id again. ugh.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement