锘??xml version="1.0" encoding="utf-8" standalone="yes"?>性做久久久久久久久,成人久久久观看免费毛片,亚洲AV无码1区2区久久http://m.shnenglu.com/ietj/category/16343.html瑙傛湜錛岀瓑寰呭彧鑳借鍑虹幇鐨勬満浼氱櫧鐧芥簻璧?/description>zh-cnTue, 22 Mar 2011 17:59:44 GMTTue, 22 Mar 2011 17:59:44 GMT60Oracle鏁版嵁搴撳紑鍙?浜?.OCI寮鍙戠ず渚?/title><link>http://m.shnenglu.com/ietj/articles/142536.html</link><dc:creator>涓璺灝?/dc:creator><author>涓璺灝?/author><pubDate>Tue, 22 Mar 2011 16:14:00 GMT</pubDate><guid>http://m.shnenglu.com/ietj/articles/142536.html</guid><wfw:comment>http://m.shnenglu.com/ietj/comments/142536.html</wfw:comment><comments>http://m.shnenglu.com/ietj/articles/142536.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/ietj/comments/commentRss/142536.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/ietj/services/trackbacks/142536.html</trackback:ping><description><![CDATA[     鎽樿: Oracle Database Development (5). A example for OCI Development Vert Melon Jun 24,2007 1.Preface  If you skimmed through some articles wrote in series before,  you would find that i am no...  <a href='http://m.shnenglu.com/ietj/articles/142536.html'>闃呰鍏ㄦ枃</a><img src ="http://m.shnenglu.com/ietj/aggbug/142536.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/ietj/" target="_blank">涓璺灝?/a> 2011-03-23 00:14 <a href="http://m.shnenglu.com/ietj/articles/142536.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Oracle鏁版嵁搴撳紑鍙?涓?.OCI寮鍙戠ず渚嬭鏄?/title><link>http://m.shnenglu.com/ietj/articles/142535.html</link><dc:creator>涓璺灝?/dc:creator><author>涓璺灝?/author><pubDate>Tue, 22 Mar 2011 16:13:00 GMT</pubDate><guid>http://m.shnenglu.com/ietj/articles/142535.html</guid><wfw:comment>http://m.shnenglu.com/ietj/comments/142535.html</wfw:comment><comments>http://m.shnenglu.com/ietj/articles/142535.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/ietj/comments/commentRss/142535.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/ietj/services/trackbacks/142535.html</trackback:ping><description><![CDATA[<span id="424q42i" class=Apple-style-span style="WORD-SPACING: 0px; FONT: medium Simsun; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span id="wqma24o" class=Apple-style-span style="FONT-SIZE: 14px; LINE-HEIGHT: 21px; FONT-FAMILY: verdana, sans-serif; TEXT-ALIGN: left"> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">Oracle Database Development (7).  The thinking of the OCI example .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">Vert Melon</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">Jun 26,2007</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> The central content in this article is about the common operations with Oracle .  Just <span id="esa46ws" class=Apple-converted-space> </span><br>follow the instructions and enrich the relevant knowledge by the OCI official document .<br>I'd like to copy many sentences from OCI official document . It would save me many<span id="22mi4ii" class=Apple-converted-space> </span><br>trouble and these sentences are more exactly .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">1. Connection</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> Connection is surely a first step done with the database . OCI provides two mode of<span id="ia224ou" class=Apple-converted-space> </span><br>connection , which is Single User, Single Connection and Multiple Sessions or Connections.<br> The example also gave the both implement .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> a. Single User, Single Connection<span id="26i6wim" class=Apple-converted-space> </span><br> -----------------------------------------------------------------------------<br> <br> An application maintains only a single user session for each database connection<span id="6k4cs2q" class=Apple-converted-space> </span><br>at any time .<br> <br> The corresponding functions in the example listed as follows :<br> OCIDB::Single_Conn()<br> OCIDB::Single_Disc()<br> <br> The calling order of routines :<br> <br> OCIEnvCreate<br> OCIHandleAlloc  <ERROR><br> OCILogon<br> <br> OCILogoff<br> OCIHandleFree   <ERROR><br> OCIHandleFree   <ENV><br> <br> An application of OCI must have one environment handle , which is created by OCIEnvCreate()<span id="42m44wu" class=Apple-converted-space> </span><br>here . The environment handle defines a context in which all OCI functions are invoked .<span id="ysq4cwe" class=Apple-converted-space> </span><br>It is the base of almost all of the other handles which would be seen in future.<br> OCIEnvCreate() creates and initializes an environment for OCI functions to work under .<br> This call should be invoked before any other OCI call and should be used instead of<br>the OCIInitialize() and OCIEnvInit() calls. OCIInitialize() and OCIEnvInit() calls will be<span id="sw4is2c" class=Apple-converted-space> </span><br>supported for backward compatibility. But if you are writing a DLL or a shared library<span id="omem624" class=Apple-converted-space> </span><br>using OCI library then this call should definitely be used instead of OCIInitialize() and<span id="24u42m4" class=Apple-converted-space> </span><br>OCIEnvInit() call . OCIInitialize() and OCIEnvInit() call is used in OCIDB::Multiple_Conn() ,<span id="4i44u24" class=Apple-converted-space> </span><br>we'll cover it soon.<br> <span id="6a22eiw" class=Apple-converted-space> </span><br> Almost all OCI calls include in their parameter list one or more handles. A handle is an<span id="k424muk" class=Apple-converted-space> </span><br>opaque pointer to a storage area allocated by the OCI library. You use a handle to store<span id="6ckw4kq" class=Apple-converted-space> </span><br>context or connection information, (for example, an environment or service context handle),<span id="sg24gwk" class=Apple-converted-space> </span><br>or it may store information about OCI functions or data (for example, an error or describe<span id="4a2q4a4" class=Apple-converted-space> </span><br>handle). Handles can make programming easier, because the library, rather than the application,<span id="6o2e2wm" class=Apple-converted-space> </span><br>maintains this data.</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> Either OCIEnvCreate() or ( OCIInitialize() and OCIEnvInit() ) allocates a environment<span id="m2444ki" class=Apple-converted-space> </span><br>handle . I defined a private member variable named m_pOCIEnv to store it . You can find<br> the both routines return a address as environment handle .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> There is also a very important handle , which appears in mostly OCI calls . That is the<span id="aqcg2mc" class=Apple-converted-space> </span><br>error handle .The error handle maintains information about errors that occur during an OCI<span id="4ec4yo2" class=Apple-converted-space> </span><br>operation. If an error occurs in a call, the error handle can be passed to OCIErrorGet() to<span id="o2ekqcs" class=Apple-converted-space> </span><br>obtain additional information about the error that occurred.<br> Go and look at OCIException::CheckError() which shows a integral error management .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> After the preparation of Environment and Error , we will come to the actual code about<span id="c6gc4o2" class=Apple-converted-space> </span><br>the connection . OCILogon() and OCILogoff() is quite easy to us . Notice that  a service<span id="a4wi44k" class=Apple-converted-space> </span><br>context handle will be created during the time processing OCILogon().<span id="kgyai4c" class=Apple-converted-space> </span><br> A service context handle defines attributes that determine the operational context for<span id="2aia2em" class=Apple-converted-space> </span><br>OCI calls to a server. The service context contains three handles as its attributes, that<span id="2w22ca2" class=Apple-converted-space> </span><br>represent a server connection, a user session, and a transaction.  OCILogon() call also<span id="4u2wyq2" class=Apple-converted-space> </span><br>implicitly allocates server and user session handles associated with the session.</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> Is is a very good custom that release the resource allocated at first in an order when<span id="i24gc4k" class=Apple-converted-space> </span><br>the program comes the end . OCIDB::Single_Disc() does it explicitly .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"><br> b. Multiple Sessions or Connections<br> -----------------------------------------------------------------------------<br> <br> If an application needs to maintain multiple user sessions on a database connection,<span id="4wc4o4q" class=Apple-converted-space> </span><br>the application requires a different set of calls to set up the sessions and connections.</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> The corresponding functions in the example listed as follows :<br> OCIDB::Multiple_Conn()<br> OCIDB::Multiple_Disc()<br> <br> The calling order of routines :<br> <br> OCIInitialize<br> OCIEnvInit<br> OCIHandleAlloc  <Error><br> OCIHandleAlloc  <Server Context ><br> <br> OCIHandleAlloc  <Server><br> OCIAttrSet  <Set Server Into ServerContext><br> OCIServerAttach <AttachServer><br> <br> OCIHandleAlloc  <Session><br> OCIAttrSet  <Set Session Into ServerContext><br> OCISessionBegin<br> <br> ...<br> <br> Compare with OCILogon() it becomes more complex . Each handle is allocated by<span id="6g222gg" class=Apple-converted-space> </span><br>hand here .<br> There is someting new . All OCI handles have attributes associated with them. These<span id="q24kuy2" class=Apple-converted-space> </span><br>attributes represent data stored in that handle. You can read handle attributes using the<span id="e64meig" class=Apple-converted-space> </span><br>attribute get call, OCIAttrGet(), and you can change them with the attribute set call, <span id="sya224o" class=Apple-converted-space> </span><br>OCIAttrSet(). OCIServerAttach() creates an access path to the data server for OCI<span id="mqsmuk4" class=Apple-converted-space> </span><br>operations. OCISessionBegin() establishes a session for a user against a particular server.<span id="ag24mm4" class=Apple-converted-space> </span><br> This call is required for the user to be able to execute any operation on the server.<span id="2sqcg2k" class=Apple-converted-space> </span><br> Notice that the calling order of OCIAttrSet() or OCIServerAttach() is random . As the<br>same , either call OCIAttrSet() before OCISessionBegin() or call OCISessionBegin() <span id="2cakso4" class=Apple-converted-space> </span><br>before OCIAttrSet() is OK .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> You can change the content of the file Main.cpp to implement the different operation .<span id="4a4wqoq" class=Apple-converted-space> </span><br>Some code for test is listed below :</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> #include "OCIDB.h"<br> int main() {<br> <br>    OCIDB db;<br>     db.Single_Conn();<br>     db.Single_Disc();<span id="g4yqg2y" class=Apple-converted-space> </span><br>    <span id="kq2oi24" class=Apple-converted-space> </span><br> } <br> <br> #include "OCIDB.h"<br> int main() {<br> <br>    OCIDB db;<br>     db.Multiple_Conn();<br>     db.Multiple_Disc();<span id="2c4ses4" class=Apple-converted-space> </span><br>    <span id="mqikgu4" class=Apple-converted-space> </span><br> }</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">2. Execute non-query SQL</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> Non-query SQL means that SQL doesn't return any data , such as create , insert , delete<br>and so on . These SQL statements also could be comprehanded as DDL . OCI also support<span id="auysk2a" class=Apple-converted-space> </span><br>the bind for extern values and we will discuss it in next section.  Please search the relevant<span id="e22mi42" class=Apple-converted-space> </span><br>code in the example.  The function OCIDB::ExecuteSql() covers it .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> At first you should allocate a statement handle in the envionment handle. A statement<span id="ceg4wcm" class=Apple-converted-space> </span><br>handle is the context that identifies a SQL or PL/SQL statement and its associated attributes.<br>Every SQL statement must be prepared for execution by OCIStmtPrepare() then. This is a<span id="e4gs2y2" class=Apple-converted-space> </span><br>completely local call, requiring no round trip to the server. No association is made at this<span id="2iwasqu" class=Apple-converted-space> </span><br>point between the statement and a particular server.</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> After finished the steps above , call OCIStmtExecute() to execute the statement. For DDL<span id="m4qik4e" class=Apple-converted-space> </span><br>statements, no further steps are necessary.</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> You may use these code statements in Main.cpp as the following :<br> <br> #include "OCIDB.h"<br> int main() {<br> <br>    OCIDB db;<br>     db.Multiple_Conn();<br>     db.ExecuteSql("update liwei_test  set id =123 where note='test' ");<br>     db.Multiple_Disc();<span id="ayi2o22" class=Apple-converted-space> </span><br>    <span id="aug4e2e" class=Apple-converted-space> </span><br> }</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> <br>3. Bind variable<br> <br> Most DML statements, and some queries (such as those with a WHERE clause), require a<span id="wiicgoy" class=Apple-converted-space> </span><br>program to pass data to Oracle as part of a SQL or PL/SQL statement. Such data can be constant<span id="eikewu2" class=Apple-converted-space> </span><br>or literal data, known when your program is compiled.</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> insert into liwei_test (id,name,note)values(1,'aABD','cadsf')</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> This statement is a simple one to insert some data known. When you prepare a SQL statement<span id="44icy42" class=Apple-converted-space> </span><br>or PL/SQL block that contains input data to be supplied at runtime, placeholders in the SQL statement<span id="m2g2awi" class=Apple-converted-space> </span><br>or PL/SQL block mark where data must be supplied. For example, the following SQL statement<span id="quo42oe" class=Apple-converted-space> </span><br>contains three placeholders, indicated by the leading colons (for example, :id), that show where<span id="mq2ce24" class=Apple-converted-space> </span><br>input data must be supplied by the program.</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> insert into liwei_test (id,name,note)values(:id,:name,:note)<br> <br> In this example I also made two different way using the bind .  Look at this content of Main.cpp :</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> A. One-off bind with a predefine structure</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> #include "OCIDB.h"<br> int main() {<br> <br>   OCIDB db;<br>   db.Multiple_Conn();<br>   db.BindAddVar(":id", 19809);<br>   db.BindAddVar(":name", "liwei");<br>   db.BindAddVar(":note", "test");<br>   db.BindSql("insert into liwei_test (id,name,note)values(:id,:name,:note) ");<br>   db.BindAddVar(":id", 169);<br>   db.BindAddVar(":name", "sstem ch");<br>   db.BindSql("insert into liwei_test (id,name)values(:id,:name) ");<br>   db.Multiple_Disc();<span id="e2gikkg" class=Apple-converted-space> </span><br>  <span id="42uwaqg" class=Apple-converted-space> </span><br> } <br> <br> OCIDB::BindAddVar() add the user parameters into the share variable which name<span id="qswg4yo" class=Apple-converted-space> </span><br>is m_BindVars . It has several overrided patterns .<br> OCIDB::BindSql() execute the SQL statement binding the structural variable . All of<span id="qu2i4oe" class=Apple-converted-space> </span><br>the OCI operation needed is called in an order .<span id="smoi24k" class=Apple-converted-space> </span><br> <br> Notice :  OCIDB::BindAddVar() allocates memory automaticly as the bind variable need .<br> <br> <br> B.  Bind the variable step by step consistent with the defined order of OCI</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> #include "OCIDB.h"<br> int main() {<br> <br>   OCIDB db;<br>   db.Multiple_Conn();<br>   db.UserPrepare("insert into liwei_test (id,name,note)values(:id,:name,:note)");<br>   db.UserBind(":id",10701);<br>   db.UserBind(":name", "liweitest");<br>   db.UserBind(":note", "asdfasdf");<br>   db.UserExecute();<br>   db.UserCommit();<br>   db.UserFree();<br>   db.Multiple_Disc();<span id="suoamig" class=Apple-converted-space> </span><br>  <span id="sm2a24m" class=Apple-converted-space> </span><br> }  <br> <br> The process had been divided into several steps here . In this case you can extend some<span id="ew4s4y4" class=Apple-converted-space> </span><br>further functions more easily . </p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> Notice :  The class function starts with "User" is a series which performs a common template .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> <br> Both the two methods above follow this calling order :<br> <br> OCIHandleAlloc  <stmt><br> OCIStmtPrepare<br> OCIBindByName/OCIBindByPos<br> OCIStmtExecute<br> OCITransCommit/OCITransRollback<br> OCIHandleFree  <stmt><br> <br> <br>4. Get the Recordset from a SQL Select statement</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> In this section i'd like to introduce a simple query example about the select statement which<br> select-list cols is known before execution.<span id="eykwo22" class=Apple-converted-space> </span><br>  Query statements return data from the database to your application.  When processing a query,<span id="qa44ee4" class=Apple-converted-space> </span><br> you must define an output variable or an array of output variables for each item in the select-list<span id="yq2m244" class=Apple-converted-space> </span><br> from which you want to retrieve data.</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> #include "OCIDB.h"<br> int main() {<br> <br>   OCIDB db;<br>   db.Multiple_Conn();<br>   db.UserSelect("select id,name,note,value from liwei_test where note='test'");<br>   while(db.UserFetch()==0) {<br>    printf("id:%f\n", db.UserGetFloat("id"));<br>    printf("name:%s\n", db.UserGetString("name"));<br>    printf("note:%s\n", db.UserGetString("note"));<br>    printf("value:%f\n\n", db.UserGetFloat("value"));<br>   }<br>   db.UserSelectFree();<br>  <span id="4omg2uc" class=Apple-converted-space> </span><br> }  <br> <br> As you see ,  a simple one is gave now , which still seems a bit complex . Firstly i defined<span id="cgqc2sq" class=Apple-converted-space> </span><br>a structure "TSelectVar"  to store select-list . "TSelectVar" had a union to store values in<span id="waku2c2" class=Apple-converted-space> </span><br>different type . Then i encapsuled the select operation into the four parts .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> UserSelect<br> UserFetch<br> UserGet<br> UserSelectFree<span id="qsuo44u" class=Apple-converted-space> </span><br> <br> So let's have a look at the first part --  OCIDB::UserSelect() .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> OCIHandleAlloc() , OCIStmtPrepare(), OCIStmtExecute() and then the OCIAttrGet() !<br> I want to know the column count of the select-list , so used OCIAttrGet() there . For each<span id="oy44444" class=Apple-converted-space> </span><br> column , i called OCIParamGet() to get a OCI parameter and then used OCIAttrGet() to<span id="me2ag62" class=Apple-converted-space> </span><br> fetch lots of useful imformation such as name, size, presision and so on .<br> <br> After the get of attribute , you should define the content of the select-list using OCIDefineByPos()<br> or OCIDefineByName() then.<br> <br> The purpose of these Get() and Define() calls is to describe the select-list for the following<span id="ysu4yo4" class=Apple-converted-space> </span><br> action which is get .  OCIDB::UserFetch() is easily comprehanded , for only one call OCIStmtFetch<br> in it .<br> <br> Pay attention to the member function like OCIDB::UserGet , these functions is interface<span id="m42q2c4" class=Apple-converted-space> </span><br> to exterior user . It is overrided also .<br> <br>   int UserGetInt(int index);<br>   int UserGetInt(char * name);<br>   char * UserGetString(int index);<br>   char * UserGetString(char * name); <span id="224m44q" class=Apple-converted-space> </span><br>   float UserGetFloat(int index);<br>   float UserGetFloat(char * name);<span id="2s4ms4c" class=Apple-converted-space> </span><br>  <span id="asogoma" class=Apple-converted-space> </span><br> Peruse the code patiently and you will gain much knowledge .<br> <br>5.The Last</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> This example is just for a demonstration or a accidence . You mush not stop here only .<span id="i2u24iy" class=Apple-converted-space> </span><br>Take this way for more info by practice and online help. Obviousely there are many points<span id="22wswmu" class=Apple-converted-space> </span><br>which are not very standard in the article , for a exam i didn't use CONST while passing a<span id="2u44444" class=Apple-converted-space> </span><br>value . This is a important aspect to improve .<br>   For you may not acclimatize youself  to the variety of the OCI type , take it easy , try to<br>get together with the OCI Function Reference and force a type conversion .</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">-------------------------------------------------------------------------------------------------------</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">Oracle鏁版嵁搴撳紑鍙?涓?.OCI紺轟緥寮鍙戣鏄?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">鑽夋湪鐡?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">2007-6-26</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 榪欑瘒鏂囩珷鐨勪富瑕佸唴瀹規槸浠嬬粛鐨勫父瑙佺殑OCI鏁版嵁鎿嶄綔銆傚彲浠ラ『鐫鏂囩珷鎬濊礬緇撳悎OCI<br>鐩稿叧Oracle鏂囨。鍘葷悊瑙c傝繖閲屼粠鍘熸枃妗d腑澶嶅埗浜嗕笉灝戝師鍙ワ紝榪欎釜鐪佷簡寰堝楹葷儲鑰屼笖<br>榪欎簺琛ㄨ揪鏇翠負鍑嗙‘銆?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">涓銆佹暟鎹簱榪炴帴</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 鏁版嵁搴撹繛鎺ユ槸鎿嶄綔鏁版嵁搴撶殑絎竴姝ャ侽CI鎻愪緵浜嗕袱縐嶆ā寮忕殑榪炴帴錛屽嵆鍗曠敤鎴?br>鍗曡繛鎺ュ拰澶氱敤鎴峰榪炴帴銆傛垜榪欓噷鐨凮CI紺轟緥涔熷垎鍒彁渚涗簡涓ょ瀹炵幇鏂瑰紡銆?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> a.鍗曠敤鎴鳳紝鍗曡繛鎺?br> -----------------------------------------------------------------------------<br> <br> 搴旂敤紼嬪簭瀵逛簬鏌愪竴鏁版嵁搴撹繛鎺ヤ粎鏀寔鍗曠敤鎴瘋繘紼嬨?br> <br> 渚嬪瓙涓搴旂殑鍑芥暟榪囩▼錛?br> OCIDB::Single_Conn()<br> OCIDB::Single_Disc()<br> <br> OCI鍐呴儴榪囩▼鐨勮皟鐢ㄩ『搴忓涓嬶細<br> <br> OCIEnvCreate<br> OCIHandleAlloc  <ERROR><br> OCILogon<br> <br> OCILogoff<br> OCIHandleFree   <ERROR><br> OCIHandleFree   <ENV><br> <br> OCI搴旂敤紼嬪簭蹇呴』鏈変竴涓幆澧冨彞鏌勶紝鍦ㄨ繖閲岀敱 OCIEnvCreate()鍒涘緩銆傜幆澧冨彞鏌勭浉褰?br>浜庡畾涔変竴涓鍣紝鍖呭惈浜嗕互鍚庣殑鎵鏈塐CI鍙ユ焺錛岃繖鏄疧CI璋冪敤鐨勫熀紜銆?br> OCIEnvCreate()鍒涘緩騫跺垵濮嬪寲浜嗕竴涓狾CI鍑芥暟鐨勫伐浣滅幆澧冿紝蹇呴』鍏堜簬鍏朵粬OCI鍑芥暟<br>涔嬪墠璋冪敤銆備竴鑸潵璇達紝浠庡吋瀹規ф柟闈㈣冭檻錛屾渶濂戒嬌鐢∣CIInitialize() 鍜?OCIEnvInit()鏇夸唬<br>OCIEnvCreate()銆備笉榪囧鏋滀綘鍦ㄥ啓dll鎴栬呭叡浜簱涔嬬被鐨勪笢瑗匡紝鏈濂借繕鏄敤OCIEnvCreate()銆?br>OCIDB::Multiple_Conn()涓氨浣跨敤浜哋CIInitialize()鍜孫CIEnvInit() 錛屾垜浠竴浼氫細鎻愬埌銆?br> <br> 緇濆ぇ澶氭暟鐨凮CI璋冪敤閮戒嬌鐢ㄤ簡涓涓垨澶氫釜鍙ユ焺銆傚彞鏌勬寚鍚戠敱OCI搴撹嚜鍔ㄥ垎閰嶇殑鍐呭瓨<br>絀洪棿銆傚彲浠ュ瓨鍌ㄨ繛鎺ョ幆澧冧俊鎭?濡傦紝鏁版嵁搴撹繛鎺ョ幆澧冩垨鏈嶅姟鐜鍙ユ焺) 錛孫CI鍑芥暟鎵ц<br>榪囩▼涓浉鍏充俊鎭?濡傦紝閿欒鍙ユ焺鎴栬呮弿榪板彞鏌?銆侽CI鍙ユ焺璁╁紑鍙戝伐浣滃彉寰楃畝鍗曡搗鏉ワ紝<br>榪欎簺鐩稿叧淇℃伅鏄敱OCI搴撴墍綆$悊錛岃屼笉鏄敤鎴風殑搴旂敤紼嬪簭銆?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 涓嶇鏄疧CIEnvCreate()榪樻槸(OCIInitialize()鍜孫CIEnvInit())閮藉垎閰嶄簡涓涓暟鎹簱鐜鍙?br>鏌勩傛垜榪欓噷瀹氫箟浜嗙鏈夋垚鍛樺彉閲弇_pOCIEnv鐢ㄦ潵瀛樺偍鐜鍙ユ焺銆?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> OCI涓繕鏈変竴涓緢閲嶈鐨勫彞鏌勶紝緇忓父鍑虹幇鍦∣CI璋冪敤榪囩▼涓傝繖灝辨槸閿欒鍙ユ焺銆傞敊璇?br>鍙ユ焺綆$悊鍦∣CI鏁版嵁鎿嶄綔涓嚭鐜扮殑鍚勭被閿欒錛屽鏋滃湪璋冪敤涓嚭閿欙紝鍙互鎶婇敊璇彞鏌?br>浼犻掔粰OCIErrorGet()鏉ヨ幏鍙栨洿澶氱殑閿欒淇℃伅銆?br> OCIException::CheckError() 鏄竴涓畬鏁寸殑閿欒澶勭悊紺轟緥銆?br> <br> 鍑嗗濂界幆澧冨彞鏌勫拰閿欒鍙ユ焺鍚庯紝璇ュ埌鏁版嵁搴撹繛鎺ョ殑瀹為檯浠g爜浜嗐傝繖閲岀殑OCILogon()<span id="c42wus4" class=Apple-converted-space> </span><br>鍜?OCILogoff() 鐞嗚В璧鋒潵騫朵笉闅俱傝娉ㄦ剰OCILogon()鎵ц榪囩▼涓繑鍥炰簡涓涓湇鍔$幆澧?br>鍙ユ焺銆?br> 鏈嶅姟鐜鍙ユ焺瀹氫箟涓浜涢噸瑕佸睘鎬э紝鐩存帴鍐沖畾浜嗚繛鎺ユ暟鎹簱鐨勬柟寮忔柟娉曘傛湇鍔$幆澧?br>鍙ユ焺鍖呭惈涓変釜灞炴э紝鍏跺疄灝辨槸鍙﹀鐙珛鐨勪笁涓彞鏌勶紝鍗蟲湇鍔¤繛鎺ワ紝鐢ㄦ埛浼氳瘽鍜屼簨鍔°?br> OCILogon()鎵ц榪囩▼涓叾瀹炰篃澹版槑浜嗘湇鍔¤繛鎺ュ拰鐢ㄦ埛浼氳瘽鐨勭浉鍏沖彞鏌勶紝鍙笉榪囨槸闅?br>寮忓0鏄庛?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 鍦ㄧ▼搴忕粨鏉熸椂鎵嬪伐閲婃斁璧勬簮鏄緢濂界殑涔犳儻錛屽彲鍙傝OCIDB::Single_Disc()銆?br> <br> b.澶氱敤鎴鳳紝澶氳繛鎺?br> -----------------------------------------------------------------------------</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 濡傛灉搴旂敤紼嬪簭瀵瑰崟涓鏁版嵁搴撹繛鎺ラ渶瑕佺淮鎶ゅ涓敤鎴蜂細璇濓紝灝遍渶瑕佷嬌鐢ㄥ彟涓縐嶆柟寮忎簡銆?br> <br> 渚嬪瓙涓搴旂殑鍑芥暟榪囩▼錛?br> OCIDB::Multiple_Conn()<br> OCIDB::Multiple_Disc()<br> <br> OCI鍐呴儴榪囩▼鐨勮皟鐢ㄩ『搴忓涓嬶細<br> <br> OCIInitialize<br> OCIEnvInit<br> OCIHandleAlloc  <Error><br> OCIHandleAlloc  <Server Context ><br> <br> OCIHandleAlloc  <Server><br> OCIAttrSet  <Set Server Into ServerContext><br> OCIServerAttach <AttachServer><br> <br> OCIHandleAlloc  <Session><br> OCIAttrSet  <Set Session Into ServerContext><br> OCISessionBegin<br> <br> ...<br> <br> 涓嶰CILogon()鐩告瘮錛屽彉鐨勬湁浜涘鏉傦紝姣忎釜鍙ユ焺鍦ㄨ繖閲岄兘鏄墜宸ュ幓鍒涘緩銆傞渶瑕佹彁鍑?br>鐨勬槸錛屾墍鏈夌殑OCI鍙ユ焺閮芥湁鍏剁浉鍏沖睘鎬э紝榪欎簺灞炴у瓨鍌ㄤ簡涓浜涙湁鐢ㄧ殑鏁版嵁銆傚彲浠ヤ嬌<br>鐢∣CIAttrGet()鑾峰彇瀵瑰簲淇℃伅錛屼篃鍙互閫氳繃OCIAttrSet()榪涜淇敼銆侽CIServerAttach()<span id="simo4ew" class=Apple-converted-space> </span><br>鍒涘緩浜嗕竴涓狾CI鎿嶄綔鐨勬暟鎹湇鍔¤闂礬寰勶紝OCISessionBegin() 紜珛鐢ㄦ埛浼氳瘽榪炴帴銆?br>榪欓噷瀹屾垚鍚庯紝鎵嶅彲浠ヨ繘琛屽疄闄呯殑鏁版嵁鎿嶄綔銆?br> 娉ㄦ剰榪欓噷鐨凮CIAttrSet()鍜孫CIServerAttach()鐨勮皟鐢ㄩ『搴忎笉鏄浐瀹氱殑錛岀被浼肩殑 OCISessionBegin()<span id="2gw444y" class=Apple-converted-space> </span><br>鍜?OCIAttrSet() 鍏堝悗欏哄簭涔熸槸鍙互浜掓崲鐨勩?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 浣犲彲浠ヨ嚜琛屾洿鏀筂ain.cpp鍐呭浠ュ畬鎴愪笉鍚岀殑鏁版嵁鎿嶄綔銆?br> <br> #include "OCIDB.h"<br> int main() {<br> <br>    OCIDB db;<br>     db.Single_Conn();<br>     db.Single_Disc();<span id="um4444m" class=Apple-converted-space> </span><br>    <span id="4c6susg" class=Apple-converted-space> </span><br> } <br> <br> #include "OCIDB.h"<br> int main() {<br> <br>    OCIDB db;<br>     db.Multiple_Conn();<br>     db.Multiple_Disc();<span id="smg2yo2" class=Apple-converted-space> </span><br>    <span id="4y424ci" class=Apple-converted-space> </span><br> }</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em">浜屻佹墽琛屾棤榪斿洖鍊肩殑SQL璇彞</p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 榪欑被璇彞涓鑸寘鎷琧reate , insert鍜宒elete絳夌瓑錛屾棤榪斿洖鍊艱鍙ヤ竴鑸篃鍙互鐞嗚В涓篋DL<br>璇彞銆侽CI涔熸敮鎸佸SQL璇彞榪涜鍙橀噺緇戝畾錛屼笅鑺備細涓撻棬璁ㄨ銆?br> 渚嬪瓙涓浉鍏崇殑鍑芥暟鏄疧CIDB::ExecuteSql() 銆?br> <br> 棣栧厛浣犻渶瑕佸湪鐜鍙ユ焺涓0鏄庝竴涓鍙ュ彞鏌勩傝鍙ュ彞鏌勫寘鍚簡SQL鎴栬匬L/SQL<br>璇彞鍙婂叾鐩稿叧灞炴э紝姣忎釜SQL璇彞鍦ㄦ墽琛屽墠蹇呴』瑕佷嬌鐢∣CIStmtPrepare()榪涜棰勫鐞嗐?br>榪欎釜鏄湰鍦板寲璋冪敤錛屼笉浼氬悜鏈嶅姟鍣ㄧ鍙戦佽姹傘?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 瀹屾垚涓婇潰姝ラ鍚庯紝灝卞彲浠ヨ皟鐢∣CIStmtExecute() 鎵цSQL璇彞浜嗐?br> <br> 浠g爜璇彞濡備笅錛?br> <br> #include "OCIDB.h"<br> int main() {<br> <br>    OCIDB db;<br>     db.Multiple_Conn();<br>     db.ExecuteSql("update liwei_test  set id =123 where note='test' ");<br>     db.Multiple_Disc();<span id="2q2cwwm" class=Apple-converted-space> </span><br>    <span id="a44c4sa" class=Apple-converted-space> </span><br> }<br> <br>涓夈佸彉閲忕粦瀹?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 澶у鏁癉ML璇彞鎴栬呬竴浜涙煡璇?甯here鏉′歡鐨?闇瑕佸悜SQL浼犻掍竴浜涙暟鎹紝涓嬮潰鐨勪緥瀛?br>鏄湪紼嬪簭緙栬瘧鏃跺氨宸茬粡鐭ラ亾瑕佷紶閫掔殑鏁板箋?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> insert into liwei_test (id,name,note)values(1,'aABD','cadsf')<br> <br> 榪欐槸涓畝鍗曠殑渚嬪瓙錛屽綋棰勫鐞嗕竴涓猄QL璇彞鎴栬匬L/SQL鍧楋紝鍏朵腑鏈変簺鏁板兼槸闇瑕佸湪榪?br>琛屼腑鎵嶈兘紜畾鐨勩傝繖鏃跺氨闇瑕佸湪榪愯鍔ㄦ佸幓緇戝畾鍙橀噺浜嗭紝鎴戜滑鍦⊿QL璇彞鎴栬匬L/SQL鍧?br>涓嬌鐢?id涔嬬被鐨勭鍙鳳紝琛ㄧず鍙互鍋氫負鍙橀噺緇戝畾銆傚錛?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> insert into liwei_test (id,name,note)values(:id,:name,:note)<br> <br> 榪欎釜渚嬪瓙涓紝鎴戜嬌鐢ㄤ簡涓ょ閫斿緞鏉ョ粦瀹氬彉閲忋?br> <br> A.閫氳繃棰勫畾涔夌殑緇撴瀯浣撲竴嬈℃х粦瀹?br> <br> #include "OCIDB.h"<br> int main() {<br> <br>   OCIDB db;<br>   db.Multiple_Conn();<br>   db.BindAddVar(":id", 19809);<br>   db.BindAddVar(":name", "liwei");<br>   db.BindAddVar(":note", "test");<br>   db.BindSql("insert into liwei_test (id,name,note)values(:id,:name,:note) ");<br>   db.BindAddVar(":id", 169);<br>   db.BindAddVar(":name", "sstem ch");<br>   db.BindSql("insert into liwei_test (id,name)values(:id,:name) ");<br>   db.Multiple_Disc();<span id="si2eye2" class=Apple-converted-space> </span><br>  <span id="ogyaige" class=Apple-converted-space> </span><br> }<br> <br> OCIDB::BindAddVar() 灝嗙浉鍏崇殑鐢ㄦ埛鍙橀噺鍙傛暟娣誨姞鍒癿_BindVars鍙橀噺涓紝榪欎釜鍑芥暟<br>鏈変笉鍚岀殑閲嶈澆褰㈠紡銆?br> OCIDB::BindSql() 緇戝畾緇撴瀯浣撳畾涔夌殑鍙橀噺錛屽茍鎵цSQL璇彞銆?br> <br> 娉ㄦ剰錛歄CIDB::BindAddVar() 鏍規嵁緇戝畾鐨勫彉閲忓艱嚜鍔ㄥ垎閰嶅唴瀛?br> <br> B. 鏍規嵁OCI鍐呴儴欏哄簭涓姝ヤ竴姝ョ粦瀹?br> <br> #include "OCIDB.h"<br> int main() {<br> <br>   OCIDB db;<br>   db.Multiple_Conn();<br>   db.UserPrepare("insert into liwei_test (id,name,note)values(:id,:name,:note)");<br>   db.UserBind(":id",10701);<br>   db.UserBind(":name", "liweitest");<br>   db.UserBind(":note", "asdfasdf");<br>   db.UserExecute();<br>   db.UserCommit();<br>   db.UserFree();<br>   db.Multiple_Disc();<span id="e4isw2y" class=Apple-converted-space> </span><br>  <span id="s4a2syy" class=Apple-converted-space> </span><br> }  <br> <br> 榪欓噷鎶婃暣涓繃紼嬪垝鍒嗘垚澶氭錛屽彲浠ユ柟渚夸互鍚庢墿灞曞姛鑳姐?br> <br> 娉ㄦ剰錛歎ser鎵撳ご鐨勮繖浜涚郴鍒楀嚱鏁幫紝鍏跺疄鏄瘮杈冨父鐢ㄧ殑涓濂楁ā鏉褲?br> <br> 榪欎袱縐嶆柟寮忚皟鐢∣CI鍐呴儴鍑芥暟鐨勯『搴忛兘鏄竴鏍風殑錛?br> <br> OCIHandleAlloc  <stmt><br> OCIStmtPrepare<br> OCIBindByName/OCIBindByPos<br> OCIStmtExecute<br> OCITransCommit/OCITransRollback<br> OCIHandleFree  <stmt>s<br> <br>鍥涖佷粠Select璇彞鑾峰彇璁板綍闆?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 榪欒妭涓昏浠嬬粛涓涓畝鍗曠殑鏌ヨ渚嬪瓙錛屼緥瀛愪腑鐨勬煡璇㈠垪鍦ㄦ墽琛屽墠宸茬粡鐭ラ亾銆?br> 鏌ヨ璇彞榪斿洖鏁版嵁搴撲腑鎵闇鏁版嵁錛屾墽琛屾煡璇㈡椂蹇呴』瑕佸畾涔夊閮ㄧ殑杈撳嚭鍙橀噺鎴栬呭彉<br>閲忔暟緇勬潵瀛樺偍浣犳墍闇瑕佹绱㈢殑鏁版嵁銆?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> #include "OCIDB.h"<br> int main() {<br> <br>   OCIDB db;<br>   db.Multiple_Conn();<br>   db.UserSelect("select id,name,note,value from liwei_test where note='test'");<br>   while(db.UserFetch()==0) {<br>    printf("id:%f\n", db.UserGetFloat("id"));<br>    printf("name:%s\n", db.UserGetString("name"));<br>    printf("note:%s\n", db.UserGetString("note"));<br>    printf("value:%f\n\n", db.UserGetFloat("value"));<br>   }<br>   db.UserSelectFree();<br>  <span id="g4424ee" class=Apple-converted-space> </span><br> }  <br> <br> 涓婇潰灝辨槸涓涓皬渚嬪瓙銆傞鍏堟垜鍏堝畾涔変簡涓涓粨鏋勪綋TSelectVar(涓庣粦瀹氬彉閲忕殑緇撴瀯浣?br>綾諱技)鍑嗗瀛樺偍榪斿洖鐨勭粨鏋滈泦銆俆SelectVar 涓嬌鐢ㄤ簡Union瀛樺偍涓嶅悓綾誨瀷鐨勬暟鍊箋傜劧鍚?br>鎴戞妸鏁翠釜OCI Select榪囩▼灝佽鎴愬涓嬪洓閮ㄥ垎錛?br> <br> UserSelect<br> UserFetch<br> UserGet<br> UserSelectFree<span id="42c4a44" class=Apple-converted-space> </span><br> <br> 鎴戜滑鍏堢湅絎竴閮ㄥ垎 OCIDB::UserSelect() 銆?br> OCIHandleAlloc() , OCIStmtPrepare(), OCIStmtExecute() 鐒跺悗鏄疧CIAttrGet() 銆?br> OCIAttrGet()涓昏鏄負浜嗚幏鍙栬繑鍥炵粨鏋滈泦鐨勫垪鏁般傚浜庢瘡涓鍒楋紝浣跨敤浜哋CIParamGet()<br> 鍏堣幏鍙栨暣鍒楃殑OCIParm錛岀劧鍚庡啀浣跨敤OCIAttrGet()渚濇鑾峰彇璞″垪鍚嶏紝鍒楀ぇ灝忥紝綺懼害絳?br> 鏈夌敤鐨勪俊鎭?br> <br> 鑾峰彇榪欎簺灞炴у悗錛屽氨闇瑕佽皟鐢∣CIDefineByPos()鎴朞CIDefineByName涓虹粨鏋滈泦瀹氫箟<br> 鍐呭浜嗐?br> <br> 鍏跺疄榪欎簺Get()鍜孌efine()灝辨槸涓轟簡鎻忚堪Select鎵ц鍚庤繑鍥炵殑緇撴灉闆嗭紝鏂逛究鎴戜滑鑾峰彇鍏朵腑<br> 鏁版嵁銆侽CIDB::UserFetch() 閲岄潰鍙湁涓狾CIStmtFetch()錛屾瘮杈冨ソ鐞嗚В錛岃鐧戒簡灝辨槸鎺у埗<br> 娓告爣銆?br> <br> 娉ㄦ剰璞CIDB::UserGet鐨勮繖浜涗釜鎴愬憳鍑芥暟錛屾槸瀵瑰鐨勬暟鎹帴鍙o紝浠ヤ笅鏄笉鍚岀殑閲嶈澆褰?br> 寮忥細<br> <br>   int UserGetInt(int index);<br>   int UserGetInt(char * name);<br>   char * UserGetString(int index);<br>   char * UserGetString(char * name); <span id="4242sqy" class=Apple-converted-space> </span><br>   float UserGetFloat(int index);<br>   float UserGetFloat(char * name);<span id="c2mi44a" class=Apple-converted-space> </span><br>  <span id="cg42ssg" class=Apple-converted-space> </span><br> 榪欓噷娌℃湁浠涔堝ソ璇寸殑錛岃璇諱唬鐮佸氨浼氭竻妤氥?br> <br>浜斻佸啓鍦ㄦ渶鍚?/p> <p style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0.9em; MARGIN: 0px; PADDING-TOP: 0.9em"> 榪欎釜渚嬩粎鍋氭紨紺恒備笉榪囦笉蹇呬粎鍋滅暀浜庢錛屽瑕佹彁楂橈紝緇撳悎鍦ㄧ嚎鏂囨。澶氱粌鍗沖彲銆?br>榪欎釜渚嬪瓙鐨勪唬鐮佸湪鏌愪簺鏂歸潰鏄劇劧涓嶅瑙勮寖錛屽鏈湪浼犲間腑浣跨敤const錛岃繖涔熸槸浠ュ悗<br>瑕佹彁楂樼殑鏂歸潰銆?br> 鍙﹀錛屽垰鎺ヨЕOCI鏃訛紝鍙兘浼氬鍐呴儴鐨勪竴鍫嗙被鍨嬩笉澶傚簲錛岃繖閲屽鐪嬬湅鍑芥暟鐨勫弬鑰冿紝<br>灝介噺鍋氫竴浜涘己鍒舵х殑杞崲銆?nbsp;</p> </span></span> <img src ="http://m.shnenglu.com/ietj/aggbug/142535.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/ietj/" target="_blank">涓璺灝?/a> 2011-03-23 00:13 <a href="http://m.shnenglu.com/ietj/articles/142535.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>Oracle鏁版嵁搴撳紑鍙?鍏?.OCI搴旂敤鍒濇帰http://m.shnenglu.com/ietj/articles/142534.html涓璺灝?/dc:creator>涓璺灝?/author>Tue, 22 Mar 2011 16:11:00 GMThttp://m.shnenglu.com/ietj/articles/142534.htmlhttp://m.shnenglu.com/ietj/comments/142534.htmlhttp://m.shnenglu.com/ietj/articles/142534.html#Feedback0http://m.shnenglu.com/ietj/comments/commentRss/142534.htmlhttp://m.shnenglu.com/ietj/services/trackbacks/142534.html

