Changeset: 276f3da3ae88 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=276f3da3ae88
Modified Files:
clients/nodejs/Tests/nodetest.js
clients/nodejs/monetdb/mapiclient.js
Branch: default
Log Message:
Extended nodejs client with an optional logging callback
diffs (65 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
@@ -87,8 +87,20 @@ conn.query('SELECT id from tables where
['connections', 0, false], function(err, res) {
assert.equal(null, err);
assert(res.rows > 0);
+});
-});
+/* Try the log callback functionality */
+var nr_log_callbacks = 0;
+conn.log_callback = function(message, error, result) {
+ assert(message); // message must contain something
+ ++nr_log_callbacks;
+}
+conn.query('SELECT id FROM tables WHERE name=? AND type=? AND readonly=?',
+ ['connections', 0, false], function(err, res) {
+ assert.equal(null, err);
+ assert(nr_log_callbacks > 0);
+ conn.log_callback = null;
+});
/* some quoting fun, jesus */
conn.query("SELECT '\\\\asdf','\"', '\\\"', '\\\\\"', '\\''", function(err,
res) {
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
@@ -8,7 +8,7 @@ function MonetDBConnection(options, conn
this.read_leftover = 0;
this.read_final = false;
this.read_str = '';
- this.read_callback = undefined;
+ this.cur_op = undefined; // object { message (str), callback (fn)}
this.conn_callback = conncallback;
this.mapi_blocksize = 8192;
this.do_close = false;
@@ -223,11 +223,14 @@ function handle_message(message) {
if (message.charAt(0) == '&') {
response = _parseresponse(message);
}
-
- if (this.read_callback != undefined) {
- this.read_callback(error, response);
- this.read_callback = undefined;
+ if(typeof(this.log_callback) == "function") {
+ this.log_callback(this.cur_op.message, error, response);
}
+ if (this.cur_op.callback != undefined) {
+ this.cur_op.callback(error, response);
+ this.cur_op.callback = undefined;
+ }
+ this.cur_op.message = undefined;
next_op.call(this);
}
@@ -243,7 +246,7 @@ function next_op() {
var op = this.queryqueue.shift();
send_message.call(this, op.message);
- this.read_callback = op.callback;
+ this.cur_op = op;
}
function cleanup() {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list