mariano / node-db-mysql

MySQL database bindings for Node.js
http://nodejsdb.org
150 stars 30 forks source link

Empty error in execute callback #30

Open nickiv opened 13 years ago

nickiv commented 13 years ago

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?

ixti commented 12 years ago

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...