ibmdb / node-ibm_db

IBM DB2 and IBM Informix bindings for node
MIT License
188 stars 151 forks source link

Batch insert truncating email data post successful run #917

Closed sagarcasm closed 1 year ago

sagarcasm commented 1 year ago

Steps to Reproduce:

I am using bulk data uploads to the Table which has 2 email columns - after successfully running the scrip with 10 records I noticed that the email get truncated after they are inserted in the table.

Below is the table DDL

create table schema.table (
   AUTO_ID integer not null GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1),
   EMAIL1 VARCHAR(1000 CODEUNITS32) NOT NULL , //tried octets too
EMAIL2 VARCHAR(1000 CODEUNITS32) NOT NULL
   PRIMARY KEY (EMAIL1),
..........
);

I am using the below code to add the bulk data with parameterized query

stmt = this.db2conn.prepareSync(sql);
await stmt.bindSync(data);
stmt.setAttrSync(ibmdb.SQL_ATTR_PARAMSET_SIZE, size);
result = await stmt.executeSync();

I tried a simple insert but later also switched to insert by casting to VARCHAR

const insertQuery = `INSERT INTO schema.table
(EMAIL1, EMAIL2)
VALUES(CAST (? AS VARCHAR),CAST (? AS VARCHAR))`;

Below is how the insert array looks like

[
  {
    ParamType: 'ARRAY',
    DataType: 'VARCHAR',
    Data: [
      email,email2
    ]
  },
  {
    ParamType: 'ARRAY',
    DataType: 'VARCHAR',
    Data: [
     email,email2
    ]
  },

Below is how the data gets inserted

Screenshot 2023-04-19 at 3 43 24 PM

This issue happens for both email fields, can you help me understand what should the email columns be cast as? while printing the data before await stmt.bindSync(data); I get all the values appropriately but post insert when I check the db they are truncated from the right.

bimalkjha commented 1 year ago

@sagarcasm Use Length:50 key in your param as used here: https://github.com/ibmdb/node-ibm_db/blob/master/test/test-array-insert.js#L25 I see data as Data: [ email,email2 ] in your shared code, should it be Data: [ email1,email2 ]? Please share the contents of EMAIL1 and EMAIL2. Better to share small test.js file to repro the issue. Thanks.

bimalkjha commented 1 year ago

@sagarcasm Hope your issue get resolved by correcting the application code. Let us know otherwise. Closing the issue now. Thanks.