📄 connection_8c-source.html
字号:
<a name="l00442"></a>00442 <span class="comment">/* cleanup the cache */</span><a name="l00443"></a>00443 <a name="l00444"></a>00444 OCI_CALL2<a name="l00445"></a>00445 (<a name="l00446"></a>00446 res, con, <a name="l00447"></a>00447 <a name="l00448"></a>00448 OCICacheFree(OCILib.env, con-><a class="code" href="struct_o_c_i___connection.html#573a359867139990b1b0f50aa7a86175">err</a>, con-><a class="code" href="struct_o_c_i___connection.html#f20d1bea40e79481aeece933a4c70898">cxt</a>)<a name="l00449"></a>00449 )<a name="l00450"></a>00450 <a name="l00451"></a>00451 <span class="comment">/* free all transactions */</span><a name="l00452"></a>00452 <a name="l00453"></a>00453 OCI_ListForEach(con->trsns, (<span class="keywordtype">boolean</span> (*)(<span class="keywordtype">void</span> *)) OCI_TransactionClose);<a name="l00454"></a>00454 OCI_ListClear(con->trsns);<a name="l00455"></a>00455 <a name="l00456"></a>00456 <span class="comment">/* free all type info objects */</span><a name="l00457"></a>00457 <a name="l00458"></a>00458 OCI_ListForEach(con->tinfs, (<span class="keywordtype">boolean</span> (*)(<span class="keywordtype">void</span> *)) OCI_TypeInfoClose);<a name="l00459"></a>00459 OCI_ListClear(con->tinfs);<a name="l00460"></a>00460 <a name="l00461"></a>00461 <span class="comment">/* close any server files not explicitly closed - no check of return code */</span><a name="l00462"></a>00462 <a name="l00463"></a>00463 if (con->nb_files > 0)<a name="l00464"></a>00464 {<a name="l00465"></a>00465 OCILobFileCloseAll(con-><a class="code" href="struct_o_c_i___connection.html#f20d1bea40e79481aeece933a4c70898">cxt</a>, con-><a class="code" href="struct_o_c_i___connection.html#573a359867139990b1b0f50aa7a86175">err</a>);<a name="l00466"></a>00466 }<a name="l00467"></a>00467 <a name="l00468"></a>00468 <span class="comment">/* close session */</span><a name="l00469"></a>00469 <a name="l00470"></a>00470 <span class="keywordflow">if</span> ((con-><a class="code" href="struct_o_c_i___connection.html#f20d1bea40e79481aeece933a4c70898">cxt</a> != NULL) && (con-><a class="code" href="struct_o_c_i___connection.html#573a359867139990b1b0f50aa7a86175">err</a> != NULL) && (con-><a class="code" href="struct_o_c_i___connection.html#09c8704dbf6d868165925c788ef3274e">ses</a> != NULL))<a name="l00471"></a>00471 {<a name="l00472"></a>00472 OCI_CALL2<a name="l00473"></a>00473 (<a name="l00474"></a>00474 res, con, <a name="l00475"></a>00475 <a name="l00476"></a>00476 OCISessionEnd(con-><a class="code" href="struct_o_c_i___connection.html#f20d1bea40e79481aeece933a4c70898">cxt</a>, con-><a class="code" href="struct_o_c_i___connection.html#573a359867139990b1b0f50aa7a86175">err</a>, con-><a class="code" href="struct_o_c_i___connection.html#09c8704dbf6d868165925c788ef3274e">ses</a>, (ub4) OCI_DEFAULT)<a name="l00477"></a>00477 )<a name="l00478"></a>00478 }<a name="l00479"></a>00479 <a name="l00480"></a>00480 <span class="comment">/* update internal status */</span><a name="l00481"></a>00481 <a name="l00482"></a>00482 <span class="keywordflow">if</span> (res == TRUE)<a name="l00483"></a>00483 {<a name="l00484"></a>00484 con-><a class="code" href="struct_o_c_i___connection.html#25639578bd259929189e6b842598a187">cstate</a> = OCI_CONN_ATTACHED;<a name="l00485"></a>00485 <a name="l00486"></a>00486 <span class="keywordflow">if</span> (OCILib.ver_runtime < OCI_9 && con-><a class="code" href="struct_o_c_i___connection.html#63a53de950b2cce15ff16958470d2c31">pool</a> != NULL)<a name="l00487"></a>00487 con-><a class="code" href="struct_o_c_i___connection.html#63a53de950b2cce15ff16958470d2c31">pool</a>-><a class="code" href="struct_o_c_i___conn_pool.html#eeacb1dbd6dce15eaf01e8413dbb06e9">nb_busy</a>--;<a name="l00488"></a>00488 }<a name="l00489"></a>00489 <a name="l00490"></a>00490 <span class="keywordflow">return</span> res;<a name="l00491"></a>00491 }<a name="l00492"></a>00492 <a name="l00493"></a>00493 <span class="comment">/* ------------------------------------------------------------------------ *</span><a name="l00494"></a>00494 <span class="comment"> * OCI_ConnectionClose</span><a name="l00495"></a>00495 <span class="comment"> * ------------------------------------------------------------------------ */</span><a name="l00496"></a>00496 <a name="l00497"></a>00497 <span class="keywordtype">boolean</span> OCI_ConnectionClose(<a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> *con)<a name="l00498"></a>00498 {<a name="l00499"></a>00499 OCI_CHECK(con == NULL, FALSE);<a name="l00500"></a>00500 <a name="l00501"></a>00501 <span class="comment">/* clear server output resources */</span><a name="l00502"></a>00502 <a name="l00503"></a>00503 <a class="code" href="group__g__plsql.html#g0d3321a0abff0722baf6b2b7233f4cb5" title="Disable the server output.">OCI_ServerDisableOutput</a>(con);<a name="l00504"></a>00504 <a name="l00505"></a>00505 <span class="comment">/* lofoff and detatch form server */</span><a name="l00506"></a>00506 <a name="l00507"></a>00507 OCI_ConnectionLogOff(con);<a name="l00508"></a>00508 OCI_ConnectionDetach(con);<a name="l00509"></a>00509 OCI_ConnectionDeallocate(con);<a name="l00510"></a>00510 <a name="l00511"></a>00511 <span class="comment">/* free internal lists */</span><a name="l00512"></a>00512 <a name="l00513"></a>00513 OCI_ListFree(con-><a class="code" href="struct_o_c_i___connection.html#624935bfd26cde34ec0a2599e4362264">stmts</a>);<a name="l00514"></a>00514 OCI_ListFree(con-><a class="code" href="struct_o_c_i___connection.html#9e86c1884cde18cf183ab6898054757f">trsns</a>);<a name="l00515"></a>00515 OCI_ListFree(con-><a class="code" href="struct_o_c_i___connection.html#15765efb0072ed02b227760220c4daab">tinfs</a>);<a name="l00516"></a>00516 <a name="l00517"></a>00517 <span class="keywordflow">if</span> (con-><a class="code" href="struct_o_c_i___connection.html#63a53de950b2cce15ff16958470d2c31">pool</a> == NULL)<a name="l00518"></a>00518 {<a name="l00519"></a>00519 <span class="comment">/* free strings */</span><a name="l00520"></a>00520 <a name="l00521"></a>00521 OCI_FREE(con-><a class="code" href="struct_o_c_i___connection.html#c8336afdd35c8b68b4d04c7881a22fa2">db</a>);<a name="l00522"></a>00522 OCI_FREE(con-><a class="code" href="struct_o_c_i___connection.html#50a2a86abeb957f56d76ae872b2bfe9d">user</a>);<a name="l00523"></a>00523 OCI_FREE(con-><a class="code" href="struct_o_c_i___connection.html#5ba3064a162ab1800c928d2805318872">pwd</a>);<a name="l00524"></a>00524 }<a name="l00525"></a>00525 <a name="l00526"></a>00526 <a name="l00527"></a>00527 OCI_FREE(con-><a class="code" href="struct_o_c_i___connection.html#bba54290b47af36c91b0595779f6f6cd">fmt_date</a>);<a name="l00528"></a>00528 OCI_FREE(con-><a class="code" href="struct_o_c_i___connection.html#e50bb96adf03db47b693afa12dbd4843">fmt_num</a>);<a name="l00529"></a>00529 OCI_FREE(con-><a class="code" href="struct_o_c_i___connection.html#ba7c1b09e628df5b1df790df53ba9ad6">version</a>);<a name="l00530"></a>00530 <a name="l00531"></a>00531 con-><a class="code" href="struct_o_c_i___connection.html#624935bfd26cde34ec0a2599e4362264">stmts</a> = NULL;<a name="l00532"></a>00532 con-><a class="code" href="struct_o_c_i___connection.html#9e86c1884cde18cf183ab6898054757f">trsns</a> = NULL;<a name="l00533"></a>00533 con-><a class="code" href="struct_o_c_i___connection.html#15765efb0072ed02b227760220c4daab">tinfs</a> = NULL;<a name="l00534"></a>00534 <a name="l00535"></a>00535 <span class="keywordflow">return</span> TRUE;<a name="l00536"></a>00536 }<a name="l00537"></a>00537 <a name="l00538"></a>00538 <span class="comment">/* ************************************************************************ *</span><a name="l00539"></a>00539 <span class="comment"> * PUBLIC FUNCTIONS</span><a name="l00540"></a>00540 <span class="comment"> * ************************************************************************ */</span><a name="l00541"></a>00541 <a name="l00542"></a>00542 <span class="comment">/* ------------------------------------------------------------------------ *</span><a name="l00543"></a>00543 <span class="comment"> * OCI_ConnectionCreate</span><a name="l00544"></a>00544 <span class="comment"> * ------------------------------------------------------------------------ */</span><a name="l00545"></a>00545 <a name="l00546"></a><a class="code" href="group__g__connect.html#gdb6e2cdf759587dd81c2fda7c5f44338">00546</a> <a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> * OCI_API <a class="code" href="group__g__connect.html#gdb6e2cdf759587dd81c2fda7c5f44338" title="Create a physical connection to an Oracle database server.">OCI_ConnectionCreate</a>(<span class="keyword">const</span> mtext *db, <a name="l00547"></a>00547 <span class="keyword">const</span> mtext *user,<a name="l00548"></a>00548 <span class="keyword">const</span> mtext *pwd,<a name="l00549"></a>00549 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> mode)<a name="l00550"></a>00550 {<a name="l00551"></a>00551 <a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> * con;<a name="l00552"></a>00552 <a name="l00553"></a>00553 <span class="comment">/* let's be sure OCI_Initialize() has been called */</span><a name="l00554"></a>00554 <a name="l00555"></a>00555 OCI_CHECK_INITIALIZED(NULL);<a name="l00556"></a>00556 <a name="l00557"></a>00557 con = OCI_ConnectionAllocate(NULL, db, user, pwd, mode);<a name="l00558"></a>00558 <a name="l00559"></a>00559 <span class="keywordflow">if</span> (con != NULL)<a name="l00560"></a>00560 {<a name="l00561"></a>00561 <span class="keywordflow">if</span> (OCI_ConnectionAttach(con) == FALSE ||<a name="l00562"></a>00562 OCI_ConnectionLogon(con) == FALSE)<a name="l00563"></a>00563 {<a name="l00564"></a>00564 <a class="code" href="group__g__connect.html#gc3fe655e96074adb119908be4650a4c9" title="Close a physical connection to an Oracle database server.">OCI_ConnectionFree</a>(con);<a name="l00565"></a>00565 con = NULL;<a name="l00566"></a>00566 }<a name="l00567"></a>00567 }<a name="l00568"></a>00568 <a name="l00569"></a>00569 OCI_RESULT(con != NULL);<a name="l00570"></a>00570 <a name="l00571"></a>00571 <span class="keywordflow">return</span> con;<a name="l00572"></a>00572 }<a name="l00573"></a>00573 <a name="l00574"></a>00574 <span class="comment">/* ------------------------------------------------------------------------ *</span><a name="l00575"></a>00575 <span class="comment"> * OCI_ConnectionFree</span><a name="l00576"></a>00576 <span class="comment"> * ------------------------------------------------------------------------ */</span><a name="l00577"></a>00577 <a name="l00578"></a><a class="code" href="group__g__connect.html#gc3fe655e96074adb119908be4650a4c9">00578</a> <span class="keywordtype">boolean</span> OCI_API <a class="code" href="group__g__connect.html#gc3fe655e96074adb119908be4650a4c9" title="Close a physical connection to an Oracle database server.">OCI_ConnectionFree</a>(<a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> *con)<a name="l00579"></a>00579 {<a name="l00580"></a>00580 <span class="keywordtype">boolean</span> res = TRUE;<a name="l00581"></a>00581 <a class="code" href="struct_o_c_i___error.html" title="Encapsulates an Oracle or OCILIB exception.">OCI_Error</a> *err = NULL;<a name="l00582"></a>00582 <a name="l00583"></a>00583 OCI_CHECK_PTR(OCI_IPC_CONNECTION, con, FALSE);<a name="l00584"></a>00584 <a name="l00585"></a>00585 <span class="comment">/* clear connection reference from current error object */</span><a name="l00586"></a>00586 <a name="l00587"></a>00587 err = OCI_ErrorGet(FALSE);<a name="l00588"></a>00588 <a name="l00589"></a>00589 <span class="keywordflow">if</span> (err != NULL && err-><a class="code" href="struct_o_c_i___error.html#0c0c732c9acdee9dd08a8e3e4503e74b">con</a> == con)<a name="l00590"></a>00590 err-><a class="code" href="struct_o_c_i___error.html#0c0c732c9acdee9dd08a8e3e4503e74b">con</a> = NULL;<a name="l00591"></a>00591 <a name="l00592"></a>00592 <span class="keywordflow">if</span> (con-><a class="code" href="struct_o_c_i___connection.html#63a53de950b2cce15ff16958470d2c31">pool</a> != NULL)<a name="l00593"></a>00593 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -