Bug #91503 NodeJS Extra padding on string fields and error on JSON field
Submitted: 29 Jun 13:27 Modified: 2 Jul 6:09
Reporter: Gabriela Ferrara Email Updates:
Status: Verified Impact on me:
None 
Category:Connector for Node.js Severity:S2 (Serious)
Version:8.0.11 OS:Any
Assigned to: CPU Architecture:Any

[29 Jun 13:27] Gabriela Ferrara
Description:
NodeJS connector is padding strings and if you have JSON NOT NULL field it gives an error. If the JSON field is nullable, the error doesn't occur, just the padding.

How to repeat:
Run the following code:

test.js

const mysqlx = require('@mysql/xdevapi')

mysqlx.getSession({ user: 'root', schema: 'testcase' })
  .then(session => {
    return session.sql('USE testcase').execute()
      .then(() => {
        return session.sql('CREATE TABLE test (id MEDIUMINT NOT NULL AUTO_INCREMENT, doc JSON NOT NULL, PRIMARY KEY (id))')
          .execute()
      })
      .then(() => {
        return session.sql(`INSERT INTO test (doc) VALUES ('{"name":"foo","age":42}')`)
          .execute()
      })
      .then(() => {
        return session.getSchema('testcase').getTable('test').select(['id', 'doc'])
          .execute(console.log)
      })
      .then(() => {
        return session.dropSchema('testcase')
      })
      .then(() => {
        return session.close()
      })
  })
  .catch(err => {
    console.log(err.stack)
    process.exit(1)
});

Error: 

 node test.js
~/Public/cloud-functions/node_modules/@mysql/xdevapi/lib/Protocol/Protobuf/Adapters/Resultset.js:490
    return asString.concat(char.repeat(size - maxSize));
                                ^

RangeError: Invalid string length
    at String.repeat (<anonymous>)
    at rightPad (~/Public/cloud-functions/node_modules/@mysql/xdevapi/lib/Protocol/Protobuf/Adapters/Resultset.js:490:33)
    at decodeOpaqueByteString (~/Public/cloud-functions/node_modules/@mysql/xdevapi/lib/Protocol/Protobuf/Adapters/Resultset.js:224:16)
    at decodeField (~/Public/cloud-functions/node_modules/@mysql/xdevapi/lib/Protocol/Protobuf/Adapters/Resultset.js:167:16)
    at proto.getFieldList.map (~/Public/cloud-functions/node_modules/@mysql/xdevapi/lib/Protocol/Protobuf/Adapters/Resultset.js:573:32)
    at Array.map (<anonymous>)
    at Object.exports.decodeRow (~/Public/cloud-functions/node_modules/@mysql/xdevapi/lib/Protocol/Protobuf/Adapters/Resultset.js:573:10)
    at SqlResultHandler.(anonymous function) (~/Public/cloud-functions/node_modules/@mysql/xdevapi/lib/Protocol/ResponseHandlers/SqlResultHandler.js:110:27)
    at Array.entry (~/Public/cloud-functions/node_modules/@mysql/xdevapi/lib/Protocol/ResponseHandlers/BaseHandler.js:90:29)
    at WorkQueue.process (~/Public/cloud-functions/node_modules/@mysql/xdevapi/lib/WorkQueue.js:75:19)
[2 Jul 6:09] Umesh Shastry
Hello Gabriela,

Thank you for the report!

Thanks,
Umesh