Permalink
Browse files

Build 3. Bug fixes. Thanks to Richard Rodger for testing

  • Loading branch information...
1 parent f4b9fd1 commit 7856080d4c7b708a3992fd62c222994b3438eed1 @robtweed committed May 26, 2011
Showing with 80 additions and 62 deletions.
  1. +5 −3 README.md
  2. +4 −2 gtm/MDB.m
  3. +71 −57 lib/mdb.js
View
@@ -5,9 +5,9 @@ node-mdb is a re-implementation of M/DB, the Open Source clone of SimpleDB
It has been completely re-written in Node.js Javascript and uses the free, Open Source GT.M database as the data repository.
Rob Tweed <rtweed@mgateway.com>
-17 May 2011, M/Gateway Developments Ltd [http://www.mgateway.com](http://www.mgateway.com)
+26 May 2011, M/Gateway Developments Ltd [http://www.mgateway.com](http://www.mgateway.com)
-Twitter@ @rtweed
+Twitter @rtweed
Google Group for discussions, support, advice etc: [http://groups.google.co.uk/group/mdb-community-forum](http://groups.google.co.uk/group/mdb-community-forum)
@@ -119,7 +119,9 @@ Install Node.js and NPM on your server. See [http://nodejs.org](http://nodejs.o
In the repository's */lib* directory, you'll find the main M/DB Node.js file: *mdb.js* and a second file named *mdbInit.js*. Copy these files to the path */usr/local/gtm/ewd/* on your GT.M server (adjust this path appropriately if you've installed GT.M for use in another directory).
-In the repository's */gtm* directory, you'll find the M/Wire interface files that are used by mdb.js to access the GT.M database (See [https://github.com/robtweed/node-mwire](https://github.com/robtweed/node-mwire) for more details on the *node-mwire* used by *node-mdb*)
+ If you've used Mike Clayton's M/DB Installer, you can skip the next steps in this section.
+
+ If not, then in the repository's */gtm* directory, you'll find the M/Wire interface files that are used by mdb.js to access the GT.M database (See [https://github.com/robtweed/node-mwire](https://github.com/robtweed/node-mwire) for more details on the *node-mwire* used by *node-mdb*)
You need to copy the files to the following directories:
View
@@ -25,10 +25,10 @@
;
;
version()
- QUIT "40"
+ QUIT "41"
;
buildDate()
- QUIT "17 May 2011"
+ QUIT "25 May 2011"
;
indexLength()
QUIT 180
@@ -1333,6 +1333,8 @@ d updateDomainMetaData(keyId,domainId)
;
i query["\'" s query=$$replaceAll^%zewdAPI(query,"\'",$c(1))
i query["''" s query=$$replaceAll^%zewdAPI(query,"''",$c(1))
+ i query[$c(32,1,39) s query=$$replaceAll^%zewdAPI(query,$c(32,1,39),$c(32,39,1))
+ i query[$c(61,1,39) s query=$$replaceAll^%zewdAPI(query,$c(61,1,39),$c(61,39,1))
i query[$c(2) s query=$$replaceAll^%zewdAPI(query,$c(2),$c(1))
s error="",predicate=""
s not=$$queryNot(.query)
View
@@ -1,7 +1,7 @@
/*
++++ node-mdb ++++
- ++++ Build 2 ++++
- ++++ 17 May 2011 ++++
+ ++++ Build 3 ++++
+ ++++ 25 May 2011 ++++
----------------------------------------------------------------------------
| node-mdb: Node.js version of M/DB |
@@ -54,7 +54,7 @@
*/
-var httpPort = 8081;
+var httpPort = 8000;
var trace = true;
var sdbURLPattern = '/';
@@ -403,44 +403,50 @@ var select = function(domainIndex, SDB) {
// other than simple select * from domain queries
MDB.select(SDB, function(error, results) {
console.log("select results: " + JSON.stringify(results));
- var nvps = SDB.nvps;
- var action = nvps.Action;
- var item;
- var itemNo;
- var attrs;
- var attr;
- var attrNo;
- var attrName;
- var valueNo;
- var values;
- var xml;
- var noOfItems = 0;
- for (itemNo in results) noOfItems++;
- if (noOfItems === 0) {
- xml = responseStart({action: action, version: nvps.Version, hasContent: false, isEmpty: true});
+ if (results.error) {
+ var error = {code: results.error.errorCode, message: results.error.errorMessage, status:400};
+ returnError(SDB, error);
}
else {
- xml = responseStart({action: action, version: nvps.Version, hasContent: true, isEmpty: false});
- }
- for (itemNo in results) {
- item = results[itemNo];
- xml = xml + '<Item><Name>' + item.i + '</Name>';
- attrs = item.a;
- for (attrNo in attrs) {
- attr = attrs[attrNo];
- attrName = attr.n;
- values = attr.v;
- for (valueNo in values) {
- value = values[valueNo];
- value = value.replace(/\\\\/g, "\\")
- xml = xml + '<Attribute><Name>' + attrName + '</Name><Value>' + xmlEscape(value) + '</Value></Attribute>';
+ var nvps = SDB.nvps;
+ var action = nvps.Action;
+ var item;
+ var itemNo;
+ var attrs;
+ var attr;
+ var attrNo;
+ var attrName;
+ var valueNo;
+ var values;
+ var xml;
+ var noOfItems = 0;
+ for (itemNo in results) noOfItems++;
+ if (noOfItems === 0) {
+ xml = responseStart({action: action, version: nvps.Version, hasContent: false, isEmpty: true});
+ }
+ else {
+ xml = responseStart({action: action, version: nvps.Version, hasContent: true, isEmpty: false});
+ }
+ for (itemNo in results) {
+ item = results[itemNo];
+ xml = xml + '<Item><Name>' + item.i + '</Name>';
+ attrs = item.a;
+ for (attrNo in attrs) {
+ attr = attrs[attrNo];
+ attrName = attr.n;
+ values = attr.v;
+ for (valueNo in values) {
+ value = values[valueNo] + '';
+ value = value.replace(/\\\\/g, "\\")
+ xml = xml + '<Attribute><Name>' + attrName + '</Name><Value>' + xmlEscape(value) + '</Value></Attribute>';
+ }
}
+ xml = xml + '</Item>';
}
- xml = xml + '</Item>';
+ var hasContent = (noOfItems > 0);
+ xml = xml + responseEnd(action, SDB.startTime, hasContent);
+ writeResponse(200, xml, SDB.response);
}
- var hasContent = (noOfItems > 0);
- xml = xml + responseEnd(action, SDB.startTime, hasContent);
- writeResponse(200, xml, SDB.response)
});
}
else {
@@ -936,6 +942,9 @@ var getAttributes = function(domainIndex, SDB) {
var values;
var valueNo;
var value;
+ var valueIndex;
+ var valueNo;
+ var valueNos;
var getAttr;
var attributes = [];
for (attribNo in results) {
@@ -949,10 +958,13 @@ var getAttributes = function(domainIndex, SDB) {
if (attrsWanted[attribName] === '') getAttr = true;
}
if (getAttr) {
- values = results[attribNo].value;
- for (valueNo in values) {
- value = values[valueNo];
- attributes.push({name:attribName, value: value});
+ values = results[attribNo].valueIndex;
+ for (valueIndex in values) {
+ valueNos = values[valueIndex];
+ for (valueNo in valueNos) {
+ value = results[attribNo].value[valueNo];
+ attributes.push({name:attribName, value: value});
+ }
}
}
}
@@ -1301,7 +1313,7 @@ var addNewAttrValue = function(max, domainIndex, itemIndex, attrIndex, value, SD
for (valueNo in values) {
if (typeof results.value !== 'undefined') {
if (typeof results.value[valueNo] !== 'undefined') {
- if (value === results.value[valueNo]) {
+ if ((value + '') === (results.value[valueNo] + '')) {
if (trace) console.log("value '" + value + "' already exists for this attribute!");
exists = true;
break;
@@ -1626,22 +1638,24 @@ var removeAttribute = function(domainIndex, itemIndex, attrIndex, attrName, SDB)
value = results.value[attrix];
break;
}
- if (typeof SDB.attributeValues[attrName] !== 'undefined') {
- specifiedValues = {};
- specifiedValueArray = SDB.attributeValues[attrName];
- for (var i=0; i < specifiedValueArray.length; i++) {
- specifiedValues[specifiedValueArray[i]] = '';
- }
- if (trace) console.log("specifiedValues = " + JSON.stringify(specifiedValues));
- if (value in specifiedValues) {
- if (trace) console.log("specified value '" + value + "' matches value in database, so delete it!");
- if (trace) console.log("itemIndex: " + itemIndex + "; attribIndex: " + attrIndex + "; valueIndex: " + attrix);
- removeValueFromAttr(domainIndex, itemIndex, attrIndex, attrName, attrix, valueNameIndex, SDB, counter);
- }
- else {
- if (trace) console.log("value in database - '" + value + " isn't in the specified list of values");
- counter.count++;
- if (counter.count === counter.noOfValues) sendDeleteAttributesResponse(SDB);
+ if (typeof SDB.attributeValues !== 'undefined') {
+ if (typeof SDB.attributeValues[attrName] !== 'undefined') {
+ specifiedValues = {};
+ specifiedValueArray = SDB.attributeValues[attrName];
+ for (var i=0; i < specifiedValueArray.length; i++) {
+ specifiedValues[specifiedValueArray[i]] = '';
+ }
+ if (trace) console.log("specifiedValues = " + JSON.stringify(specifiedValues));
+ if (value in specifiedValues) {
+ if (trace) console.log("specified value '" + value + "' matches value in database, so delete it!");
+ if (trace) console.log("itemIndex: " + itemIndex + "; attribIndex: " + attrIndex + "; valueIndex: " + attrix);
+ removeValueFromAttr(domainIndex, itemIndex, attrIndex, attrName, attrix, valueNameIndex, SDB, counter);
+ }
+ else {
+ if (trace) console.log("value in database - '" + value + " isn't in the specified list of values");
+ counter.count++;
+ if (counter.count === counter.noOfValues) sendDeleteAttributesResponse(SDB);
+ }
}
}
else {

0 comments on commit 7856080

Please sign in to comment.