lib/duckdb/result.rb in duckdb-0.7.1 vs lib/duckdb/result.rb in duckdb-0.8.0
- old
+ new
@@ -1,5 +1,9 @@
+# frozen_string_literal: true
+
+require 'bigdecimal'
+
module DuckDB
# The Result class encapsulates a execute result of DuckDB database.
#
# The usage is as follows:
#
@@ -26,12 +30,13 @@
3 => :_to_smallint,
4 => :_to_integer,
5 => :_to_bigint,
10 => :_to_float,
11 => :_to_double,
- 16 => :_to_hugeint,
+ 16 => :_to_hugeint_internal,
18 => :_to_blob,
+ 19 => :_to_decimal_internal
}
ToRuby.default = :_to_string
alias column_size column_count
@@ -67,8 +72,24 @@
private
def _to_hugeint(row, col)
_to_string(row, col).to_i
+ end
+
+ def _to_hugeint_internal(row, col)
+ lower, upper = __to_hugeint_internal(row, col)
+ upper * Converter::HALF_HUGEINT + lower
+ end
+
+ def _to_decimal(row, col)
+ BigDecimal(_to_string(row, col))
+ end
+
+ def _to_decimal_internal(row, col)
+ lower, upper, _width, scale = __to_decimal_internal(row, col)
+ v = (upper * Converter::HALF_HUGEINT + lower).to_s
+ v[-scale, 0] = '.'
+ BigDecimal(v)
end
end
end