📄 otl3_stream_class.htm
字号:
</tr>
<tr>
<td style="vertical-align: top;"><font size="-1"><b>otl_var_varchar_long</b></font></td>
<td style="vertical-align: top;">9<br>
</td>
<td style="vertical-align: top;"><font size="-1">datatype that
is
mapped into
LONG in Oracle 7/8/9/10/11, TEXT in MS SQL Server and Sybase, CLOB in
DB2<br>
</font></td>
</tr>
</tbody>
</table>
<ul>
<font size="-1"><br>
</font>Here is the function prototype:
</ul>
<pre> <a name="describe_select"></a>otl_column_desc* describe_select(int& desc_len);</pre>
<ul>
Besides the pointer to be returned, the function has an output
parameter: <i>desc_len. </i>The length of the output column list is
returned
via this
parameter. The pointer points to an internal structure inside the
stream
which gets deallocated at the moment of the stream desctruction, so the
user does not need to do any memory deallocation operations with the
pointer.
</ul>
<ul>
<li>Read objects from the stream</li>
</ul>
<pre> <a name="operator_gg"></a><br><br><br>#if defined(<a
href="otl3_compile.htm#OTL_UNICODE">OTL_UNICODE</a>)<br><br> // OTL_UNICODE is enabled (2-byte Unicode)<br><br> <a
name="unicode_unsigned_read"></a>otl_stream& operator>>(unsigned char* s);<br> // returns a null terminated array of unsigned short's<br> // (double-byte Unicode characters). Therefore, "unsigned char*" <br> // needs to be type cast to "unsigned short*". Also, it's recommended<br> // to allocate 2 bytes per each Unicode character. For Oracle Unicode,<br> // add extra 2 bytes per possible surrogate character.<br><br> otl_stream& operator>>(<a
href="otl3_long_string.htm#otl_long_unicode_string">otl_long_unicode_string</a>& s);<br> // read the Unicode LOB from the stream<br><a
name="unicode_gg"></a><br> #if defined(<a
href="otl3_compile.htm#OTL_UNICODE_CHAR_TYPE">OTL_UNICODE_CHAR_TYPE</a>)<br> otl_stream& operator>>(OTL_UNICODE_CHAR_TYPE& c); // read Unicode character<br> otl_stream& operator>>(OTL_UNICODE_CHAR_TYPE* s); // read Unicode string<br> #endif<br><a
name="unicode_string_gg"></a><br> #if defined(<a
href="otl3_compile.htm#OTL_UNICODE_STRING_TYPE">OTL_UNICODE_STRING_TYPE</a>)<br> otl_stream& operator>>(OTL_UNICODE_STRING_TYPE& s); <br> // read Unicode string into a string class variable. VARCHAR/CHAR can be <br> // read as well as Large Text Objects (NTEXT, CLOB, NCLOB, etc.)<br> #endif<br><br>#else<br><br> // default, one-byte character sets<br><br> otl_stream& operator>>(char& c); <br> otl_stream& operator>>(unsigned char& c); <br> otl_stream& operator>>(char* s); <br> otl_stream& operator>>(unsigned char* s); <br> <a
name="long_string_read"></a>otl_stream& operator>>(<a
href="otl3_long_string.htm">otl_long_string</a>& s); // read the LOB from the stream<br> <a
name="stl_string_read"></a>otl_stream& operator>>(std::string& s); // read the ANSI C++ std::string<br><br>#endif<br><br> otl_stream& operator>>(int& n);<br> otl_stream& operator>>(unsigned& u);<br> otl_stream& operator>>(short& sh);<br> otl_stream& operator>>(long int& l);<br> otl_stream& operator>>(float& f);<br> otl_stream& operator>>(double& d);<br> <a
name="64_bit_integer_write"></a>otl_stream& operator>>(<a
href="otl3_compile.htm#OTL_BIGINT">OTL_BIGINT</a>& d); <br><span
style="text-decoration: underline;"></span> // when #define <a
href="otl3_compile.htm#OTL_BIGINT">OTL_BIGINT</a> is enabled.<br> // For ODBC drivers that do not support bigint binding <br> // of host variables natively, this operator can convert<br> // a numeric string value to a bigint numeric value. That is, when<br> // a numeric value is returned from the SQL statement as a string, <br> // this operator will convert the string to a signed 64-bit integer <br> // in C++.<br> otl_stream& operator>>(TIMESTAMP_STRUCT& s); // read the <a
href="otl3_bind_variables.htm#timestamp">timestamp</a> from the stream<br> // (OTL 4.0/ODBC and OTL 4.0/DB2-CLI <br> // only)<br> otl_stream& operator>>(<a
href="#otl_datetime">otl_datetime</a>& dt); // read date/time info from the stream<br> otl_stream& operator>>(<a
href="otl3_pl_tab.htm">otl_XXX_tab</a><…>& tab); // read PL/SQL tables from the stream (OCIx)<br> <a
name="stream_read_lob"></a>otl_stream& operator>>(<a
href="otl3_lob_stream.htm">otl_lob_stream</a>& lob); <br> // read reference to CLOB/BLOB/TEXT/IMAGE from otl_stream <br> // into otl_lob_stream. In other words,<br> // initialize otl_lob_stream for reading CLOB/BLOB/TEXT/IMAGE<br> // in stream mode<br><br> <a
name="stream_read_refcur"></a>otl_stream& operator>>(<a
href="otl4_refcur_stream.htm">otl_refcur_stream</a>& refcur);<br> // read a reference cursor descriptor to a variable of <br> // the <a
href="otl4_refcur_stream.htm">otl_refcur_stream</a> type. That is, initialize <br> // otl_refcur_stream for reading rows from the<br> // reference cursor.<br><br></pre>
<ul>
<li><a name="operator_ll"></a>Write objects into the stream</li>
</ul>
<pre>#if defined(<a
href="file:///D%7C/oscl/vc/doc/otl4/otl3_compile.htm#OTL_UNICODE">OTL_UNICODE</a>)<br><br> // OTL_UNICODE is enabled (2-byte Unicode)<br><br> <a
name="unicode_unsigned_char_write"></a>otl_stream& operator<<(const unsigned char* s);<br> // writes a null terminated array of unsigned short's<br> // (double-byte Unicode characters) into the stream . <br> // Therefore, "unsigned short*" <br> // needs to be type cast to "unsigned char*". Also, it's recommended<br> // to allocate 2 bytes per each Unicode character. For Oracle Unicode, <br> // add extra 2 bytes per possible surrogate character.<br><span
style="font-family: monospace;"> <br> otl_stream& operator<<(</span><a
style="font-family: monospace;"
href="file:///D%7C/oscl/vc/doc/otl4/otl3_long_string.htm#otl_long_unicode_string">otl_long_unicode_string</a><span
style="font-family: monospace;">& s); </span><br
style="font-family: monospace;"> // write a Unicode LOB to the stream<br><a
name="unicode_ll"></a> <span style="font-family: monospace;"> <br></span> #if defined(<a
href="file:///D%7C/oscl/vc/doc/otl4/otl3_compile.htm#OTL_UNICODE_CHAR_TYPE">OTL_UNICODE_CHAR_TYPE</a>)<br> otl_stream& operator<<(const OTL_UNICODE_CHAR_TYPE& c); // write Unicode character<br> otl_stream& operator<<(const OTL_UNICODE_CHAR_TYPE* s); // write Unicode string<br> #endif<br><a
name="unicode_string_ll"></a><br> #if defined(<a
href="otl3_compile.htm#OTL_UNICODE_STRING_TYPE">OTL_UNICODE_STRING_TYPE</a>)<br> otl_stream& operator>>(const OTL_UNICODE_STRING_TYPE& s); <br> // write Unicode string from a string class variable into the stream.<br> // VARCHAR/CHAR can be written as well <br> // as Large Text Objects (NTEXT, CLOB, NCLOB, etc.)<br> #endif<br><br>#else<br><br> // default, one-byte character sets<br><br> otl_stream& operator<<(const char c);<br> otl_stream& operator<<(const unsigned char c);<br> otl_stream& operator<<(const char* s);<br> otl_stream& operator<<(const unsigned char* s);<br> <a
name="long_string_write"></a>otl_stream& operator<<(const <a
href="otl3_long_string.htm">otl_long_string</a>& d); // write the LOB into the stream<br> <a
name="stl_string_write"></a>otl_stream& operator<<(const std::string& s); <br> // write the ANSI C++ std::string.<br><br>#endif<br> <br> otl_stream& operator<<(const int n);<br> otl_stream& operator<<(const unsigned u);<br> otl_stream& operator<<(const short sh);<br> otl_stream& operator<<(const long int l);<br> otl_stream& operator<<(const float f);<br> otl_stream& operator<<(const double d);<br> <a
name="64_bit_integer_read"></a>otl_stream& operator<<(const <a
href="otl3_compile.htm#OTL_BIGINT">OTL_BIGINT</a> d); <br> // When #define <a
href="otl3_compile.htm#OTL_BIGINT">OTL_BIGINT</a> is enabled.<br> // For ODBC drivers that do not support bigint binding <br> // of host variables natively, this operator can convert<br> // a C++ bigint numeric value to a string value. That is, when <br> // a numeric value is being written to the stream and the<br> // corresponding host variable has a string binding, <br> // this operator will convert a signed 64-bit integer <br> // in C++ to a string, which will get passed to <br> // the SQL statement.<br> <br> otl_stream& operator<<(const <a
href="#otl_null">otl_null</a> n); // write NULL into the stream<br> otl_stream& operator<<(const TIMESTAMP_STRUCT& d); // write the <a
href="otl3_bind_variables.htm#timestamp">timestamp</a> into the stream<br> // (OTL 4.0/ODBC and OTL 4.0/DB2-CLI only)<br> otl_stream& operator<<(const <a
href="#otl_datetime">otl_datetime</a>& dt); // write date/time info into the stream<br> otl_stream& operator<<(const <a
href="otl3_pl_tab.htm">otl_XXX_tab</a><…>& tab); // read PL/SQL tables from the stream (OCIx)<br> <a
name="stream_write_lob"></a>otl_stream& operator<<(<a
href="otl3_lob_stream.htm">otl_lob_stream</a>& lob); <br> // write otl_lob_stream descriptor intoto otl_stream (OCI8).<br> // In other words, initialize otl_lob_stream <br> // for writing CLOB/BLOB in stream mode.<span
style="font-family: monospace;"></span><br></pre>
<ul>
<p>OTL 4.0 defines a dummy class to allow NULLs to be written into
the
stream:</p>
</ul>
<pre> <a
name="otl_null"></a>class otl_null{<br> public:<br> otl_null(){}<br> ~otl_null(){}<br> };</pre>
<ul>
OTL 4.0 also defines the otl_datetime class to allow date/time
information
to written into / read from the stream:
</ul>
<pre> <a name="otl_datetime"></a>class otl_datetime{<br> public:<br> int year; <br> int month; <br> int day;<br> int hour;<br> int minute;<br> int second;<br><br> unsigned long fraction; // second's fractional part. Equals 0 by default.<br> int frac_precision; // second's precision. Equals 0 by default<br><br> #if defined(<a
href="otl3_compile.htm#OTL_ORA_TIMESTAMP">OTL_ORA_TIMESTAMP</a>) || defined(<a
href="otl3_compile.htm#OTL_ODBC_TIME_ZONE">OTL_ODBC_TIME_ZONE</a>)<br> short int tz_hour; // time zone hour<br> short int tz_minute; // time zone minute<br> #endif<br><br> };</pre>
<blockquote><i>Fraction</i> can be up to nine significant decimal
digits
long, depending on what the second's precision (frac_precision) is
supported
by the database (MS SQL Server down to milliseconds, Sybase down
to milliseconds, DB2 down to microseconds, etc.), and what precision is
specified in the timestamp datatype (Oracle 9i/10g: decimal digits in
the
range
of [1..6] digits). Fraction does not have any effect in case if the
database
supports the timestamp datatype with whole seconds only.</blockquote>
<ul>
<li> <a name="set_all_column_types"></a>Set data types of a group of
SELECT
output columns. This function can override data types of column groups:
all numeric columns to string, all date columns to string, or the
combination
of both. <i>amask </i>parameter can be set to the following values:</li>
<ul>
<li>otl_all_num2str, e.g.: set_all_column_types(otl_all_num2str);</li>
<li>otl_all_date2str, e.g.: set_all_column_types(otl_all_date2str);</li>
<li>otl_all_num2str | otl_all_date2str, e.g.:
set_all_column_types(otl_all_num2str
| otl_all_date2str);</li>
</ul>
<pre>void set_all_column_types(const unsigned int amask=0);</pre>
<li> <a name="set_column_type"></a>Set a SELECT output column
datatype.
In other
words, override the default mapping of output column datatypes.</li>
</ul>
<pre> void set_column_type(const int column_ndx,<br> const int col_type,<br> const int col_size=0);</pre>
<blockquote><i>column_ndx</i> is the relative index of the columns in
the
query: 1,2,3...
<p><i>col_type</i> is one of the <a href="#otl_var_dbtype">datatype
constants</a>,
defined by OTL. </p>
<p><i>col_size</i> is the size, associated with the new datatype of
the
column. It has be to specified for the otl_var_char type only. Sizess
of
all numeric types are calculated. </p>
<p>This function can be called for straight SELECT statements (both
Oracle
and ODBC), referenced cursor SELECT statements (Oracle), and implicit
SELECT
statements / result sets (ODBC for MS SQL Server and Sybase). </p>
<p>The usability of this function is limited by the following
datatype
compatibility matrix. <br>
</p>
<p><a name="mapping"></a><br>
<br>
<table border="1" cols="3" width="100%">
<caption><br>
</caption><tbody>
</tbody> <tbody>
<tr>
<td><b>Database datatype</b></td>
<td><b>Default datatype</b></td>
<td><b>Datatype override</b></td>
</tr>
<tr>
<td>NUMBER (Oracle)</td>
<td>otl_var_double</td>
<td>otl_var_char, otl_var_int, otl_var_float, otl_var_short,
otl_var_unsigned_int</td>
</tr>
<tr>
<td>NUMERIC, FLOAT, REAL, MONEY, DECIMAL (MS SQL Server,
Sybase, DB2)</td>
<td>otl_var_double</td>
<td>otl_var_char, otl_var_int, otl_var_float, otl_var_short,
otl_var_unsigned_int,
otl_var_long_int</td>
</tr>
<tr>
<td>INT (MS SQL Server, Sybase, DB2)</td>
<td>otl_var_int</td>
<td>otl_var_char, otl_var_double, otl_var_float, otl_var_short,
otl_var_unsigned_int,
otl_var_long_int</td>
</tr>
<tr>
<td>SMALLINT, TINYINT (MS SQL Server, Sybase, DB2)</td>
<td>otl_var_short</td>
<td>otl_var_char, otl_var_int, otl_var_float, otl_var_double,
otl_var_unsigned_int,
otl_var_long_int</td>
</tr>
<tr>
<td>DATE (Oracle), DATETIME (MS SQL Server, Sybase)</td>
<td>otl_timestamp</td>
<td>otl_var_char</td>
</tr>
<tr>
<td>LONG (Oracle)</td>
<td>otl_var_varchar_long</td>
<td>otl_var_char (<=32000 bytes)</td>
</tr>
<tr>
<td>TEXT (MS SQL Server, Sybase)<
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -