Enable formatting nested arrays for bulk inserts #230

Closed
wants to merge 6 commits into
from

Conversation

Projects
None yet
6 participants
Contributor

demian85 commented Jun 20, 2012

I think this might be useful. Actually I need it right now...
I know its sintactic sugar, but it requires just a few extra lines of code.
You can do bulk inserts easily:

var mysql = require('node-mysql');
var conn = mysql.createConnection({
    ...
});

var sql = "INSERT INTO Test (name, email, n) VALUES ?";
var values = [
    ['demian', 'demian@gmail.com', 1],
    ['john', 'john@gmail.com', 2],
    ['mark', 'mark@gmail.com', 3],
    ['pete', 'pete@gmail.com', 4]
];
conn.query(sql, [values], function(err) {
    if (err) throw err;
    conn.end();
});
Collaborator

felixge commented Jun 25, 2012

Thanks, I'll need a little bit to catch up with this as I'm traveling a lot right now. So it may take me until after nodeconf (july 2-3) to merge this, but I'm generally open to the change and like that you included a test.

Contributor

demian85 commented Jul 10, 2012

I don't know is it's OK, but I keep merging your master branch with my fork because I'm using this module in production with bulk inserts. I hope you merge this request soon!

Collaborator

felixge commented Jul 24, 2012

Thanks, merged this patch in. Would be great if you could also add some documentation for this (as long as there are no docs, I will consider this feature experimental : ).

felixge closed this Jul 24, 2012

This should be merged fast until Chuck doesn't notice.

before Chuck notice it ;)

is it possible to do bulk insert with sp name , instead of using query !
see the bellow example !

what u have suggested --> var sql = "INSERT INTO Test (name, email, n) VALUES ?"; [this one works]

what i want to try --> var sql = 'CALL usp_InsertConnections_Insert (?)'; [ facing error with this]

when im tryng to do this , im facing this error --> ER_BAD_FIELD_ERROR

i have gone thru my code & mysql workbench several times , but i couldn't figure out where's the problem :( here is my code !

var mysql = require('node-mysql');
var conn = mysql.createConnection({
    ...
});

var sql =  'CALL usp_InsertConnections_Insert (?)' ;
var values = [
  ['wersfijkz' ,'demian', 'demian@gmail.com', 1], --> [ customerID, customerName, cusEmail , userID] 
    ['dfertiqx' ,'john', 'john@gmail.com', 2],
    ['axzpwuv' ,'mark', 'mark@gmail.com', 3],
    ['pmnsdfe' ,'pete', 'pete@gmail.com', 4]
];
conn.query(sql, [values], function(err) {
    if (err) throw err;
    conn.end();
});

when i execute this ....im getting !

[Error: ER_BAD_FIELD_ERROR: Unknown column 'CustomerID' in 'field list']
code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sqlState: '42S22',
index: 0 }

but i have created the table properly with the above mentioned fields :( ,

Can any1 help me out :/

Collaborator

dougwilson commented Jan 21, 2015

@weezyboyaxy as far as I know, it's impossible to use that syntax with stored procedure calls; a limitation of MySQL server itself.

woa thanx for clearing the doubt @dougwilson 👍

thanx alot....u saved my time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment