Ott is a very important tool in OCI to access object-type data. It maps object types or geometric objects in the database into structures in C language for OCI programs. In all operating systems that support Oracle, The OTT tool works as a command line. To use it, we must first make some preparations.
Set the ORACLE_HOME environment variable. my options are c: \ app \ zxg \ product \ 11.1.0 \ db_1.
In Windows command line mode, enter Ott and the following information appears,
Example of Ott usage method: first, create a type under the Scott user
Create type emp_t as object
(Name varchar2 (30 ),
Empno number,
Deptno number,
Hiredate date,
Salary number );
On the local machine, I run this program in the root directory of the D Drive. In the root directory of the D Drive, create the file demoin. TPY and write it into the file.
Case = lower
Type emp_t
And save. Enter the OTT command,
D: \> Ott userid = Scott/tiger intype = demoin. TPY outtype = demoout. TPY code = C hfile = demo. h initfile = demov. c
Specifically, use the username Scott and password tiger to connect to the database and convert the type definition in the input file demoin. TPY to the struct declaration in the C language. Output to the header file demo. H (struct definition in C) and demoout. TPY. The implementation file demov. C contains information about user-defined type conversion and initialization functions.
After executing this command, the demoout. TPY file generated by Ott is as follows:
Case = lower
Initfile = demov. c
Initfunc = demov
Type Scott. emp_t as emp_t
Version = "$8.0"
Hfile = demo. h
The contents of the header file demo. h generated by Ott are as follows:
# Ifndef demo_oracle
# Define demo_oracle
# Ifndef oci_oracle
# Include <OCI. h>
# Endif
Typedef ociref emp_t_ref;
Struct emp_t
{
Ocistring * Name;
Ocinumber empno;
Ocinumber deptno;
Ocidate hiredate;
Ocinumber salary;
};
Typedef struct emp_t;
Struct emp_t_ind
{
Ociind _ atomic;
Ociind name;
Ociind empno;
Ociind deptno;
Ociind hiredate;
Ociind salary;
};
Typedef struct emp_t_ind;
# Endif
The implementation file demov. c generated by Ott is as follows:
# Ifndef oci_oracle
# Include <OCI. h>
# Endif
Sword demov (ocienv * ENV, ocierror * ERR)
{
Sword status = ocitypevtinit (ENV, err );
If (status = oci_success)
Status = ocitypevtinsert (ENV, err,
(Unsigned char *) "Scott", 5,
(Unsigned char *) "emp_t", 5,
(Unsigned char *) "$8.0", 4 );
Return status;
}
Once the OTT type conversion is completed, the header file contains a struct definition of the corresponding type for each object type in the intype file, and a struct represents a Null Indicator of this type. For example, in the header file, the struct emp_t represents the object type emp_t, and a corresponding indicator struct emp_t_ind.
This is only for the C language. to convert it to the C ++ source file, you must enter a command similar to the following:
Ott userid = Scott/tiger intype = demoin. TPY outtype = demoout. TPY code = CPP hfile =
Sdogeometry. h cppfile = sdogeometry. cpp
After the input is correct, the following file is obtained.