'use strict';
/*jslint unparam: true, indent:2, nomen: true, plusplus: true, vars: true */
var lexer = require('./lexer');

exports = module.exports = function (anyDB) {

  function wrapConnect(conn) {
    conn.real_query = conn.query;
    conn.query = function (text, params, callback) {
      if (typeof params === 'function') {
        callback = params;
        params = {};
      }
      try {
        var tokens = lexer.tokenize(text);
        var s = text, i = 0, p = [];
        tokens.forEach(function (token) {
          if (token[0] === 'VAR') {
            i = i + 1;
            if (conn.adapter.name === 'postgres') {
              s = s.replace(token[1], '$' + i);
            } else {
              s = s.replace(token[1], '?');
            }
            p.push(token[1].substr(1, token[1].length));
          }
        });
        var prm = [];
        p.forEach(function (col) {
          prm.push(params[col] || null);
        });
        return conn.real_query(s, prm, callback);
      } catch (e) {
        callback('not found script' + e);
      }
    };
    return conn;
  }

  return {
    createConnection: function (url) {
      return wrapConnect(anyDB.createConnection(url));
    },
    connect: function (url) {
      return wrapConnect(anyDB.createConnection(url));
    },
    createPool: function (url, prm) {
      return wrapConnect(anyDB.createPool(url, prm));
    }
  };
};
@@ -904,38 +904,207 @@
     
-prm.push(params%5Bcol%5D %7C%7C null);
+if (params%5Bcol%5D === undefined) %7B%0A            prm.push(null);%0A          %7D else if (params%5Bcol%5D === null) %7B%0A            prm.push(null);%0A          %7D else %7B%0A            prm.push(params%5Bcol%5D);%0A          %7D
 %0A   

fix mapping false value arguments