Oracle Database Development (6). A first exploration of OCI

Vert Melon

Jun 25,2007

1.Preface

 Last time , i provided a full example of OCI , which contains the actual code of connection 
and SQL . Certainly it could not cover all of the knowledge , but i think it is a good beginning 
for the fresher .

 As the same as Pro*C you might confirm that you have installed it correctly .  Look at this 
paths as follows :
 
 Windows   :   $ORACLE_HOME\oci
 Linux/Unix  :   $ORACLE_HOME/rdbms/demo
 
 There are many examples offered by ORACLE . Though it seems like a clutter , you also 
can get some useful imformation .

 The main platform we use here is Linux .  And the Windows ?  How can i config it in Windows ? 
It would be a comfy thing if you have read the chapters recorded in  <Oracle Database Development (1). Config OCI In Windows> .
It is easily comprehend by analogy .


2.Something you should know

 What is the Oracle Call Interface?

 The Oracle Call Interface (OCI) is a set of low-level APIs (Application Programming Interface Calls) 
used to interact with Oracle databases. It allows one to use operations like logon, execute, 
parse, fetch, etc. OCI programs are normally written in C or C++, although they can be written
in almost any programing language. Unlike with the Oracle Precompilers (like Pro*C and Pro*COBOL), 
OCI programs are not precompiled.

 Also I have found a official explaination about the choice between Pro*C and OCI .
 
 Should one use OCI or the Oracle Precompilers?
 
 OCI is superior to Pro*C in the following ways: 
  Performance is much better with OCI 
  Reduced code size 
  Direct access to built-in functions (No intermediate files or substitutions). 
  Piecewise Operation on LONG fields (All LONG field problems are solved) 
  In Pro*C one cannot dynamically allocate memory to be used as bind variables 
  You cannot control the Pro*C precompiler to provide better and more compilable C-code. 
  ...
   
 Common problems with OCI: 
  OCI code is difficult to write and to maintain 
  Very few people can write, let alone maintain OCI code 
  ...
  
 An OCI application program must do the following: 
  Connect to one or more databases: call the OCILogon (olog, olon or orlon) routines 
  Open the cursors needed by the program: use oexec, oexn, ofen or oftech calls. 
  Process the SQL statements that are needed to perform the application's tasks. 
  Close the cursors using the oclose routine. 
  Disconnect from the databases: use ologoff to close an open connection to oracle.  

