lib/mysql2xxxx/xml.rb in mysql2xxxx-0.0.2 vs lib/mysql2xxxx/xml.rb in mysql2xxxx-0.0.3

- old
+ new

@@ -6,26 +6,25 @@ def initialize(options = {}) @properties = Properties.new options end - def client - @client ||= Client.new properties - end - # this matches the xml generated by "mysql --xml" # i tried to use builder, but the String#to_xs nonsense got in the way def to_file(f) + @client = ::Mysql2::Client.new properties.database_config f.write %{<?xml version="1.0" encoding="utf-8" ?>} f.write %{<resultset statement="#{properties.execute.to_xs}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">} - client.select_each(properties.execute) do |hsh| + @client.query(properties.execute).each do |hsh| f.write %{<row>} hsh.each do |k, v| f.write %{<field name="#{k.to_xs}"#{' xsi:nil="true"' if v.nil?}>#{v.to_s.to_xs}</field>} end f.write %{</row>} end f.write %{</resultset>} nil + ensure + @client.try :close end end end