lib/monetdb/connection/query.rb in monetdb-0.2.2 vs lib/monetdb/connection/query.rb in monetdb-0.2.3

- old
+ new

@@ -3,20 +3,24 @@ module Query def query(statement) raise ConnectionError, "Not connected to server" unless connected? + start = Time.now + write "s#{statement};" response = read.split("\n") + log :info, "\n SQL (#{((Time.now - start) * 1000).round(1)}ms) #{statement}" + query_header, table_header = extract_headers!(response) if query_header[:type] == Q_TABLE unless query_header[:rows] == response.size raise QueryError, "Amount of fetched rows does not match header value (#{response.size} instead of #{query_header[:rows]})" end - response = parse_rows(table_header, response.join("\n")) + response = parse_rows(query_header, table_header, response.join("\n")) else response = true end response @@ -81,17 +85,21 @@ column_lengths = header[3].collect(&:to_i) {:table_name => table_name, :column_names => column_names, :column_types => column_types, :column_lengths => column_lengths}.freeze end - def parse_rows(table_header, response) + def parse_rows(query_header, table_header, response) + start = Time.now column_types = table_header[:column_types] + response.slice(0..-3).split("\t]\n").collect do |row| parsed, values = [], row.slice(1..-1).split(",\t") values.each_with_index do |value, index| parsed << parse_value(column_types[index], value.strip) end parsed + end.tap do + log :info, " RUBY (#{((Time.now - start) * 1000).round(1)}ms) [ Rows: #{query_header[:rows]}, Bytesize: #{response.bytesize} bytes ]" end end def parse_value(type, value) unless value == "NULL"