⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otl4_ex391.htm

📁 ISO_C++:C++_OTL开发文档
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
  <meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Sergei Kuchin">
  <meta name="GENERATOR"
 content="Mozilla/4.75 [en] (Win98; U) [Netscape]">
  <meta name="KeyWords"
 content="OTL, Oracle, ODBC, DB2, CLI, database API, C++, Template Library">
  <title>OTL 4.0, Example 391 (Insert/Update/Select with MySQL LONGTEXT
in stream mode, without otl_lob_stream::set_Len())</title>
</head>
<body>
<center>
<h1>OTL 4.0, Example 391 (Insert/Update/Select with MySQL LONGTEXT in
stream
mode, without otl_lob_stream::set_len())</h1>
</center>
This example demonstrates INSERT, UPDATE, and SELECT statements with
the
MySQL LONGTEXT datatype in the <a href="otl3_lob_stream.htm">stream
mode</a>, without otl_lob_stream::set_len() in OTL 4.0.138 and higher.<br>
<h2>Source Code</h2>
<pre>#include &lt;iostream&gt;<br>using namespace std;<br><br>#include &lt;stdio.h&gt;</pre>
<pre>#define <a href="otl3_compile.htm#OTL_ODBC">OTL_ODBC</a> // Compile OTL 4.0/ODBC<br>// The following #define is required with MyODBC 3.51.11 and higher<br>#define <a
 href="otl3_compile.htm#OTL_ODBC_SELECT_STM_EXECUTE_BEFORE_DESCRIBE">OTL_ODBC_SELECT_STM_EXECUTE_BEFORE_DESCRIBE</a><br>#include &lt;otlv4.h&gt; // include the OTL 4.0 header file<br><br><a
 href="otl3_connect_class.htm">otl_connect</a> db; // connect object<br><br>void insert()<br>// insert rows into table<br>{<a
 href="otl3_long_string.htm">otl_long_string</a> f2(6000); // define long string variable<br>&nbsp;<a
 href="otl3_stream_class.htm">otl_stream</a> o; // defined an otl_stream variable<br>&nbsp;o.<a
 href="otl3_stream_class.htm#set_lob_stream_mode">set_lob_stream_mode</a>(true); // set the "lob stream mode" flag<br>&nbsp;o.<a
 href="otl3_stream_class.htm#open">open</a>(1, // buffer size has to be set to 1 for operations with LOBs<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "insert into test_tab values(:f1&lt;int&gt;,:f2&lt;varchar_long&gt;, "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ":f3&lt;varchar_long&gt;) ",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // SQL statement<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db // connect object<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br>&nbsp;o.<a
 href="otl3_stream_class.htm#set_commit">set_commit</a>(0); // setting stream "auto-commit" to "off". It is required<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // when LOB stream mode is used.</pre>
<pre>&nbsp;int i,j;<br>&nbsp;<a href="otl3_lob_stream.htm">otl_lob_stream</a> lob; // LOB stream for reading/writing unlimited number<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // of bytes regardless of the buffer size.<br>&nbsp;<a
 href="otl3_lob_stream.htm">otl_lob_stream</a> lob2; // LOB stream for reading/writing unlimited number<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // of bytes regardless of the buffer size.<br><br>&nbsp;for(i=1;i&lt;=20;++i){<br>&nbsp; o&lt;&lt;i;<br>&nbsp; o<a
 href="otl3_stream_class.htm#stream_write_lob">&lt;&lt;</a>lob; // Initialize otl_lob_stream by writing it<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // into otl_stream.<br>&nbsp; o<a
 href="otl3_stream_class.htm#stream_write_lob">&lt;&lt;</a>lob2; // Initialize otl_lob_stream by writing it<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // into otl_stream.<br><br>&nbsp; for(j=0;j&lt;5000;++j)<br>&nbsp;&nbsp; f2[j]='*';<br>&nbsp; f2[5000]='?';<br>&nbsp; f2.<a
 href="otl3_long_string.htm#set_len">set_len</a>(5001);<br><br>// OTL 4.0.138 and higher does not require the LOB's total length to be <br>// set beforehand. Instead, otl_long_string::last_piece can be used.<br>//&nbsp; lob.<a
 href="otl3_lob_stream.htm#set_len">set_len</a>(5001+2123); // setting the total&nbsp; size of<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // the LONGTEXT to be written.<br>&nbsp;&nbsp;<br>&nbsp; lob<a
 href="otl3_lob_stream.htm#write">&lt;&lt;</a>f2; // writing first chunk of the LONGTEXT into lob<br><br><br>&nbsp; f2[2122]='?';<br>&nbsp; f2.set_len(2123); // setting the size of the second chunk<br><br>&nbsp; lob&lt;&lt;f2; // writing the second chunk of the LONGTEXT into lob<br>&nbsp; lob.<a
 href="otl3_lob_stream.htm">close</a>(); // closing the otl_lob_stream<br><br>&nbsp; for(j=0;j&lt;5000;++j)<br>&nbsp;&nbsp; f2[j]='*';<br>&nbsp; f2[5000]='?';<br>&nbsp; f2.<a
 href="otl3_long_string.htm#set_len">set_len</a>(5001);<br>// OTL 4.0.138 and higher does not require the LOB's total length to be <br>// set beforehand. Instead, otl_long_string::last_piece can be used.<br>//&nbsp; lob2.<a
 href="otl3_lob_stream.htm#set_len">set_len</a>(5001+2123); // setting the total&nbsp; size of<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // the LONGTEXT to be written.<br>&nbsp;&nbsp;<br>&nbsp; lob2<a
 href="otl3_lob_stream.htm#write">&lt;&lt;</a>f2; // writing first chunk of the LONGTEXT into lob<br><br>&nbsp; f2[2122]='?';<br>&nbsp; f2.set_len(2123); // setting the size of the second chunk<br><br>&nbsp; lob2&lt;&lt;f2; // writing the second chunk of the LONGTEXT into lob<br>&nbsp; lob2.<a
 href="otl3_lob_stream.htm">close</a>(); // closing the otl_lob_stream<br><br>&nbsp;}<br><br>&nbsp;db.commit(); // committing transaction.<br>}</pre>
<pre>void update()<br>// insert rows in table<br>{</pre>
<pre>&nbsp;<a href="otl3_long_string.htm">otl_long_string</a> f2(6200); // define long string variable<br><br>&nbsp;<a
 href="otl3_stream_class.htm">otl_stream</a> o; // defined an otl_stream variable<br>&nbsp;o.<a
 href="otl3_stream_class.htm#set_lob_stream_mode">set_lob_stream_mode</a>(true); // set the "lob stream mode" flag<br>&nbsp;o.<a
 href="otl3_stream_class.htm#open">open</a>(1, // buffer size has to be set to 1 for operations with LOBs<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "update test_tab "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&nbsp;&nbsp; set f2=:f2&lt;varchar_long&gt; "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "where f1=:f1&lt;int&gt; ",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // SQL statement<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db // connect object<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br><br>&nbsp; <a
 href="otl3_lob_stream.htm">otl_lob_stream</a> lob;<br><br>&nbsp; o.<a
 href="otl3_stream_class.htm#set_commit">set_commit</a>(0); // setting stream "auto-commit" to "off".&nbsp;<br><br><br>&nbsp;for(int j=0;j&lt;6000;++j){<br>&nbsp; f2[j]='#';<br>&nbsp;}<br><br>&nbsp;f2[6000]='?';<br>&nbsp;f2.<a
 href="otl3_long_string.htm#set_len">set_len</a>(6001);<br><br>&nbsp;o<a
 href="otl3_stream_class.htm#stream_write_lob">&lt;&lt;</a>lob; // Initialize otl_lob_stream by writing it<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // into otl_stream.<br>&nbsp;o&lt;&lt;5;<br><br>// lob.<a
 href="otl3_lob_stream.htm#set_len">set_len</a>(6001*4); // setting the total size of of the LONGTEXT to be written<br>&nbsp;for(int i=1;i&lt;=4;++i)<br>&nbsp; lob<a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -