|
| 1 | +/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */ |
| 2 | + |
| 3 | +/****************************************************************************** |
| 4 | + * |
| 5 | + * You may not use the identified files except in compliance with the Apache |
| 6 | + * License, Version 2.0 (the "License.") |
| 7 | + * |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0. |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * The node-oracledb test suite uses 'mocha', 'should' and 'async'. |
| 19 | + * See LICENSE.md for relevant licenses. |
| 20 | + * |
| 21 | + * NAME |
| 22 | + * 60. clobPlsqlString.js |
| 23 | + * |
| 24 | + * DESCRIPTION |
| 25 | + * |
| 26 | + * PL/SQL OUT CLOB parameters can also be bound as `STRING` |
| 27 | + * The returned length is limited to the maximum size of maxSize option. |
| 28 | + * |
| 29 | + * NUMBERING RULE |
| 30 | + * Test numbers follow this numbering rule: |
| 31 | + * 1 - 20 are reserved for basic functional tests |
| 32 | + * 21 - 50 are reserved for data type supporting tests |
| 33 | + * 51 onwards are for other tests |
| 34 | + * |
| 35 | + *****************************************************************************/ |
| 36 | +"use strict"; |
| 37 | + |
| 38 | +var oracledb = require('oracledb'); |
| 39 | +var async = require('async'); |
| 40 | +var should = require('should'); |
| 41 | +var dbConfig = require('./dbConfig.js'); |
| 42 | +var assist = require('./dataTypeAssist.js'); |
| 43 | + |
| 44 | +describe('60. clobPlsqlString.js', function() { |
| 45 | + |
| 46 | + if(dbConfig.externalAuth){ |
| 47 | + var credential = { externalAuth: true, connectString: dbConfig.connectString }; |
| 48 | + } else { |
| 49 | + var credential = dbConfig; |
| 50 | + } |
| 51 | + |
| 52 | + var connection = null; |
| 53 | + var tableName = "oracledb_myclobs"; |
| 54 | + |
| 55 | + before('get one connection, prepare table', function(done) { |
| 56 | + async.series([ |
| 57 | + function(callback) { |
| 58 | + oracledb.getConnection( |
| 59 | + credential, |
| 60 | + function(err, conn) { |
| 61 | + should.not.exist(err); |
| 62 | + connection = conn; |
| 63 | + callback(); |
| 64 | + } |
| 65 | + ); |
| 66 | + }, |
| 67 | + function(callback) { |
| 68 | + assist.createTable(connection, tableName, callback); |
| 69 | + }, |
| 70 | + function(callback) { |
| 71 | + connection.execute( |
| 72 | + "INSERT INTO oracledb_myclobs (num, content) VALUES (1, 'abcdefghijklmnopqrstuvwxyz')", |
| 73 | + function(err) { |
| 74 | + should.not.exist(err); |
| 75 | + callback(); |
| 76 | + } |
| 77 | + ); |
| 78 | + } |
| 79 | + ], done); |
| 80 | + |
| 81 | + }) |
| 82 | + |
| 83 | + after('release connection', function(done) { |
| 84 | + async.series([ |
| 85 | + function(callback) { |
| 86 | + connection.execute( |
| 87 | + "DROP TABLE oracledb_myclobs", |
| 88 | + function(err) { |
| 89 | + should.not.exist(err); |
| 90 | + callback(); |
| 91 | + } |
| 92 | + ); |
| 93 | + }, |
| 94 | + function(callback) { |
| 95 | + connection.release( function(err) { |
| 96 | + should.not.exist(err); |
| 97 | + callback(); |
| 98 | + }); |
| 99 | + } |
| 100 | + ], done); |
| 101 | + |
| 102 | + }) |
| 103 | + |
| 104 | + it('60.1 PL/SQL OUT CLOB parameters can also be bound as STRING', function(done) { |
| 105 | + connection.execute( |
| 106 | + "BEGIN SELECT content INTO :cbv FROM oracledb_myclobs WHERE num = :id; END;", |
| 107 | + { |
| 108 | + id: 1, |
| 109 | + cbv: { type: oracledb.STRING, dir: oracledb.BIND_OUT} |
| 110 | + }, |
| 111 | + function(err, result) { |
| 112 | + should.not.exist(err); |
| 113 | + (result.outBinds.cbv).should.be.a.String; |
| 114 | + (result.outBinds.cbv).should.eql('abcdefghijklmnopqrstuvwxyz'); |
| 115 | + done(); |
| 116 | + } |
| 117 | + ); |
| 118 | + }) |
| 119 | + |
| 120 | + it('60.2 The returned length is limited to the maximum size', function(done) { |
| 121 | + connection.execute( |
| 122 | + "BEGIN SELECT content INTO :cbv FROM oracledb_myclobs WHERE num = :id; END;", |
| 123 | + { |
| 124 | + id: 1, |
| 125 | + cbv: { type: oracledb.STRING, dir: oracledb.BIND_OUT, maxSize: 5 } |
| 126 | + }, |
| 127 | + function(err, result) { |
| 128 | + should.exist(err); |
| 129 | + (err.message).should.startWith('ORA-06502'); // PL/SQL: numeric or value error |
| 130 | + done(); |
| 131 | + } |
| 132 | + ); |
| 133 | + }) |
| 134 | +}) |
0 commit comments