group__lob.html

来自「一个很好用的Linux/Unix下Oracle OCI开发接口封装库」· HTML 代码 · 共 1,040 行 · 第 1/4 页

HTML
1,040
字号
<tr><td valign=top><em>piece</em>&nbsp;</td><td>
I - The piece indicator <ul>
<li>SQLO_ONE_PIECE <li>SQLO_FIRST_PIECE <li>SQLO_NEXT_PIECE <li>SQLO_LAST_PIECE </ul>
</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
<ul>
<li>SQLO_SUCCESS <li>SQLO_STILL_EXECUTING <li>SQLO_ERROR </ul>
</dl><dl compact><dt><b>Since: </b></dt><dd>
Version 2.2 </dl><dl compact><dt><b>Example:</b></dt><dd>
 <div class="fragment"><pre><span class="comment">/* $Id: group__lob.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
<span class="preprocessor">#include &lt;stdio.h&gt;</span>
<span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<span class="preprocessor">#include "examples.h"</span>


<span class="keywordtype">int</span> insert_into_blob_table(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh, <span class="keywordtype">int</span> key )
{
  <span class="keywordtype">char</span> * stmt = 
    <span class="stringliteral">"INSERT INTO T_SQLORA_BLOB (KEY, CDATA) "</span>
    <span class="stringliteral">"VALUES (:b1, EMPTY_CLOB()) RETURNING CDATA INTO :b2"</span>;

  <span class="keywordtype">char</span> data[MAX_BLOB_BUFFER_DATA];        <span class="comment">/* a data buffer */</span>
  <a class="code" href="group__typedefs.html#a2">sqlo_lob_desc_t</a> loblp;                  <span class="comment">/* the lob locator */</span>
  <a class="code" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth;
  <span class="keywordtype">int</span> status;
  <span class="keywordtype">int</span> k = key;


  <span class="comment">/* create the test table */</span>
  create_blob_table(dbh);

  <span class="comment">/* fill the data buffer with some characters */</span>
  fillbuf(data, MAX_BLOB_BUFFER_DATA);

  <span class="comment">/* parse the statement */</span>

  <span class="keywordflow">if</span> (0&gt;(sth = <a class="code" href="group__complex.html#a0">sqlo_prepare</a>(dbh, stmt)))
    error_exit(dbh, <span class="stringliteral">"sqlo_prepare"</span>);

  <span class="comment">/* alloate the lob descriptor */</span>
  <span class="keywordflow">if</span> (0 &gt; <a class="code" href="group__lob.html#a0">sqlo_alloc_lob_desc</a>(dbh, &amp;loblp))
    error_exit(dbh, <span class="stringliteral">"sqlo_alloc_lob_desc"</span>);

  <span class="comment">/* bind input variables. Note: we bind the lob descriptor here */</span>
  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != 
      (<a class="code" href="group__complex.html#a3">sqlo_bind_by_pos</a>(sth, 1, <a class="code" href="group__constants.html#a6a56">SQLOT_INT</a>, &amp;k, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), NULL, 0)) ||
      (<a class="code" href="group__complex.html#a3">sqlo_bind_by_pos</a>(sth, 2, <a class="code" href="group__constants.html#a6a81">SQLOT_CLOB</a>, &amp;loblp, 0, NULL, 0))
      ) {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_bind_by_pos"</span>);
  }

  <span class="comment">/* execute the statement */</span>
  status = <a class="code" href="group__complex.html#a8">sqlo_execute</a>(sth, 1);

  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != status) {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>);
  }

  <span class="comment">/* write the lob */</span>
  status = <a class="code" href="group__lob.html#a2">sqlo_lob_write_buffer</a>(dbh, loblp, MAX_BLOB_BUFFER_DATA, data, 
                                 MAX_BLOB_BUFFER_DATA, <a class="code" href="group__constants.html#a5a50">SQLO_ONE_PIECE</a>);

  <span class="keywordflow">if</span> (status &lt; 0) {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_log_write_buffer"</span>);
  }

  <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
  <a class="code" href="group__easy.html#a13">sqlo_close</a>(sth);
  
  <span class="keywordflow">return</span> (1);
}

<span class="keywordtype">void</span> create_blob_table(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)
{
  <span class="keywordtype">char</span> * stmt=
    <span class="stringliteral">"CREATE TABLE T_SQLORA_BLOB (KEY INTEGER, CDATA CLOB, BDATA BLOB)"</span>;

  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a class="code" href="group__easy.html#a14">sqlo_exec</a>(dbh, stmt))
    <span class="keywordflow">if</span> (<a class="code" href="group__error.html#a1">sqlo_geterrcode</a>(dbh) != 955) <span class="comment">/* table exists already */</span>
      error_exit(dbh, <span class="stringliteral">"sqlo_exec"</span>);
}

<span class="keywordtype">void</span> drop_blob_table(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)
{
  <span class="keywordtype">char</span> * stmt = <span class="stringliteral">"DROP TABLE T_SQLORA_BLOB"</span>;

  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a class="code" href="group__easy.html#a14">sqlo_exec</a>(dbh, stmt))
    error_exit(dbh, <span class="stringliteral">"sqlo_exec"</span>);
}

<span class="keywordtype">void</span> fillbuf(<span class="keywordtype">char</span> * data, <span class="keywordtype">int</span> len)
{
  <span class="keywordtype">int</span> i;
  <span class="keywordflow">for</span> (i = 0; i &lt; len; ++i) {
    data[i] = <span class="charliteral">'A'</span> + i % 26;
  }
}

<span class="comment">/* $Id */</span>
</pre></div> </dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex13_8c-example.html#a5">ex13.c</a>.</dl>    </td>
  </tr>
