A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://sidorares.github.io/node-mysql2/docs/documentation/prepared-statements below:

Prepared Statements | Quickstart

Prepared Statements Automatic creation, cached and re-used by connection

Similar to connection.query().

connection.execute('select 1 + ? + ? as result', [5, 6], (err, rows) => {


});


connection.unprepare('select 1 + ? + ? as result');

Note that connection.execute() will cache the prepared statement for better performance, remove the cache with connection.unprepare() when you're done.

Manual prepare / execute

Manually prepared statements doesn't comes with LRU cache and SHOULD be closed using statement.close() instead of connection.unprepare().

connection.prepare('select ? + ? as tests', (err, statement) => {





statement.execute([1, 2], (err, rows, columns) => {

});



statement.close();
});

Note that you should not use statement after connection reset (changeUser() or disconnect). Statement scope is connection, you need to prepare statement for each new connection in order to use it.

Configuration

maxPreparedStatements : We keep the cached statements in a lru-cache. Default size is 16000 but you can use this option to override it. Any statements that are dropped from cache will be closed.

Serialization of bind parameters

The bind parameter values passed to execute are serialized JS -> MySQL as:

Passing in undefined or a function will result in an error.

Prepared Statements Helper

MySQL2 provides execute helper which will prepare and query the statement. You can also manually prepare / unprepare statement with prepare / unprepare methods.

connection.execute(
'select ?+1 as qqq, ? as rrr, ? as yyy',
[1, null, 3],
(err, rows, fields) => {
console.log(err, rows, fields);
connection.execute(
'select ?+1 as qqq, ? as rrr, ? as yyy',
[3, null, 3],
(err, rows, fields) => {
console.log(err, rows, fields);
connection.unprepare('select ?+1 as qqq, ? as rrr, ? as yyy');
connection.execute(
'select ?+1 as qqq, ? as rrr, ? as yyy',
[3, null, 3],
(err, rows, fields) => {
console.log(err, rows, fields);
}
);
}
);
}
);
Examples

For Prepared Statements examples, please see here.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4