Skip to content

Commit acab1ef

Browse files
committed
Add compatible version check to soda5.js
1 parent 339e87c commit acab1ef

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

test/soda5.js

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -511,29 +511,52 @@ describe('173. soda5.js', () => {
511511
should.not.exist(err);
512512
}
513513

514+
let compatibleVersion;
515+
if (dbconfig.test.DBA_PRIVILEGE) {
516+
try {
517+
const connectionDetails = {
518+
user : dbconfig.test.DBA_user,
519+
password : dbconfig.test.DBA_password,
520+
connectString : dbconfig.connectString,
521+
privilege : oracledb.SYSDBA,
522+
};
523+
let conn = await oracledb.getConnection(connectionDetails);
524+
let res = await conn.execute("select name, value from v$parameter where name like lower('%'||:x||'%')", ['COMPATIBLE']);
525+
if(res.rows.length > 0) {
526+
compatibleVersion = res.rows[0][1];
527+
}
528+
await conn.close();
529+
} catch (err) {
530+
should.not.exist(err);
531+
}
532+
}
533+
const isCreateIndexEnabled = sodaUtil.versionStringCompare(compatibleVersion, '12.2.0.0.0');
514534
try {
515535
let indexSpec = {
516536
"name": "TEST_IDX",
517537
"search_on": "none",
518538
"dataguide": "on"
519539
};
520-
await collection.createIndex(indexSpec);
521-
522-
let outDocument = await collection.getDataGuide();
523-
should.exist(outDocument);
524-
540+
if (isCreateIndexEnabled >= 0) {
541+
await collection.createIndex(indexSpec);
542+
let outDocument = await collection.getDataGuide();
543+
should.exist(outDocument);
544+
} else if(isCreateIndexEnabled < 0){
545+
await sodaUtil.assertThrowsAsync(async () => {await collection.createIndex(indexSpec);}, /ORA-00406:/);
546+
}
525547
} catch(err) {
526548
should.not.exist(err);
527549
}
528-
529-
try {
530-
let result = await collection.dropIndex('TEST_IDX');
531-
should.strictEqual(result.dropped, true);
532-
await conn.commit();
533-
await collection.drop();
534-
await conn.close();
535-
} catch(err) {
536-
should.not.exist(err);
550+
if (isCreateIndexEnabled >= 0) {
551+
try {
552+
let result = await collection.dropIndex('TEST_IDX');
553+
should.strictEqual(result.dropped, true);
554+
await conn.commit();
555+
await collection.drop();
556+
await conn.close();
557+
} catch(err) {
558+
should.not.exist(err);
559+
}
537560
}
538561

539562
}); // 173.12

test/sodaUtil.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,27 @@ sodaUtil.t_contents = [
105105
{ id: 1005, name: "May", office: "London" },
106106
{ id: 1006, name: "Joe", office: "San Francisco" },
107107
{ id: 1007, name: "Gavin", office: "New York" }
108-
];
108+
];
109+
110+
111+
// Function versionStringCompare returns:
112+
// * 1 if version1 is greater than version2
113+
// * -1 if version1 is smaller than version2
114+
// * 0 if version1 is equal to version2
115+
// * undefined if eigher version1 or version2 is not string
116+
sodaUtil.versionStringCompare = function(version1, version2) {
117+
if (typeof version1 === 'string' && typeof version2 === 'string') {
118+
let tokens1 = version1.split('.');
119+
let tokens2 = version2.split('.');
120+
let len = Math.min(tokens1.length, tokens2.length);
121+
for (let i = 0; i < len; i++) {
122+
const t1 = parseInt(tokens1[i]), t2 = parseInt(tokens2[i]);
123+
if (t1 > t2) return 1;
124+
if (t1 < t2) return -1;
125+
}
126+
if (tokens1.length < tokens2.length) return 1;
127+
if (tokens1.length > tokens2.length) return -1;
128+
return 0;
129+
}
130+
return undefined;
131+
}

0 commit comments

Comments
 (0)