ORAPP - Oracle OCI C Interface Library
Using ORAPP: Simple Sql Statements
Extern "C" {
#include
}
#include
INT main (void) {
ORAPP :: Connection DB;
IF (! DB.Connect ("TNS", "User", "Pass")) {
Printf ("FAILED TO Connect:% S / N", DB.Error (). c_str ());
Return 1;
}
/ *
* One can pre-propulate the query object.
* /
ORAPP :: Query * Q = DB.Query ("SELECT 1 AS One, 2 as Two from Dual");
IF (! q> execute ()) {
Printf ("Failed to SELECT:% S / N", DB.Error (). c_str ());
Return 1;
}
ORAPP :: ROW * R = Q-> fetch ();
/ *
* You can do Type Conversions Directly in ORAPP BY Changing Your
* Typecast of the row object.
* /
Printf ("One =% S, TWO =% u / N", (const char *) (* r) ["one"], (* r) ["two"]);
/ *
* Or use the indirection operators to populate the query.
* /
* Q << "Insert Into Table (Field) Values ('FOOBAR')"
IF (! q> execute ()) {
Printf ("Failed to Execute:% S / N", DB.Error (). c_str ());
Return 1;
}
/ *
* ORAPP MANAGES All ITS OWN Memory, So in Order to Clean Up All
* That Has to Happen Is That The Main Connection Object Go Out
* of scope.
* /
IF (! db.disconnect ()) {
Printf ("Failed to Disconnect Properly / N");
Return 1;
}
Return 0;
}
Using ORAPP: Inbound and Outbound Bindings
Extern "C" {
#include
}
#include
Using namespace orapp;
INT main (void) {
Connection DB;
IF (! DB.Connect ("TNS", "User", "Pass")) {
Printf ("FAILED TO Connect:% S / N", DB.Error (). c_str ());
Return 1;
}
/ *
* One can pre-propulate the query object.
* /
Query * Q = DB.Query ("Begin Select ID, Name Into: ID,: Name WHERE AGE =: Age; End"); unsigned age = 25;
Q-> Bind (": agn", age);
UNSIGNED ID;
CHAR Name [80] = {0};
Q-> Bind (": id", id);
Q-> Bind (": name", name, sizeof (name));
/ *
* When doing bind () 's, only one execute () is Required, Which IF
* Successful Will Populate Any Writable (Inbound) Bind's That
* Were Specified. Otherwise, IF Thee WERE JUST Read (Outbound)
* Bind's, IT Would Still Be Necessary To Call Fetch () (SELECTS).
* /
IF (! q> execute ()) {
Printf ("Failed to SELECT:% S / N", Q-> Error (). c_str ());
Return 1;
}
/ *
* Variables Should Be Populated Now.
* /
Printf ("Age =% U, ID =% U, Name =% S / N", AGE, ID, NAME);
/ *
* ORAPP MANAGES All ITS OWN Memory, So in Order to Clean Up All
* That Has to Happen Is That The Main Connection Object Go Out
* of scope.
* /
IF (! db.disconnect ()) {
Printf ("Failed to Disconnect Properly / N");
Return 1;
}
Return 0;
}
For A More Detailed and Thorough Demonstration of the Capabilities of Orapp, please booked with this library.