From 04b77c12d4d68ac99d39abd21ed70ba810857a41 Mon Sep 17 00:00:00 2001 From: steveaffleck <11939877+steveaffleck@users.noreply.github.com> Date: Thu, 6 Apr 2023 08:21:53 -0600 Subject: [PATCH] Add support for MySql::Type::Decimal --- src/mysql/types.cr | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/mysql/types.cr b/src/mysql/types.cr index e90548a..cfc24e0 100644 --- a/src/mysql/types.cr +++ b/src/mysql/types.cr @@ -285,6 +285,20 @@ abstract struct MySql::Type packet.read_lenenc_string.to_f64 end end + decl_type Decimal, 0x00u8 do + def self.read(packet) + str = packet.read_lenenc_string + BigDecimal.new(str) + end + + def self.write(packet, v : BigDecimal) + packet.write_lenenc_string v.to_s + end + + def self.parse(str : ::String) + BigDecimal.new(str) + end + end decl_type Enum, 0xf7u8 decl_type Set, 0xf8u8 decl_type TinyBlob, 0xf9u8