3.Obsolescent OCI Routines

 After get through the section "Something you should know" ,  you may find some strange 
words : oexec , ologoff  or oclose . There are old routines in preceding release . 
 Release 8.0 of the Oracle Call Interface introduced an entirely new set of functions which 
were not available in release 7.3. Release 8.1 added more new functions. Oracle9i OCI continues 
to support these new functions, and adds more new calls. The earlier 7.x calls are still available, 
but Oracle strongly recommends that existing applications use the new calls to improve performance 
and provide increased functionality.
 To get more information ,  check it in the chapter named "Introduction and Upgrading" in 
OCI document .


4. Introduce to OCI Makefile

 It's time to make out the source file , and the first one is Makefile which is a trunk in a project .
But then it is the end of  a first exploration .

 Notice that the head files of OCI are put in two directories and the lib file is libclntsh.so.9.0 
which is the same as Pro*C .  This is a simple one ,  just copy the code in last article and 
divide into the corresponding files as the list . Then use "make all" or "make clean" to deal with 
the source file automaticly . You would see something like this .

[root@liwei oci]# make clean;
rm -f OCIDB OCIDB.o OCIException.o Exception.o OCIError.o Main.o
[root@liwei oci]# make all;
[OCIDB.o]
---------------------
g++ -g -o OCIDB.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c OCIDB.cpp

