Revise test/fetchRowidAsString.js by removing oversized raw column test

This commit is contained in:
Christopher Jones 2019-03-23 07:58:36 +11:00 committed by Christopher Jones
parent 4e630baa30
commit b15e0567bc
2 changed files with 186 additions and 224 deletions

View File

@ -76,6 +76,38 @@ describe('188. fetchRowidAsString.js', function() {
before(async function() { before(async function() {
try { try {
conn = await oracledb.getConnection(dbConfig); conn = await oracledb.getConnection(dbConfig);
const sqlCreateTable = `BEGIN \n` +
` DECLARE \n` +
` e_table_missing EXCEPTION; \n` +
` PRAGMA EXCEPTION_INIT(e_table_missing, -00942);\n` +
` BEGIN \n` +
` EXECUTE IMMEDIATE ('DROP TABLE ${tableName} PURGE' ); \n` +
` EXCEPTION \n` +
` WHEN e_table_missing \n` +
` THEN NULL; \n` +
` END; \n` +
` EXECUTE IMMEDIATE ( ' \n` +
` CREATE TABLE ${tableName} ( \n` +
` raw_content RAW(${rawMaxLength}) NULL, \n` +
` content_type VARCHAR(20) \n` +
` ) \n` +
` '); \n` +
`END; `;
await conn.execute(sqlCreateTable);
let sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_to_raw('${rawContentString}'), 'string')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_from_number(${rawContentNumber}), 'number')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_from_binary_double(${rawContentFloat}), 'binary_double')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_from_binary_float(${rawContentFloat}), 'binary_float')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_from_binary_integer(${rawContentNumber}), 'binary_integer')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_to_raw('${rawMaxLengthString}'), 'max_length_string')`;
await conn.execute(sql);
await conn.commit();
} catch (err) { } catch (err) {
should.not.exist(err); should.not.exist(err);
} }
@ -105,219 +137,146 @@ describe('188. fetchRowidAsString.js', function() {
oracledb.fetchAsString = []; oracledb.fetchAsString = [];
}); });
describe("188.1 Normal Use Cases", function() { it("188.1 Fetch RAW by default should be oracledb.BUFFER type", async function() {
try {
before(async function() { let res = await conn.execute(`select raw_content from ${tableName} where content_type='string'`);
try { should.exist(res.rows);
const sqlCreateTable = `BEGIN \n` + should.strictEqual(res.rows.length, 1);
` DECLARE \n` + let fetchedContent = res.rows[0][0];
` e_table_missing EXCEPTION; \n` + fetchedContent.should.be.type("object");
` PRAGMA EXCEPTION_INIT(e_table_missing, -00942);\n` + should.strictEqual(fetchedContent.toString("hex"), Buffer.from(rawContentString).toString("hex"));
` BEGIN \n` + } catch (err) {
` EXECUTE IMMEDIATE ('DROP TABLE ${tableName} PURGE' ); \n` + should.not.exist(err);
` EXCEPTION \n` + }
` WHEN e_table_missing \n` +
` THEN NULL; \n` +
` END; \n` +
` EXECUTE IMMEDIATE ( ' \n` +
` CREATE TABLE ${tableName} ( \n` +
` raw_content RAW(${rawMaxLength}) NULL, \n` +
` content_type VARCHAR(20) \n` +
` ) \n` +
` '); \n` +
`END; `;
await conn.execute(sqlCreateTable);
let sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_to_raw('${rawContentString}'), 'string')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_from_number(${rawContentNumber}), 'number')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_from_binary_double(${rawContentFloat}), 'binary_double')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_from_binary_float(${rawContentFloat}), 'binary_float')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_from_binary_integer(${rawContentNumber}), 'binary_integer')`;
await conn.execute(sql);
sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_to_raw('${rawMaxLengthString}'), 'max_length_string')`;
await conn.execute(sql);
await conn.commit();
} catch (err) {
should.not.exist(err);
}
});
it("188.1.1 Fetch RAW by default should be oracledb.BUFFER type", async function() {
try {
let res = await conn.execute(`select raw_content from ${tableName} where content_type='string'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("object");
should.strictEqual(fetchedContent.toString("hex"), Buffer.from(rawContentString).toString("hex"));
} catch (err) {
should.not.exist(err);
}
});
it("188.1.2 Fetch RAW as string by defining fetchAsString", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='string'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), Buffer.from(rawContentString).toString("hex"));
} catch (err) {
should.not.exist(err);
}
});
it("188.1.3 Fetch RAW as string by defining fetchInfo", async function() {
try {
oracledb.fetchAsString = [];
let res = await conn.execute(
`select raw_content from ${tableName} where content_type='string'`, [],
{ fetchInfo: {"RAW_CONTENT": {type: oracledb.STRING}} }
);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), Buffer.from(rawContentString).toString("hex"));
} catch (err) {
should.not.exist(err);
}
});
it("188.1.4 Fetch number converted RAW as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='number'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), getHex(rawContentNumber, "number"));
} catch (err) {
should.not.exist(err);
}
});
it("188.1.5 Fetch binary double converted RAW as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='binary_double'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), getHex(rawContentFloat, "double"));
} catch (err) {
should.not.exist(err);
}
});
it("188.1.6 Fetch binary float converted RAW as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='binary_float'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), getHex(rawContentFloat, "float"));
} catch (err) {
should.not.exist(err);
}
});
it("188.1.7 Fetch binary integer converted RAW as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='binary_integer'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), getHex(rawContentNumber, "integer"));
} catch (err) {
should.not.exist(err);
}
});
it("188.1.8 Insert a string of maximum lenght of RAW then fetch it as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='max_length_string'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), Buffer.from(rawMaxLengthString).toString("hex"));
} catch (err) {
should.not.exist(err);
}
});
it("188.1.9 Insert a string exceeds maximum lenght of RAW", async function() {
try {
let contentString = random.getRandomLengthString(rawMaxLength+1);
const sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_to_raw('${contentString}'), 'string')`;
await testUtil.assertThrowsAsync(async () => {
await conn.execute(sql);
await conn.commit();
}, /ORA-12899:/); // ORA-12899: value too large for column "HR"."NODB_RAWTOSTRING"."RAW_CONTENT" (actual: 21, maximum: 20)
} catch (err) {
should.not.exist(err);
}
});
it("188.1.10 Insert null to RAW column then fetch it as string", async function() {
try {
const sql = `INSERT INTO ${tableName} VALUES(null, 'null')`;
await conn.execute(sql);
await conn.commit();
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='null'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
should.strictEqual(res.rows[0][0], null);
} catch (err) {
should.not.exist(err);
}
});
}); });
describe("188.2 Boundary Cases", function() { it("188.2 Fetch RAW as string by defining fetchAsString", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='string'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), Buffer.from(rawContentString).toString("hex"));
} catch (err) {
should.not.exist(err);
}
});
it("188.2.1 Creating table specifing length greater than RAW max limit", async function() { it("188.3 Fetch RAW as string by defining fetchInfo", async function() {
try { try {
const sql_create_table = `BEGIN \n` + oracledb.fetchAsString = [];
` DECLARE \n` + let res = await conn.execute(
` e_table_missing EXCEPTION; \n` + `select raw_content from ${tableName} where content_type='string'`, [],
` PRAGMA EXCEPTION_INIT(e_table_missing, -00942);\n` + { fetchInfo: {"RAW_CONTENT": {type: oracledb.STRING}} }
` BEGIN \n` + );
` EXECUTE IMMEDIATE ('DROP TABLE ${tableName} PURGE' ); \n` + should.exist(res.rows);
` EXCEPTION \n` + should.strictEqual(res.rows.length, 1);
` WHEN e_table_missing \n` + let fetchedContent = res.rows[0][0];
` THEN NULL; \n` + fetchedContent.should.be.type("string");
` END; \n` + should.strictEqual(fetchedContent.toLowerCase(), Buffer.from(rawContentString).toString("hex"));
` EXECUTE IMMEDIATE ( ' \n` + } catch (err) {
` CREATE TABLE ${tableName} ( \n` + should.not.exist(err);
` raw_content RAW(2001), \n` + }
` content_type VARCHAR(20) \n` + });
` ) \n` +
` '); \n` +
`END; `;
await testUtil.assertThrowsAsync(async () => {
await conn.execute(sql_create_table);
}, /ORA-00910:/); // ORA-00910: specified length too long for its datatype
} catch (err) {
should.not.exist(err);
}
});
it("188.4 Fetch number converted RAW as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='number'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), getHex(rawContentNumber, "number"));
} catch (err) {
should.not.exist(err);
}
});
it("188.5 Fetch binary double converted RAW as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='binary_double'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), getHex(rawContentFloat, "double"));
} catch (err) {
should.not.exist(err);
}
});
it("188.6 Fetch binary float converted RAW as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='binary_float'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), getHex(rawContentFloat, "float"));
} catch (err) {
should.not.exist(err);
}
});
it("188.7 Fetch binary integer converted RAW as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='binary_integer'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), getHex(rawContentNumber, "integer"));
} catch (err) {
should.not.exist(err);
}
});
it("188.8 Insert a string of maximum lenght of RAW then fetch it as string", async function() {
try {
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='max_length_string'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
let fetchedContent = res.rows[0][0];
fetchedContent.should.be.type("string");
should.strictEqual(fetchedContent.toLowerCase(), Buffer.from(rawMaxLengthString).toString("hex"));
} catch (err) {
should.not.exist(err);
}
});
it("188.9 Insert a string exceeds maximum lenght of RAW", async function() {
try {
let contentString = random.getRandomLengthString(rawMaxLength+1);
const sql = `INSERT INTO ${tableName} VALUES(utl_raw.cast_to_raw('${contentString}'), 'string')`;
await testUtil.assertThrowsAsync(async () => {
await conn.execute(sql);
await conn.commit();
}, /ORA-12899:/); // ORA-12899: value too large for column "HR"."NODB_RAWTOSTRING"."RAW_CONTENT" (actual: 21, maximum: 20)
} catch (err) {
should.not.exist(err);
}
});
it("188.10 Insert null to RAW column then fetch it as string", async function() {
try {
const sql = `INSERT INTO ${tableName} VALUES(null, 'null')`;
await conn.execute(sql);
await conn.commit();
oracledb.fetchAsString = [oracledb.BUFFER];
let res = await conn.execute(`select raw_content from ${tableName} where content_type='null'`);
should.exist(res.rows);
should.strictEqual(res.rows.length, 1);
should.strictEqual(res.rows[0][0], null);
} catch (err) {
should.not.exist(err);
}
}); });
}); });

