| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Need help with OCILobWrite
Hello together,
I have a problem, using the OCILobWrite function to copy
a byte-stream into a BLOB.
If I try to write a BLOB of 300 Bytes, this could normally done
in one piece, but all time the OCILobWrite funtion returns with
Error-code 1.
Any Idea?
blob is a properly allocated handle, buffer contains the data of "bytes"
bytes.
All handles are also properly initialized.
For example a Fetch of a Blob, using OCILobRead works without problems.
Thanx in advance
--
MfG / Best Regards
Frank an der Heiden
ESA - Energotec Systeme und Automation GmbH
Grafenberger Allee 130 a
40237 Düsseldorf
Tel.: +49 (0)211 91440-19
email: fh_at_energotec.de
"I came, saw and installed everything new"
Here is the code:
************************
void write_blob(OCILobLocator *blob, const void *buffer, int bytes)
{
ub4 offset = 1;
ub4 loblen = 0;
ub1 bufp[32000];
ub4 amtp = bytes;
ub1 piece;
sword retval;
ub4 bytes2write;
ub4 remainder = bytes;
printf("--> To do streamed write lob, amount = %d\n", bytes);
OCILobGetLength(oschp, errhp, blob, &loblen);
printf("Before stream write, LOB length = %lu\n\n", loblen);
if (bytes > 32000)
bytes2write = 32000;
else
bytes2write = bytes;
memmove(bufp,buffer,bytes2write);
remainder = remainder - bytes2write;
if (remainder == 0) /* exactly one piece in the file */
{
if (retval = OCILobWrite(oschp, errhp, blob, &amtp, offset, (dvoid
*)bufp,
(ub4)bytes2write, OCI_ONE_PIECE, (dvoid *)0,
(sb4 (*)(dvoid *, dvoid *, ub4 *, ub1 *)) 0,
(ub2) 0, (ub1) SQLCS_IMPLICIT) != OCI_SUCCESS)
{
printf("ERROR: OCILobWrite(), retval = %d\n", retval);
return;
}
}
else /* more than one piece */
{
if (OCILobWrite(oschp, errhp, blob, &amtp, offset, (dvoid *) bufp,
(ub4) 32000, OCI_FIRST_PIECE, (dvoid *)0,
(sb4 (*)(dvoid *, dvoid *, ub4 *, ub1 *)) 0,
(ub2) 0, (ub1) SQLCS_IMPLICIT) != OCI_NEED_DATA)
{
printf("ERROR: OCILobWrite().\n");
return;
}
piece = OCI_NEXT_PIECE;
do
{
if (remainder > 32000)
bytes2write = 32000;
else
{
bytes2write = remainder;
piece = OCI_LAST_PIECE;
}
memmove(bufp,buffer+(bytes-remainder),bytes2write);
retval = OCILobWrite(oschp, errhp, blob, &amtp, offset, (dvoid *)
bufp,
(ub4) bytes2write, piece, (dvoid *)0,
(sb4 (*)(dvoid *, dvoid *, ub4 *, ub1 *)) 0,
(ub2) 0, (ub1) SQLCS_IMPLICIT);
remainder = remainder - bytes2write;
} while (retval == OCI_NEED_DATA && remainder>0);
}
if (retval != OCI_SUCCESS)
{
printf("Error: stream writing LOB.\n");
return;
}
OCILobGetLength(oschp, errhp, blob, &loblen);
printf("After stream write, LOB length = %lu\n\n", loblen);
return;
}
Received on Sat Dec 02 2000 - 16:21:47 CST
![]() |
![]() |