COPY-LOB statement
Copies large object data between BLOBs, CLOBs, MEMPTRs, and LONGCHARs. It also copies large object data to and from the file system, and converts large object data to or from a specified code page.
Note: You cannot copy large object data between BLOBs and CLOBs directly. However, you can copy a BLOB or CLOB to a MEMPTR or LONGCHAR (which converts the data) and then copy the MEMPTR or LONGCHAR to the CLOB or BLOB, respectively.Syntax
[ OBJECT ]source-lob
FILEsource-filename
A character expression that specifies the name of a file containing the source object data to be copied. The object data in this source file is copied to the specified target object or file. You can specify an absolute or relative pathname. Any relative pathname is relative to the current working directory.The AVM raises the ERROR condition ifsource-filename
resolves to the Unknown value (?
) or the source file cannot be read.STARTING ATn
An integer expression indicating a one-based offset position, in the source object or file, from which to start copying. The copy begins at offset 1, by default. The AVM raises the ERROR condition if the specified offset position is less than 1, greater than the size of the object or file, or the Unknown value (?
).Note: Offsets are measured in bytes for binary data (BLOB or MEMPTR), and characters for character data (CLOB or LONGCHAR).FORlength
An integer expression indicating the number of bytes or characters to copy from the source object or file starting at the specified offset position. The AVM copies from the specified offset position to the end of the object or file, by default. The AVM raises the ERROR condition if the specified length is less than 0, greater than the size of the object or file, or the Unknown value (?
).Note: Offsets are measured in bytes for binary data (BLOB or MEMPTR), and characters for character data (CLOB or LONGCHAR).[ OBJECT ]target-lob
The target object to receive the copy, which can be a MEMPTR or LONGCHAR variable, a BLOB or CLOB database or temp-table field, or a dynamic expression that resolves to a BLOB or CLOB database or temp-table field. The object data in the specified source object or file is copied to the target object.If the specified target object does not yet exist, the AVM either creates a BLOB or a CLOB, or allocates memory for a MEMPTR or a LONGCHAR. If the specified target object already exists, the AVM deletes the object before the copy operation begins, by default. You can specify the OVERLAY ATn
option to overlay some portion of an existing target object.Note: Although the AVM allocates memory for a target MEMPTR, you are responsible for freeing that memory.OVERLAY ATn
[ TRIM ]
An overlay position in the target object. The AVM copies the source object or file to an existing BLOB, CLOB, MEMPTR, or LONGCHAR target starting at the given position. If the operation results in writing past the end of a target BLOB, CLOB, or LONGCHAR, the AVM extends the target object as necessary. If the operation results in writing past the end of a target MEMPTR, the AVM raises the ERROR condition.If the target object does not yet exist, the AVM raises the ERROR condition. If the specified overlay position is less than 1, greater than the size of the object, or the Unknown value (?
), the AVM raises the ERROR condition.You can specify the TRIM option only if the target object is a BLOB or CLOB. In this case, the AVM copies the source object or file to the existing target object and truncates any data remaining in the target object. If the target object is a MEMPTR or LONGCHAR, the AVM ignores this option.FILEtarget-filename
[ APPEND ]
A character expression that specifies the name of the target file to which the object data in the specified source object or file is copied. You can specify an absolute or relative pathname. Any relative pathname is relative to the current working directory.If the target file does not exist, the AVM creates the file. If the target file exists, and you specify theAPPEND
option, the AVM opens the file and appends the object data to the end of a file. If the target file exists, but you do not specify theAPPEND
option, the AVM creates the target file anew (which overwrites the original file).Iftarget-filename
resolves to the Unknown value (?
), or the target file cannot be created or written, the AVM raises the ERROR condition.NO-CONVERT | CONVERTconvert-phrase
Lets you specify the character conversion behavior between the source and target objects.TheNO-CONVERT
option specifies that no conversions occur. However, if the target is a LONGCHAR or a CLOB, the AVM validates the character data based on the target object’s code page. For a CLOB, this is the code page of the CLOB. For a LONGCHAR, this is-cpinternal
unless the LONGCHAR’s code page was set using the FIX-CODEPAGE statement. If the validation fails, the AVM raises the ERROR condition.TheCONVERT
option lets you specify how the AVM converts object data. Following is the syntax forconvert-phrase:
SpecifySOURCE
CODEPAGE
to indicate that a source object is in the specified code page. If you specifyTARGET
CODEPAGE
, the AVM converts the target object to the specified code page.Table 18 lists the default character conversions the AVM performs when copying data between the source and target objects. References to CLOBCP and CLOBDB represent CLOB data in either the CLOB’s defined code page or the database's defined code page, respectively. References to the "fixed code page" represent the code page of a target LONGCHAR variable set using the FIX-CODEPAGE statement.
Note: If either the source or target object is a file, the target’s code page defaults to-cpstream
.NO-ERROR
Suppresses ABL errors or error messages that would otherwise occur and diverts them to the ERROR-STATUS system handle. If an error occurs, the action of the statement is not done and execution continues with the next statement. If the statement fails, any persistent side-effects of the statement are backed out. If the statement includes an expression that contains other executable elements, like methods, the work performed by these elements may or may not be done, depending on the order the AVM resolves the expression elements and the occurrence of the error.To check for errors after a statement that uses the NO-ERROR option:
- Check the ERROR-STATUS:ERROR attribute to see if the AVM raised the ERROR condition.
- Check if the ERROR-STATUS:NUM-MESSAGES attribute is greater than zero to see if the AVM generated error messages. ABL handle methods used in a block without a CATCH end block treat errors as warnings and do not raise ERROR, do not set the ERROR-STATUS:ERROR attribute, but do add messages to the ERROR-STATUS system handle. Therefore, this test is the better test for code using handle methods without CATCH end blocks. ABL handle methods used in a block with a CATCH end block raise ERROR and add messages to the error object generated by the AVM. In this case, the AVM does not update the ERROR-STATUS system handle.
- Use ERROR-STATUS:GET-MESSAGE(
message-num
) to retrieve a particular message, wheremessage-num
is 1 for the first message.If the statement does not include the NO-ERROR option, you can use a CATCH end block to handle errors raised by the statement.Some other important usage notes on the NO-ERROR option:
- NO-ERROR does not suppress errors that raise the STOP or QUIT condition.
- A CATCH statement, which introduces a CATCH end block, is analogous to a NO-ERROR option in that it also suppresses errors, but it does so for an entire block of code. It is different in that the error messages are contained in a class-based error object (generated by the AVM or explicitly thrown), as opposed to the ERROR-STATUS system handle. Also, if errors raised in the block are not handled by a compatible CATCH block, ON ERROR phrase, or UNDO statement, then the error is not suppressed, but handled with the default error processing for that block type.
- When a statement contains the NO-ERROR option and resides in a block with a CATCH end block, the NO-ERROR option takes precedence over the CATCH block. That is, an error raised on the statement with the NO-ERROR option will not be handled by a compatible CATCH end block. The error is redirected to the ERROR-STATUS system handle as normal.
- If an error object is thrown to a statement that includes the NO-ERROR option, then the information and messages in the error object will be used to set the ERROR-STATUS system handle. This interoperability feature is important for those integrating code that uses the traditional NO-ERROR technique with the newer, structured error handling that features error objects and CATCH end blocks.
Notes
- If a source or target object is stored in a database, its record must be available to copy. The lock mode of the record containing the target object must be EXCLUSIVE-LOCK or SHARE-LOCK and upgradeable; otherwise, the COPY-LOB statement raises the ERROR condition.
- You can also assign large object data from one BLOB or MEMPTR to another, and one CLOB or LONGCHAR to another, using the Assignment (=) statement or ASSIGN statement. You cannot use the Assignment (=) statement or ASSIGN statement to assign large object data between BLOBs or MEMPTRs and CLOBs or LONGCHARs.
OpenEdge Release 10.2B
|