Skip to content

Instantly share code, notes, and snippets.

@AsaAyers
Created March 30, 2012 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsaAyers/2255412 to your computer and use it in GitHub Desktop.
Save AsaAyers/2255412 to your computer and use it in GitHub Desktop.
nodejs-mysql-native Issue 62 test
// To run this you'll have to change the db.auth, but the rest should run without modification.
"use strict";
var create_query = "create temporary table test (`id` int(11) NOT NULL AUTO_INCREMENT, StringA varchar(255) NOT
NULL, BoolA tinyint(1) NOT NULL, StringB varchar(255) NOT NULL, BoolB tinyint(1) NOT NULL, PRIMARY KEY (`id`))";
var db = require("mysql-native").createTCPClient(); // localhost:3306 by default
db.auto_prepare = true;
db.auth("wko", "root", "");
var test_data = {
"INSERT INTO test (StringA, BoolA, StringB, BoolB) VALUES (?, ?, ?, ?); -- false test": [
'Once a boolean is encountered all following columns get the same value (BoolA is false)',
false,
'Broken String B',
true,
],
"INSERT INTO test (StringA, BoolA, StringB, BoolB) VALUES (?, ?, ?, ?); -- true test": [
'Once a boolean is encountered all following columns get the same value (BoolA is true',
true,
'Broken String B',
false,
],
"INSERT INTO test (StringA, StringB, BoolA, BoolB) VALUES (?, ?, ?, ?)": [
// I'm including this because it was the first *almost* solution I found.
'By reordering my strings I can keep them, but BoolB should be true here',
'Broken String B',
false,
true,
],
"INSERT INTO test (BoolA, BoolB, StringA, StringB) VALUES (?, ?, ?, ?)": [
false ? 1 : 0,
true ? 1 : 0,
'If all of the booleans are converted to 1 or 0 before being passed to execute you get all of the correct values',
'Broken String B',
],
}
function displayResults()
{
db.execute("Select * from test")
.on('row',function(row){
console.log(row);
})
.on('end', function(){ db.close() });
}
db.execute(create_query).on('end', function(){
var completed = 0;
var total = 0;
for (var query in test_data)
{
total++;
}
for (var query in test_data)
{
db.execute(query, test_data[query])
.on('end', function(){
if (++completed == total)
{
displayResults();
}
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment