|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { assert } = require('poku'); |
| 4 | +const { createConnection } = require('../common.test.cjs'); |
| 5 | + |
| 6 | +(async () => { |
| 7 | + const conn = createConnection({ multipleStatements: true }); |
| 8 | + const captured1 = []; |
| 9 | + const captured2 = []; |
| 10 | + const sql1 = |
| 11 | + 'select * from information_schema.columns order by table_schema, table_name, column_name limit 1;'; |
| 12 | + const sql2 = |
| 13 | + 'select * from information_schema.columns order by table_schema, table_name, ordinal_position limit 1;'; |
| 14 | + |
| 15 | + await conn.promise().query('set global max_allowed_packet=524288000'); |
| 16 | + |
| 17 | + const compare1 = await conn.promise().query(sql1); |
| 18 | + const compare2 = await conn.promise().query(sql2); |
| 19 | + |
| 20 | + if (!compare1 || compare1.length < 1) { |
| 21 | + assert.fail('no results for comparison 1'); |
| 22 | + } |
| 23 | + if (!compare2 || compare2.length < 1) { |
| 24 | + assert.fail('no results for comparison 2'); |
| 25 | + } |
| 26 | + |
| 27 | + const stream = conn.query(`${sql1}\n${sql2}`).stream(); |
| 28 | + stream.on('result', (row, datasetIndex) => { |
| 29 | + if (datasetIndex === 0) { |
| 30 | + captured1.push(row); |
| 31 | + } else { |
| 32 | + captured2.push(row); |
| 33 | + } |
| 34 | + }); |
| 35 | + // note: this is very important: |
| 36 | + // after each result set is complete, |
| 37 | + // the stream will emit "readable" and if we don't |
| 38 | + // read then 'end' won't be emitted and the |
| 39 | + // test will hang. |
| 40 | + stream.on('readable', () => { |
| 41 | + stream.read(); |
| 42 | + }); |
| 43 | + |
| 44 | + await new Promise((resolve, reject) => { |
| 45 | + stream.on('error', (e) => reject(e)); |
| 46 | + stream.on('end', () => resolve()); |
| 47 | + }); |
| 48 | + |
| 49 | + assert.equal(captured1.length, 1); |
| 50 | + assert.equal(captured2.length, 1); |
| 51 | + assert.deepEqual(captured1[0], compare1[0][0]); |
| 52 | + assert.deepEqual(captured2[0], compare2[0][0]); |
| 53 | + |
| 54 | + conn.end(); |
| 55 | +})(); |
0 commit comments