[OCIException.o]
---------------------
g++ -g -o OCIException.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c OCIException.cpp

[Exception.o]
---------------------
g++ -g -o Exception.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c Exception.cpp

[OCIError.o]
---------------------
g++ -g -o OCIError.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c OCIError.cpp

[Main.o]
---------------------
g++ -g -o Main.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c Main.cpp

[link] ... 
---------------------
g++ -g -o OCIDB OCIDB.o OCIException.o Exception.o OCIError.o Main.o -L/home/ora/ora9/oracle/lib -lclntsh

 That's good . Take a rest for next step .

-------------------------------------------------------------------------------------------------------

Oracle鏁版嵁搴撳紑鍙?鍏?.OCI搴旂敤鍒濇帰

鑽夋湪鐡?/p>

2007.6.25  
 
涓銆佸簭

 鍦ㄤ笂涓嬈★紝鎴戞彁渚涗簡涓涓畬鏁寸殑OCI紺轟緥錛屽唴瀹瑰寘鎷暟鎹簱榪炴帴鍜孲QL鎿嶄綔鐨勫疄闄呬唬鐮併?br>褰撶劧涓涓皬渚嬪瓙涓嶅彲鑳藉寘鎷墍鏈夊唴瀹癸紝涓嶈繃鎴戣涓哄鍒濆鑰呮槸涓涓笉閿欑殑寮濮嬨?/p>

 涓嶱ro*C涓鏍鳳紝闇瑕佺‘璁ゅ畨瑁匫CI緇勪歡錛屾煡鐪嬩笅闈㈢殑璺緞錛?br> 
 Windows   :   $ORACLE_HOME\oci
 Linux/Unix  :   $ORACLE_HOME/rdbms/demo
 
 榪欎簺鐩綍鍖呭惈涓浜涚敱ORACLE鎻愪緵鐨勪竴浜涚ず渚嬨傝櫧鐒舵湁浜涙潅涔憋紝涓嶈繃榪樻槸涓浜涘府鍔╃殑銆?br> 鎴戜滑榪欓噷浣跨敤鐨勪富瑕佸鉤鍙版槸Linux銆?Windows涓嬫庝箞璁劇疆鍛紵鍙互鍙傝銆奜racle鏁版嵁搴?br>寮鍙?涓).Windows涓嬮厤緗嬌鐢≒roC銆嬩竴鏂囷紝閮芥槸綾諱技鐨勩?/p>


