📄 group__g__demo.html
字号:
print_text(<span class="stringliteral">"> article : "</span>); print_dstr(temp); print_text(<span class="stringliteral">"\n"</span>);}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * test_fetch</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> test_fetch(<span class="keywordtype">void</span>){ <span class="keywordtype">int</span> i, n; print_text(<span class="stringliteral">"\n>>>>> SIMPLE TEST FETCH WITH META DATA\n\n"</span>); <span class="comment">/* execute query in one go */</span> <a class="code" href="group__g__exec.html#gf2163ec44e644cc734c393188707985b" title="Parse and execute a SQL statement or PL/SQL block.">OCI_ExecuteStmt</a>(st, MT(<span class="stringliteral">"select * from test_fetch"</span>)); rs = <a class="code" href="group__g__fetch.html#gf2a9e28b66a9538ba0ffb62bffb87c16" title="Retrieve the resultset handle from an executed statement.">OCI_GetResultset</a>(st); n = <a class="code" href="group__g__fetch.html#g8935f9c6ff0d6f1d94c70afb3418a916" title="Return the number of columns in the resultset.">OCI_GetColumnCount</a>(rs); <span class="comment">/* print resultset columns info */</span> <span class="keywordflow">for</span>(i = 1; i <= n; i++) { <a class="code" href="struct_o_c_i___column.html" title="Oracle SQL Column and Type member representation.">OCI_Column</a> *col = <a class="code" href="group__g__fetch.html#g7b64be082fc14ac73347b081cdb66de0" title="Return the column object handle at the given index in the resultset.">OCI_GetColumn</a>(rs, i); print_frmt(<span class="stringliteral">"> Field : #%i "</span>, i); print_text(<span class="stringliteral">"- Name : "</span>); print_mstr(<a class="code" href="group__g__fetch.html#gd22f87322cdb788a03a0c259ab126a94" title="Return the name of the given column.">OCI_ColumnGetName</a>(col)); print_text(<span class="stringliteral">"\n"</span>); } print_text(<span class="stringliteral">"\n"</span>); <span class="comment">/* print resultset content */</span> <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)) { print_frmt(<span class="stringliteral">"> code : %i"</span>, <a class="code" href="group__g__fetch.html#ga8d80dc30b2012eaddd13efa9dfb711d" title="Return the current integer value of the column at the given index in the resultset...">OCI_GetInt</a>(rs, 1)); print_text(<span class="stringliteral">", action : "</span>); print_dstr(<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, 2)); print_frmt(<span class="stringliteral">", price : %g"</span>, <a class="code" href="group__g__fetch.html#gdfbe8b6c23200810823e9ca6a1956cd7" title="Return the current double value of the column at the given index in the resultset...">OCI_GetDouble</a>(rs,3)); print_text(<span class="stringliteral">", date : "</span>); print_dstr(<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, 4)); print_text(<span class="stringliteral">"\n"</span>); } print_frmt(<span class="stringliteral">"\n%d row(s) fetched\n"</span>, <a class="code" href="group__g__fetch.html#g93bd9197720088dbda2bef593ad1c07c" title="Retrieve the number of rows fetched so far.">OCI_GetRowCount</a>(rs));}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * test_bind1</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> test_bind1(<span class="keywordtype">void</span>){ <span class="keywordtype">int</span> code = 1; print_text(<span class="stringliteral">"\n>>>>> TEST BINDING \n\n"</span>); <span class="comment">/* execute query in three steps */</span> <a class="code" href="group__g__exec.html#gd5a7fcffe7d24da001e44636cfc06578" title="Prepare a SQL statement or PL/SQL block.">OCI_Prepare</a>(st, MT(<span class="stringliteral">"select * from test_fetch where code = :code"</span>)); <a class="code" href="group__g__bind.html#g4d08024d2242b6140fecea8c2ec05c81" title="Bind an integer variable.">OCI_BindInt</a>(st, MT(<span class="stringliteral">":code"</span>), &code); <a class="code" href="group__g__exec.html#g7189aa353845909aaedc8d5956429450" title="Execute a prepared SQL statement or PL/SQL block.">OCI_Execute</a>(st); 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="comment">/* print resultset content */</span> <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)) { print_frmt(<span class="stringliteral">"> code : %i"</span>, <a class="code" href="group__g__fetch.html#ga8d80dc30b2012eaddd13efa9dfb711d" title="Return the current integer value of the column at the given index in the resultset...">OCI_GetInt</a>(rs, 1)); print_text(<span class="stringliteral">", action : "</span>); print_dstr(<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, 2)); print_frmt(<span class="stringliteral">", price : %g"</span>, <a class="code" href="group__g__fetch.html#gdfbe8b6c23200810823e9ca6a1956cd7" title="Return the current double value of the column at the given index in the resultset...">OCI_GetDouble</a>(rs,3)); print_text(<span class="stringliteral">", date : "</span>); print_dstr(<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, 4)); print_text(<span class="stringliteral">"\n"</span>); } print_frmt(<span class="stringliteral">"\n%d row(s) fetched\n"</span>, <a class="code" href="group__g__fetch.html#g93bd9197720088dbda2bef593ad1c07c" title="Retrieve the number of rows fetched so far.">OCI_GetRowCount</a>(rs));}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * test_bind2</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> test_bind2(<span class="keywordtype">void</span>){ <a class="code" href="struct_o_c_i___lob.html" title="Oracle Internal Large objects:.">OCI_Lob</a> *lob; <a class="code" href="struct_o_c_i___date.html" title="Oracle internal date representation.">OCI_Date</a> *date; <a class="code" href="struct_o_c_i___file.html" title="Oracle External Large objects:.">OCI_File</a> *file; <span class="keywordtype">int</span> i; <span class="keywordtype">double</span> flt; print_text(<span class="stringliteral">"\n>>>>> SINGLE BINDING \n\n"</span>); <span class="comment">/* prepare SQL */</span> <a class="code" href="group__g__exec.html#gd5a7fcffe7d24da001e44636cfc06578" title="Prepare a SQL statement or PL/SQL block.">OCI_Prepare</a>(st, MT(<span class="stringliteral">"insert into test_array "</span>) MT(<span class="stringliteral">"( "</span>) MT(<span class="stringliteral">" val_int, val_flt, val_str, val_date, "</span>) MT( <span class="stringliteral">" val_lob, val_file "</span>) MT( <span class="stringliteral">") "</span> ) MT( <span class="stringliteral">"values "</span>) MT( <span class="stringliteral">"( "</span>) MT( <span class="stringliteral">" :val_int, :val_flt, :val_str, :val_date, "</span>) MT( <span class="stringliteral">" :val_lob, :val_file "</span>) MT(<span class="stringliteral">") "</span>)); <span class="comment">/* create objects and set values */</span> <span class="comment">/* date */</span> date = <a class="code" href="group__g__date.html#ge80eacef54641a68c3b82be85f4a5042" title="Create a local date object.">OCI_DateCreate</a>(cn); <a class="code" href="group__g__date.html#gd7c5c65d88b52e6ecb46b3e9ba8843dc" title="Return the current system date/time into the date handle.">OCI_DateSysDate</a>(date); <span class="comment">/* lob */</span> lob = <a class="code" href="group__g__lob.html#g318f1273603e24b51c3d9e4c29f42685" title="Create a local temporary Lob instance.">OCI_LobCreate</a>(cn, OCI_CLOB); sprint_dt(temp, SIZE_STR, DT(<span class="stringliteral">"lob value00"</span>)); <a class="code" href="group__g__lob.html#g949f7050609430486c9ef0f3c488d38a" title="Write a buffer into a LOB.">OCI_LobWrite</a>(lob, temp, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) dtslen(temp)+1); <span class="comment">/* file */</span> file = <a class="code" href="group__g__file.html#g199d6ce1a1231feb56b456ad6cbc2714" title="Create a file object instance.">OCI_FileCreate</a>(cn, OCI_BFILE); <a class="code" href="group__g__file.html#ge31e36e786faf43a2663806a28814c68" title="Set the directory and file name of FILE handle.">OCI_FileSetName</a>(file, MT(<span class="stringliteral">"mydir"</span>), MT(<span class="stringliteral">"file00.txt"</span>)); <span class="comment">/* scalar types */</span> i = 1; flt = 3.14; sprint_dt(temp, 30, DT(<span class="stringliteral">"Name00"</span>)); <span class="comment">/* bind scalar C types arrays */</span> <a class="code" href="group__g__bind.html#g4d08024d2242b6140fecea8c2ec05c81" title="Bind an integer variable.">OCI_BindInt</a>(st, MT(<span class="stringliteral">":val_int"</span>), &i); <a class="code" href="group__g__bind.html#g66c7c882c40d302003b3b239b70c54d3" title="Bind a double variable.">OCI_BindDouble</a>(st, MT(<span class="stringliteral">":val_flt"</span>), &flt); <a class="code" href="group__g__bind.html#g49988b9ca8f00b55cc3e62ca2385778b" title="Bind a string variable.">OCI_BindString</a>(st, MT(<span class="stringliteral">":val_str"</span>), (dtext*) temp, 30); <span class="comment">/* bind oracle types arrays */</span> <a class="code" href="group__g__bind.html#ga0000a7b00b751b88459692f6790e018" title="Bind a date variable.">OCI_BindDate</a>(st, MT(<span class="stringliteral">":val_date"</span>), date); <a class="code" href="group__g__bind.html#geee7fa2d4a2bae58cd7cdf9348367ef2" title="Bind a Lob variable.">OCI_BindLob</a>(st, MT(<span class="stringliteral">":val_lob"</span>), lob); <a class="code" href="group__g__bind.html#g92cba59c0aabe28391b5e7053baee708" title="Bind a File variable.">OCI_BindFile</a>(st, MT(<span class="stringliteral">":val_file"</span>), file); <span class="comment">/* do insert */</span> <a class="code" href="group__g__exec.html#g7189aa353845909aaedc8d5956429450" title="Execute a prepared SQL statement or PL/SQL block.">OCI_Execute</a>(st); print_frmt(<span class="stringliteral">"Row inserted : %d\n\n"</span>, <a class="code" href="group__g__exec.html#g1cf932261960da80cd36d650a08565c3" title="Return the number of rows affected by the SQL statement.">OCI_GetAffectedRows</a>(st)); <span class="comment">/* free objets */</span> <a class="code" href="group__g__date.html#gedf77cfe4bd5dab7909e4c2fb5173b48" title="Free an OCI_Date handle.">OCI_DateFree</a>(date); <a class="code" href="group__g__lob.html#gac269a3de312c2c7d1a6193a9ab79545" title="Free a local temporary lob.">OCI_LobFree</a>(lob); <a class="code" href="group__g__file.html#gd4b58b6d80e24bb045fb82d78c5cf36a" title="Free a local File object.">OCI_FileFree</a>(file); <span class="comment">/* commit; */</span> <a class="code" href="group__g__transac.html#gee1ba614ed2dc5bd83bf788ca08f3e71" title="Commit current pending changes.">OCI_Commit</a>(cn);}<span class="comment">/* ------------------------------------------------------------------------ *</span><span class="comment"> * test_piecewise_insert</span><span class="comment"> * ------------------------------------------------------------------------ */</span><span class="keywordtype">void</span> test_piecewise_insert(<span class="keywordtype">void</span>){ FILE *f; print_text(<span class="stringliteral">"\n>>>>> TEST PIECEWISE INSERTING\n\n"</span>); <span class="comment">/* this code could have been used with a text file in a LONG column</span><span class="comment"> as well... */</span> <span class="comment">/* open the app file in for reading*/</span> f = fopen(EXE_NAME, <span class="stringliteral">"rb"</span>); <span class="keywordflow">if</span> (f) { <span class="keywordtype">int</span> n; <a class="code" href="struct_o_c_i___long.html" title="Oracle Long datatype.">OCI_Long</a> *lg; <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buffer[SIZE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -