crystal-lang / crystal-mysql

MySQL connector for Crystal
MIT License
107 stars 36 forks source link

Missing block in decl_type *Blob ? #98

Closed andre-luiz-dos-santos closed 2 years ago

andre-luiz-dos-santos commented 3 years ago

The query SELECT COALESCE(username, '') FROM radcheck was causing the exception below:

Unhandled exception: not supported read (Exception)
  from lib/mysql/src/mysql/types.cr:86:5 in 'read'
  from lib/mysql/src/mysql/result_set.cr:85:10 in 'read'
  from lib/db/src/db/result_set.cr:79:15 in 'read'
  from src/user_radius.cr:37:8 in 'read'
  from src/user.cr:32:11 in 'read'
  from src/command_auth_copy.cr:9:13 in 'run'
  from src/crystalville.cr:48:3 in '__crystal_main'
  from /snap/crystal/600/share/crystal/src/crystal/main.cr:110:5 in 'main_user_code'
  from /snap/crystal/600/share/crystal/src/crystal/main.cr:96:7 in 'main'
  from /snap/crystal/600/share/crystal/src/crystal/main.cr:119:3 in 'main'
  from __libc_start_main
  from _start
  from ???

The same query without COALESCE worked: SELECT username FROM radcheck.

Copying the block in types.cr decl_type Blob to the decl_type MediumBlob made it work:

  decl_type MediumBlob, 0xfau8, ::Bytes do
    def self.write(packet, v : ::Bytes)
      packet.write_blob v
    end

    def self.write(packet, v : ::StaticArray(T, N)) forall T, N
      packet.write_blob v.to_slice
    end

    def self.read(packet)
      packet.read_blob
    end

    def self.parse(str : ::String)
      str.to_slice
    end
  end

Versions:

Crystal 0.36.1 [c3a3c1823] (2021-02-02)

LLVM: 10.0.0
Default target: x86_64-unknown-linux-gnu

10.3.23-MariaDB-0+deb10u1

shard.lock:
  mysql:
    git: https://github.com/crystal-lang/crystal-mysql.git
    version: 0.13.0

CREATE TABLE `radcheck` (
  `username` text NOT NULL DEFAULT ''

I'm new to Crystal and don't know anything about the MySQL protocol, but why only type Blob has that block?