浜屻佷竴浜涗綘闇瑕佺煡閬撶殑涓滆タ

 OCI鏄粈涔?錛?br> 
 OCI鏄竴緇勫簳灞傜殑API(搴旂敤紼嬪簭鎺ュ彛)錛屼富瑕佸拰Oracle鏁版嵁搴撹繘琛屼氦浜掋備綘鍙互璋冪敤涓浜?br>鎿嶄綔濡?logon , execute, parse, fecth 絳夌瓑銆侽CI鏀寔澶ф暟鎹璦錛岄氬父浣跨敤C/C++銆備笌Oracle
Pro*C絳変笉鍚岋紝OCI涓嶉渶瑕侀緙栬瘧銆?/p>

 鎴戣繖閲屼篃鎵劇潃涓浠藉叧浜庡湪Pro*C鍜孫CI涔嬮棿閫夋嫨鐨勫畼鏂硅鏄庛?br> 
 鎴戝簲璇ヤ嬌鐢∣CI榪樻槸Pro*C錛?br> 
 OCI姣擯ro*C鐨勪竴浜涗紭鍔匡細
  
  OCI鐨勬ц兘鍗佸垎鍑鴻壊
  浠g爜澶ч噺緙╁噺
  瀵瑰唴緗嚱鏁扮洿鎺ヨ闂?br>  瀵筁ONG綾誨瀷鐨勫垎孌墊搷浣?鍙互澶勭悊LONG鐩稿叧鐨勪換浣曢敊璇?
  Pro*C涓嶈兘涓虹粦瀹氬彉閲忓姩鎬佸垎閰嶅唴瀛?br>  涓嶈兘鎺у埗Pro*C鑷姩鐢熸垚鐨勪唬鐮?span class=Apple-converted-space> 
  
 OCI寮鍙戠殑涓浜涘父瑙侀棶棰橈細
 
  OCI浠g爜涓嶅鏄撴帉鎻?br>  ...
  
 OCI寮鍙戞祦紼嬶細
 
  榪炴帴澶氫釜鏁版嵁搴擄細浣跨敤OCILogon (olog, olon or orlon)
  鎵撳紑娓告爣錛歰exec, oexn, ofen 鎴栬?oftech
  鎵ц鐩稿簲SQL璇彞
  鍏充簬娓告爣錛歰close
  鏂紑榪炴帴錛歰logoff
  
