"use strict";

var sqlite = require('sqlite3'),
    logger = require('./logging'),
    db;

function openDatabase(callback){
  if(!db){
    db = new sqlite.Database('machines.db',function(oerr){
      if (oerr){
        logger.error("Could not open database ", oerr);
        callback(oerr);
      }
      db.exec(
        'CREATE TABLE IF NOT EXISTS address (mac CHARACTER(17), machine VARCHAR(50) PRIMARY KEY)',
        callback);
    });
  }
  else
    callback();
}

exports.close = function(callback){
  if (db)
    db.close(callback);
};

exports.address = function(name,a,b){
  var callback = typeof(a) === 'function' ? a : b;
  openDatabase(function(err){
    if (typeof(a) === 'function'){
      logger.info('Selecting mac for ' + name);
      db.get('SELECT mac FROM address WHERE machine = ?',[name],
        function(error,row){
          callback(error,row ? row.mac : row);
        });
    }
    else {
      logger.info('Saving mac ' + a + ' for ' + name);
      db.run('REPLACE INTO address(mac,machine) VALUES (?,?)',
        a,name,
        callback);
    }
  });
};

exports.list = function(callback){
  openDatabase(function(err){
    if (err)
      callback(err);
    else
      db.all('SELECT * FROM address',callback);
  });
};

@@ -72,24 +72,142 @@
 /logging'),%0A
+    path = require('path'),%0A    dbpath = path.resolve(path.dirname(require('clipp').parse().script),'./machines.db'),%0A
     db;%0A%0Afun
@@ -280,21 +280,14 @@
 ase(
-'machines.db'
+dbpath
 ,fun

Use absolute Path for machines.db