兼容OCI接口
兼容OCI接口¶
SeaboxSQL数据库提供兼容OCI语法的API,在几乎不用改动原有Oracle OCI程序的基础上,通过提供的头文件和动态库,实现对SeaboxSQL数据库的增删查改功能。除此之外,还支持Bind语句执行和Define输出结果。
支持的结构体¶
SeaboxSQL兼容OCI接口支持以下Oracle OCI程序结构体:
-
OCISession
-
OCIServer
-
OCISvcCtx
-
OCIBind
-
OCIDefine
-
OCIEnv
支持的函数¶
SeaboxSQL兼容OCI接口支持以下Oracle OCI程序函数:
-
OCIEnvCreate
-
OCIHandleAlloc
-
OCIServerAttach
-
OCIAttrSet
-
OCISessionBegin
-
OCIStmtPrepare
-
OCIDefineByPos
-
OCIStmtExecute
-
OCIBindByName
-
OCIBindByPos
-
OCIHandleFree
-
OCISessionEnd
-
OCITerminate
支持OCI的Bind语句执行¶
SeaboxSQL兼容OCI接口支持以下Oracle OCI程序bind语句执行:
-
涉及结构体
-
OCIBind
-
涉及函数
-
OCIBindByPos
-
OCIBindByName
支持OCI的Define输出结果¶
SeaboxSQL兼容OCI接口支持以下Oracle OCI程序Define输出结果:
-
涉及结构体
-
OCIDefine
-
涉及函数
-
OCIDefineByPos
使用方法¶
以cdemo.c为例
-
环境说明
-
已有名为seabox的数据库用户,密码为123456,设置端口号为15432,数据库名为test,工作目录为
$SDHOME/sd_oci
-
连接数据库
ssql -d test -p 15432
-
执行以下语句
- 编译说明\i demo/oci_demo.sql
gcc demo/cdemo.c -I include -L lib -l pq -l oci -o build/oci_demo
g++ demo/occidml.cpp -I include -L lib -l pq -l occi -o build/occi_demo
- 动态库环境变量设置
export LD_LIBRARY_PATH=$SDHOME/sd_oci/lib:$LD_LIBRARY_PATH
- 用管道处理输入输出并执行
build/oci_demo 15432 < demo/input/ocidemo.input > oci.out
[seabox@test-4 sd_oci]$ cat oci.out
Enter employee name (or CR to EXIT):
Enter employee job:
Enter employee salary:
Enter employee dept:
name1 added to the dep1 department as employee number 13
Enter employee name (or CR to EXIT):
Enter employee job:
Enter employee salary:
Enter employee dept:
name2 added to the dep2 department as employee number 23
Enter employee name (or CR to EXIT):
Enter employee job:
Enter employee salary:
Enter employee dept:
name3 added to the dep3 department as employee number 33
Enter employee name (or CR to EXIT):
Enter employee job:
Enter employee salary:
Enter employee dept:
name4 added to the dep4 department as employee number 43
Enter employee name (or CR to EXIT):
Enter employee job:
Enter employee salary:
Enter employee dept:
name5 added to the dep5 department as employee number 53
Enter employee name (or CR to EXIT):
Enter employee job:
Enter employee salary:
Enter employee dept:
name6 added to the dep6 department as employee number 63
Enter employee name (or CR to EXIT):
Enter employee job:
Enter employee salary:
Enter employee dept:
The dept you entered doesn't exist.
Enter employee dept:
The dept you entered doesn't exist.
Enter employee dept:
The dept you entered doesn't exist.
Enter employee dept:
The dept you entered doesn't exist.
Enter employee dept:
The dept you entered doesn't exist.
Enter employee dept:
name7 added to the dep7 department as employee number 73
Enter employee name (or CR to EXIT):
Exiting...
- 用ssql连接数据库test,执行以下语句查看OCI执行结果
sql
test=# SELECT * FROM emp ORDER BY empno;
empno | ename | job | sal | deptno
-------+-------+------+-----+--------
3 | name0 | job0 | 0 | 0
13 | name1 | job1 | 1 | 1
23 | name2 | job2 | 2 | 2
33 | name3 | job3 | 3 | 3
43 | name4 | job4 | 4 | 4
53 | name5 | job5 | 5 | 5
63 | name6 | job6 | 6 | 6
73 | name7 | job7 | 7 | 7
(8 rows)
兼容接口注意事项¶
- 不使用默认端口号和本机地址时需要手动指定,方法是在需要链接的数据库名称后加" host=IP地址 port=端口号",必须有空格
例子:
dbname="test"
dbname="test host=192.168.1.2 port=1234"
-
不支持OCI的异常处理和查询状态
-
不支持自定义数据类型
-
如果需要支持事务,需要分多次调用执行函数分别执行
BEGIN;
需要执行的SQL语句;
COMMIT;
即需要调用三次执行函数,回滚同理
兼容OCCI接口¶
SeaboxSQL数据库提供兼容OCCI语法的API,在几乎不用改动原有Oracle OCCI程序的基础上,通过提供的头文件和动态库,实现对SeaboxSQL数据库的增删查改功能。
支持的类¶
SeaboxSQL兼容OCI接口支持以下Oracle OCCI程序类:
-
Environment
-
Connection
-
Statement
-
ResultSet
支持的成员函数¶
SeaboxSQL兼容OCI接口支持以下Oracle OCCI程序成员函数:
-
Environment
-
createEnvironment
-
createConnection
-
terminateConnection
-
terminateEnvironment
-
Connection
-
Connection构造函数
-
createStatement
-
terminateStatement
-
Statement
-
Statement构造函数
-
executeUpdate
-
setInt
-
setString
-
setBFloat
-
setBDouble
-
closeResultSet
-
executeQuery
-
getResultSet
-
ResultSet
-
next
-
getInt
-
getString
-
getBFloat
支持的数据类型¶
SeaboxSQL兼容OCCI接口支持以下数据类型:
-
int
-
string
-
BFloat
-
BDounble
使用方法¶
以occidml.cpp为例
-
环境说明
-
已有名为seabox的数据库用户,密码为123456,设置端口号为15432,数据库名为test,工作目录为
$SDHOME/sd_oci
-
连接数据库
ssql -d test -p 15432
- 执行以下语句
\i demo/oci_demo.sql
- 编译说明
g++ demo/occidml.cpp -I include -L lib -l pq -l occi -o build/occi_demo
- 动态库环境变量设置
export LD_LIBRARY_PATH=$SDHOME/sd_oci/lib:$LD_LIBRARY_PATH
- 用管道处理输入输出并执行
build/occi_demo 15432 > occi.out
- 查看执行结果
[seabox@test-4 sd_oci]$ cat occi.out
occidml - Exhibiting simple insert, delete & update operations
Displaying all records before any operation
author_id: 333 author_name: JOE
author_id: 444 author_name: SMITH
Inserting a record into the table author_tab
insert - Success
Displaying the records after insert
author_id: 111 author_name: ASHOK
author_id: 333 author_name: JOE
author_id: 444 author_name: SMITH
Inserting a records into the table author_tab using dynamic bind
insert - Success
Displaying the records after insert using dynamic bind
author_id: 111 author_name: ASHOK
author_id: 222 author_name: ANAND
author_id: 333 author_name: JOE
author_id: 444 author_name: SMITH
deleting a row with author_id as 222 from author_tab table
delete - Success
updating a row with author_id as 444 from author_tab table
update - Success
displaying all rows after all the operations
author_id: 111 author_name: ASHOK
author_id: 333 author_name: JOE
author_id: 444 author_name: ADAM
inserting radio active element properties
insertElement - Success
insertElement - Success
insertElement - Success
insertElement - Success
insertElement - Success
displaying all radio active element properties
Element Name: Curium
Molar Volume: 18.17 cm3 mol-1
Atomic Weight: 247.0703 g/mole
Element Name: Plutonium
Molar Volume: 12.12 cm3 mol-1
Atomic Weight: 244.0642 g/mole
Element Name: Radium
Molar Volume: 41.337 cm3 mol-1
Atomic Weight: 226.0254 g/mole
Element Name: Thorium
Molar Volume is NULL
Atomic Weight is NULL
Element Name: Uranium
Molar Volume: 12.572 cm3 mol-1
Atomic Weight: 238.0289 g/mole
occidml - done
- 用ssql连接数据库test,执行以下语句查看OCCI执行结果
```sql test=# SELECT * FROM author_tab ORDER BY author_id; author_id | author_name -----------+------------- 111 | ASHOK 333 | JOE 444 | ADAM (3 rows)
test=# SELECT * FROM elements ORDER BY element_name;
element_name | molar_volume | atomic_weight
--------------+--------------+---------------
Curium | 18.17 | 247.0703
Plutonium | 12.12 | 244.0642
Radium | 41.337 | 226.0254
Thorium | |
Uranium | 12.572 | 238.0289
(5 rows)
```
兼容接口注意事项¶
- 不使用默认端口号和本机地址时需要手动指定,方法是在需要链接的数据库名称后加" host=IP地址 port=端口号",必须有空格
例子:
dbname="test"
dbname="test host=192.168.1.2 port=1234"
-
不支持OCI的异常处理和查询状态
-
不支持自定义数据类型
-
如果需要支持事务,需要分多次调用执行函数分别执行
BEGIN;
需要执行的SQL语句;
COMMIT;
即需要调用三次执行函数,回滚同理