Skip to content

Duplicate Column Names: null values can cause incomplete Arrays #1161

@MichaelKorn

Description

@MichaelKorn

If a SELECT uses duplicate column names some rows can have incomplete Arrays if null Values are returned.

Minimal example:

const sql = require("mssql/msnodesqlv8");
sql.connect({
  server: 'localhost',
  driver: 'msnodesqlv8',
  options: {
    trustedConnection: true
  }
}).then(async pool => {
  const result = await pool.query(`
  CREATE TABLE #TempTable (
    col1 int,
    col2 int,
    col3 int,
  );
        
  INSERT INTO #TempTable VALUES 
    (null,null,null),
    (null,null,3),
    (null,2,null),
    (null,2,3),
    (1,null,null),
    (1,null,3),
    (1,2,null),
    (1,2,3);
        
  Select col1 as col,col2 as col,col3 as col From #TempTable;`);
  console.table(result.recordset);
})

Expected behaviour:

┌─────────┬──────────────────────┐
│ (index) │          col         │
├─────────┼──────────────────────┤
│    0    │ [ null, null, null ] │
│    1    │  [ null, null, 3 ]   │
│    2    │  [ null, 2, null ]   │
│    3    │    [ null, 2, 3 ]    │
│    4    │  [ 1, null, null ]   │
│    5    │    [ 1, null, 3 ]    │
│    6    │    [ 1, 2, null ]    │
│    7    │      [ 1, 2, 3 ]     │
└─────────┴──────────────────────┘

Actual behaviour:

┌─────────┬───────────────────┐
│ (index) │        col        │
├─────────┼───────────────────┤
│    0    │       null        │
│    1    │         3         │
│    2    │    [ 2, null ]    │
│    3    │     [ 2, 3 ]      │
│    4    │ [ 1, null, null ] │
│    5    │  [ 1, null, 3 ]   │
│    6    │  [ 1, 2, null ]   │
│    7    │    [ 1, 2, 3 ]    │
└─────────┴───────────────────┘

Software versions

  • NodeJS: v14.15.1
  • node-mssql: 6.3.1
  • msnodesqlv8: 2.0.9 and 1.1.8
  • SQL Server: SQL Server: Microsoft SQL Server 2017 (RTM-GDR) (KB4505224) - 14.0.2027.2 (X64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions