OTL 4.0, otl_read_from_stream / otl_write_to_stream template functions

otl_read_from_stream / otl_write_to_stream functions are a simplified, more efficient version of the STL-compliant stream iterators by usage. std::copy() works fine with the STL-compliant stream iterators, but it calls too many copy / move constructors for the underlying class. otl_read_from_stream / otl_write_to_stream functions are template stand alone functions defined in the global namespace. Here are the signatures of the functions:

template<typename OTLStream,typename OutputIterator>
void otl_read_from_stream
(OTLStream& s,
OutputIterator result,
size_t max_number_of_rows_to_read=0);

template<typename OTLStream,typename InputIterator>
void otl_write_to_stream(InputIterator first, InputIterator last, OTLStream &s);
otl_read_from_stream can be used with std::back_inserter, or std::inserter template functions. otl_write_to_stream can be used with begin() / end() member or global template functions defined in STL containers like std::vector, std::set/multiset, std::map/multimap, etc. These functions should be used as a replacement for less efficient, STL-compliant stream iterator based code, if performance is a concern. Conversion from the STL-compliant stream iterators to calls to otl_read_from_stream / otl_write_to_stream is straightforward.

max_number_of_rows_to_read specifies the maximum number of rows to be read from the stream. Default value of 0 means "to read the whole result set". A positive number puts a cap on how many rows should be read from the stream.

Also, see code example 754 (OCI7), 755 (OCI8 and higher), 756 (MS SQL), 757 (DB2), 758 (PostgreSQL). These code examples may be easily modified to work with the rest of the OTL supported database types.

Go Home

Copyright © 1996-2023, Sergei Kuchin, email: skuchin@gmail.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. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.