Skip to content

Commit 6f2ce2d

Browse files
committed
test optimizations
1 parent 53838eb commit 6f2ce2d

12 files changed

+651
-901
lines changed

test/binding_DMLInsert.js

Lines changed: 80 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,14 @@
3535

3636
const oracledb = require('oracledb');
3737
const assert = require('assert');
38-
const sql = require('./sql.js');
3938
const dbConfig = require('./dbconfig.js');
4039
const assist = require('./dataTypeAssist.js');
4140
const random = require('./random.js');
41+
const testsUtil = require('./testsUtil.js');
4242

4343
describe('92.binding_DMLInsert.js', function() {
4444

4545
let connection = null;
46-
const executeSql = async function(sql) {
47-
await connection.execute(sql);
48-
};
4946

5047
before(async function() {
5148
connection = await oracledb.getConnection(dbConfig);
@@ -55,154 +52,111 @@ describe('92.binding_DMLInsert.js', function() {
5552
await connection.close();
5653
});
5754

58-
const doTest = async function(table_name, content, dbColType, bindType, nullBind, largeVal) {
59-
let bindVar = { c: { val: content, type: bindType, dir: oracledb.BIND_IN } };
60-
await dmlInsert(table_name, dbColType, bindVar, bindType, nullBind, largeVal);
61-
62-
bindVar = [ { val: content, type: bindType, dir: oracledb.BIND_IN } ];
63-
await dmlInsert(table_name, dbColType, bindVar, bindType, nullBind, largeVal);
64-
};
65-
66-
const dmlInsert = async function(table_name, dbColType, bindVar, bindType, nullBind, largeVal) {
67-
const createTable = sql.createTable(table_name, dbColType);
68-
const drop_table = "DROP TABLE " + table_name + " PURGE";
69-
await executeSql(createTable);
55+
const getExpectedErrorPattern = function(bindType, dbColType, largeVal, nullBind) {
56+
if (bindType === oracledb.STRING) {
57+
// STRING bindings
58+
if (nullBind === true) {
59+
return null;
60+
}
7061

71-
if (largeVal === true) {
72-
if (bindType === oracledb.STRING) {
62+
if (largeVal === true) {
63+
// Large STRING value tests
7364
if (dbColType.indexOf("CHAR") > -1) {
74-
await assert.rejects(
75-
async () => {
76-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
77-
},
78-
// ORA-12899: value too large for column "HR"."TABLE_9250"."CONTENT"
79-
/ORA-12899:/
80-
);
65+
return /ORA-12899:/; // value too large for column "HR"."TABLE_9250"."CONTENT"
8166
}
8267
if (dbColType === "NUMBER" || dbColType.indexOf("FLOAT") > -1 || dbColType === "BINARY_DOUBLE") {
83-
await assert.rejects(
84-
async () => {
85-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
86-
},
87-
// ORA-01722: invalid number
88-
/ORA-01722:/
89-
);
68+
return /ORA-01722:/; // invalid number
9069
}
9170
if (dbColType === "DATE") {
92-
await assert.rejects(
93-
async () => {
94-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
95-
},
96-
// ORA-01858: a non-numeric character was found where a numeric was expected
97-
/ORA-01858:/
98-
);
71+
return /ORA-01858:/; // non-numeric character found where numeric expected
9972
}
10073
if (dbColType === "TIMESTAMP") {
101-
await assert.rejects(
102-
async () => {
103-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
104-
},
105-
// ORA-01877: string is too long for internal buffer
106-
// ORA-01866: the datetime class is invalid
107-
// ORA-01830: The string being converted to a date is too long to
108-
// match the date format 'DD-MON-RR HH.MI.SSXFF AM'
109-
/ORA-01877:|ORA-01866:|ORA-01830:/
110-
);
74+
return /ORA-01877:|ORA-01866:|ORA-01830:/;
75+
// ORA-01877: string is too long for internal buffer
76+
// ORA-01866: the datetime class is invalid
77+
// ORA-01830: The string being converted to a date is too long to
78+
// match the date format 'DD-MON-RR HH.MI.SSXFF AM'
11179
}
11280
if (dbColType === "BLOB" || dbColType.indexOf("RAW") > -1) {
113-
await assert.rejects(
114-
async () => {
115-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
116-
},
117-
// ORA-01465: invalid hex number
118-
/ORA-01465:/
119-
);
81+
return /ORA-01465:/; // invalid hex number
12082
}
12183
if (dbColType === "CLOB") {
122-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
84+
return null;
12385
}
12486
} else {
125-
if (dbColType === "NUMBER" || dbColType === "DATE" || dbColType === "TIMESTAMP" || dbColType.indexOf("FLOAT") > -1) {
126-
await assert.rejects(
127-
async () => {
128-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
129-
},
130-
// NUMBER: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
131-
// DATE: ORA-00932: inconsistent datatypes: expected DATE got BINARY
132-
// TIMESTAMP: ORA-00932: inconsistent datatypes: expected TIMESTAMP got BINARY
133-
// FLOAT: ORA-00932: inconsistent datatypes: expected BINARY_FLOAT got BINARY
134-
/ORA-00932:/
135-
);
87+
// Small STRING value tests
88+
if (dbColType.indexOf("CHAR") > -1 || dbColType === "CLOB") {
89+
return null;
13690
}
137-
if (dbColType.indexOf("CHAR") > -1 || dbColType.indexOf("RAW") > -1) {
138-
await assert.rejects(
139-
async () => {
140-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
141-
},
142-
// ORA-12899: value too large for column "HR"."TABLE_9250"."CONTENT"
143-
/ORA-12899:/
144-
);
91+
if (dbColType === "NUMBER" || dbColType.indexOf("FLOAT") > -1 || dbColType === "BINARY_DOUBLE") {
92+
return /ORA-01722:/; // invalid number
14593
}
146-
if (dbColType === "BLOB" || dbColType === "CLOB") {
147-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
94+
if (dbColType === "TIMESTAMP" || dbColType === "DATE") {
95+
return /ORA-01858:/; // non-numeric character found where numeric expected
96+
}
97+
if (dbColType === "BLOB" || dbColType.indexOf("RAW") > -1) {
98+
return /ORA-01465:/; // invalid hex number
14899
}
149100
}
150101
} else {
151-
if (bindType === oracledb.STRING) {
152-
if (nullBind === true) {
153-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
154-
} else {
155-
if (dbColType.indexOf("CHAR") > -1 || dbColType === "CLOB") {
156-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
157-
}
158-
if (dbColType === "NUMBER" || dbColType.indexOf("FLOAT") > -1 || dbColType === "BINARY_DOUBLE") {
159-
await assert.rejects(
160-
async () => {
161-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
162-
},
163-
// ORA-01722: invalid number
164-
/ORA-01722:/
165-
);
102+
// BUFFER bindings
103+
// BUFFER bindings to incompatible types always fail with ORA-00932, even with null values
104+
if (dbColType === "NUMBER" || dbColType === "DATE" || dbColType === "TIMESTAMP" ||
105+
dbColType.indexOf("FLOAT") > -1 || dbColType === "BINARY_DOUBLE") {
106+
return /ORA-00932:/; // inconsistent datatypes
107+
}
108+
109+
if (nullBind === true) {
110+
// Null BUFFER bindings to compatible types succeed
111+
if (dbColType === "BLOB" || dbColType === "CLOB" || dbColType.indexOf("CHAR") > -1 || dbColType.indexOf("RAW") > -1) {
112+
return null;
113+
}
114+
} else {
115+
// Non-null BUFFER bindings
116+
if (largeVal === true) {
117+
// Large BUFFER values
118+
if (dbColType.indexOf("CHAR") > -1 || dbColType.indexOf("RAW") > -1) {
119+
return /ORA-12899:/; // value too large for column
166120
}
167-
if (dbColType === "TIMESTAMP" || dbColType === "DATE") {
168-
await assert.rejects(
169-
async () => {
170-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
171-
},
172-
// ORA-01858: a non-numeric character was found where a numeric was expected
173-
/ORA-01858:/
174-
);
121+
if (dbColType === "BLOB" || dbColType === "CLOB") {
122+
return null;
175123
}
176-
if (dbColType === "BLOB" || dbColType.indexOf("RAW") > -1) {
177-
await assert.rejects(
178-
async () => {
179-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
180-
},
181-
// ORA-01465: invalid hex number
182-
/ORA-01465:/
183-
);
124+
} else {
125+
// Small BUFFER values
126+
if (dbColType === "BLOB" || dbColType === "CLOB" || dbColType.indexOf("CHAR") > -1 || dbColType.indexOf("RAW") > -1) {
127+
return null;
184128
}
185129
}
186-
} else {
187-
if (dbColType === "NUMBER" || dbColType === "DATE" || dbColType === "TIMESTAMP" || dbColType.indexOf("FLOAT") > -1) {
188-
await assert.rejects(
189-
async () => {
190-
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
191-
},
192-
// NUMBER: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
193-
// DATE: ORA-00932: inconsistent datatypes: expected DATE got BINARY
194-
// TIMESTAMP: ORA-00932: inconsistent datatypes: expected TIMESTAMP got BINARY
195-
// FLOAT: ORA-00932: inconsistent datatypes: expected BINARY_FLOAT got BINARY
196-
/ORA-00932:/
197-
);
198-
}
130+
}
131+
}
132+
return null;
133+
};
199134

200-
if (dbColType === "BLOB" || dbColType === "CLOB" || dbColType.indexOf("CHAR") > -1 || dbColType.indexOf("RAW") > -1) {
135+
const doTest = async function(table_name, content, dbColType, bindType, nullBind, largeVal) {
136+
let bindVar = { c: { val: content, type: bindType, dir: oracledb.BIND_IN } };
137+
await dmlInsert(table_name, dbColType, bindVar, bindType, nullBind, largeVal);
138+
139+
bindVar = [ { val: content, type: bindType, dir: oracledb.BIND_IN } ];
140+
await dmlInsert(table_name, dbColType, bindVar, bindType, nullBind, largeVal);
141+
};
142+
143+
const dmlInsert = async function(table_name, dbColType, bindVar, bindType, nullBind, largeVal) {
144+
await testsUtil.createBindingTestTable(connection, table_name, dbColType);
145+
146+
const expectedError = getExpectedErrorPattern(bindType, dbColType, largeVal, nullBind);
147+
148+
if (expectedError) {
149+
await assert.rejects(
150+
async () => {
201151
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
202-
}
203-
}
152+
},
153+
expectedError
154+
);
155+
} else {
156+
await connection.execute("insert into " + table_name + " ( content ) values (:c)", bindVar);
204157
}
205-
await executeSql(drop_table);
158+
159+
await testsUtil.dropTable(connection, table_name);
206160
};
207161

208162
const tableNamePre = "table_92";

0 commit comments

Comments
 (0)