</table>
<a name="a4" doxytag="sqlora.h::sqlo_lob_write_stream"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
  <tr>
    <td class="md">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td class="md" nowrap valign="top"> int sqlo_lob_write_stream </td>
          <td class="md" valign="top">(&nbsp;</td>
          <td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a>&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>dbh</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap><a class="el" href="group__typedefs.html#a2">sqlo_lob_desc_t</a>&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>loblp</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>unsigned int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>filelen</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>FILE *&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>fp</em></td>
        </tr>
        <tr>
          <td></td>
          <td class="md">)&nbsp;</td>
          <td class="md" colspan="2"></td>
        </tr>

      </table>
    </td>
  </tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
  <tr>
    <td>
      &nbsp;
    </td>
    <td>

<p>
Write lob data from a file into the lob column.
<p>
This function reads the  data from the stream and writes it into the lob column via  <a class="el" href="group__lob.html#a2">Functions to insert/select LOBs</a>.
<p>
<dl compact><dt><b>Attention: </b></dt><dd>
The function does not close or rewind the fp.</dl><dl compact><dt><b>Parameters: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em>dbh</em>&nbsp;</td><td>
I - A database handle. </td></tr>
<tr><td valign=top><em>loblp</em>&nbsp;</td><td>
I - A lob locator. </td></tr>
<tr><td valign=top><em>filelen</em>&nbsp;</td><td>
I - The size of the file (total lob length) </td></tr>
<tr><td valign=top><em>fp</em>&nbsp;</td><td>
I - The filepointer</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
<ul>
<li>SQLO_SUCCESS <li>SQLO_ERROR </ul>
</dl><dl compact><dt><b>Since: </b></dt><dd>
Version 2.2 </dl><dl compact><dt><b>Example:</b></dt><dd>
 <div class="fragment"><pre><span class="comment">/* $Id: group__lob.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
<span class="preprocessor">#include &lt;stdio.h&gt;</span>
<span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<span class="preprocessor">#include "examples.h"</span>

<span class="keywordtype">int</span> insert_file_into_blob_table(<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh, <span class="keywordtype">int</span> key, <span class="keyword">const</span> <span class="keywordtype">char</span> * fname )
{

  <span class="keywordtype">char</span> * stmt = 
    <span class="stringliteral">"INSERT INTO T_SQLORA_BLOB (KEY, BDATA) "</span>
    <span class="stringliteral">"VALUES (:b1, EMPTY_BLOB()) RETURNING BDATA INTO :b2"</span>;
  <a class="code" href="group__typedefs.html#a2">sqlo_lob_desc_t</a> loblp;                  <span class="comment">/* the lob locator */</span>
  <a class="code" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth;
  <span class="keywordtype">int</span> status;
  FILE * fp;
  <span class="keywordtype">unsigned</span> filelen;
  <span class="keywordtype">short</span> ind;
  <span class="keywordtype">int</span> k = key;

  create_blob_table(dbh);

  <span class="keywordflow">if</span> (! (fp = fopen(fname, <span class="stringliteral">"r"</span>))) {
    printf(<span class="stringliteral">"ERROR: cannot open file %s\n"</span>, fname);
    <span class="keywordflow">return</span> 0;
  }

  <span class="comment">/* determine file len */</span>
  fseek(fp, 0, SEEK_END);
  filelen = ftell(fp);
  fseek(fp, 0, 0);

  <span class="comment">/* parse */</span>
  <span class="keywordflow">if</span> (0&gt;(sth = <a class="code" href="group__complex.html#a0">sqlo_prepare</a>(dbh, stmt)))
    error_exit(dbh, <span class="stringliteral">"sqlo_prepare"</span>);

  <span class="comment">/* allocate the lob locator */</span>
  <span class="keywordflow">if</span> (0 &gt; <a class="code" href="group__lob.html#a0">sqlo_alloc_lob_desc</a>(dbh, &amp;loblp))
    error_exit(dbh, <span class="stringliteral">"sqlo_alloc_lob_desc"</span>);

  <span class="comment">/* bind input variables */</span>
  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != 
      (<a class="code" href="group__complex.html#a3">sqlo_bind_by_pos</a>(sth, 1, <a class="code" href="group__constants.html#a6a56">SQLOT_INT</a>, &amp;k, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>), NULL, 0)) ||
      (<a class="code" href="group__complex.html#a3">sqlo_bind_by_pos</a>(sth, 2, <a class="code" href="group__constants.html#a6a82">SQLOT_BLOB</a>, &amp;loblp, 0, &amp;ind, 0))
      ) {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_bind_by_pos"</span>);
  }

  <span class="comment">/* execute */</span>
  status = <a class="code" href="group__complex.html#a8">sqlo_execute</a>(sth, 1);

  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != status) {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>);
  }

  <span class="comment">/* write the lob */</span>
  status = <a class="code" href="group__lob.html#a4">sqlo_lob_write_stream</a>(dbh, loblp, filelen, fp);

  <span class="keywordflow">if</span> (status &lt; 0) {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_lob_write_stream"</span>);
  }

  <a class="code" href="group__easy.html#a13">sqlo_close</a>(sth);
  <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
  fclose(fp);

  <span class="keywordflow">return</span> (1);
}


<span class="comment">/* $Id */</span>
</pre></div></dl><dl compact><dt><b>See also: </b></dt><dd>
<a class="el" href="group__lob.html#a2">sqlo_lob_write_buffer</a> </dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex14_8c-example.html#a5">ex14.c</a>.</dl>    </td>
  </tr>
</table>
<hr><address style="align: right;"><small>Generated on Thu Aug 14 18:02:53 2003 for libsqlora8 by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.18 </small></address>
</body>
</html>

⌨️ 快捷键说明

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