Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[BUG] null value bind to number value results in nulls for numeric values for subsequent calls even when afterwards a non null value is bound

Abierto
#334 5 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
javascript, node.js

Línea de trabajo

Ejecuta la reproducción proporcionada en Node.js y comienza por las llamadas a statement.bind y statement.execute, centrándote en cómo se reutilizan los parámetros entre iteraciones del bucle. Se considera terminado cuando la tercera fila insertada conserva su valor numérico vinculado de 3 después de que la segunda fila vincule null.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

confirmed

Describe your system

  • odbc Package Version: 2.4.7
  • ODBC Driver: Microsoft ODBC Driver V18
  • Database Name: SQLServer
  • Database Version: 2019
  • Database OS: Windows
  • Node.js Version: 16.15.1
  • Node.js OS: Mac Ventura 13.3

Describe the bug
A prepared statement is created to insert values into a table with 3 parameters.
In a loop 3 rows will be inserted:

  • For the first row all parameters will be bound to values.
  • In the second row parameters 2 and 3 are bound to null values.
  • in the third row parameters 2 and 3 are bound to values.

The bound value for the numeric value for row 3 is not inserted in the database. The column value is inserted as a null value.
It seems that after binding a null value to a numeric afterwards non null values are inserted as null values in the database.

Expected behavior
Proper insert of values after bind.

To Reproduce
Execute the provided script under code.

Code

const odbc = require('odbc');

run().then(
    () => process.exit(),
    error => {
        console.log(error);
        process.exit();
    },
);

async function run() {
    // connect to the database
    const driver = 'MSSQL2019';
    const server = 'localhost';
    const uid = 'sa';
    const password = 'iRefact2017';
    const connectionString = `DSN=${driver};Uid=${uid};Pwd=${password};TrustServerCertificate=yes;`;
    const connection = await odbc.connect(connectionString);
    // initialize the connection
    await connection.setIsolationLevel(odbc.SQL_TXN_READ_COMMITTED);
    await connection.beginTransaction();
    await connection.query('set nocount on');
    // create a table to test the reuse of parameters
    await connection.query('create table dbo.test_parameters (id int, textValue varchar(100), numValue int);');
    // create a statement to insert values into the table using parameters
    const statement = await connection.createStatement();
    await statement.prepare('insert into dbo.test_parameters values (?, ?, ?);');
    // insert 3 rows:
    // row 1 with values for all parameters
    // row 2 with null values for parameters 2 and 3
    // row 3 with values for all parameters
    const textValues = ['row 1', null, 'row 3'];
    const numValues = [1, null, 3];
    for (let i = 0; i < textValues.length; i++) {
        await statement.bind([i + 1, textValues[i], numValues[i]]);
        await statement.execute();
    }
    // get the inserted rows
    const rows = await connection.query('select * from dbo.test_parameters order by id');
    console.dir([...rows]);
    // The result of row 3 has a null value for numValue. Expected the value to be 3!!!.
    // close the connection
    await connection.rollback();
    await connection.close();
}

Additional context

This is the result of retrieving the inserting rows from the table:

[
{ id: 1, textValue: 'row 1', numValue: 1 },
{ id: 2, textValue: null, numValue: null },
{ id: 3, textValue: 'row 3', numValue: null }
]

Lenguaje dominante
JavaScript
Estrellas
159
Forks
92
Merge medio
5 h 59 min
PR fusionados (30 d)
3

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de IBM/node-odbc

Todos los issues de IBM/node-odbc

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.