Skip to content

Commit 1f5421f

Browse files
committed
Fixed some issues found during unit testing
ixml.js - line 293 changed const to let ran into reassignment error with const - changed iXmlNodeSqlParmOpen set io attribute, incorrectly set name attribute before xmlToJson - When converting <sql> xmlOut stmt: property would return ']]>' from CDATA output - Example: "stmt":"SELECT '' AS BLANK, STATE FROM QIWS.QCUSTCDT]]>" - Not sure if every version of XMLSERVICE adds CDATA to returned statement. - Added a check to see if the matched success string contains CDATA and replaced extra characters. iConn.setTimeout() - could not be set, if condition checked flag instead of seconds iSql.rowCount() - added check to allow optional options object iSql.count() - called iXmlNodeSqlRowCount instead of iXmlNodeSqlCount iProd.getProductInfo - Fixed issue that occured when calling with (productId, cb) signature - the callback function definition was being appended to the options causing the pgm call to fail
1 parent 163939c commit 1f5421f

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

lib/iprod.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,25 @@ class iProd {
168168
];
169169
if(!cb) { // If we do not get the third param,
170170
if(option) { // If we get two params,
171-
if(xt.getClass(option) == "Function") // If it is a function,
171+
if(xt.getClass(option) == "Function"){ // If it is a function,
172172
cb = option; // then it is the callback.
173+
option = "0000";
174+
}
173175
}
174176
else { // If we have only one param,
175177
option = "0000"; // then use *BASE as default.
176178
}
177179

178180
}
179-
if(option < 0 || option > 99)
180-
option = "0000";
181-
else if(option < 10)
182-
option = "000" + option;
183-
else option = "00" + option;
184-
181+
if(Number.isInteger(option)) {
182+
if(option < 0 || option > 99)
183+
option = "0000";
184+
else if(option < 10)
185+
option = "000" + option;
186+
else
187+
option = "00" + option;
188+
}
189+
185190
let ProdInfo = [
186191
[prodID, "7A"],
187192
["*ONLY", "6A"],

lib/itoolkit.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,14 @@ const xmlToJson = (xml) => {
137137
let sucFlag = sqlData[i].match(successReg);
138138
if(sucFlag && sucFlag.length > 0) {
139139
rs.success = true;
140-
if(sucFlag.length > 1)
141-
rs.stmt = sucFlag[1];
140+
if(sucFlag.length > 1){
141+
if(sucFlag[0].includes('![CDATA')){
142+
let fixed = sucFlag[1].replace(/]]>/, '');
143+
rs.stmt = fixed;
144+
} else{
145+
rs.stmt = sucFlag[1];
146+
}
147+
}
142148
}
143149
else {
144150
rs.success = false;
@@ -224,7 +230,7 @@ class iConn {
224230
}
225231
// setTimeout() override the default timeout value for sync mode.
226232
setTimeout(seconds) {
227-
if(__getClass(flag) == "Number")
233+
if(__getClass(seconds) == "Number")
228234
this.timeout = seconds * 1000;
229235
}
230236
// debug() get current verbose mode or enable/disable verbose mode for debugging.
@@ -535,11 +541,14 @@ class iSql {
535541
}
536542

537543
rowCount(options) {
538-
this.xml += i_xml.iXmlNodeSqlRowCount(options.action, options.error);
544+
if(options && options.error)
545+
this.xml += i_xml.iXmlNodeSqlRowCount(options.error);
546+
else
547+
this.xml += i_xml.iXmlNodeSqlRowCount();
539548
}
540549

541550
count(options) {
542-
this.xml += i_xml.iXmlNodeSqlRowCount(options.desc, options.error);
551+
this.xml += i_xml.iXmlNodeSqlCount(options.desc, options.error);
543552
}
544553

545554
describe(options) {

lib/ixml.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ const iXmlNodeSqlConnect = (db, uid, pwd, option_label) => {
289289
}
290290

291291
const iXmlNodeSqlOptions = (options) => {
292-
const iXml = iXmlNodeOpen(I_XML_NODE_SQL_OPTIONS_OPEN);
292+
let iXml = iXmlNodeOpen(I_XML_NODE_SQL_OPTIONS_OPEN);
293293
for(const i in options)
294294
iXml += iXmlAttrDefault(options[i].desc, options[i].value, I_XML_ATTR_VALUE_OPTIONAL);
295295
return iXml + I_XML_NODE_CLOSE + I_XML_NODE_SQL_OPTIONS_CLOSE;
@@ -332,7 +332,7 @@ const iXmlNodeSqlExecuteClose = () => {
332332

333333
const iXmlNodeSqlParmOpen = (xio) => {
334334
return iXmlNodeOpen(I_XML_NODE_PARM_OPEN)
335-
+ iXmlAttrDefault(I_XML_ATTR_KEY_NAME,xio,I_XML_ATTR_VALUE_OPTIONAL)
335+
+ iXmlAttrDefault(I_XML_ATTR_KEY_IO,xio,I_XML_ATTR_VALUE_OPTIONAL)
336336
+ I_XML_NODE_CLOSE;
337337
}
338338

0 commit comments

Comments
 (0)