26
26
* PL/SQL OUT CLOB parameters can also be bound as `STRING`
27
27
* The returned length is limited to the maximum size of maxSize option.
28
28
*
29
+ * When the types of bind out variables are not STRING or BUFFER,
30
+ * maxSize option will not take effect.
31
+ *
29
32
* NUMBERING RULE
30
33
* Test numbers follow this numbering rule:
31
34
* 1 - 20 are reserved for basic functional tests
38
41
var oracledb = require ( 'oracledb' ) ;
39
42
var async = require ( 'async' ) ;
40
43
var should = require ( 'should' ) ;
44
+ var stream = require ( 'stream' ) ;
41
45
var dbConfig = require ( './dbConfig.js' ) ;
42
46
var assist = require ( './dataTypeAssist.js' ) ;
43
47
@@ -51,35 +55,25 @@ describe('60. clobPlsqlString.js', function() {
51
55
52
56
var connection = null ;
53
57
var tableName = "oracledb_myclobs" ;
54
-
58
+
55
59
before ( 'get one connection, prepare table' , function ( done ) {
56
60
async . series ( [
57
61
function ( callback ) {
58
62
oracledb . getConnection (
59
- credential ,
63
+ credential ,
60
64
function ( err , conn ) {
61
- should . not . exist ( err ) ;
62
- connection = conn ;
63
- callback ( ) ;
65
+ should . not . exist ( err ) ;
66
+ connection = conn ;
67
+ callback ( ) ;
64
68
}
65
69
) ;
66
70
} ,
67
71
function ( callback ) {
68
72
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
73
}
79
74
] , done ) ;
75
+ } ) // before
80
76
81
- } )
82
-
83
77
after ( 'release connection' , function ( done ) {
84
78
async . series ( [
85
79
function ( callback ) {
@@ -98,37 +92,122 @@ describe('60. clobPlsqlString.js', function() {
98
92
} ) ;
99
93
}
100
94
] , done ) ;
95
+ } ) // after
101
96
102
- } )
97
+ describe ( '60.1 BIND OUT as STRING' , function ( ) {
98
+ before ( 'insert data' , function ( done ) {
99
+ connection . execute (
100
+ "INSERT INTO oracledb_myclobs (num, content) VALUES (1, 'abcdefghijklmnopqrstuvwxyz')" ,
101
+ function ( err ) {
102
+ should . not . exist ( err ) ;
103
+ done ( ) ;
104
+ }
105
+ ) ;
106
+ } ) // before
107
+
108
+ it ( '60.1.1 PL/SQL OUT CLOB parameters can also be bound as STRING' , function ( done ) {
109
+ connection . execute (
110
+ "BEGIN SELECT content INTO :cbv FROM oracledb_myclobs WHERE num = :id; END;" ,
111
+ {
112
+ id : 1 ,
113
+ cbv : { type : oracledb . STRING , dir : oracledb . BIND_OUT }
114
+ } ,
115
+ function ( err , result ) {
116
+ should . not . exist ( err ) ;
117
+ ( result . outBinds . cbv ) . should . be . a . String ;
118
+ ( result . outBinds . cbv ) . should . eql ( 'abcdefghijklmnopqrstuvwxyz' ) ;
119
+ done ( ) ;
120
+ }
121
+ ) ;
122
+ } ) // 60.1.1
103
123
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
- } )
124
+ it ( '60.1.2 The returned length is limited to the maximum size' , function ( done ) {
125
+ connection . execute (
126
+ "BEGIN SELECT content INTO :cbv FROM oracledb_myclobs WHERE num = :id; END;" ,
127
+ {
128
+ id : 1 ,
129
+ cbv : { type : oracledb . STRING , dir : oracledb . BIND_OUT , maxSize : 5 }
130
+ } ,
131
+ function ( err , result ) {
132
+ should . exist ( err ) ;
133
+ ( err . message ) . should . startWith ( 'ORA-06502' ) ; // PL/SQL: numeric or value error
134
+ done ( ) ;
135
+ }
136
+ ) ;
137
+ } ) // 60.1.2
138
+ } ) // 60.1
139
+
140
+ describe ( '60.2 BIND OUT as CLOB' , function ( ) {
141
+ var dataLength = 1000000 ;
142
+ var rawData = assist . createCharString ( dataLength ) ;
143
+
144
+ it ( '60.2.1 maxSize option does not take effect when bind out type is clob' , function ( done ) {
145
+ async . series ( [
146
+ function doInsert ( callback ) {
147
+ connection . execute (
148
+ "INSERT INTO " + tableName + " VALUES (2, EMPTY_CLOB()) RETURNING content INTO :lobbv" ,
149
+ { lobbv : { type : oracledb . CLOB , dir : oracledb . BIND_OUT } } ,
150
+ { autoCommit : false } ,
151
+ function ( err , result ) {
152
+ should . not . exist ( err ) ;
153
+
154
+ var lob = result . outBinds . lobbv [ 0 ] ;
155
+ lob . on ( 'error' , function ( err ) {
156
+ should . not . exist ( err ) ;
157
+ return callback ( err ) ;
158
+ } ) ;
159
+
160
+ var inStream = new stream . Readable ( ) ;
161
+ inStream . _read = function noop ( ) { } ;
162
+ inStream . push ( rawData ) ;
163
+ inStream . push ( null ) ;
164
+
165
+ inStream . on ( 'error' , function ( err ) {
166
+ should . not . exist ( err ) ;
167
+ return callback ( err ) ;
168
+ } ) ;
169
+
170
+ inStream . on ( 'end' , function ( ) {
171
+ connection . commit ( function ( err ) {
172
+ should . not . exist ( err ) ;
173
+ callback ( ) ;
174
+ } ) ;
175
+ } ) ;
176
+
177
+ inStream . pipe ( lob ) ;
178
+ }
179
+ ) ;
180
+ } ,
181
+ function doQuery ( callback ) {
182
+ connection . execute (
183
+ "BEGIN SELECT content INTO :bv FROM " + tableName + " WHERE num = 2; END;" ,
184
+ { bv : { dir : oracledb . BIND_OUT , type : oracledb . CLOB } } ,
185
+ { maxRows : 500 } ,
186
+ function ( err , result ) {
187
+ should . not . exist ( err ) ;
188
+
189
+ var content = '' ;
190
+ var lob = result . outBinds . bv ;
191
+ lob . setEncoding ( 'utf8' ) ;
192
+
193
+ lob . on ( 'data' , function ( chunk ) {
194
+ content += chunk ;
195
+ } ) ;
196
+
197
+ lob . on ( 'end' , function ( ) {
198
+ ( content . length ) . should . be . exactly ( dataLength ) ;
199
+ ( content ) . should . eql ( rawData ) ;
200
+ callback ( ) ;
201
+ } ) ;
202
+
203
+ lob . on ( 'error' , function ( err ) {
204
+ should . not . exist ( err ) ;
205
+ } ) ;
206
+ }
207
+ ) ;
208
+ }
209
+ ] , done ) ;
210
+ } )
211
+ } ) // 60.2
212
+
134
213
} )
0 commit comments