group__loginout.html
来自「一个很好用的Linux/Unix下Oracle OCI开发接口封装库」· HTML 代码 · 共 622 行 · 第 1/2 页
HTML
622 行
<!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>Functions to do login/logout to/from a database</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>Functions to do login/logout to/from a database</h1><table border=0 cellpadding=0 cellspacing=0>
<tr><td></td></tr>
<tr><td colspan=2><br><h2>Functions</h2></td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__loginout.html#a0">sqlo_connect</a> (<a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> *dbhp, const char *cstr)</td></tr>
<tr><td> </td><td><font size=-1><em>Connect to a database.</em> <a href="#a0"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__loginout.html#a1">sqlo_finish</a> (<a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)</td></tr>
<tr><td> </td><td><font size=-1><em>Finish the session.</em> <a href="#a1"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__loginout.html#a2">sqlo_split_cstring</a> (const char *cstr, char *uid, char *pwd, char *tnsname, unsigned int bufsize)</td></tr>
<tr><td> </td><td><font size=-1><em>Split an Oracle connect string.</em> <a href="#a2"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__loginout.html#a3">sqlo_server_attach</a> (<a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> *dbhp, const char *tnsname)</td></tr>
<tr><td> </td><td><font size=-1><em>Attach to a database server.</em> <a href="#a3"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__loginout.html#a4">sqlo_session_begin</a> (<a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh, const char *username, const char *password)</td></tr>
<tr><td> </td><td><font size=-1><em>Begin a session.</em> <a href="#a4"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__loginout.html#a5">sqlo_server_detach</a> (<a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)</td></tr>
<tr><td> </td><td><font size=-1><em>Detach from server.</em> <a href="#a5"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="group__loginout.html#a6">sqlo_session_end</a> (<a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)</td></tr>
<tr><td> </td><td><font size=-1><em>End a session.</em> <a href="#a6"></a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>const char * </td><td valign=bottom><a class="el" href="group__loginout.html#a7">sqlo_getdatabase</a> (<a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh)</td></tr>
<tr><td> </td><td><font size=-1><em>Returns the tnsname.</em> <a href="#a7"></a><em></em></font><br><br></td></tr>
</table>
<hr><h2>Function Documentation</h2>
<a name="a0" doxytag="sqlora.h::sqlo_connect"></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_connect </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> * </td>
<td class="mdname" nowrap> <em>dbhp</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>const char * </td>
<td class="mdname" nowrap> <em>cstr</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Connect to a database.
<p>
This is the short form of <a class="el" href="group__loginout.html#a3">Functions to do login/logout to/from a database</a> followed by <a class="el" href="group__loginout.html#a4">Functions to do login/logout to/from a database</a><dl compact><dt><b>Parameters: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em>dbhp</em> </td><td>
O - The database handle </td></tr>
<tr><td valign=top><em>cstr</em> </td><td>
I - A Oracle connect string.</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
<ul>
<li>SQLO_SUCCESS <li> < 0 on error </ul>
</dl><dl compact><dt><b>Example:</b></dt><dd>
<div class="fragment"><pre><span class="comment">/* $Id: group__loginout.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 "<a class="code" href="sqlora_8h.html">sqlora.h</a>"</span>
<span class="preprocessor">#include "examples.h"</span>
<span class="keyword">static</span> CONST <span class="keywordtype">char</span> * _defuser = <span class="stringliteral">"scott/tiger"</span>;
<span class="keyword">static</span> <span class="keywordtype">int</span> _abort_flag = 0;
<span class="keywordtype">void</span> sigint_handler(<span class="keywordtype">void</span>);
<span class="keywordtype">void</span> sigint_handler(<span class="keywordtype">void</span>) {
printf(<span class="stringliteral">"Catched SIGINT\n"</span>);
_abort_flag++;
}
<span class="preprocessor">#define RETURN_ON_ABORT if (_abort_flag) { sqlo_rollback(dbh); return EXIT_FAILURE; }</span>
<span class="preprocessor"></span>
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
{
CONST <span class="keywordtype">char</span> * cstr = _defuser;
<a class="code" href="group__typedefs.html#a0">sqlo_db_handle_t</a> dbh;
<span class="keywordtype">int</span> stat;
<a class="code" href="group__typedefs.html#a1">sqlo_stmt_handle_t</a> sth;
<span class="keywordtype">double</span> min_income;
<span class="keywordtype">char</span> server_version[1024];
<span class="keywordtype">int</span> handle; <span class="comment">/* handle of the interrupt handler */</span>
<span class="keywordflow">if</span> (argc > 1)
cstr = argv[1];
<span class="comment">/* init */</span>
<span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a class="code" href="group__init.html#a0">sqlo_init</a>(<a class="code" href="group__constants.html#a5a45">SQLO_OFF</a>, 1, 100)) {
printf(<span class="stringliteral">"Failed to init libsqlora8\n"</span>);
<span class="keywordflow">return</span> EXIT_FAILURE;
}
<span class="comment">/* register the interrupt handler */</span>
<a class="code" href="group__misc.html#a12">sqlo_register_int_handler</a>(&handle, sigint_handler);
<span class="comment">/* login */</span>
<span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a class="code" href="group__loginout.html#a0">sqlo_connect</a>(&dbh, cstr)) {
printf(<span class="stringliteral">"Cannot login with %s\n"</span>, cstr);
<span class="keywordflow">return</span> EXIT_FAILURE;
}
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="keywordflow">if</span> (<a class="code" href="group__constants.html#a3a25">SQLO_SUCCESS</a> != <a class="code" href="group__misc.html#a6">sqlo_server_version</a>(dbh, server_version, <span class="keyword">sizeof</span>(server_version))) {
printf(<span class="stringliteral">"Failed to get the server version: %s\n"</span>, <a class="code" href="group__error.html#a0">sqlo_geterror</a>(dbh));
<span class="keywordflow">return</span> EXIT_FAILURE;
}
printf(<span class="stringliteral">"Connected to:\n%s\n\n"</span>, server_version);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex1.c */</span>
<span class="keywordflow">if</span> (!table_exists(dbh, <span class="stringliteral">"EMP"</span>)) {
printf(<span class="stringliteral">"Table EMP does not exist. Please install Oracle demo tables\n"</span>);
<span class="keywordflow">return</span> EXIT_FAILURE;
}
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex2.c */</span>
<span class="comment">/* EMP should have 8 columns */</span>
<span class="keywordflow">if</span> ( 8 != (stat = col_count(dbh, <span class="stringliteral">"EMP"</span>)))
printf(<span class="stringliteral">"Expected 8 columns in EMP, but counted %d\n"</span>, stat);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex3.c */</span>
stat = update_manager(dbh);
printf(<span class="stringliteral">"Reduced the salary of %d managers\n"</span>, stat);
<a class="code" href="group__transactions.html#a1">sqlo_rollback</a>(dbh);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex4.c */</span>
sth = open_cursor(dbh);
<a class="code" href="group__easy.html#a13">sqlo_close</a>(sth);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex5.c */</span>
sth = open_cursor2(dbh, 2500.0);
<a class="code" href="group__easy.html#a13">sqlo_close</a>(sth);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex6.c */</span>
sth = reopen_cursor(dbh, 2500.0);
<span class="keywordflow">if</span> (sth != (stat = reopen_cursor(dbh, 5000.0))) {
printf(<span class="stringliteral">"reopen_cursor returned a new handle %d, expected %d\n"</span>, stat, sth);
}
<span class="comment">/* we don't close this cursor */</span>
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex7.c */</span>
do_select(dbh, 3000); <span class="comment">/* note: we reuse the cursor opened by ex6.c */</span>
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex8.c */</span>
stat = update_emp(dbh, 2.0, <span class="stringliteral">"MANAGER"</span>);
printf(<span class="stringliteral">"Doubled the salary of %d managers.\n"</span>, stat);
<a class="code" href="group__transactions.html#a1">sqlo_rollback</a>(dbh);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex9.c */</span>
call_plsql(dbh);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex10.c */</span>
min_income = 2500;
sth = prepare_cursor(dbh, &min_income);
<a class="code" href="group__easy.html#a13">sqlo_close</a>(sth);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex11.c */</span>
printf(<span class="stringliteral">"Employees with salary >= 3000:\n"</span>);
do_select2(dbh, 3000); <span class="comment">/* note: we reuse the cursor opened by ex6.c */</span>
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex12.c */</span>
printf(<span class="stringliteral">"Employees with salary >= 1200:\n"</span>);
do_array_select(dbh, 1200);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex13.c */</span>
insert_into_blob_table(dbh, 1);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex14.c */</span>
insert_file_into_blob_table(dbh, 2, <span class="stringliteral">"examples"</span>);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex15.c */</span>
select_from_blob_table(dbh, 1);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex16.c */</span>
select_file_from_blob_table(dbh, 2, <span class="stringliteral">"examples.cmp"</span>);
<span class="keywordflow">if</span> ( 0 != system(<span class="stringliteral">"diff -q examples examples.cmp"</span>)) {
printf(<span class="stringliteral">"ERROR: examples is different from examples.cmp!!!\n"</span>);
}
<a class="code" href="group__transactions.html#a1">sqlo_rollback</a>(dbh);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex17.c */</span>
printf(<span class="stringliteral">"Employees with salary (via refcursor) >= 1200:\n"</span>);
select_refcursor(dbh, 1200);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex18.c */</span>
printf(<span class="stringliteral">"Employees with salary (via refcursor with bind vars) >= 1200:\n"</span>);
select_refcursor2(dbh, 1200);
RETURN_ON_ABORT; <span class="comment">/* finish if SIGINT was catched */</span>
<span class="comment">/* ex19.c */</span>
printf(<span class="stringliteral">"Employees, departements and locations via ntable\n"</span>);
select_ntable(dbh);
<span class="comment">/* rollback */</span>
<a class="code" href="group__transactions.html#a1">sqlo_rollback</a>(dbh);
<span class="comment">/* logout */</span>
<a class="code" href="group__loginout.html#a1">sqlo_finish</a>(dbh);
<span class="keywordflow">return</span> EXIT_SUCCESS;
}
<span class="comment">/* $Id: group__loginout.html,v 1.1 2005/01/13 02:56:43 cvsroot Exp $ */</span>
</pre></div> </dl><dl compact><dt><b>See also: </b></dt><dd>
<a class="el" href="group__loginout.html#a1">sqlo_finish</a>, <a class="el" href="group__loginout.html#a3">sqlo_server_attach</a>, <a class="el" href="group__loginout.html#a4">sqlo_session_begin</a> </dl> </td>
</tr>
</table>
<a name="a1" doxytag="sqlora.h::sqlo_finish"></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_finish </td>
<td class="md" valign="top">( </td>
<td class="md" nowrap valign="top"><a class="el" href="group__typedefs.html#a0">sqlo_db_handle_t</a> </td>
<td class="mdname1" valign="top" nowrap> <em>dbh</em> </td>
<td class="md" valign="top">) </td>
<td class="md" nowrap></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
Finish the session.
<p>
Finish the session with implicit commit. This is the short form of <a class="el" href="group__loginout.html#a6">Functions to do login/logout to/from a database</a> followed by <a class="el" href="group__loginout.html#a5">Functions to do login/logout to/from a database</a>.<dl compact><dt><b>Parameters: </b></dt><dd>
<table border=0 cellspacing=2 cellpadding=0>
<tr><td valign=top><em>dbh</em> </td><td>
I - A database handle</td></tr>
</table>
</dl><dl compact><dt><b>Returns: </b></dt><dd>
<ul>
<li>SQLO_SUCCESS <li> < 0 on error </ul>
</dl><dl compact><dt><b>See also: </b></dt><dd>
<a class="el" href="group__loginout.html#a0">sqlo_connect</a>, <a class="el" href="group__loginout.html#a6">sqlo_session_end</a>, <a class="el" href="group__loginout.html#a5">sqlo_server_detach</a>, <a class="el" href="group__loginout.html#a3">sqlo_server_attach</a> </dl> </td>
</tr>
</table>
<a name="a7" doxytag="sqlora.h::sqlo_getdatabase"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?