|
| 1 | +/* Copyright 2024, Oracle and/or its affiliates. */ |
| 2 | + |
| 3 | +/****************************************************************************** |
| 4 | + * |
| 5 | + * This software is dual-licensed to you under the Universal Permissive License |
| 6 | + * (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License |
| 7 | + * 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose |
| 8 | + * either license. |
| 9 | + * |
| 10 | + * If you elect to accept the software under the Apache License, Version 2.0, |
| 11 | + * the following applies: |
| 12 | + * |
| 13 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | + * you may not use this file except in compliance with the License. |
| 15 | + * You may obtain a copy of the License at |
| 16 | + * |
| 17 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 18 | + * |
| 19 | + * Unless required by applicable law or agreed to in writing, software |
| 20 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | + * See the License for the specific language governing permissions and |
| 23 | + * limitations under the License. |
| 24 | + * |
| 25 | + * NAME |
| 26 | + * 301. plsqlRowtype.js |
| 27 | + * |
| 28 | + * DESCRIPTION |
| 29 | + * Test cases using %ROWTYPE in plsql. |
| 30 | + * |
| 31 | + *****************************************************************************/ |
| 32 | +'use strict'; |
| 33 | + |
| 34 | +const oracledb = require('oracledb'); |
| 35 | +const dbConfig = require('./dbconfig.js'); |
| 36 | +const assert = require('assert'); |
| 37 | +const testsUtil = require('./testsUtil.js'); |
| 38 | + |
| 39 | +describe('304. plSqlRowType.js', function() { |
| 40 | + let connection; |
| 41 | + const table = 'NODB_ROWTYPE'; |
| 42 | + const typeName = `NODB_OBJ`; |
| 43 | + const stmts = [ |
| 44 | + `CREATE OR REPLACE PACKAGE FOO_TEST AS |
| 45 | + TYPE NODB_ROWTYPE_ARRAY IS TABLE OF NODB_ROWTYPE%ROWTYPE |
| 46 | + INDEX BY BINARY_INTEGER; |
| 47 | + PROCEDURE prGetRecords(out_rec OUT FOO_TEST.NODB_ROWTYPE_ARRAY); |
| 48 | + END FOO_TEST;`, |
| 49 | + |
| 50 | + `CREATE OR REPLACE PACKAGE BODY FOO_TEST IS |
| 51 | + PROCEDURE prGetRecords(out_rec OUT FOO_TEST.NODB_ROWTYPE_ARRAY) |
| 52 | + IS |
| 53 | + CURSOR c_NODB_ROWTYPE IS |
| 54 | + SELECT * |
| 55 | + FROM NODB_ROWTYPE; |
| 56 | + BEGIN |
| 57 | + OPEN c_NODB_ROWTYPE; |
| 58 | + FETCH c_NODB_ROWTYPE BULK COLLECT INTO out_rec; |
| 59 | + CLOSE c_NODB_ROWTYPE; |
| 60 | + END prGetRecords; |
| 61 | + END FOO_TEST;` |
| 62 | + ]; |
| 63 | + |
| 64 | + const dropPackageSql = `DROP PACKAGE FOO_TEST`; |
| 65 | + |
| 66 | + const ObjSql = ` |
| 67 | + CREATE OR REPLACE TYPE ${typeName} AS OBJECT ( |
| 68 | + id NUMBER, |
| 69 | + name NVARCHAR2(30) |
| 70 | + );`; |
| 71 | + |
| 72 | + |
| 73 | + const createTableSql = `CREATE TABLE ${table}( |
| 74 | + NUMBERVALUE NUMBER(12), |
| 75 | + STRINGVALUE VARCHAR2(2), |
| 76 | + FIXEDCHARVALUE CHAR(10), |
| 77 | + NSTRINGVALUE NVARCHAR2(60), |
| 78 | + NFIXEDCHARVALUE NCHAR(10), |
| 79 | + RAWVALUE RAW(15), |
| 80 | + INTVALUE INTEGER, |
| 81 | + SMALLINTVALUE SMALLINT, |
| 82 | + REALVALUE REAL, |
| 83 | + DOUBLEPRECISIONVALUE DOUBLE PRECISION, |
| 84 | + FLOATVALUE FLOAT, |
| 85 | + BINARYFLOATVALUE BINARY_FLOAT, |
| 86 | + BINARYDOUBLEVALUE BINARY_DOUBLE, |
| 87 | + DATEVALUE DATE, |
| 88 | + TIMESTAMPVALUE TIMESTAMP, |
| 89 | + TIMESTAMPTZVALUE TIMESTAMP WITH TIME ZONE, |
| 90 | + TIMESTAMPLTZVALUE TIMESTAMP WITH LOCAL TIME ZONE, |
| 91 | + CLOBVALUE CLOB, |
| 92 | + NCLOBVALUE NCLOB, |
| 93 | + BLOBVALUE BLOB, |
| 94 | + OBJECTVALUE NODB_OBJ, |
| 95 | + INVISIBLEVALUE NUMBER INVISIBLE)`; |
| 96 | + |
| 97 | + let expectedTypes = { |
| 98 | + NUMBERVALUE: { type: oracledb.DB_TYPE_NUMBER, typeName: 'NUMBER' }, |
| 99 | + STRINGVALUE: { type: oracledb.DB_TYPE_VARCHAR, typeName: 'VARCHAR2' }, |
| 100 | + FIXEDCHARVALUE: { type: oracledb.DB_TYPE_CHAR, typeName: 'CHAR' }, |
| 101 | + NSTRINGVALUE: { type: oracledb.DB_TYPE_NVARCHAR, typeName: 'NVARCHAR2' }, |
| 102 | + NFIXEDCHARVALUE: { type: oracledb.DB_TYPE_NCHAR, typeName: 'NCHAR' }, |
| 103 | + RAWVALUE: { type: oracledb.DB_TYPE_RAW, typeName: 'RAW' }, |
| 104 | + INTVALUE: { type: oracledb.DB_TYPE_NUMBER, typeName: 'NUMBER' }, |
| 105 | + SMALLINTVALUE: { type: oracledb.DB_TYPE_NUMBER, typeName: 'NUMBER' }, |
| 106 | + REALVALUE: { type: oracledb.DB_TYPE_NUMBER, typeName: 'NUMBER' }, |
| 107 | + DOUBLEPRECISIONVALUE: { |
| 108 | + type: oracledb.DB_TYPE_NUMBER, |
| 109 | + typeName: 'NUMBER' |
| 110 | + }, |
| 111 | + FLOATVALUE: { type: oracledb.DB_TYPE_NUMBER, typeName: 'NUMBER' }, |
| 112 | + BINARYFLOATVALUE: { |
| 113 | + type: oracledb.DB_TYPE_BINARY_FLOAT, |
| 114 | + typeName: 'BINARY_FLOAT' |
| 115 | + }, |
| 116 | + BINARYDOUBLEVALUE: { |
| 117 | + type: oracledb.DB_TYPE_BINARY_DOUBLE, |
| 118 | + typeName: 'BINARY_DOUBLE' |
| 119 | + }, |
| 120 | + DATEVALUE: { type: oracledb.DB_TYPE_DATE, typeName: 'DATE' }, |
| 121 | + TIMESTAMPVALUE: { |
| 122 | + type: oracledb.DB_TYPE_TIMESTAMP, |
| 123 | + typeName: 'TIMESTAMP' |
| 124 | + }, |
| 125 | + TIMESTAMPTZVALUE: { |
| 126 | + type: oracledb.DB_TYPE_TIMESTAMP_TZ, |
| 127 | + typeName: 'TIMESTAMP WITH TIME ZONE' |
| 128 | + }, |
| 129 | + TIMESTAMPLTZVALUE: { |
| 130 | + type: oracledb.DB_TYPE_TIMESTAMP_LTZ, |
| 131 | + typeName: 'TIMESTAMP WITH LOCAL TIME ZONE' |
| 132 | + }, |
| 133 | + CLOBVALUE: { type: oracledb.DB_TYPE_CLOB, typeName: 'CLOB' }, |
| 134 | + NCLOBVALUE: { type: oracledb.DB_TYPE_NCLOB, typeName: 'NCLOB' }, |
| 135 | + BLOBVALUE: { type: oracledb.DB_TYPE_BLOB, typeName: 'BLOB' }, |
| 136 | + }; |
| 137 | + |
| 138 | + before(async function() { |
| 139 | + connection = await oracledb.getConnection(dbConfig); |
| 140 | + await testsUtil.createType(connection, typeName, ObjSql); |
| 141 | + await testsUtil.createTable(connection, table, createTableSql); |
| 142 | + for (const s of stmts) { |
| 143 | + await connection.execute(s); |
| 144 | + } |
| 145 | + const objType = await connection.getDbObjectClass("NODB_OBJ"); |
| 146 | + const OBJECTVALUE = { |
| 147 | + type: oracledb.DB_TYPE_OBJECT, |
| 148 | + typeName: objType.prototype.fqn, |
| 149 | + typeClass: objType |
| 150 | + }; |
| 151 | + expectedTypes = {...expectedTypes, OBJECTVALUE }; |
| 152 | + }); |
| 153 | + |
| 154 | + after(async function() { |
| 155 | + await testsUtil.dropTable(connection, table); |
| 156 | + await testsUtil.dropType(connection, typeName); |
| 157 | + await connection.execute(dropPackageSql); |
| 158 | + await connection.close(); |
| 159 | + }); |
| 160 | + |
| 161 | + it('304.1 %ROWTYPE', async function() { |
| 162 | + const name = "NODB_ROWTYPE%ROWTYPE"; |
| 163 | + const objClass = await connection.getDbObjectClass(name); |
| 164 | + const types = objClass.prototype.attributes; |
| 165 | + assert.deepStrictEqual(expectedTypes, types); |
| 166 | + }); // 304.1 |
| 167 | + |
| 168 | + it('304.2 %ROWTYPE collection', async function() { |
| 169 | + const name = "FOO_TEST.NODB_ROWTYPE_ARRAY"; |
| 170 | + const objClass = await connection.getDbObjectClass(name); |
| 171 | + const types = objClass.prototype.elementTypeClass.prototype.attributes; |
| 172 | + assert.deepStrictEqual(expectedTypes, types); |
| 173 | + }); // 304.2 |
| 174 | + |
| 175 | +}); // 304 |
0 commit comments