涓夈佸簾寮冪殑涓浜涚▼搴忔爣鍑?/p>

 鐪嬭繃涓婅妭錛屼綘浼氬彂鐜頒竴浜涘鎬殑鍗曡瘝錛宱exec , ologoff  鎴?oclose 銆傝繖浜涢兘鏄厛鍓嶇増鏈?br>鏃х殑OCI鏍囧噯銆?/p>

 OCI 8.0 寮曞叆涓濂楀叏鏂扮殑紼嬪簭緇撴瀯錛屾槸7.3浠ュ墠娌℃湁鐨勩?.1鐗堟湰鍙堟墿灞曚簡涓浜涘嚱鏁般?br>鍦∣racle 9i涓櫧鐒舵敮鎸佽繖浜涙棫鐨勬爣鍑嗭紝涓嶈繃Oracle寮虹儓寤鴻浣跨敤鍏ㄦ柊鐨凮CI鏍囧噯搴撱?br> 鍙傝僌CI鏂囨。涓?浠嬬粛鍜屽崌綰у唴瀹?涓鑺傦紝鑾峰彇鏇村淇℃伅銆?br> 
鍥涖丱CI Makefile 浠嬬粛

 鐜板湪宸笉澶氳浠嬬粛婧愪唬鐮佷簡錛岄鍏堢殑鏄疢akefile鏂囦歡錛屽彲浠ヨ鎴愭槸鏁翠釜欏圭洰鐨勪腑蹇冿紝鍙?br>鐪嬩緥涓殑鏂囦歡鍐呭銆傛敞鎰忓ご鏂囦歡鐩綍鏈変袱涓紝搴撴枃浠跺拰Pro*C浣跨敤鐨勪竴鏍鳳紝榪樻槸 libclntsh.so.9.0 錛?br>鐩稿叧璺緞鑷凡璋冩暣銆?br> 榪欎釜Makefile姣旇緝綆鍗曪紝鎶婂墠闈㈡枃绔犵綏鍒楃殑鎵鏈変唬鐮佸鍒跺茍寤虹珛鐩稿簲鏂囦歡錛屼嬌鐢?make all"
