Changeset: 1e2d2b994490 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1e2d2b994490
Modified Files:
        clients/nodejs/Tests/nodetest.js
        clients/nodejs/monetdb/README
        clients/nodejs/monetdb/mapiclient.js
        clients/nodejs/monetdb/package.json
Branch: default
Log Message:

Node.JS connector: Prepared statements and deadlock fix


diffs (162 lines):

diff --git a/clients/nodejs/Tests/nodetest.js b/clients/nodejs/Tests/nodetest.js
--- a/clients/nodejs/Tests/nodetest.js
+++ b/clients/nodejs/Tests/nodetest.js
@@ -20,6 +20,7 @@ monetdb.connect({dbname:dbname, user:'no
 /* now actually connect */
 var conn = monetdb.connect({dbname:dbname, port:dbport, debug: false}, 
function(err) {
        assert.equal(null, err);
+       assert.equal(conn.env.gdk_dbname, dbname);
 });
 
 
diff --git a/clients/nodejs/monetdb/README b/clients/nodejs/monetdb/README
--- a/clients/nodejs/monetdb/README
+++ b/clients/nodejs/monetdb/README
@@ -2,7 +2,15 @@ This package connects node.js and MonetD
 
 Example usage:
 
-var conn = require('../monetdb').connect({'dbname':'mydb'} , function(err) {
+var options = {
+       host     : 'localhost', 
+       port     : 50000, 
+       dbname   : 'mydb', 
+       user     : 'monetdb', 
+       password : 'monetdb'
+};
+
+var conn = require('monetdb').connect(options , function(err) {
        if (!err) console.log('connected');
 });
 
@@ -15,4 +23,4 @@ conn.query('SELECT id FROM tables WHERE 
        if (!err) console.log(res);
 });
 
-conn.close()
\ No newline at end of file
+conn.close();
diff --git a/clients/nodejs/monetdb/mapiclient.js 
b/clients/nodejs/monetdb/mapiclient.js
--- a/clients/nodejs/monetdb/mapiclient.js
+++ b/clients/nodejs/monetdb/mapiclient.js
@@ -12,6 +12,7 @@ function MonetDBConnection(options, conn
        this.conn_callback = conncallback;
        this.mapi_blocksize = 8192;
        this.do_close = false;
+       this.alldone = false;
 
        this.queryqueue = [];
        var thizz = this;
@@ -40,7 +41,7 @@ function MonetDBConnection(options, conn
                }
                thizz.env = {};
                resp.data.forEach(function(l) { 
-                       thizz.env[l.name] = l.value;
+                       thizz.env[l[resp.col.name]] = l[resp.col.value];
                 });
        });
        this.request('SELECT 42', function(x) {
@@ -52,7 +53,6 @@ function MonetDBConnection(options, conn
 MonetDBConnection.prototype.request = 
 MonetDBConnection.prototype.query = function() {
        var message = arguments[0];
-
        var params = [];
        var callback = undefined;
        var raw = false;
@@ -101,6 +101,11 @@ MonetDBConnection.prototype.query = func
                        message = 's' + message + ';';
                }
                this.queryqueue.push({'message' : message , 'callback' : 
callback});
+               /* if no other queries are still running, we need to call 
next_op to send it */
+               if (this.alldone) {
+                       this.alldone = false;
+                       next_op.call(this);
+               }
        }
        return this;
 }
@@ -112,17 +117,12 @@ MonetDBConnection.prototype.prepare = fu
        thizz.query(query, function(error, resp) {
                if (!error) {
                        var execfun = function(bindparams, ecallback) {
-                               /* the prepare response tells us how many 
parameters we need to bind */
-                               if (bindparams.length != resp.rows-1) {
-                                       ecallback('missing parameters');
-                                       return;
-                               }
                                var quoted = bindparams.map(function(param) {
                                        var type = typeof param;
                                        switch(type) {
                                                case 'boolean':
                                                case 'number':
-                                                       return ''+param;
+                                                       return '' + param;
                                                        break
                                                case 'string':
                                                /* escape single quotes except 
if they are already escaped */
@@ -142,7 +142,7 @@ MonetDBConnection.prototype.prepare = fu
                                thizz.query('Xrelease ' + resp.queryid, 
undefined, true);
                        }
 
-                       callback(null, {'message' : 'ok', 'prepare' :  resp, 
'exec' : execfun, 'release' : releasefun});
+                       callback(null, {'prepare' :  resp, 'exec' : execfun, 
'release' : releasefun});
                }
                else {
                        callback(error);
@@ -151,7 +151,6 @@ MonetDBConnection.prototype.prepare = fu
        return this;
 }
 
-/* we need to wait till everything is done before we close the socket */
 MonetDBConnection.prototype.disconnect = 
 MonetDBConnection.prototype.close = function() {
        this.do_close = true;
@@ -164,7 +163,7 @@ exports.connect = exports.open = functio
 
 function handle_message(message) {
        if (this.options.debug)
-               console.log('RX ['+this.state+']: '+message);
+               console.log('RX ['+this.state+']: ' + message);
 
        /* prompt, good */
        if (message == '') {
@@ -203,7 +202,7 @@ function handle_message(message) {
 
        /* error message */
        if (message.charAt(0) == '!') {
-               error = message.substring(1,message.length-1);
+               error = message.substring(1, message.length - 1);
        }
 
        /* query result */
@@ -221,6 +220,7 @@ function handle_message(message) {
 
 function next_op() {
        if (this.queryqueue.length < 1) {
+               this.alldone = true;
                if (this.do_close) {
                        this.socket.destroy();
                }
@@ -455,5 +455,3 @@ function __get_connect_args(options) {
        __check_arg(options, 'debug'   , 'boolean', false);
   return options;
 }
-
-
diff --git a/clients/nodejs/monetdb/package.json 
b/clients/nodejs/monetdb/package.json
--- a/clients/nodejs/monetdb/package.json
+++ b/clients/nodejs/monetdb/package.json
@@ -1,10 +1,10 @@
 {
   "name": "monetdb",
-  "version": "0.1.1",
+  "version": "0.1.5",
   "description": "Connect MonetDB and node.js",
   "main": "mapiclient.js",
   "author": "Hannes Mühleisen <[email protected]>",
   "license": "MonetDB License, https://www.monetdb.org/Legal/MonetDBLicense";,
-  "repository" : { "type" : "hg"  , "url" : 
"http://dev.monetdb.org/hg/MonetDB/"},
+  "repository" : { "type" : "hg", "url" : 
"http://dev.monetdb.org/hg/MonetDB/"},
   "bugs": { "url": "https://www.monetdb.org/bugzilla/"}
 }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to