group__lob.html

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

HTML
1,040
字号
      <span class="comment">/* read the data into the buffer */</span>
      status = <a class="code" href="group__lob.html#a6">sqlo_lob_read_buffer</a>(dbh, loblp, loblen, data, loblen);

      <span class="keywordflow">if</span> ( 0 &gt; status)  {
          printf(<span class="stringliteral">"sqlo_lob_read_buffer failed: %s\n"</span>, <a class="code" href="group__error.html#a0">sqlo_geterror</a>(dbh) );
          <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
          error_exit(dbh, <span class="stringliteral">"sqlo_lob_read_buffer"</span>);
        }

      <span class="comment">/* compare with our reference data */</span>
      <span class="keywordflow">if</span> (memcmp(data, &amp;cmp_data, MAX_BLOB_BUFFER_DATA)) {
        <span class="keywordtype">int</span> i;
        printf(<span class="stringliteral">"LOB read is different from LOB written\n"</span>);
        <span class="keywordflow">for</span> (i = 0; i &lt;= MAX_BLOB_BUFFER_DATA; ++i) {
          <span class="keywordflow">if</span> (data[i] != cmp_data[i])
            printf(<span class="stringliteral">"diff at pos %d\n"</span>, i);
        }
      }

    } <span class="keywordflow">else</span> {
      printf(<span class="stringliteral">"LOB is NULL\n"</span>);
      <span class="keywordflow">return</span> 0;
    }

  <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="comment">/* $Id */</span>
</pre></div> </dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex15_8c-example.html#a8">ex15.c</a>.</dl>    </td>
  </tr>
</table>
<a name="a7" doxytag="sqlora.h::sqlo_lob_read_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_read_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>loblen</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>
Read lob data from lob column into a stream.
<p>
Use <a class="el" href="group__lob.html#a5">Functions to insert/select LOBs</a> to get the loblen you have to use here.<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>loblen</em>&nbsp;</td><td>
I - The length of the lob </td></tr>
<tr><td valign=top><em>fp</em>&nbsp;</td><td>
I - A filepointer</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> select_file_from_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">"SELECT KEY, BDATA FROM T_SQLORA_BLOB WHERE KEY = :1"</span>;
  <span class="keywordtype">int</span> status;
  <a class="code" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth = <a class="code" href="group__constants.html#a5a49">SQLO_STH_INIT</a>;
  <span class="keywordtype">int</span> k = key;
  FILE * fp;
  <a class="code" href="group__typedefs.html#a2">sqlo_lob_desc_t</a> loblp;
  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> loblen;
  <span class="keywordtype">short</span> ind;

  <span class="keywordflow">if</span> (!(fp = fopen(fname, <span class="stringliteral">"w"</span>))) {
    printf(<span class="stringliteral">"ERROR: Cannot open %s for write\n"</span>, fname);
    <span class="keywordflow">return</span> 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">/* bind input */</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>(k), 0, 0)))
    error_exit(dbh, <span class="stringliteral">"sqlo_bind_by_pos"</span>);

  <span class="comment">/* alloc lob desc */</span>
  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> !=  <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">/* define output */</span>
  <span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != 
      (<a class="code" href="group__complex.html#a5">sqlo_define_by_pos</a>(sth, 1, <a class="code" href="group__constants.html#a6a56">SQLOT_INT</a>, &amp;k, <span class="keyword">sizeof</span>(k), 0, 0, 0)) ||
      (<a class="code" href="group__complex.html#a5">sqlo_define_by_pos</a>(sth, 2, <a class="code" href="group__constants.html#a6a82">SQLOT_BLOB</a>, &amp;loblp, 0, &amp;ind, 0, 0))) {
    <a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &amp;loblp);
    error_exit(dbh, <span class="stringliteral">"sqlo_define_by_pos2"</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> ( 0 &gt; 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">/* get the LOB length */</span>
  status = <a class="code" href="group__lob.html#a5">sqlo_lob_get_length</a>(dbh, loblp, &amp;loblen);

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

  <span class="comment">/* write it to the file */</span>
  status = <a class="code" href="group__lob.html#a7">sqlo_lob_read_stream</a>(dbh, loblp, loblen, fp);

  <span class="keywordflow">if</span> ( 0 &gt; status) {
    <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);
    error_exit(dbh, <span class="stringliteral">"sqlo_lob_read_stream"</span>);
  }

  fclose(fp);

  <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);

  <a class="code" href="group__transactions.html#a1">sqlo_rollback</a>(dbh);
  drop_blob_table(dbh);

  <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#a6">sqlo_lob_read_buffer</a> </dl><dl compact><dt><b>Examples: </b></dt><dd>
<a class="el" href="ex16_8c-example.html#a7">ex16.c</a>.</dl>    </td>
  </tr>
</table>
<a name="a2" doxytag="sqlora.h::sqlo_lob_write_buffer"></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_buffer </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>loblen</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>void *&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>bufp</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>unsigned int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>bufl</em>, </td>
        </tr>
        <tr>
          <td></td>
          <td></td>
          <td class="md" nowrap>unsigned int&nbsp;</td>
          <td class="mdname" nowrap>&nbsp; <em>piece</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 buffer into the lob column.
<p>
<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>loblen</em>&nbsp;</td><td>
I - The length of the lob. </td></tr>
<tr><td valign=top><em>loblp</em>&nbsp;</td><td>
I - A lob locator. </td></tr>
<tr><td valign=top><em>bufp</em>&nbsp;</td><td>
I - A buffer of data. </td></tr>
<tr><td valign=top><em>bufl</em>&nbsp;</td><td>
I - The length of the buffer in terms of bytes. </td></tr>

⌨️ 快捷键说明

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