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

Using SET NAMES in 3.0.0 fails with TypeError #199

Closed
Supinic opened this issue Apr 24, 2022 · 1 comment
Closed

Using SET NAMES in 3.0.0 fails with TypeError #199

Supinic opened this issue Apr 24, 2022 · 1 comment

Comments

@Supinic
Copy link

Supinic commented Apr 24, 2022

When using the SET NAMES statement inside of a pool.query({ sql: query }) call, the execution fails with TypeError opts.emit is not a function.

Consider the following script:

(async () => {
    const { strictEqual } = require("assert");
    const Maria = require("mariadb");
    const pool = Maria.createPool({
    	user: "user",
    	password: "password",
    	host: "host"
    });
    
    const query = "SET NAMES 'utf8'";
    
    // Using string directly works as expected
    const result1 = await pool.query(query); 
    strictEqual(result1.constructor.name, "OkPacket");
    console.log("result 1 ok");

    // Using { sql: string } fails
    const result2 = await pool.query({ sql: query }); 
    strictEqual(result2.constructor.name, "OkPacket");
    console.log("result 2 ok");
})();

In mariadb version 2.5.2, the snippet passes, whereas in 3.0.0, the following error is thrown when attempting to initialize result2:

Uncaught TypeError: opts.emit is not a function
    at Query.parseOkPacket (VM195 command.js:142:24)
    at Query.readOKPacket (VM214 parser.js:108:27)
    at Query.readResponsePacket (VM214 parser.js:46:21)
    at PacketInputStream.receivePacketBasic (VM164 packet-input-stream.js:76:9)
    at PacketInputStream.onData (VM164 packet-input-stream.js:139:20)
    at Socket.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

Using other meta SQL commands (such as USE database) seems to cause no issues. Other arguments for SET NAMES fail similarly to utf8mb4.

Tested on NodeJS versions 12.22.9, 14.15.0, 16.14.2, 18.0.0, with identical results.

@rusher
Copy link
Collaborator

rusher commented Apr 26, 2022

Thanks for clear description !
Created a task for that (https://jira.mariadb.org/browse/CONJS-194)
This will be corrected in 3.0.1 release

@rusher rusher closed this as completed Apr 26, 2022
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

2 participants