diff --git a/lib/postgres-pure.js b/lib/postgres-pure.js index 67b052c..c0e642f 100644 --- a/lib/postgres-pure.js +++ b/lib/postgres-pure.js @@ -262,7 +262,7 @@ function Connection(args) { if (queue.length === 0) { return; } var first = queue[0]; var code = String.fromCharCode(first[0]); - var length = first.int32Read(1) - 4; + var length = first.length >= 5 ? first.int32Read(1) - 4 : 0; // Make sure we have a whole message, TCP comes in chunks if (first.length < length + 5) { @@ -386,7 +386,8 @@ function Connection(args) { } }); events.addListener('CommandComplete', function (data) { - query_callback.call(this, null, results); + var tag = data.split (' '); + query_callback.call(this, null, results, tag.slice (1, tag.length)); }); conn.execute = function (sql/*, *parameters*/) { @@ -428,8 +429,8 @@ function Connection(args) { callback(); }}); } else { - query_queue.push({sql: sql, callback: function (err, data) { - callback(err, data); + query_queue.push({sql: sql, callback: function (err, data, tag) { + callback(err, data, tag); }}); } diff --git a/lib/sql.js b/lib/sql.js index b9772e1..44deb47 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -32,7 +32,7 @@ function sql_escape(value) { return "FALSE"; } if (value.constructor.name === 'String') { - return "'" + value.replace("'", "''") + "'"; + return "'" + value.replace(/'/g, "''") + "'"; } return value.toString(); }