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

TypeError: Cannot read properties of undefined (reading '0') : Inserting rows with batch. #258

Closed
markddrake opened this issue Nov 4, 2023 · 5 comments

Comments

@markddrake
Copy link

markddrake commented Nov 4, 2023

Uploading ONLINE_MEDIA.zip…
Running the following code

"use strict"
import mariadb from 'mariadb';
import fs from 'fs';

async function main() {

    const connectionDetails = {
            host      : "yadamu-db2"
           ,user      : "root"
           ,password  : "oracle"
           ,port      : 3307
           ,database  : "mysql"
           ,multipleStatements: true
           ,typeCast:true
		   ,bigNumberStrings:true
		   ,dateStrings:true
		   ,rowsAsArray:true}
    
  let results;
    
  try {
    
    const pool = mariadb.createPool(connectionDetails);
    const conn = await pool.getConnection();
    results = await conn.query(`SET AUTOCOMMIT = 0, TIME_ZONE = '+00:00',SESSION INTERACTIVE_TIMEOUT = 600000, WAIT_TIMEOUT = 600000, SQL_MODE='ANSI_QUOTES,PAD_CHAR_TO_FULL_LENGTH', GROUP_CONCAT_MAX_LEN = 1024000, GLOBAL LOCAL_INFILE = 'ON';`);
    results = await conn.query(`drop schema if exists "PM";`);    
    results = await conn.query(`create schema "PM";`);    
	
	
    results = await conn.query(`USE "PM"`);    
    results = await conn.query(`create table  if not exists "PM"."ONLINE_MEDIA"("PRODUCT_ID" decimal(6) ,"PRODUCT_PHOTO" longtext ,"PRODUCT_PHOTO_SIGNATURE" longtext ,"PRODUCT_THUMBNAIL" longtext ,"PRODUCT_VIDEO" longtext ,"PRODUCT_AUDIO" longtext ,"PRODUCT_TEXT" longtext ,"PRODUCT_TESTIMONIALS" longtext )`);

    const testData = fs.readFileSync('ONLINE_MEDIA.json');
	const data = JSON.parse(testData)
	console.log('ROWS',data.length)
	
	const sql = `insert into "PM"."ONLINE_MEDIA" ("PRODUCT_ID","PRODUCT_PHOTO","PRODUCT_PHOTO_SIGNATURE","PRODUCT_THUMBNAIL","PRODUCT_VIDEO","PRODUCT_AUDIO","PRODUCT_TEXT","PRODUCT_TESTIMONIALS") values  (?,?,?,?,?,?,?,?)`
	
    try {
		
	  results = await conn.beginTransaction()
	  results = await conn.query(`SAVEPOINT YADAMU_INSERT; `)
      results = await conn.batch(sql,data);
	  results = await conn.commit()
    } catch (e) {
      console.log(e)
    } 

   conn.end()
   pool.end();
 } catch(e) {
   console.log(e);
 }
}

main().then(() => {console.log("Success")}).catch((e) => {console.log(e)}

Results in the following error

C:\Development\YADAMU\src\scratch\mariadb>node batchIssue.js
9
TypeError: Cannot read properties of undefined (reading '0')
    at BatchBulk.sendComStmtBulkExecute (C:\Development\YADAMU\src\node_modules\mariadb\lib\cmd\batch-bulk.js:261:32)
    at BatchBulk.start (C:\Development\YADAMU\src\node_modules\mariadb\lib\cmd\batch-bulk.js:61:10)
    at Connection.addCommandEnablePipeline (C:\Development\YADAMU\src\node_modules\mariadb\lib\connection.js:1087:11)
    at Connection.executeBulkPromise (C:\Development\YADAMU\src\node_modules\mariadb\lib\connection.js:286:10)
    at new Promise (<anonymous>)
    at C:\Development\YADAMU\src\node_modules\mariadb\lib\connection.js:210:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async main (file:///C:/Development/YADAMU/src/scratch/mariadb/batchIssue.js:43:17)
Success

Environment


C:\Development\YADAMU\src\scratch\mariadb>node -v
v20.7.0

C:\Development\YADAMU\src\scratch\mariadb>npm ls
yadamu@1.0.0 C:\Development\YADAMU\src
+-- @aws-sdk/client-s3@3.441.0
+-- @aws-sdk/lib-storage@3.441.0
+-- @azure/storage-blob@12.16.0
+-- @electron/remote@2.0.12
+-- bootstrap-icons@1.11.1
+-- bootstrap@5.3.2
+-- cookie-parser@1.4.6
+-- csv-parser@3.0.0
+-- electron-packager@17.1.2
+-- electron@27.0.2
+-- express-session@1.17.3
+-- express@4.18.2
+-- font-awesome@4.7.0
+-- ibm_db_electron@npm:ibm_db@3.2.2
+-- ibm_db@3.2.2
+-- install@0.13.0
+-- jquery@3.7.1
+-- mariadb@3.2.2
+-- mime-types@2.1.35
+-- mongodb@6.2.0
+-- mssql@10.0.1
+-- mysql@2.18.1
+-- npm@10.2.1
+-- oracledb@6.2.0
+-- pg-copy-streams@6.0.6
+-- pg-query-stream@4.5.3
+-- pg@8.11.3
+-- readable-stream@4.4.2
+-- snowflake-sdk@1.9.0
+-- uuid@9.0.1
`-- wkx@0.5.0


C:\Development\YADAMU\src\scratch\mariadb>

testdata attached in ZIP format

@markddrake
Copy link
Author

I suspect that this could be related to the length of the strings being uploaded.

@rusher
Copy link
Collaborator

rusher commented Nov 7, 2023

Connectors is normally sending a proper error message when not having all expected value parameters, but that's not the case here, resulting in the error you have.
Could you please send the ONLINE_MEDIA.json / zip (link is empty in issue) ?

@markddrake
Copy link
Author

ONLINE_MEDIA.zip
Done

rusher added a commit that referenced this issue Nov 30, 2023
@rusher
Copy link
Collaborator

rusher commented Nov 30, 2023

Thanks for reproductive case. This will be corrected with next version (3.2.3)

@rusher rusher closed this as completed Nov 30, 2023
@markddrake
Copy link
Author

@rusher : Finally got around to testing this fix and it solved the issue - thanks. However further testing resulted in 3 new (and probably related) issues. Would appreciate it if you could take a look. #272, #273 & #274.

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