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

📄 connection_8c-source.html

📁 ORACLE编程的好东西,纯C写的OCI封装.很好用,支持数据池.
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="l00286"></a>00286     <a name="l00287"></a>00287     OCI_CHECK(con == NULL, FALSE);<a name="l00288"></a>00288 <a name="l00289"></a>00289     <span class="comment">/* set context server attribute */</span><a name="l00290"></a>00290     <a name="l00291"></a>00291     OCI_CALL2<a name="l00292"></a>00292     (<a name="l00293"></a>00293         res, con, <a name="l00294"></a>00294         <a name="l00295"></a>00295         OCIAttrSet((dvoid *) con-&gt;<a class="code" href="struct_o_c_i___connection.html#f20d1bea40e79481aeece933a4c70898">cxt</a>, (ub4) OCI_HTYPE_SVCCTX, <a name="l00296"></a>00296                    (dvoid *) con-&gt;<a class="code" href="struct_o_c_i___connection.html#5e5c78e07f642e570f44331b8e646b46">svr</a>, (ub4) sizeof (con-&gt;<a class="code" href="struct_o_c_i___connection.html#5e5c78e07f642e570f44331b8e646b46">svr</a>), <a name="l00297"></a>00297                    (ub4) OCI_ATTR_SERVER, con-&gt;<a class="code" href="struct_o_c_i___connection.html#573a359867139990b1b0f50aa7a86175">err</a>)<a name="l00298"></a>00298     )<a name="l00299"></a>00299 <a name="l00300"></a>00300     <span class="comment">/* set session login attribute */</span><a name="l00301"></a>00301 <a name="l00302"></a>00302     <a name="l00303"></a>00303 <a name="l00304"></a>00304    if ((res == TRUE) &amp;&amp; (con-&gt;user != NULL) &amp;&amp; (con-&gt;user[0] != 0))<a name="l00305"></a>00305     {<a name="l00306"></a>00306         osize = -1;<a name="l00307"></a>00307         ostr  = OCI_GetInputMetaString(con-&gt;<a class="code" href="struct_o_c_i___connection.html#50a2a86abeb957f56d76ae872b2bfe9d">user</a>, &amp;osize);<a name="l00308"></a>00308 <a name="l00309"></a>00309         OCI_CALL2<a name="l00310"></a>00310         (<a name="l00311"></a>00311             res, con,<a name="l00312"></a>00312             <a name="l00313"></a>00313             OCIAttrSet((dvoid *) con-&gt;<a class="code" href="struct_o_c_i___connection.html#09c8704dbf6d868165925c788ef3274e">ses</a>,(ub4)  OCI_HTYPE_SESSION, <a name="l00314"></a>00314                        (dvoid *) ostr, (ub4) osize, <a name="l00315"></a>00315                        (ub4) OCI_ATTR_USERNAME, con-&gt;<a class="code" href="struct_o_c_i___connection.html#573a359867139990b1b0f50aa7a86175">err</a>)<a name="l00316"></a>00316         )<a name="l00317"></a>00317 <a name="l00318"></a>00318         OCI_ReleaseMetaString(ostr);<a name="l00319"></a>00319     }<a name="l00320"></a>00320 <a name="l00321"></a>00321     <span class="comment">/* set session password attribute */</span><a name="l00322"></a>00322 <a name="l00323"></a>00323     if ((res == TRUE) &amp;&amp; (con-&gt;pwd != NULL) &amp;&amp; (con-&gt;pwd[0] != 0))<a name="l00324"></a>00324     {<a name="l00325"></a>00325         osize = -1;<a name="l00326"></a>00326         ostr  = OCI_GetInputMetaString(con-&gt;<a class="code" href="struct_o_c_i___connection.html#5ba3064a162ab1800c928d2805318872">pwd</a>, &amp;osize);<a name="l00327"></a>00327 <a name="l00328"></a>00328         OCI_CALL2<a name="l00329"></a>00329         (<a name="l00330"></a>00330             res, con,<a name="l00331"></a>00331             <a name="l00332"></a>00332             OCIAttrSet((dvoid *) con-&gt;<a class="code" href="struct_o_c_i___connection.html#09c8704dbf6d868165925c788ef3274e">ses</a>, (ub4) OCI_HTYPE_SESSION, <a name="l00333"></a>00333                        (dvoid *) ostr, (ub4) osize, <a name="l00334"></a>00334                        (ub4) OCI_ATTR_PASSWORD, con-&gt;<a class="code" href="struct_o_c_i___connection.html#573a359867139990b1b0f50aa7a86175">err</a>)<a name="l00335"></a>00335         )<a name="l00336"></a>00336 <a name="l00337"></a>00337         OCI_ReleaseMetaString(ostr);<a name="l00338"></a>00338     }<a name="l00339"></a>00339 <a name="l00340"></a>00340     <span class="comment">/* start session */</span><a name="l00341"></a>00341     <a name="l00342"></a>00342     if (res == TRUE)<a name="l00343"></a>00343     {<a name="l00344"></a>00344         ub4 credt = OCI_CRED_RDBMS;<a name="l00345"></a>00345 <a name="l00346"></a>00346         <span class="keywordflow">if</span>  (((con-&gt;<a class="code" href="struct_o_c_i___connection.html#50a2a86abeb957f56d76ae872b2bfe9d">user</a> == NULL) || (con-&gt;<a class="code" href="struct_o_c_i___connection.html#50a2a86abeb957f56d76ae872b2bfe9d">user</a>[0] == 0)) &amp;&amp;<a name="l00347"></a>00347              ((con-&gt;<a class="code" href="struct_o_c_i___connection.html#5ba3064a162ab1800c928d2805318872">pwd</a>  == NULL) || (con-&gt;<a class="code" href="struct_o_c_i___connection.html#5ba3064a162ab1800c928d2805318872">pwd</a>[0]  == 0)))<a name="l00348"></a>00348         {<a name="l00349"></a>00349             credt = OCI_CRED_EXT;<a name="l00350"></a>00350         }<a name="l00351"></a>00351 <a name="l00352"></a>00352         OCI_CALL2<a name="l00353"></a>00353         (<a name="l00354"></a>00354             res, con,<a name="l00355"></a>00355             <a name="l00356"></a>00356             OCISessionBegin(con-&gt;<a class="code" href="struct_o_c_i___connection.html#f20d1bea40e79481aeece933a4c70898">cxt</a>, con-&gt;<a class="code" href="struct_o_c_i___connection.html#573a359867139990b1b0f50aa7a86175">err</a>, con-&gt;<a class="code" href="struct_o_c_i___connection.html#09c8704dbf6d868165925c788ef3274e">ses</a>, credt, con-&gt;<a class="code" href="struct_o_c_i___connection.html#642ca8589aad1bcb1578c536e0d2d7ae">mode</a>)<a name="l00357"></a>00357         )<a name="l00358"></a>00358  <a name="l00359"></a>00359     <span class="comment">/* This call has moved after OCISessionBegin() call to enable connection</span><a name="l00360"></a>00360 <span class="comment">       pooling (an error ORA-24324 was thrown is the session handle was set to</span><a name="l00361"></a>00361 <span class="comment">       the service context handle before OCISessionBegin() */</span><a name="l00362"></a>00362     <a name="l00363"></a>00363         OCI_CALL2<a name="l00364"></a>00364         (<a name="l00365"></a>00365             res, con,<a name="l00366"></a>00366             <a name="l00367"></a>00367             OCIAttrSet((dvoid *) con-&gt;cxt, (ub4) OCI_HTYPE_SVCCTX, <a name="l00368"></a>00368                        (dvoid *) con-&gt;ses, (ub4) sizeof(con-&gt;ses), <a name="l00369"></a>00369                        (ub4) OCI_ATTR_SESSION, con-&gt;err))<a name="l00370"></a>00370 <a name="l00371"></a>00371    }<a name="l00372"></a>00372     <a name="l00373"></a>00373     <span class="comment">/* check for success */</span><a name="l00374"></a>00374 <a name="l00375"></a>00375     if (res == TRUE)<a name="l00376"></a>00376     {<a name="l00377"></a>00377         <span class="comment">/* get server version */</span><a name="l00378"></a>00378 <a name="l00379"></a>00379         <a class="code" href="group__g__connect.html#ged47a25a1f96fd630f176fe702ac443a" title="Return the connected database server version.">OCI_GetVersionServer</a>(con);<a name="l00380"></a>00380 <a name="l00381"></a>00381         <span class="comment">/* create default transaction object */</span><a name="l00382"></a>00382 <a name="l00383"></a>00383         con-&gt;trs  = <a class="code" href="group__g__transac.html#g206d14aa9a25befd218a7f91a56d5c47" title="Create a new global transaction or a serializable/read-only local transaction.">OCI_TransactionCreate</a>(con, 1, OCI_TRANS_READWRITE, NULL);<a name="l00384"></a>00384 <a name="l00385"></a>00385         <span class="comment">/* start transaction */</span><a name="l00386"></a>00386         <a name="l00387"></a>00387         res = <a class="code" href="group__g__transac.html#gf8e8d8d04d91f2c18dbf34d875b8e42f" title="Start global transaction.">OCI_TransactionStart</a>(con-&gt;trs);<a name="l00388"></a>00388     }<a name="l00389"></a>00389 <a name="l00390"></a>00390    <span class="comment">/* update internal status */</span><a name="l00391"></a>00391     <a name="l00392"></a>00392     <span class="keywordflow">if</span> (res == TRUE)<a name="l00393"></a>00393     {<a name="l00394"></a>00394         <span class="keywordflow">if</span> (OCILib.ver_runtime &lt; OCI_9 &amp;&amp; con-&gt;<a class="code" href="struct_o_c_i___connection.html#63a53de950b2cce15ff16958470d2c31">pool</a> != NULL)<a name="l00395"></a>00395             con-&gt;<a class="code" href="struct_o_c_i___connection.html#63a53de950b2cce15ff16958470d2c31">pool</a>-&gt;<a class="code" href="struct_o_c_i___conn_pool.html#eeacb1dbd6dce15eaf01e8413dbb06e9">nb_busy</a>++;<a name="l00396"></a>00396 <a name="l00397"></a>00397         con-&gt;<a class="code" href="struct_o_c_i___connection.html#25639578bd259929189e6b842598a187">cstate</a> = OCI_CONN_LOGGED;<a name="l00398"></a>00398     }<a name="l00399"></a>00399 <a name="l00400"></a>00400     <span class="keywordflow">return</span> res;<a name="l00401"></a>00401 }<a name="l00402"></a>00402 <a name="l00403"></a>00403 <span class="comment">/* ------------------------------------------------------------------------ *</span><a name="l00404"></a>00404 <span class="comment"> * OCI_ConnectionLogOff</span><a name="l00405"></a>00405 <span class="comment"> * ------------------------------------------------------------------------ */</span><a name="l00406"></a>00406 <a name="l00407"></a>00407 <span class="keywordtype">boolean</span> OCI_ConnectionLogOff(<a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> *con)<a name="l00408"></a>00408 {<a name="l00409"></a>00409     <span class="keywordtype">boolean</span> res = TRUE;<a name="l00410"></a>00410 <a name="l00411"></a>00411     OCI_CHECK(con == NULL, FALSE);<a name="l00412"></a>00412     OCI_CHECK(con-&gt;<a class="code" href="struct_o_c_i___connection.html#25639578bd259929189e6b842598a187">cstate</a> != OCI_CONN_LOGGED, FALSE);<a name="l00413"></a>00413 <a name="l00414"></a>00414     <span class="comment">/* free all statements */</span><a name="l00415"></a>00415     <a name="l00416"></a>00416     OCI_ListForEach(con-&gt;<a class="code" href="struct_o_c_i___connection.html#624935bfd26cde34ec0a2599e4362264">stmts</a>, (boolean (*)(<span class="keywordtype">void</span> *)) OCI_StatementClose);<a name="l00417"></a>00417     OCI_ListClear(con-&gt;<a class="code" href="struct_o_c_i___connection.html#624935bfd26cde34ec0a2599e4362264">stmts</a>);<a name="l00418"></a>00418 <a name="l00419"></a>00419     <span class="comment">/* free all transactions */</span><a name="l00420"></a>00420     <a name="l00421"></a>00421     OCI_ListForEach(con-&gt;<a class="code" href="struct_o_c_i___connection.html#9e86c1884cde18cf183ab6898054757f">trsns</a>, (boolean (*)(<span class="keywordtype">void</span> *)) OCI_TransactionClose);<a name="l00422"></a>00422     OCI_ListClear(con-&gt;<a class="code" href="struct_o_c_i___connection.html#9e86c1884cde18cf183ab6898054757f">trsns</a>);<a name="l00423"></a>00423 <a name="l00424"></a>00424     <span class="comment">/* free all schema objects */</span><a name="l00425"></a>00425     <a name="l00426"></a>00426     OCI_ListForEach(con-&gt;<a class="code" href="struct_o_c_i___connection.html#220b45c2fd519a7e20e7977490e04ee6">sobjs</a>, (boolean (*)(<span class="keywordtype">void</span> *)) OCI_SchemaClose);<a name="l00427"></a>00427     OCI_ListClear(con-&gt;<a class="code" href="struct_o_c_i___connection.html#220b45c2fd519a7e20e7977490e04ee6">sobjs</a>);<a name="l00428"></a>00428 <a name="l00429"></a>00429    <span class="comment">/* close any server files not explicitly closed - no check of return code */</span><a name="l00430"></a>00430    <a name="l00431"></a>00431     <span class="keywordflow">if</span> (con-&gt;<a class="code" href="struct_o_c_i___connection.html#bae9541681344ed1e1aca4e9fd2908b5">nb_files</a> &gt; 0)<a name="l00432"></a>00432     {<a name="l00433"></a>00433         OCILobFileCloseAll(con-&gt;<a class="code" href="struct_o_c_i___connection.html#f20d1bea40e79481aeece933a4c70898">cxt</a>, con-&gt;<a class="code" href="struct_o_c_i___connection.html#573a359867139990b1b0f50aa7a86175">err</a>);<a name="l00434"></a>00434     }<a name="l00435"></a>00435 

⌨️ 快捷键说明

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