"make clean" 鍛戒護錛屼綘搴旇鑳界湅鍒板涓嬬被浼肩殑鍐呭錛?nbsp;

[root@liwei oci]# make clean;
rm -f OCIDB OCIDB.o OCIException.o Exception.o OCIError.o Main.o
[root@liwei oci]# make all;
[OCIDB.o]
---------------------
g++ -g -o OCIDB.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c OCIDB.cpp

[OCIException.o]
---------------------
g++ -g -o OCIException.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c OCIException.cpp

[Exception.o]
---------------------
g++ -g -o Exception.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c Exception.cpp

[OCIError.o]
---------------------
g++ -g -o OCIError.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c OCIError.cpp

[Main.o]
---------------------
g++ -g -o Main.o -I/home/ora/ora9/oracle/rdbms/demo -I/home/ora/ora9/oracle/rdbms/public -c Main.cpp

[link] ... 
---------------------
g++ -g -o OCIDB OCIDB.o OCIException.o Exception.o OCIError.o Main.o -L/home/ora/ora9/oracle/lib -lclntsh

 Makefile鐩稿叧鐭ヨ瘑鍙互鍘籊oogle涓涓嬶紝鏂囩珷浠庣幇鍦ㄥ紑濮嬶紝灝辮闄嗙畫浠嬬粛涓浜汷CI
瀹炶川鎬х殑鍐呭浜嗐?/p>

]]>
Oracle鍏ラ棬 - OCI浠嬬粛http://m.shnenglu.com/ietj/articles/142533.html涓璺灝?/dc:creator>涓璺灝?/author>Tue, 22 Mar 2011 16:10:00 GMThttp://m.shnenglu.com/ietj/articles/142533.htmlhttp://m.shnenglu.com/ietj/comments/142533.htmlhttp://m.shnenglu.com/ietj/articles/142533.html#Feedback0http://m.shnenglu.com/ietj/comments/commentRss/142533.htmlhttp://m.shnenglu.com/ietj/services/trackbacks/142533.html

OCI(Oracle Call Inte***ce)鏄敱澶存枃浠跺拰搴撳嚱鏁扮瓑緇勬垚鐨勪竴濂桹racle鏁版嵁搴撳簲鐢ㄧ▼搴忕紪紼嬫帴鍙e伐鍏鳳紝OCI紼嬪簭瀹炶川涓婂氨鏄敤楂樼駭璇█鍐欑殑紼嬪簭錛屽叾鐗圭偣鏄唴閮ㄥ惈鏈夊OCI瀛愬嚱鏁板簱鐨勮皟鐢ㄣ?br>OCI紼嬪簭瀵瑰紑鍙戠幆澧冪殑瑕佹眰鐩稿杈冧綆錛屽彧瑕佹湁C璇█鐨凮CI寮鍙戝伐鍏峰寘鍜孋緙栬瘧鍣ㄥ氨鍙互錛岀▼搴忚璁$浉姣擯RO*C澶嶆潅浜嗙偣銆?/p>

1銆佸垱寤哄拰鍒濆鍖朞CI鐜
棣栧厛瑕佸湪婧愮▼搴忎腑鍖呭惈OCI澶存枃浠訛細#include <oci.h>
OCI鐜鍗砄CI鍑芥暟鐨勫伐浣滅幆澧冿紝鍦ㄨ皟鐢ㄥ叾浠栧嚱鏁頒箣鍓嶅繀欏誨厛璋冪敤OCIInitialize()鍜孫CIEnvInit()鍑芥暟鍒涘緩鍜屽垵濮嬪寲OCI鐜錛屽叾浠朞CI鍑芥暟瑕佸湪榪欎釜鐜涓墠鑳芥墽琛屻?br>鍏堝畾涔夊彉閲忥細
OCIEnv**   m_envhp;
OCIError*  m_errhp;
OCIServer* m_srvhp;
OCISvcCtx* m_svchp;
OCIStmt *  m_stmthp;

OCIInitialize(
               (ub4) OCI_DEFAULT,
               (dvoid *)0,
               (dvoid * (*)(dvoid *, size_t))0,
               (dvoid * (*)(dvoid *, dvoid *, size_t))0,
               (void (*)(dvoid *, dvoid *))0
              );

OCIEnvInit(
            (OCIEnv **)&m_envhp,
            OCI_DEFAULT, (size_t)0,
            (dvoid **)0
           );

鍏朵腑m_envhp涓鴻緭鍑哄弬鏁幫紝鏄竴涓寚鍚慜CI鐜鍙ユ焺鐨勬寚閽堬紝OCI_DEFAULT 鏄疧CI鐜鐨勫垵濮嬪寲妯″紡銆侽CIEnvInit()鍑芥暟涓殑size_t綾誨瀷鍙橀噺涓哄垎閰嶇粰鐢ㄦ埛鐨勫唴瀛樻暟閲忥紝dvoid **綾誨瀷鍙橀噺鎸囧悜鐢ㄦ埛鐨勫唴瀛樺尯鍩燂紝璇ュ尯鍩熺殑澶у皬絳変簬size_t綾誨瀷鍙橀噺銆?br>OCI鍑芥暟涓紝澶ч噺浣跨敤OCI瀹氫箟鐨勬暟鎹被鍨嬪拰瀹忥紝鍏跺畾涔夊彲鍙傝?ORACLE_HOME/rdbms/demo鐩綍涓嬬殑oci.h澶存枃浠躲?/p>

2銆佺敵璇峰彞鏌?br>鍙ユ焺鏄寚鍚慜CI搴撴墍鍒嗛厤鐨勫唴瀛樺尯鍩熺殑鎸囬拡錛岃鍐呭瓨鍖哄煙涓殑鏁版嵁鐢監CI搴撶淮鎶わ紝搴旂敤紼嬪簭鍙氳繃鍙ユ焺璁塊棶鍏朵腑鐨勬暟鎹備笅闈㈡槸搴旂敤紼嬪簭涓渶甯哥敤鐨勫嚑涓彞鏌勶細
OCIHandleAlloc(
                (dvoid *)m_envhp,
                (dvoid **)&m_errhp,
                 OCI_HTYPE_ERROR,
                (size_t)0,
                (dvoid **)0
               );

