[CONJS-234] Result seems to have an extra blank row Created: 2023-01-02  Updated: 2023-01-23  Resolved: 2023-01-20

Status: Closed
Project: MariaDB Connector/node.js
Component/s: other
Affects Version/s: None
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Tom Miller Assignee: Diego Dupin
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Windows and Linux : 10.6.5 / 10.6.7
nodejs driver 3.0.2



 Description   

I do a select statement and loop through it, there always seems to be an extra blank row. So I have to check for the "key" to see if it is undefined, so my loop ignores the last row.

I hope I have my code right and you don't mean to have a blank row at the bottom.

dlog is a console.log thingy that runs (!production)

 
    const resultEmailAttachments = await mdbConn.query(
      "SELECT * FROM EM_EmailAttachments WHERE EmailID = ? ;", [data.EmailId]
    );
 
    // Build the array of attachments.
    const aAttachList = [];
    const emailAttchData = resultEmailAttachments;
    dlog("AttchData.length", emailAttchData.length);
    if (emailAttchData.length > 0) {
      for (var k in emailAttchData) {
       *{color:red} if (emailAttchData[k].AttachmentFileName) {{color}*
          let aFilePath = path.normalize(emailAttchData[k].AttachmentFileName);
          dlog("emailAttchData.aFilePath", aFilePath);
          let aFileName = path.basename(aFilePath);
          dlog("emailAttchData.aFileName", aFileName);
          let aAttachment = emailAttchData[k].Attachment;
          aAttachList.push({
            filename: aFileName,
            content: aAttachment,
            encoding: "base64",
          });
        }  
      }  dlog("Trace", "leave loop");
    }
}



 Comments   
Comment by Diego Dupin [ 2023-01-20 ]

Query result is an array with an additional meta property.

using "for (var k in emailAttchData)" meta property will be listed.

There are 2 solutions :

  • set option `metaEnumerable` to false. meta property will then not be enumerated
  • using expected behavior when iterating on array with 'of' keyword, like :

     for (const data of emailAttchData) {
           if (data.AttachmentFileName) {
              let aFilePath = path.normalize(data.AttachmentFileName);
    
    

hmm, metaEnumerable default to false already, it would seems you use an old version of connector, could you confirm ?

Generated at Thu Feb 08 03:23:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.