title: nodejs mysql amazing row duplicates
body: <p>I have problem for node.js.</p>
  
  <p>I read data for socket, using <code>dgram.createSocket('udp4')</code>.
  I parse data and write to mysql db (use <a href="https://npmjs.org/package/mysql" rel="nofollow">https://npmjs.org/package/mysql</a>) with code:</p>
  
  <pre><code>var result = {
                    CarID: "0094455",
                    Lat: 55.0405,
                    Lon: 82.981,
                    Time: 1373435075
  };
  connectionPool.getConnection(function(err, connection) {
       connection.query('SELECT * FROM lastPosition WHERE CarID = ? ORDER BY Time DESC LIMIT 1',[result.CarID], 
              function(err, rows, fields) {
            if (rows.length) {
              connection.query('UPDATE lastPosition SET ? WHERE CarID = ?', [result, result.CarID]);
            } else {
              connection.query('INSERT INTO lastPosition SET ?', result);
           }
          });
       connection.end();
  });
  </code></pre>
  
  <p>The problem is that I see row duplicates in "lastPosition" table for key CarID, although this excludes the code. Where did I go wrong?</p>