ex15_8c-example.html
来自「一个很好用的Linux/Unix下Oracle OCI开发接口封装库」· HTML 代码 · 共 125 行
HTML
125 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Example Documentation</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.18 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="globals.html">Globals</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindex" href="examples.html">Examples</a> </center>
<hr><h1>ex15.c</h1> Example for selecting blob data into a buffer
<p>
<div class="fragment"><pre><span class="comment">/* $Id: ex15_8c-example.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
<span class="preprocessor">#include <stdio.h></span>
<span class="preprocessor">#include <stdlib.h></span>
<span class="preprocessor">#include "examples.h"</span>
<span class="keywordtype">int</span> select_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="keywordtype">char</span> * stmt =
<span class="stringliteral">"SELECT KEY, CDATA 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;
<span class="keywordtype">char</span> * data;
<span class="keywordtype">short</span> ind;
<span class="keywordtype">char</span> cmp_data[MAX_BLOB_BUFFER_DATA]; <span class="comment">/* our buffer to compare the result */</span>
<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;
fillbuf(cmp_data, MAX_BLOB_BUFFER_DATA); <span class="comment">/* our reference data */</span>
<span class="comment">/* parse */</span>
<span class="keywordflow">if</span> (0 > (sth = <a name="a0"></a><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 name="a1"></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>, &k, <span class="keyword">sizeof</span>(k), 0, 0))) {
error_exit(dbh, <span class="stringliteral">"sqlo_bind_by_pos"</span>);
}
<span class="comment">/* allocate a lob descriptor */</span>
<span class="keywordflow">if</span> (0 > <a name="a2"></a><a class="code" href="group__lob.html#a0">sqlo_alloc_lob_desc</a>(dbh, &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 name="a3"></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>, &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#a6a81">SQLOT_CLOB</a>, &loblp, 0, &ind, 0, 0))) {
<a name="a4"></a><a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &loblp);
error_exit(dbh, <span class="stringliteral">"sqlo_define_by_pos2"</span>);
}
<span class="comment">/* execute */</span>
status = <a name="a5"></a><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, &loblp);
error_exit(dbh, <span class="stringliteral">"sqlo_execute"</span>);
}
<span class="keywordflow">if</span> (ind != <a class="code" href="group__constants.html#a5a47">SQLO_NULL_IND</a>)
{
status = <a name="a6"></a><a class="code" href="group__lob.html#a5">sqlo_lob_get_length</a>(dbh, loblp, &loblen);
<span class="keywordflow">if</span> ( 0 > status) {
<a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &loblp);
error_exit(dbh, <span class="stringliteral">"sqlo_free_lob_desc"</span>);
}
<span class="keywordflow">if</span> (loblen != MAX_BLOB_BUFFER_DATA) {
printf(<span class="stringliteral">"Invalid LOB size. Expected %d, got %d\n"</span>, MAX_BLOB_BUFFER_DATA,
loblen);
<a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &loblp);
<a name="a7"></a><a class="code" href="group__easy.html#a13">sqlo_close</a>(sth);
<span class="keywordflow">return</span> 0;
}
<span class="comment">/* allocate the buffer for the data */</span>
data = malloc(loblen * <span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<span class="keywordflow">if</span> (!data) {
printf(<span class="stringliteral">"FATAL: malloc error at %d\n"</span>, __LINE__);
<a class="code" href="group__lob.html#a1">sqlo_free_lob_desc</a>(dbh, &loblp);
exit(EXIT_FAILURE);
}
<span class="comment">/* read the data into the buffer */</span>
status = <a name="a8"></a><a class="code" href="group__lob.html#a6">sqlo_lob_read_buffer</a>(dbh, loblp, loblen, data, loblen);
<span class="keywordflow">if</span> ( 0 > status) {
printf(<span class="stringliteral">"sqlo_lob_read_buffer failed: %s\n"</span>, <a name="a9"></a><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, &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, &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 <= 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, &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><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 + -
显示快捷键?