📄 group__g__format.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>OCILIB (C Driver for Oracle): Formatted functions</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.4 --><div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> </ul></div><h1>Formatted functions</h1><hr><a name="_details"></a><h2>Detailed Description</h2>OCILIB offers some smart routines that takes a variable number of arguments in order to minimize OCILIB function calls and reduce the amount of code lines<p>On Windows platforms, the target programming language must support the __cdecl calling convention<p><dl class="note" compact><dt><b>Note:</b></dt><dd><a class="el" href="group__g__format.html#g85318e359913e49d5654d2f53a070ef7" title="Perform 3 calls (prepare+execute+fetch) in 1 call.">OCI_Immediate()</a> and <a class="el" href="group__g__format.html#g845524c6dce7499a0cc27488052a93c2" title="Performs 4 call (prepare+bind+execute+fetch) in 1 call.">OCI_ImmediateFmt()</a> support all OCILIB supported types for output result, except :<ul><li><a class="el" href="struct_o_c_i___long.html" title="Oracle Long datatype.">OCI_Long</a></li><li><a class="el" href="struct_o_c_i___statement.html" title="Oracle SQL or PL/SQL statement.">OCI_Statement</a> If a query output result contains one of these unsupported types, the function returns FALSE</li></ul><p>In the parameter list, every output placeholder MUST be preceded by an integer parameter that indicates the type of the placeholder in order to handle correctly the given pointer.</dd></dl>Possible values for indicating placeholders type :<p><ul><li>OCI_ARG_SHORT ------> short *</li><li>OCI_ARG_USHORT -----> unsigned short *</li><li>OCI_ARG_INT --------> int *</li><li>OCI_ARG_UINT -------> unsigned int*</li><li>OCI_ARG_BIGINT -----> big_int *</li><li>OCI_ARG_BIGUINT ----> unsigned big_int *</li><li>OCI_ARG_DOUBLE ----> double *</li><li>OCI_ARG_TEXT -------> dtext *</li><li>OCI_ARG_RAW --------> void *</li><li>OCI_ARG_DATETIME ---> <a class="el" href="struct_o_c_i___date.html" title="Oracle internal date representation.">OCI_Date</a> *</li><li>OCI_ARG_LOB --------> <a class="el" href="struct_o_c_i___lob.html" title="Oracle Internal Large objects:.">OCI_Lob</a> *</li><li>OCI_ARG_FILE -------> <a class="el" href="struct_o_c_i___file.html" title="Oracle External Large objects:.">OCI_File</a> *</li><li>OCI_ARG_TIMESTAMP --> OCI_Timstamp *</li><li>OCI_ARG_INTERVAL ---> <a class="el" href="struct_o_c_i___interval.html" title="Oracle internal interval representation.">OCI_Interval</a> *</li></ul><p><dl class="note" compact><dt><b>Note:</b></dt><dd>For output strings and Raws, returned data is copied to the given buffer instead of returning a pointer the real data. So theses buffers must be big enough to hold the column content. No size check is performed.</dd></dl><ul><li>For strings, only the real string is copied.</li><li>For Raws, the number of bytes copied is the column size</li></ul><p><dl class="warning" compact><dt><b>Warning:</b></dt><dd>Input parameters for formatted function only support a restricted set of datatypes !</dd></dl>Supported input identifiers :<p><ul><li>'s' : (dtext *) ----------> input string (quotes are added)</li><li>'m' : (dtext *) ----------> metadata string (no quotes added)</li><li>'t' : (<a class="el" href="struct_o_c_i___date.html" title="Oracle internal date representation.">OCI_Date</a> *) -------> Date</li><li>'p' : (<a class="el" href="struct_o_c_i___timestamp.html" title="Oracle internal timestamp representation.">OCI_Timestamp</a> *) --> timestamp</li><li>'v' : (<a class="el" href="struct_o_c_i___interval.html" title="Oracle internal interval representation.">OCI_Interval</a> *) ---> Interval</li><li>'i' : (int) --------------> signed 32 bits integer</li><li>'u' : (unsigned int) -----> unsigned 32 bits integer</li><li>'li' : (big_int) ----------> signed 64 bits integer</li><li>'lu' : (big_uint) ---------> unsigned 64 bits integer</li><li>'hi' : (short) ------------> signed 16 bits integer</li><li>'hu' : (unsigned short) ---> unsigned 16 bits integer</li><li>'g' : (double ) ----------> Numerics</li></ul><p><dl class="user" compact><dt><b>Example</b></dt><dd><div class="fragment"><pre class="fragment"><span class="preprocessor">#include "ocilib.h"</span><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>){ <a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> *cn; <a class="code" href="struct_o_c_i___statement.html" title="Oracle SQL or PL/SQL statement.">OCI_Statement</a> *st; <a class="code" href="struct_o_c_i___resultset.html" title="Collection of output columns from a select statement.">OCI_Resultset</a> *rs; <span class="keywordtype">int</span> code = 1; <span class="keywordtype">char</span> name[50]; <span class="keywordflow">if</span> (!<a class="code" href="group__g__init.html#gcdb642d75f7c8478e083634144bc813c" title="Initializes the library.">OCI_Initialize</a>(err_handler, NULL, OCI_ENV_DEFAULT)) <span class="keywordflow">return</span> EXIT_FAILURE; cn = <a class="code" href="group__g__connect.html#gdb6e2cdf759587dd81c2fda7c5f44338" title="Create a physical connection to an Oracle database server.">OCI_ConnectionCreate</a>(<span class="stringliteral">"db"</span>, <span class="stringliteral">"usr"</span>, <span class="stringliteral">"pwd"</span>, OCI_SESSION_DEFAULT); st = <a class="code" href="group__g__exec.html#g335822f983af0fb5c529431f06a9a17b" title="Create a statement object and return its handle.">OCI_StatementCreate</a>(cn); <span class="comment">/* sql format with params ----------------------------------------------- */</span> <a class="code" href="group__g__format.html#ge1b4805b4ed6530b496cd637b52a2adf" title="Parse and execute a formatted SQL statement or PL/SQL block.">OCI_ExecuteStmtFmt</a>(st, <span class="stringliteral">"select article from test_fetch where code = %i"</span>, code); rs = <a class="code" href="group__g__fetch.html#gf2a9e28b66a9538ba0ffb62bffb87c16" title="Retrieve the resultset handle from an executed statement.">OCI_GetResultset</a>(st); <span class="keywordflow">while</span> (<a class="code" href="group__g__fetch.html#g36ac26dcea78f6074421781e401f97ba" title="Fetch the next row of the resultset.">OCI_FetchNext</a>(rs)) printf(<span class="stringliteral">"article : %s\n"</span>, <a class="code" href="group__g__fetch.html#g755a9b07c174feacd05c86e0e44b0ab0" title="Return the current string value of the column at the given index in the resultset...">OCI_GetString</a>(rs, 1)); <span class="comment">/* sql immediate (parse, exec, one fetch) ------------------------------- */</span> <a class="code" href="group__g__format.html#g85318e359913e49d5654d2f53a070ef7" title="Perform 3 calls (prepare+execute+fetch) in 1 call.">OCI_Immediate</a>(cn, <span class="stringliteral">"select code, article from test_fetch where code = 1"</span>, OCI_ARG_INT, &code, OCI_ARG_TEXT, name); printf(<span class="stringliteral">"article : %s - code %i\n"</span>, name, code); <span class="comment">/* sql immediate (parse, exec, one fetch) with params ------------------- */</span> <a class="code" href="group__g__format.html#g845524c6dce7499a0cc27488052a93c2" title="Performs 4 call (prepare+bind+execute+fetch) in 1 call.">OCI_ImmediateFmt</a>(cn, <span class="stringliteral">"select article from test_fetch where code = %i"</span>, code, OCI_ARG_TEXT, name); printf(<span class="stringliteral">"article : %s\n"</span>, name); <a class="code" href="group__g__init.html#g639706aa8e9689c7ebffc018fac6d3ae" title="Clean up all resources allocated by the library.">OCI_Cleanup</a>(); <span class="keywordflow">return</span> EXIT_SUCCESS;}</pre></div> </dd></dl><p><table border="0" cellpadding="0" cellspacing="0"><tr><td></td></tr><tr><td colspan="2"><br><h2>Functions</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT boolean </td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__format.html#g85318e359913e49d5654d2f53a070ef7">OCI_Immediate</a> (<a class="el" href="struct_o_c_i___connection.html">OCI_Connection</a> *con, const mtext *sql,...)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Perform 3 calls (prepare+execute+fetch) in 1 call. <a href="#g85318e359913e49d5654d2f53a070ef7"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT boolean </td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__format.html#g845524c6dce7499a0cc27488052a93c2">OCI_ImmediateFmt</a> (<a class="el" href="struct_o_c_i___connection.html">OCI_Connection</a> *con, const mtext *sql,...)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Performs 4 call (prepare+bind+execute+fetch) in 1 call. <a href="#g845524c6dce7499a0cc27488052a93c2"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT boolean </td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__format.html#g86178afd9c5ad75be6082abc01cf9f49">OCI_PrepareFmt</a> (<a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *stmt, const mtext *sql,...)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Prepare a formatted SQL statement or PL/SQL block. <a href="#g86178afd9c5ad75be6082abc01cf9f49"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">OCI_EXPORT boolean </td><td class="memItemRight" valign="bottom"><a class="el" href="group__g__format.html#ge1b4805b4ed6530b496cd637b52a2adf">OCI_ExecuteStmtFmt</a> (<a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> *stmt, const mtext *sql,...)</td></tr><tr><td class="mdescLeft"> </td><td class="mdescRight">Parse and execute a formatted SQL statement or PL/SQL block. <a href="#ge1b4805b4ed6530b496cd637b52a2adf"></a><br></td></tr></table><hr><h2>Function Documentation</h2><a class="anchor" name="ge1b4805b4ed6530b496cd637b52a2adf"></a><!-- doxytag: member="ocilib.h::OCI_ExecuteStmtFmt" ref="ge1b4805b4ed6530b496cd637b52a2adf" args="(OCI_Statement *stmt, const mtext *sql,...)" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">OCI_EXPORT boolean OCI_ExecuteStmtFmt </td> <td>(</td> <td class="paramtype"><a class="el" href="struct_o_c_i___statement.html">OCI_Statement</a> * </td> <td class="paramname"> <em>stmt</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">const mtext * </td> <td class="paramname"> <em>sql</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype"> </td> <td class="paramname"> <em>...</em></td><td> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td><td width="100%"></td> </tr> </table></div><div class="memdoc"><p>Parse and execute a formatted SQL statement or PL/SQL block. <p><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>stmt</em> </td><td>- Statement handle </td></tr> <tr><td valign="top"></td><td valign="top"><em>sql</em> </td><td>- SQL statement </td></tr> <tr><td valign="top"></td><td valign="top"><em>...</em> </td><td>- List of program values to format the SQL</td></tr> </table></dl><dl class="return" compact><dt><b>Returns:</b></dt><dd>TRUE on success otherwise FALSE </dd></dl><p>Definition at line <a class="el" href="statement_8c-source.html#l01389">1389</a> of file <a class="el" href="statement_8c-source.html">statement.c</a>.</p><p>References <a class="el" href="group__g__exec.html#g7189aa353845909aaedc8d5956429450">OCI_Execute()</a>, and <a class="el" href="group__g__exec.html#gd5a7fcffe7d24da001e44636cfc06578">OCI_Prepare()</a>.</p></div></div><p><a class="anchor" name="g85318e359913e49d5654d2f53a070ef7"></a><!-- doxytag: member="ocilib.h::OCI_Immediate" ref="g85318e359913e49d5654d2f53a070ef7" args="(OCI_Connection *con, const mtext *sql,...)" --><div class="memitem">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -