Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batch Cannot read properties of undefined (reading '0') #299

Open
endingisnight opened this issue Nov 3, 2024 · 0 comments
Open

batch Cannot read properties of undefined (reading '0') #299

endingisnight opened this issue Nov 3, 2024 · 0 comments

Comments

@endingisnight
Copy link

server version: 11.5.2-1
connector: 3.4.0

const config = require(`./config.json`).db;
const maria = require(`mariadb/callback`);
globalThis.sql = maria.createPool({
    host: config.host,
    user: config.user,
    password: config.pass,
    database: `debug`,
})

// DROP TABLE IF EXISTS tab; CREATE TABLE tab (a JSON, b JSON, c LONGTEXT);
let vals = require(`./data.json`)
console.log(vals.flatMap(x => Buffer.from(x).byteLength));

// with query it works, but not with batch :)
sql.batch(
    `INSERT INTO tab (a,b,c) VALUES (?,?,?)`,
    vals, async (err, res) => {
        if (err) throw err;
        console.log(res);
        process.exit(0);
    })

data.json is 19MB so you'll have to increase max_allowed_packet from it's default 16MB

node_modules/.pnpm/mariadb@3.4.0/node_modules/mariadb/lib/cmd/batch-bulk.js:74
      const val = value[i];
                       ^

TypeError: Cannot read properties of undefined (reading '0')
    at BatchBulk.parameterHeaderFromValue (node_modules/.pnpm/mariadb@3.4.0/node_modules/mariadb/lib/cmd/batch-bulk.js:74:24)
    at BatchBulk.sendComStmtBulkExecute (node_modules/.pnpm/mariadb@3.4.0/node_modules/mariadb/lib/cmd/batch-bulk.js:306:38)
    at BatchBulk.start (node_modules/.pnpm/mariadb@3.4.0/node_modules/mariadb/lib/cmd/batch-bulk.js:60:10)
    at Connection.addCommandEnablePipeline (node_modules/.pnpm/mariadb@3.4.0/node_modules/mariadb/lib/connection.js:1151:11)
    at Connection.executeBulkPromise (node_modules/.pnpm/mariadb@3.4.0/node_modules/mariadb/lib/connection.js:290:10)
    at new Promise (<anonymous>)
    at node_modules/.pnpm/mariadb@3.4.0/node_modules/mariadb/lib/connection.js:214:16
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v23.1.0

For me, removing the "!" here fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant