Skip to content

Instantly share code, notes, and snippets.

@sidorares
Last active December 22, 2015 23:18
Show Gist options
  • Save sidorares/6545549 to your computer and use it in GitHub Desktop.
Save sidorares/6545549 to your computer and use it in GitHub Desktop.
SELECT IN / NOT IN + prepared statements test
mysql> select * from insert_test limit 10;
+----+--------------+
| id | title |
+----+--------------+
| 1 | test abc xyz |
| 2 | test abc xyz |
| 3 | test abc xyz |
| 4 | test abc xyz |
| 5 | test abc xyz |
| 6 | test abc xyz |
| 7 | test abc xyz |
| 8 | test abc xyz |
| 9 | test abc xyz |
| 10 | test abc xyz |
+----+--------------+
var mysql = require('../test/common').createConnection();
mysql.execute("select * from insert_test where id not in (?, ?, ?, ?) limit 10", [1, 2, 3, 4], function(err, rows, fields) {
console.log(rows, fields);
});
mysql.execute("select * from insert_test where id in (?, ?, ?, ?) limit 10", [1, 2, 3, 4], function(err, rows, fields) {
console.log(rows, fields);
});
examples git:master ❯ node simple-select.js ✹
[ { id: 1, title: 'test abc xyz' },
{ id: 2, title: 'test abc xyz' },
{ id: 3, title: 'test abc xyz' },
{ id: 4, title: 'test abc xyz' } ] [ { catalog: 'def',
schema: 'test',
table: 'insert_test',
orgTable: 'insert_test',
name: 'id',
orgName: 'id',
characterSet: 63,
columnLength: 11,
columnType: 3,
flags: 16931,
decimals: 0 },
{ catalog: 'def',
schema: 'test',
table: 'insert_test',
orgTable: 'insert_test',
name: 'title',
orgName: 'title',
characterSet: 33,
columnLength: 765,
columnType: 253,
flags: 4097,
decimals: 0 } ]
[ { id: 5, title: 'test abc xyz' },
{ id: 6, title: 'test abc xyz' },
{ id: 7, title: 'test abc xyz' },
{ id: 8, title: 'test abc xyz' },
{ id: 9, title: 'test abc xyz' },
{ id: 10, title: 'test abc xyz' },
{ id: 11, title: 'test abc xyz' },
{ id: 12, title: 'test abc xyz' },
{ id: 13, title: 'test abc xyz' },
{ id: 14, title: 'test abc xyz' } ] [ { catalog: 'def',
schema: 'test',
table: 'insert_test',
orgTable: 'insert_test',
name: 'id',
orgName: 'id',
characterSet: 63,
columnLength: 11,
columnType: 3,
flags: 16931,
decimals: 0 },
{ catalog: 'def',
schema: 'test',
table: 'insert_test',
orgTable: 'insert_test',
name: 'title',
orgName: 'title',
characterSet: 33,
columnLength: 765,
columnType: 253,
flags: 4097,
decimals: 0 } ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment