Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble updating rows in node-mysql
    primarykey
    data
    text
    <p>I've just started with node-mysql, and have created a database 'users'. I can select and create just fine, following instructions from the <a href="https://github.com/felixge/node-mysql" rel="nofollow noreferrer">repository</a>. The database currently has values</p> <pre><code>[ { id: 1, user_login: 'mwilson' }, { id: 2, user_login: 'newbie' } ] </code></pre> <p>and fields [id, user_login, user_nicename]. </p> <p>However when I run the update function to update the second user, my results show me that I have 1 row matched but 0 rows changed, and SELECT confirms that there was no update.</p> <p>My code:</p> <pre><code>connection.query('UPDATE users SET user_nicename = ? WHERE user_login = ?', ['New User','newbie'], function(err, results) { if(err) { console.log("Failed on query",err); } else { console.log(results); </code></pre> <p>Results:</p> <pre><code>{ fieldCount: 0, affectedRows: 1, insertId: 0, serverStatus: 34, warningCount: 0, message: '(Rows matched: 1 Changed: 0 Warnings: 0', protocol41: true, changedRows: 0 } </code></pre> <p>And after connection.query('SELECT id, user_login FROM users'):</p> <pre><code>[ { id: 1, user_login: 'mwilson' }, { id: 2, user_login: 'newbie' } ] </code></pre> <p>The closest other question I could find to mine is <a href="https://stackoverflow.com/questions/14992879/node-js-mysql-query-syntax-issues-update-where">Node.js mysql query syntax issues UPDATE WHERE</a>. My code follows the format given by the first answer; other attempts gave query errors. I also saw a post from someone that got this result when trying to increment a NULL field.</p> <p>If I use WHERE id = 2 I get the same error. My configuration parameters use an account I've given permissions to (GRANT ALL PRIVILEGES ON testdb.* TO 'dev'@'%' IDENTIFIED BY 'dev';)</p> <p>Any thoughts on how I can update my update?</p> <p>EDIT: To form the database I ran:</p> <pre><code>CREATE TABLE users( id int auto_increment primary key, user_login varchar(25), user_nicename varchar(75) ); </code></pre> <p>So by default the user fields aside from id are NULL.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload