Skip to content

Commit e11fe2b

Browse files
committed
Merge branch 'obakhir' into 'oramain'
Fixed rwlreadlob See merge request rwp/rwloadsim!8
2 parents 89b1426 + 3f99b0b commit e11fe2b

File tree

6 files changed

+149
-20
lines changed

6 files changed

+149
-20
lines changed

src/rwlerror.h

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*
1212
* History
1313
*
14+
* obakhir 24-jun-2024 - Add RWL_ERROR_CLOB_TOO_LARGE for rwlreadlob
1415
* bengsig 4-jun-2024 - $ora01013:break
1516
* bengsig 17-apr-2024 - nostatistics statement
1617
* bengsig 13-mar-2024 - Save sql_id rather than a pointer to it
@@ -1820,6 +1821,12 @@ RWLEDESC("The $ora01013:break directive is in effect and ctrl-c has caused a bre
18201821
"You need to also have a $ora01013:reset directive later in your rwl program" RWL_LINEEND
18211822
"to allow any clean up procedures to be called")
18221823

1824+
#define RWL_ERROR_CLOB_TOO_LARGE 323
1825+
RWLERROR("Only %d out of %d NLS characters from clob saved in string of size %d bytes", RWL_ERROR_RUNTIME)
1826+
RWLEDESC("When performing the OCILobRead2 call, the clob in the database has more" RWL_LINEEND
1827+
"characters than would would fit in the string variable provided. The return" RWL_LINEEND
1828+
"value has been truncated to a lower of number of characters")
1829+
18231830
// When adding new errors, add them before these lines
18241831
// and make sure the #define follows a format like
18251832
// #define RWL_ERROR_whatever_reasonable_here NNN

src/rwlsql.c

