sql server - Node.js MySQL mass insert operation fails -


below code mass insert mysql db

connectionpool.getconnection(function(err, connection){         if(err) {             winston.log('info', '------- error while getting connection: ' + err.message);             connection.release();             return;         }          connection.query('insert polloptions (idpolloption, option, pollid) values ?', [polloptionsarray], function(err, rows){             if(err) {                 winston.info('info', '----------------------- error: ' + err);                 connection.release();                 return;             }             connection.release();         });     }); 

where polloptionsarray is

[   ["pope1lrkxmy9q","adam","poll4yrfxzkcx"],   ["popvy-stxgjcm","mike","poll4yrfxzkcx"],["popnkmsfmgy97","lucy","poll4yrfxzkcx"] ] 

the database table has following columns

idpolloption, option, pollid (all varchar)

it gives me following error:

error: error: er_parse_error: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'option, pollid) values ('pope1lrkxmy9q', 'adam', 'poll4yrfxzkcx'), ('popvy-stxgj' @ line 1

i tried hardcode sql input this:

var temp = [         ['123', 'demian@gmail.com', 'pollvjsbgijyq'],         ['345', 'john@gmail.com', 'pollvjsbgijyq'],         ['567', 'mark@gmail.com', 'pollvjsbgijyq'],         ['678', 'pete@gmail.com', 'pollvjsbgijyq']     ]; 

but still gives me same error. don't understand doing wrong. sql syntax incorrect @ values remedy?

i tried remove '[]' in polloptionsarray , gives me same error.

any idea going on here?

try put `` around each column name , table name this:

 connection.query('insert `polloptions` (`idpolloption`, `option`, `pollid`) values ?', [polloptionsarray], function(err, rows) 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -