OTL 4.0, OTL LOB stream class

OTL LOB stream class

This class is used for reading / writing Large Objects (Oracle 8(i)'s [N]CLOBs/BLOBs, DB2's CLOBs/BLOBs, MS SQL Server's TEXT/IMAGE, MySQL's LONGTEXTs/LONGBLOBs, Sybase's (via ODBC) TEXTs/IMAGEs) in the stream mode. The stream mode allows an unlimited number of bytes to be read/written, regardless of the buffer size.

otl_lob_stream does not have any specific constructor by which an actual instance of otl_lob_stream can be created. Instead, the stream gets initialized by writing / reading an otl_lob_stream variable to / from the otl_stream.

Potentially, the otl_lob_stream class may raise an OTL defined exception.

class otl_lob_stream {
public:
     void set_len(const int alen);
     otl_lob_stream& operator<<(const std::string& s);
       // when OTL_STL is defined and OTL_UNICODE is not defined
     otl_lob_stream& operator<<(const ACE_TString& s);      
       // when OTL_ACE is defined and OTL_UNICODE is not defined
     otl_lob_stream& operator>>(std::string& s);
       // when OTL_STL is defined and OTL_UNICODE is not defined
     otl_lob_stream& operator>>(ACE_TString& s);      
       // when OTL_ACE is defined and OTL_UNICODE is not defined

     void setStringBuffer(const int chunk_size);

       // sets an internal buffer of "chunk_size" to help reduce
       // the number of calls to string::operator +=() in
       // the operators >>() above. The bigger the buffer,
       // the fewer the calls to the +=() to concatenate chunks
       // of the CLOB value to the output string.

     otl_lob_stream& operator<<(const otl_long_string& s);

     otl_lob_stream& operator<<(const otl_long_unicode_string& s);
       // In case if #define OTL_UNICODE is enabled
    otl_lob_stream& operator>>(otl_long_string& s);

    otl_lob_stream& operator>>(otl_long_unicode_string& s);
       // In case if #define OTL_UNICODE is enabled
     int len(void);
     int eof(void);
     void close(void);
}; // end of otl_lob_stream
The ODBC as well as DB2 CLI standards recommend to put LOBs at the end of  INSERT/SELECT statements. For example:

    INSERT INTO my_tab (f1,f2,f3_lob,f4_lob)...
   SELECT f1,f2,f3_lob,f4_lob FROM my_tab...

The recommendation applies especially in the case of piece-wise data operations, that is, in the OTL LOB stream mode. At the same time, the standards say that it is up to the ODBC drivers/database APIs to either enforce or not to enforce that rule.the LOB's part of OCI8 in Oracle does not require that kind of thing, so it is really up to the developer to decide what to do. However, the general recommendation for writing portable code, that uses the LOB stream mode, would be to put LOBs at the end of the column lists in INSERT or SELECT statements.

In order to use the otl_lob_stream class for OTL/ODBC and OTL/DB2-CLI, a call to otl_stream::set_lob_stream_mode() is required.

Also, see example 56, 57, 122, 123, 124, 125, 126, 127, 128, 129.


Prev NextContentsGo Home

Copyright © 1996, 2007, Sergei Kuchin, email: skuchin@ispwest.com, skuchin@gmail.com .

Permission to use, copy, modify and redistribute this document for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies.