Document Type | Technical Information
Category | Interface/Integration
Applicable Product Versions | Tibero6, Tibero7
Document Number | TIITI070
Overview
This guide explains how to connect to the Tibero server in a Windows environment using the Oracle Call Interface (OCI) library.
Note
Testing was conducted in the following environment.
OS: Windows 10 (64 bit)
DB: Tibero 6 FS06
IDE: VS 2017
Method
OCI Installation
1. Copy OCI Library
Copy the library files included in the Tibero binary (%TB_HOME%binlibtboci.lib, %TB_HOME%binlibtboci.dll) to the client Windows machine where you want to use them.
CautionOnly the 32/64 bit version of the Tibero binary is built accordingly. Copy from the binary with the same bit version that matches the platform bit of the application you want to compile.
2. Copy Oracle OCI Headers
$ORACLE_HOME/rdbms/public folder, copy the .h files located there to the client Windows machine.3. Add Environment Settings
1) Add library and header file directories on the [C/C++] - [General] tab in the property page under [Project] - [Properties].
2) Set additional library directories on the [Linker] - [General] tab.
3) Add the Tibero OCI library as a dependency on the [Linker] - [Input] tab.
Working with Tibero Using OCI
1. Add OCI Header
#include โoci.hโ
2. Initialize OCI Objects
static OCIEnv *p_env; static OCIError *p_err; static OCISvcCtx *p_svc; static OCIStmt *p_sql; static OCIDefine *p_dfn = (OCIDefine *)0; static OCIBind *p_bnd = (OCIBind *)0; int p_bvi; char p_sli[20]; int rc; OraText errbuf[100]; int errcode; rc = OCIInitialize((ub4)OCI_DEFAULT, (dvoid )0, / Initialize OCI */ (dvoid * (*)(dvoid *, size_t)) 0, (dvoid * (*)(dvoid *, dvoid *, size_t))0, (void(*)(dvoid *, dvoid *)) 0); /* Initialize environment */ rc = OCIEnvInit((OCIEnv **)&p_env, OCI_DEFAULT, (size_t)0, (dvoid **)0); /* Initialize handles */ rc = OCIHandleAlloc((dvoid *)p_env, (dvoid **)&p_err, OCI_HTYPE_ERROR, (size_t)0, (dvoid **)0); rc = OCIHandleAlloc((dvoid *)p_env, (dvoid **)&p_svc, OCI_HTYPE_SVCCTX, (size_t)0, (dvoid **)0); SQL
3. Connect to Tibero Database
Enter the account and database information.
NoteDepending on the version, string data (char) can be compiled by casting to the Oracle-defined type (OraText).
/* Connect to database server */
rc = OCILogon(p_env, p_err, &p_svc, (OraText)โsysโ, 3, (OraText)โtiberoโ, 6,
(OraText*)โtiberoโ, 6);
if (rc != 0) {
OCIErrorGet((dvoid *)p_err, (ub4)1, (text *)NULL, &errcode, errbuf, (ub4)
sizeof(errbuf), OCI_HTYPE_ERROR);
printf("Error - %.*sn", 512, errbuf);
exit(8);
}
4. Preprocess SQL (select)
/* Allocate and prepare SQL statement */ rc = OCIHandleAlloc((dvoid *)p_env, (dvoid **)&p_sql, OCI_HTYPE_STMT, (size_t)0, (dvoid **)0); rc = OCIStmtPrepare(p_sql, p_err, (OraText*)โselect * from dualโ, (ub4)37, (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT);
5. Execute SQL (select) and Output Results
/* Execute the SQL statement */
rc = OCIStmtExecute(p_svc, p_sql, p_err, (ub4)1, (ub4)0,
(CONST OCISnapshot *) NULL, (OCISnapshot *)NULL, OCI_DEFAULT);
while (rc != OCI_NO_DATA) { /* Fetch the remaining data */
printf("%s", p_sli);
rc = OCIStmtFetch(p_sql, p_err, 1, 0, 0);
}
6. Preprocess SQL (insert)
/* sql prepare */ rc = OCIStmtPrepare(p_sql, p_err, (OraText*)โinsert into test values(โdummyโ, 100);โ, (ub4)37, (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT);
7. Execute SQL (insert) and Confirm Results
When set to OCI_COMMIT_ON_SUCCESS mode, the query will automatically commit if it is successfully applied.
rc = OCIStmtExecute(p_svc, p_sql, p_err, (ub4)1, (ub4)0, (CONST OCISnapshot *) NULL, (OCISnapshot *)NULL, OCI_COMMIT_ON_SUCCESS);
Reference) OCI SQL Processing Flow
3.2 OCI programming guide
https://docs.oracle.com/en/database/oracle/oracle-database/12.2/lnoci/ociprogramming-basics.html#GUID-8C59F2D9-3A69-41EE-927B-13659F6AD411