From: Hans Meier Date: 2007-08-01T17:12:50+09:00 Subject: Re: parse xml file, put results in mysql db Robert Klemme wrote: > 2007/7/31, Hans Meier : >> >> m.select_db(dbname) >> > the XML doc and then execute for each iteration. >> > Kind regards >> >> >> sth.execute("#{model}", "#{manufacturer}", "#{mobil_device_id}") >> >> >> sth.finish >> dbh.disconnect >> >> >> >> But there is one problem: it writes only one row in the database. Can >> anyone say why? > > Yes. You did not follow my directions. :-) Think a moment about the > logic you are employing and it should be immediately clear why you > only get one record in the DB. > > robert Ok, thanks. now i know why. my code looks this way now: mobils = REXML::Document.new(f) root = mobils.root models = [] manufacturers = [] mobil_device_ids = [] mobils.elements.each("MobileDevices/MobileDevice") { |element| puts element.attributes["model"] models.push element.attributes["model"] } mobils.elements.each("MobileDevices/MobileDevice") { |element| puts element.attributes["manufacturer"] manufacturers.push element.attributes["manufacturer"] } mobils.elements.each("MobileDevices/MobileDevice") { |element| puts element.attributes["id"] mobil_device_ids.push element.attributes["id"] } dbname="abo_development" m = Mysql.new("localhost", "root", "") dbh=DBI.connect("dbi:Mysql:abo_development:localhost", "root", "") m.select_db(dbname) sth=dbh.prepare("INSERT INTO mobil_devices (model, manufacturer, mobil_device_id,) VALUES (?,?,?)") models.each_index do |index| model = models[index] manufacturer = manufacturers[index] mobil_device_id = mobil_device_ids[index] sth.execute("mobils.xml", "abo_development", "#{model}", "#{manufacturer}", "#{mobil_device_id}") end but i get unfortunattely this failure message: RuntimeError: Too many SQL parameters from /usr/local/lib/ruby/site_ruby/1.8/dbi/sql.rb:192:in `bind' from /usr/local/lib/ruby/site_ruby/1.8/DBD/Mysql/Mysql.rb:569:in `execute' from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:617:in `execute' from ./script/../config/../config/../lib/rails_maintainer.rb:57:in `importContentDelivery' from ./script/../config/../config/../lib/rails_maintainer.rb:53:in `each_index' from ./script/../config/../config/../lib/rails_maintainer.rb:53:in `importContentDelivery' from (irb):1 >> -- Posted via http://www.ruby-forum.com/.