⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otl3_connect_class.htm

📁 ISO_C++:C++_OTL开发文档
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
  <meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Sergei Kuchin">
  <meta name="GENERATOR"
 content="Mozilla/4.77 [en] (Win95; U) [Netscape]">
  <meta name="KeyWords"
 content="OTL, Oracle, ODBC, DB2, CLI, database API, C++, Template Library">
  <title>OTL 4.0 connect class</title>
</head>
<body>
<center>
<h1>OTL 4.0, OTL connect class</h1>
</center>
<h1>
<a name="otl_connect_class"></a>OTL connect class</h1>
This class encapsulates <i>connect </i>functions: connect,
disconnect,
commit, roll back, etc. In other words, the otl_connect class is the
class
for creating and handling <i>connect</i> objects together with
transaction
management.
<pre><font size="+2">class otl_connect{&nbsp;<br>public:</font></pre>
<ul>
  <li> <i><a name="connected"></a>Connection </i>flag which shows
whether the object is
connected
to the
database or not. The flag only shows that the otl_connect object was
successfully connected to the database.If there has not been any
database calls on the otl_connect object, and, say, the database
connection was closed, the flag would still be set to 1 (true). In
order to check out whether the database connect still exists or not, a
"heartbeat" database round-trip needs to be made, say, a "SELECT
&lt;current time&gt; FROM &lt;dual table&gt;", or an actual,
application related SQL statement. <br>
  </li>
</ul>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int connected;</pre>
<ul>
  <li> <a name="otl_initialize"></a>Static (in class) function to
initialize the
OTL environment. It needs to be called only once at the beginning of
the
program before making the very first connection to the database. The <i>threaded_mode
    </i>is a parameter for specifying if the program is running in the
multi-threaded
mode but it does not automatically guarantee thread safety, because OTL
does not set any mutex locks or critical sections. Threaded_mode = 1
means
the multi-threaded mode, 0 -- the single threaded mode.</li>
</ul>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static int otl_initialize(const int threaded_mode=0);</pre>
<ul>
  <li> <a name="otl_terminate"></a>Static (in class) function to
terminate
the
Oracle 8i/9i OCI environment. It needs to be called only once at the
end
of the program after closing the very last database connection. This
function
is just a wrapper around the OCITerminate() call. Usually, in
multi-threaded
programs, in order to be able to terminate/end the main thread of
control,
otl_terminate needs to be called, because it detaches the process from
the OCI client side shared memory, and does something else, that is not
well documented.</li>
</ul>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static int otl_terminate(void);</pre>
<blockquote>
  <li><a name="cancel"></a><i>OTL/OCI8/9/10/11 only<b>. </b></i>Cancel
any
operation / database call, executing / active in the connect object /
database
session. Say, the database session is in the <i>active </i>state, or,
in
other words, has a running SQL statement in a thread. This function can
be called from another thread, to cancel the execution of the SQL
statement
asynchronously. Right after the cancel() call returns, the first thread
will raise an otl_exception with the following message: <i>user
requested
cancel of current operation.</i></li>
</blockquote>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void cancel(void);</pre>
<ul>
  <li> <a name="change_password"></a><i>OTL/OCI8/9/10/11 only</i>.
This function
changes Oracle user's passwords. The program needs to attach to an
Oracle
server, and only then this function can be called.</li>
</ul>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void change_password<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (const char* user_name,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char* old_password,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char* new_password<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );</pre>
<blockquote>
  <li><a name="set_transaction_isolation_level"></a>Set
transaction
isolation
level. <i>OTL/DB2-CLI, OTL/ODBC only</i>. The function allows the user
to set the following levels: READ COMMITTED, READ UNCOMMITTED,
REPEATABLE
READ, SERIALIZABLE. For more detail on the transaction isolation
levels,
see the regular database manuls.</li>
</blockquote>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void set_transaction_isolation_level(const long int level);</pre>
<blockquote>OTL/ODBC and OTL/DB2-CLI define the following global
constants,
which can be used as substitutes for the <i>level </i>parameter of
the
function:
  <ul>
    <ul>
      <li> <b>otl_tran_read_uncommitted - </b>READ UNCOMITTED</li>
      <li> <b>otl_tran_read_committed - </b>READ COMITTED</li>
      <li> <b>otl_tran_repetable_read -</b>REPEATABLE READ</li>
      <li> <b>otl_tran_serializable - </b>SERIALIZABLE</li>
    </ul>
  </ul>
</blockquote>
<ul>
  <li> <a name="set_max_long_size"></a>Set the maximum buffer size for
operations
with Large Objects: <a href="otl3_bind_variables.htm#varchar_long">varchar_long</a>,
    <a href="otl3_bind_variables.htm#raw_long">raw_long</a>, <a
 href="otl3_bind_variables.htm#clob">clob</a>
and <a href="otl3_bind_variables.htm#blob">blob</a>. This function
needs
to be called in order to increase the buffer size (default size is
32767).</li>
</ul>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void set_max_long_size(const int amax_size);</pre>
<ul>
  <li>Get the maximum buffer size for operations with Large Objects: <a
 href="otl3_bind_variables.htm#varchar_long">varchar_long</a>, <a
 href="otl3_bind_variables.htm#varchar_long">raw_long</a>, <a
 href="otl3_bind_variables.htm#clob">clob</a>
and <a href="otl3_bind_variables.htm#blob">blob</a>.</li>
</ul>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int get_max_long_size(void);</pre>
<ul>
  <li>This function works in OTL 4.0/ODBC and OTL 4.0/DB2-CLI only, and
it
has
not effect in OTL 4.0/OCIx. Set the cursor type. Once the cursor type
is
set, the setting will be propagated to all SELECT statements opened via
the <a href="otl3_stream_class.htm">otl_stream</a> class in the
current
connect object.</li>
</ul>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void set_cursor_type(const int acursor_type=0);</pre>
<ul>
  <font size="-1">The following cursor types are available (for more
detail,
see the ODBC Programmer's Guide, or the DB2 CLI Programmer's Guide):</font>
  <ul>
    <li> <font size="-1">SQL_CURSOR_FORWARD_ONLY (default setting)</font></li>
    <li> <font size="-1">SQL_CURSOR_STATIC</font></li>
    <li> <font size="-1">SQL_CURSOR_KEYSET_DRIVEN</font></li>
    <li> <font size="-1">SQL_CURSOR_DYNAMIC</font></li>
  </ul>
</ul>
<ul>
  <li>This function works in OTL 4.0/ODBC, OTL 4.0/DB2-CLI for Windows
only,
and has no effect in OTL 4.0/OCIx. Set the timeout for the current
connect
object. Once the timeout is set, the setting will be effective for all
SQL statements opened in the current connect object. The time unit for
the function is 1 second, e.g. setting 60 means the timeout of 1 minute.</li>
  <p><br>
If a timeout is set (this function gets called) before logging onto
/ connecting to the database, and if the logon / connect request is not
getting through to the database, the request will time out, according
to
the time interval that was set as a timeout. </p>
  <p>In the future, if the OCI provides similar functionality, this
function
may be implemented. In OCIx, a different technique is used to simulate
timeouts: create a worker thread that will execute your SQL statement,
and a control thread with a timer. If the timer goes off and the SQL
statement
is still executing, the control thread can call otl_connect::<a
 href="#cancel">cancel</a>()
on the same connect object that is being used to execute the SQL
statement.</p>
</ul>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a name="set_timeout"></a>void set_timeout(const int atimeout=0);</pre>
<ul>
  <li> <a name="constructor"></a>General constructor. It creates an
otl_connect
object and then calls the <a href="#rlogon">rlogon()</a> function.</li>
</ul>
<pre>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; otl_connect(const char* connect_str,const int auto_commit=0);</pre>
<ul>
  <li> <a name="rlogon"></a>Log on / connect to the database.</li>
</ul>
<ul>
  <pre>&nbsp; void rlogon(const char* connect_str,const int auto_commit=0);</pre>
</ul>
<ul>
  <font size="-1">OTL 4.0/OCIx, OTL 4.0/ODBC, and OTL 4.0/DB2-CLI have
different styles of <i>connect strings:<br>
  <br>
  </i></font>
  <ul>
    <li> <font size="-1">OTL 4.0/OCIx style<br>
      <br>
      </font></li>
    <ul>
      <li> <font size="-1">"USER/PASSWORD" (for local Oracle
connections)</font></li>
      <li> <font size="-1">"USER/PASSWORD@TNS_ALIAS" (for remote
Oracle
connections
via SQL*Net)<br>
        <br>
        </font></li>
    </ul>
    <li> <font size="-1">OTL 4.0/ODBC and OTL 4.0/DB2-CLI style<br>
      <br>
      </font></li>
    <ul>
      <li> <font size="-1">"USER/PASSWORD/@DSN" (Oracle-like style for
ODBC or DB2-CLI
connections)</font></li>
      <li> <font size="-1">"DSN=value;UID=value;PWD=value" (ODBC-like
style for ODBC
or DB2-CLI connection)</font></li>
    </ul>
  </ul>
</ul>
<div style="margin-left: 40px;"><font size="-1"><a
 name="AT_IN_CONNECT_STR"></a>In OTL/ODBC/OCI8/OCI8i/OCI9i/OCI10g, it
is possible for a&nbsp;
password value to have a "@" (commercial at character) in it. In order
to specify a "@" in a password, the character has to be prefixed&nbsp;
with a "<span style="font-weight: bold;">\</span>", for example:
"userid/pass\\@word@DSN", or "UID=scott;PWD=ti\\@ger;DSN=mssql" (in
these examples, "\\" was used because the examples show C++ string
literals).<br>

⌨️ 快捷键说明

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