OCIHandleAlloc(
                (dvoid *)m_envhp,
                (dvoid **)&m_srvhp,
                OCI_HTYPE_SERVER,
                (size_t)0,
                (dvoid **)0
              );

OCIHandleAlloc(
                (dvoid *)m_envhp,
                (dvoid **)&m_svchp,
                 OCI_HTYPE_SVCCTX,
                (size_t) 0,
                (dvoid **)0
              );

OCIHandleAlloc(
                (dvoid *)m_envhp,
                (dvoid **)&m_stmthp,
                 OCI_HTYPE_STMT,
                (size_t)0,
                (dvoid **)0
               );

鍏朵腑m_errhp涓烘柊鐢寵鐨勫彞鏌勶紝m_envhp涓哄畠鐨勭埗鐜鍙ユ焺錛孫CI_HTYPE_ERROR涓哄彞鏌勭被鍨嬶紝琛ㄧず榪欐槸涓涓敊璇姤鍛婂彞鏌勶紝OCI_HTYPE_SERVER琛ㄧず鏈嶅姟鍣ㄥ彞鏌勶紝OCI_HTYPE_SVCCTX琛ㄧず鏈嶅姟鐜鍙ユ焺錛孫CI_HTYPE_STMT琛ㄧず璇彞鍙ユ焺銆?/p>

瀛樺偍鍦ㄥ彞鏌勪腑鐨勬暟鎹О涓哄彞鏌勫睘鎬э紝鎵鏈塐CI鍙ユ焺閮藉叿鏈夊睘鎬э紝鍙互璋冪敤OCIAttrGet()鍜孫CIAttrSet()鍑芥暟鏉ヨ鍙栥佽緗彞鏌勫睘鎬с?/p>

3銆佽繛鎺ユ湇鍔″櫒寤虹珛浼氳瘽
棣栧厛璋冪敤
OCIServerAttach(m_srvhp, m_errhp, (text *)"", strlen(""), OCI_DEFAULT);
鍑芥暟寤虹珛涓庢寚瀹氭湇鍔″櫒鐨勮繛鎺ワ紝text *綾誨瀷鍙橀噺涓虹┖錛岃〃紺鴻繛鎺ラ粯璁ゆ暟鎹簱鏈嶅姟錛孫CI_DEFAULT琛ㄧず搴旂敤紼嬪簭鐨勬搷浣滄ā寮忎負闃誨妯″紡錛屽湪榪欑鏂瑰紡涓嬶紝鍙湁褰揙CI璋冪敤瀹屾垚鍚庢墠灝嗘帶鍒舵潈榪斿洖緇欏鎴風搴旂敤紼嬪簭銆?/p>

鐒跺悗璋冪敤
OCILogon(m_envhp,m_errhp, &m_svchp, (text*)m_szUser,strlen(m_szUser), (text*)m_szPassword, strlen(m_szPassword), (text*)m_szDbName, strlen(m_szDbName));
寤虹珛鏁版嵁搴撲細璇濄傛鍑芥暟闅愬惈鐢寵鏈嶅姟鍣ㄥ彞鏌勫拰鐢ㄦ埛浼氳瘽鍙ユ焺錛岀櫥褰曞悗錛屽彞鏌勬槸鍙鐨勶紝涓嶈兘鍐嶈緗彞鏌勫睘鎬с?/p>

4銆佹墽琛孲QL璇彞騫跺鐞嗘暟鎹?br>灝嗚鎵ц鐨凷QL璇彞copy鍒皊zSqlStr瀛楃涓蹭腑:
snprintf( szSqlStr, sizeof(szSqlStr), "select PASSWORD from USERS where USERNAME=’chen’ ");
鎵ц涓嬪垪璇彞錛?/p>

OCIStmtPrepare(m_stmthp, m_errhp, (text*)szSqlStr, (ub4) strlen(szSqlStr), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT); //鍑嗗SQL璇彞

OCIDefine *defnp0 = (OCIDefine *) 0; //瀹氫箟杈撳嚭鍙橀噺

OCIDefineByPos( m_stmthp, &defnp0, m_errhp, 1, (dvoid *)szUSERNAME, 100, SQLT_STR, (dvoid *) 0, (ub2 *)0, (ub2 *)0, OCI_DEFAULT); //緇戝畾鍙橀噺

OCIStmtExecute( m_svchp, m_stmthp, m_errhp, (ub4) 1, (ub4) 0, (OCISnapshot *) NULL,(OCISnapshot *) NULL, (ub4) OCI_DEFAULT); //鎵цSQL璇彞

5銆佺粨鏉熶細璇濇柇寮鏁版嵁搴撹繛鎺?br>OCILogoff( m_svchp, m_errhp );

6銆佹柇寮涓庢暟鎹簮鐨勮繛鎺ワ紝閲婃斁鍙ユ焺
OCIServerDetach( m_srvhp, m_errhp, OCI_DEFAULT ); //鏂紑涓庢暟鎹簮鐨勮繛鎺?br>OCIHandleFree((dvoid *) m_stmthp, OCI_HTYPE_STMT); //閲婃斁鍙ユ焺
OCIHandleFree((dvoid *) m_svchp, OCI_HTYPE_SVCCTX);
OCIHandleFree((dvoid *) m_srvhp, OCI_HTYPE_SERVER);
OCIHandleFree((dvoid *) m_errhp, OCI_HTYPE_ERROR)
3.7鐢熸垚鍙墽琛屾枃浠訛紙涓ょ鏂規硶錛?br>(1)鍚屾櫘閫氱殑C紼嬪簭錛?br>   gcc -o exampled –I. –I$(ORACLE_HOME)/precomp/public example.c

(2)鍒╃敤Oracle鑷甫鐨凪ake鏂囦歡錛?br>棣栧厛灝?ORACLE_HOME/rdbms/demo/demo_rdbms.mk鏂囦歡copy鍒癘CI婧愮▼搴忔墍鍦ㄧ殑鐩綍錛屽皢婧愭枃浠剁紪璇戜負鐩爣鏂囦歡錛?br>#gcc –c example.o -I$(ORACLE_HOME)/rdbms/demo -I$(ORACLE_HOME)/network/public -I$(ORACLE_HOME)/rdbms/public/ example.c
鐒跺悗鐢ㄥ懡浠わ細#make -f demo_rdbms.mk build OBJ*=**ample.o EXE=exampled錛宔xampled灝變負鐢熸垚鐨勫彲鎵ц鏂囦歡



]]>
Oracle甯哥敤鐨凮CI鍑芥暟http://m.shnenglu.com/ietj/articles/142532.html涓璺灝?/dc:creator>涓璺灝?/author>Tue, 22 Mar 2011 16:09:00 GMThttp://m.shnenglu.com/ietj/articles/142532.htmlhttp://m.shnenglu.com/ietj/comments/142532.htmlhttp://m.shnenglu.com/ietj/articles/142532.html#Feedback0http://m.shnenglu.com/ietj/comments/commentRss/142532.htmlhttp://m.shnenglu.com/ietj/services/trackbacks/142532.html闃呰鍏ㄦ枃

]]>
午夜久久久久久禁播电影| yy6080久久| 久久久久久狠狠丁香| 久久国产视频99电影| 久久久久青草线蕉综合超碰| 久久久久亚洲av无码专区喷水 | 国产成人久久精品麻豆一区| 久久久久久噜噜精品免费直播| 久久久一本精品99久久精品88| 国产精品久久久久久影院| 久久大香萑太香蕉av| www.久久热| 麻豆AV一区二区三区久久 | 伊人色综合九久久天天蜜桃| 国产精品对白刺激久久久| 日韩欧美亚洲综合久久影院Ds | 亚洲AV无码久久精品成人| 国产农村妇女毛片精品久久| 色综合久久无码五十路人妻| 久久久精品久久久久特色影视| 国产综合久久久久| 少妇无套内谢久久久久| 久久毛片免费看一区二区三区| 久久99毛片免费观看不卡| 新狼窝色AV性久久久久久| 色综合合久久天天给综看| 久久99精品久久久久久不卡| 97久久精品国产精品青草| 久久水蜜桃亚洲av无码精品麻豆 | 久久精品国产清高在天天线| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 亚洲综合久久综合激情久久| 国产精品久久久久无码av| 亚洲AV无码久久| 日产精品99久久久久久| 亚洲精品美女久久久久99| 囯产精品久久久久久久久蜜桃| 99久久综合国产精品免费| 无码人妻精品一区二区三区久久| 亚洲精品无码久久千人斩| 国产美女久久精品香蕉69|