+55-19
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*
1212
* History
1313
*
14+
* obakhir 24-jun-2024 - rwlreadlob : enablement of piecewise reading and error handling using RWL_ERROR_CLOB_TOO_LARGE
1415
* bengsig 22-may-2024 - lobwrite: trim before write
1516
* bengsig 4-apr-2024 - $oraerror:showoci directive
1617
* bengsig 21-mar-2024 - fix reconnect
@@ -4373,27 +4374,67 @@ void rwlreadlob(rwl_xeqenv *xev
43734374
, rwl_location *loc
43744375
, text *fname
43754376
)
4376-
{
4377-
ub8 amtchr = pres->slen;
4377+
{
4378+
ub8 byte_amt = 0;
4379+
ub8 char_amt = 0;
4380+
ub8 offset = 1;
4381+
ub8 byte_inc = 0; // Incrementation of read bytes from the CLOB inside the loop
4382+
ub8 char_inc = 0; // Incrementation of read chars from the CLOB inside the loop
4383+
ub8 len = 0; // Variable that will store CLOB length in characters
4384+
4385+
RWL_OATIME_BEGIN(xev, loc, db->seshp, 0, fname, 1)
4386+
OCILobGetLength2( db->svchp
4387+
, xev->errhp
4388+
, lobp
4389+
, &len); // Get the CLOB length in characters
4390+
RWL_OATIME_END
43784391

4392+
char_amt = len;
4393+
43794394
if (!db)
43804395
{
43814396
rwlexecsevere(xev, loc, "[rwlreadlob-nodb]");
43824397
return;
43834398
}
43844399
rwlinitstrvar(xev, pres);
4385-
RWL_OATIME_BEGIN(xev, loc, db->seshp, 0, fname, 1)
4400+
4401+
do
4402+
{
4403+
RWL_OATIME_BEGIN(xev, loc, db->seshp, 0, fname, 1)
43864404
xev->status = OCILobRead2(db->svchp
43874405
, xev->errhp
43884406
, lobp
4389-
, 0 /*byte_amtp*/
4390-
, &amtchr
4391-
, 1 /*offset*/
4392-
, pres->sval, amtchr
4393-
, OCI_ONE_PIECE
4394-
, 0,0
4395-
, (ub2) 0, (ub1) SQLCS_IMPLICIT);
4396-
RWL_OATIME_END
4407+
, &byte_amt
4408+
, &char_amt
4409+
, offset
4410+
, pres->sval+byte_inc
4411+
, pres->slen-byte_inc
4412+
, OCI_FIRST_PIECE // This piece parameter value will change to OCI_NEXT_PIECE internally in OCILobRead2() after the first the first iteration
4413+
, (void *)0
4414+
, (OCICallbackLobRead2)0
4415+
, (ub2)0
4416+
, (ub1)SQLCS_IMPLICIT);
4417+
RWL_OATIME_END
4418+
4419+
byte_inc+=byte_amt;
4420+
char_inc+=char_amt;
4421+
4422+
// If BUFFSIZE < CLOB_Byte_Length
4423+
if(pres->slen-byte_inc <= 4 && xev->status == OCI_NEED_DATA )
4424+
{
4425+
pres->sval[byte_inc] = '\0';
4426+
rwlexecerror(xev, loc, RWL_ERROR_CLOB_TOO_LARGE, char_inc, len, pres->slen);
4427+
pres->ival=rwlatosb8(pres->sval);
4428+
pres->dval=rwlatof(pres->sval);
4429+
pres->isnull = 0;
4430+
OCIBreak(db->svchp, xev->errhp);
4431+
OCIReset(db->svchp, xev->errhp);
4432+
return;
4433+
}
4434+
4435+
} while (xev->status == OCI_NEED_DATA);
4436+
4437+
43974438
if (OCI_SUCCESS != xev->status)
43984439
{
43994440
rwldberrorc1(xev, loc, (text *)"OCILobRead2", fname);
@@ -4402,17 +4443,12 @@ void rwlreadlob(rwl_xeqenv *xev
44024443
pres->dval=0.0;
44034444
}
44044445
else
4405-
{
4406-
if (bit(xev->tflags, RWL_THR_DSQL))
4407-
{
4408-
rwldebugcode(xev->rwm,loc,"OCILobRead got amtchr=%d %.*s"
4409-
, amtchr, amtchr, pres->sval);
4410-
}
4411-
pres->sval[amtchr] = 0;
4446+
{
4447+
pres->sval[byte_inc] = '\0';
44124448
pres->ival=rwlatosb8(pres->sval);
44134449
pres->dval=rwlatof(pres->sval);
4450+
pres->isnull = 0;
44144451
}
4415-
pres->isnull = 0;
44164452
}
44174453

44184454
void rwlreadloblo(rwl_xeqenv *xev

test/392.rwl

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# Test for correct lobread
3+
#
4+
# run it both of these:
5+
# rwloadsim 392.rwl
6+
# rwloadsim 392.rwl --buflength=50
7+
#
8+
# Note that the file has characters in AL32UTF8 format
9+
# and that you must have this environment:
10+
# NLS_LANG=american_america.al32utf8
11+
#
12+
$include:"testuserinfo.rwl"
13+
$include:"testdefault.rwl"
14+
15+
# This will fail first time only
16+
drop table clobtest purge
17+
/
18+
19+
create table clobtest(id number primary key, cl clob)
20+
/
21+
22+
clob cl;
23+
24+
integer buflength := 46; $useroption:buflength
25+
26+
string(60) str;
27+
string(buflength) buf, chr;
28+
29+
integer dblen, mylen;
30+
31+
integer id := 0;
32+
for str := "only ascii㗼𝄢"
33+
, "one utf Bjørn Engsig"
34+
, "aGarçon blåbærsyltetøj four Bjørn 㗼㛛"
35+
, "abGarçon blåbærsyltetøj four Bjørn 㗼㛛"
36+
, "abcGarçon blåbærsyltetøj four Bjørn 㗼㛛"
37+
loop
38+
39+
# insert a row
40+
insert into clobtest values (:id, empty_clob());
41+
select cl from clobtest where id=:id;
42+
43+
# write the string as a lob
44+
writelob cl, str;
45+
46+
# get it back
47+
readlob cl, buf;
48+
mylen := lengthb(buf);
49+
select dbms_lob.getlength(:cl) dblen from dual;
50+
51+
# and also read is as normal varchar2 define
52+
select cl chr from clobtest where id = :id;
53+
printf "inlen=%d mylen=%d, dblen=%d, chrlen=%d\nstr='%s'\nbuf='%s'\nchr='%s'\n\n"
54+
, lengthb(str), mylen, dblen, lengthb(chr), str, buf, chr;
55+
commit;
56+
57+
id += 1;
58+
end loop;
59+

test/test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ then
4747
testlist="$*"
4848
else
4949
# note that 323..326 test CQN which we don't currently compile in
50-
testlist='1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 400 401'
50+
testlist='1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 400 401'
5151
fi
5252

5353
diffokcount=0;

test/testres/392.err.good

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RWL-323: error at [392.rwl;47]<-[392.rwl;58]: Only 36 out of 37 NLS characters from clob saved in string of size 47 bytes
2+
RWL-323: error at [392.rwl;47]<-[392.rwl;58]: Only 37 out of 38 NLS characters from clob saved in string of size 47 bytes

test/testres/392.out.good

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
inlen=17 mylen=17, dblen=13, chrlen=17
2+
str='only ascii㗼𝄢'
3+
buf='only ascii㗼𝄢'
4+
chr='only ascii㗼𝄢'
5+
6+
inlen=21 mylen=21, dblen=20, chrlen=21
7+
str='one utf Bjørn Engsig'
8+
buf='one utf Bjørn Engsig'
9+
chr='one utf Bjørn Engsig'
10+
11+
inlen=45 mylen=45, dblen=36, chrlen=45
12+
str='aGarçon blåbærsyltetøj four Bjørn 㗼㛛'
13+
buf='aGarçon blåbærsyltetøj four Bjørn 㗼㛛'
14+
chr='aGarçon blåbærsyltetøj four Bjørn 㗼㛛'
15+
16+
inlen=46 mylen=43, dblen=37, chrlen=46
17+
str='abGarçon blåbærsyltetøj four Bjørn 㗼㛛'
18+
buf='abGarçon blåbærsyltetøj four Bjørn 㗼'
19+
chr='abGarçon blåbærsyltetøj four Bjørn 㗼㛛'
20+
21+
inlen=47 mylen=44, dblen=38, chrlen=46
22+
str='abcGarçon blåbærsyltetøj four Bjørn 㗼㛛'
23+
buf='abcGarçon blåbærsyltetøj four Bjørn 㗼'
24+
chr='abcGarçon blåbærsyltetøj four Bjørn 㗼�'
25+

0 commit comments

Comments
 (0)