Skip to content

Typcast parsing error #321

@Gabilabrebi

Description

@Gabilabrebi

My boolean fields are tinyint and i wanted to cast them as real boolean.

I used

typeCast: function (field, next) {
    // Check if the field is a TINYINT(1)
    if (field.type === 'TINY' && field.columnLength === 1) {
      const val = field.string();
      return val === null ? null : val === '1';
    }
    return next();
  }

but it keep throwing.

Trying to troubleshooting, I discovered that field.string(), (and many other methods of field) actually fails on some JSON columns.

For example a field typed as JSON and with value [["12:00","15:30"],["19:00","22:30"]]

will throw

undefined:1
"12:00","15:30"],["19:00","22:30"]]%[["12:00","15:30"],["19:00","22:30"]]%[["12:00","15:30"
       ^

SyntaxError: Unexpected non-whitespace character after JSON at position 7 (line 1 column 8)
    at JSON.parse (<anonymous>)
    at readJsonBinary (C:\Users\Gabi\Documents\Web\yesresto\node_modules\mariadb\lib\cmd\decoder\binary-decoder.js:249:49)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions