title: Js mysql query not using boolean value given with GET request
body: <p>I'm trying to search the <strong>MySQL</strong> database for <em>active</em> or <em>inactive</em> users that have the value isActive, the idea is that a <strong>GET request</strong> is sent with either <code>isActive=true</code> or <code>isActive=false</code> and all users that are active or inactive will be sent in the response. The problem is that the <code>isActive</code> value is not being used, I can only get it to work by hardcoding it into the SQL query.</p>
  <p>When I send a request with the <code>firstName</code> value defined it does work, so I think it might have to do with the <code>isActive</code> being a <code>boolean</code> and not converting correctly but I have not been able to fix that.</p>
  <p>Also, I'm using <strong>MySQL2</strong> for the database.</p>
  <p>Any help would be greatly appreciated.</p>
  <pre><code>    getUsers: (req, res, next) =&gt; {
          const queryParams = req.query
          logger.debug(queryParams)
  
          let { firstName, isActive } = req.query
          
          let queryString = 'SELECT * FROM `user`'
          if (firstName || isActive) {
              queryString += ' WHERE '
              if (firstName) {
                  queryString += '`firstName` LIKE ?'
                  firstName = '%' + firstName + '%'
              }
              if (firstName &amp;&amp; isActive) queryString += ' AND '
              if (isActive) {
                  queryString += '`isActive` = ?'
              }
          }
          queryString += ';'
          logger.debug(`queryString = ${queryString}`)
  
          dbconnection.getConnection(function (err, connection) {
              if (err) next(err) // not connected!
  
              // Use the connection
              connection.query(queryString, [firstName, isActive], function (error, results) {
                      // When done with the connection, release it.
                      connection.release()
  
                      // Handle error after the release.
                      if (error) next(error)
  
                      // Don't use the connection here, it has been returned to the pool.
                      logger.debug('#results = ', results.length)
                      res.status(200).json({
                          status: 200,
                          results: results,
                      })
                  }
              )
          })
      },
  </code></pre>
  <p>Here are the logs of when I call the <strong>GET method</strong>:</p>
  <pre><code>2022-05-20T14:16:12Z [DEBUG] user.controller.js:66 : { isActive: 'false' }
  2022-05-20T14:16:12Z [DEBUG] user.controller.js:83 : queryString = SELECT * FROM `user` WHERE `isActive` = ?;
  2022-05-20T14:16:13Z [DEBUG] dbconnection.js:23 : Connected to database '2186751'
  2022-05-20T14:16:13Z [DEBUG] dbconnection.js:27 : Connection 46 acquired
  2022-05-20T14:16:13Z [DEBUG] dbconnection.js:31 : Connection 46 released
  2022-05-20T14:16:13Z [DEBUG] user.controller.js:97 : #results =  0
  </code></pre>
  <p>What the <code>firstName</code> and <code>isActive</code> are defined as in the <strong>MySQL</strong> database:</p>
  <pre><code>  `firstName` varchar(255) NOT NULL,
    `isActive` tinyint NOT NULL DEFAULT '1',
  </code></pre>