Uploaded image for project: 'MariaDB Connector/node.js'
  1. MariaDB Connector/node.js
  2. CONJS-189

connector doesn't seem to support multi statements.

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None
    • node => v16.13.1
      "express": "^4.17.2",
      "joi": "^17.6.0",
      "mariadb": "^2.5.5",

    Description

      We use stored procedures for everything. We also use sequences and want to return the sequence number back from the stored procedure as an out parameter. We still haven't gotten to select statements yet in our prototype work, but that is beginning to scare me too. I am new to JavaScript, so it could be me making a newbie mistake with promises. Here is my route.

      authProcRoutes.post('/userinvite', async (req, res, next) => {
          let conn;
          let emailSent = false;
       
          console.log(req.body);
       
          try {
              // validate input 
              const inputValidated = await validateUserInviteInput(req.body); 
              if (typeof inputValidated === 'string' || inputValidated instanceof String) {
                  return res.status(400).send((inputValidated)); 
              }
       
              // process security settings
              const exprDateTimeUTC = new Date(getDatePlus(48).toUTCString());
              const userPWResetExpr = exprDateTimeUTC.toISOString().replace('Z','').replace('T', ' ');
              const userPWResetToken = await hashPassword(userPWResetExpr + req.body.userEmail);
       
              // connect to database
              const mdbpool = getPool();
              conn = await mdbpool.getConnection();
              console.log("connected ! connection id is " + conn.threadId);
       
              const dbResponse = await conn.query(
                  'CALL auth_user_P__userinvite_sp(?,?,?,?,?,?,?,?,?,@NewRcrdID); SELECT @NewRcrdID;', [
                      req.body.customerID,  
                      req.body.userEmail, 
                      req.body.userFirstName, 
                      req.body.userLastName, 
                      userPWResetToken,
                      userPWResetExpr,
                      req.body.userType,
                      req.body.userSummary,
                      req.body.userRequesterID 
                  ]
              );
          
       
              console.log(dbResponse);
              const dbrSQL1 = dbResponse[0];
              const dbrOkPacket = dbResponse[1];
              const dbrSQL2 = dbResponse[2];
              const resObject = dbrSQL2[0]; 
              console.log(dbrSQL1);
              console.log(dbrOkPacket);
              console.log(dbrSQL2);
              console.log(resObject['@NewRcrdID']);
       
              if (dbResponse[1].affectedRows > 1) {
                  // emailSent = code to send email 
       
              };  
       
              if (conn) conn.end();
              console.log('conn.end()');
              res.send('Invite sent to ' + req.body.userFirstName);
          } catch (err) {
              if (conn) conn.end();
              console.error("Catch Block: ", err);
              res.status(500).send('Error: ' + err.text);
          }
      });
      

      And I get this as my result from my console.log deconstruction of the dbResponse object:
      There has to be a better way to get to the data vs what I have in my function. I can't imagine doing this kind of stuff for 100 rows of data vs one out param.
      [
      [

      { '@NewRcrdID': null }

      , meta: [ [ColumnDef] ] ],
      OkPacket

      { affectedRows: 2, insertId: 0, warningStatus: 0 }

      ,
      [

      { '@NewRcrdID': 10014 }

      , meta: [ [ColumnDef] ] ]
      ]
      [

      { '@NewRcrdID': null }

      ,
      meta: [
      ColumnDef

      { _parse: [StringParser], collation: [Collation], columnLength: 16777216, columnType: 251, flags: 128, scale: 39, type: 'LONG_BLOB' }

      ]
      ]
      OkPacket

      { affectedRows: 2, insertId: 0, warningStatus: 0 }

      [

      { '@NewRcrdID': 10014 }

      ,
      meta: [
      ColumnDef

      { _parse: [StringParser], collation: [Collation], columnLength: 20, columnType: 8, flags: 128, scale: 0, type: 'LONGLONG' }

      ]
      ]
      10014

      Attachments

        Activity

          No workflow transitions have been executed yet.

          People

            diego dupin Diego Dupin
            1222tmiller Tom Miller
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.