View File

@ -265,7 +265,7 @@ Overview of node-oracledb functional tests
12.3.11 Negative - set the 1st parameter of getRows() to be -5 12.3.11 Negative - set the 1st parameter of getRows() to be -5
12.3.12 Negative - set the 1st parameter of getRows() to be null 12.3.12 Negative - set the 1st parameter of getRows() to be null
12.4 Testing function getRow() 12.4 Testing function getRow()
12.4.1 works well with all correct setting (39ms) 12.4.1 works well with all correct setting
12.4.2 data in resultSet is array when setting outFormat ARRAY 12.4.2 data in resultSet is array when setting outFormat ARRAY
12.4.3 data in resultSet is object when setting outFormat OBJECT 12.4.3 data in resultSet is object when setting outFormat OBJECT
12.4.4 query 0 row 12.4.4 query 0 row
@ -2027,7 +2027,7 @@ Overview of node-oracledb functional tests
88.1.3 works with small value 88.1.3 works with small value
88.1.4 works with (64K - 1) value 88.1.4 works with (64K - 1) value
88.1.5 works with (64K + 1) value 88.1.5 works with (64K + 1) value
88.1.6 works with (1MB + 1) value (121ms) 88.1.6 works with (1MB + 1) value
88.1.7 works with dbms_lob.substr() 88.1.7 works with dbms_lob.substr()
88.1.8 works with EMPTY_BLOB() 88.1.8 works with EMPTY_BLOB()
88.1.9 fetch multiple BLOB rows as Buffer 88.1.9 fetch multiple BLOB rows as Buffer
@ -4398,6 +4398,7 @@ Overview of node-oracledb functional tests
184.4.9 Close connection from pool with {drop: 0} 184.4.9 Close connection from pool with {drop: 0}
184.4.10 Close connection from pool with empty dict 184.4.10 Close connection from pool with empty dict
184.4.11 Close connection from pool with {drop: random string} 184.4.11 Close connection from pool with {drop: random string}
185. cqn.js 185. cqn.js
185.1 Positive Cases 185.1 Positive Cases
185.1.1 Register simple callback and unsubscribe 185.1.1 Register simple callback and unsubscribe
@ -4418,8 +4419,10 @@ Overview of node-oracledb functional tests
185.2 Negative Cases 185.2 Negative Cases
185.2.1 Does not throw error when trying to unsubscribe twice 185.2.1 Does not throw error when trying to unsubscribe twice
185.2.2 Throw error ORA-29972 if CHANGE NOTIFICATION is revoked from the user 185.2.2 Throw error ORA-29972 if CHANGE NOTIFICATION is revoked from the user
186. instanceof2.js 186. instanceof2.js
186.1 instanceof checks for SODA classes 186.1 instanceof checks for SODA classes
187. plsqlBindList.js 187. plsqlBindList.js
187.1 Positive Cases 187.1 Positive Cases
187.1.1 Bind Object of List by position with type specified 187.1.1 Bind Object of List by position with type specified
@ -4439,26 +4442,26 @@ Overview of node-oracledb functional tests
187.2.8 Bind STRING List by position while required type is NUMBER 187.2.8 Bind STRING List by position while required type is NUMBER
187.2.9 Bind NUMBER List by name while required type is STRING 187.2.9 Bind NUMBER List by name while required type is STRING
187.2.10 Bind NUMBER List by position while required type is STRING 187.2.10 Bind NUMBER List by position while required type is STRING
188. fetchRowidAsString.js 188. fetchRowidAsString.js
188.1 Normal Use Cases 188.1 Fetch RAW by default should be oracledb.BUFFER type
188.1.1 Fetch RAW by default should be oracledb.BUFFER type 188.2 Fetch RAW as string by defining fetchAsString
188.1.2 Fetch RAW as string by defining fetchAsString 188.3 Fetch RAW as string by defining fetchInfo
188.1.3 Fetch RAW as string by defining fetchInfo 188.4 Fetch number converted RAW as string
188.1.4 Fetch number converted RAW as string 188.5 Fetch binary double converted RAW as string
188.1.5 Fetch binary double converted RAW as string 188.6 Fetch binary float converted RAW as string
188.1.6 Fetch binary float converted RAW as string 188.7 Fetch binary integer converted RAW as string
188.1.7 Fetch binary integer converted RAW as string 188.8 Insert a string of maximum lenght of RAW then fetch it as string
188.1.8 Insert a string of maximum lenght of RAW then fetch it as string 188.9 Insert a string exceeds maximum lenght of RAW
188.1.9 Insert a string exceeds maximum lenght of RAW 188.10 Insert null to RAW column then fetch it as string
188.1.10 Insert null to RAW column then fetch it as string
188.2 Boundary Cases
188.2.1 Creating table specifing length greater than RAW max limit
189. writableProperties2.js 189. writableProperties2.js
189.1 Allows overwriting of public methods on SodaDatabase instance 189.1 Allows overwriting of public methods on SodaDatabase instance
189.2 Allows overwriting of public methods on SodaDocument instance 189.2 Allows overwriting of public methods on SodaDocument instance
189.3 Allows overwriting of public methods on SodaCollection instance 189.3 Allows overwriting of public methods on SodaCollection instance
189.4 Allows overwriting of public methods on SodaOperation instance 189.4 Allows overwriting of public methods on SodaOperation instance
189.5 Allows overwriting of public methods on SodaDocCursor instance 189.5 Allows overwriting of public methods on SodaDocCursor instance
190. fetchBinaryTypesAsString.js 190. fetchBinaryTypesAsString.js
190.1 Fetch binary double 190.1 Fetch binary double
190.1.1 Fetch binary double should return JS number 190.1.1 Fetch binary double should return JS number