Empty error in execute callback #30

Open
nickiv opened this Issue Sep 1, 2011 · 1 comment

Projects

None yet

3 participants

@nickiv
nickiv commented Sep 1, 2011

Sample code:


var mysql = require('db-mysql');
var db = new mysql.Database({
    hostname: '192.168.100.10',
    user: 'root',
    password: '11',
    database: 'db1'
});
db.connect(function(err){
    if (err){
        throw err;
    }
    db.query('SET names utf8').execute(function(err){
        if (err){
            throw err;
        }
        ['proc1', 'proc2', 'proc3', 'proc4', 'proc5'].forEach(function(sp_name){
            db.query('SHOW CREATE PROCEDURE ' + sp_name + '_backup').execute(function(err, rows){
                console.log(sp_name);
                if (err){
                    console.log(err);
                } else {
                    console.log(rows);
                }
            });
        });
    });
});

There is no procedures in database.
Executing this script rarely produces same output.
Sometimes err parameter in callback is empty and rows is undefined!

Is it bug, or I should execute queries sequentally?

@mariano mariano was assigned Oct 23, 2011
@ixti
ixti commented Nov 17, 2011

I have similar (I believe) problem.

var db = new mysql.Database({
    hostname: 'localhost',
    user: 'ixti',
    password: '',
    database: 'ixti'
});

function getDb(callback) {
    if (db.isConnected()) {
      callback(null, db);
      return;
    }

    db.connect(function (err, server) {
      if (err) {
        // I ASSUME WITH WRONG CREDENTIALS IT SHOULD ALWAYS FIRE THIS CALLBACK
        callback(err);
        return;
      }

      if (db.isConnected()) {
        callback(null, db);
        return;
      }

      // THIS SHOULD NEVER HAPPEN, BUT IT DOES
      callback(new Error("Database not connected"));
    });
}

according to the snippet above, if I provide invalid credentials of db, I got my error at about 50% of times and 50% error that should be...

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