-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathswoole_oracle.cc
152 lines (125 loc) Β· 6.01 KB
/
swoole_oracle.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
+----------------------------------------------------------------------+
| Swoole |
+----------------------------------------------------------------------+
| Copyright (c) 2012-2018 The Swoole Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.0 of the Apache license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.apache.org/licenses/LICENSE-2.0.html |
| If you did not receive a copy of the Apache2.0 license and are unable|
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: NathanFreeman <[email protected]> |
+----------------------------------------------------------------------+
*/
#include "php_swoole_private.h"
#include "php_swoole_cxx.h"
#include "swoole_coroutine.h"
#include "php_swoole_oracle.h"
#ifdef SW_USE_ORACLE
static SW_THREAD_LOCAL bool swoole_oracle_blocking = true;
void swoole_oracle_set_blocking(bool blocking) {
swoole_oracle_blocking = blocking;
}
sword swoole_oci_session_begin(OCISvcCtx *svchp, OCIError *errhp, OCISession *usrhp, ub4 credt, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_session_begin");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCISessionBegin(svchp, errhp, usrhp, credt, mode); });
return result;
}
sword swoole_oci_server_detach(OCIServer *srvhp, OCIError *errhp, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_server_detach");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIServerDetach(srvhp, errhp, mode); });
return result;
}
sword swoole_oci_stmt_prepare(
OCIStmt *stmtp, OCIError *errhp, const OraText *stmt, ub4 stmt_len, ub4 language, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_prepare");
sword result = 0;
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtPrepare(stmtp, errhp, stmt, stmt_len, language, mode); });
return result;
}
sword swoole_oci_stmt_execute(OCISvcCtx *svchp,
OCIStmt *stmtp,
OCIError *errhp,
ub4 iters,
ub4 rowoff,
const OCISnapshot *snap_in,
OCISnapshot *snap_out,
ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_execute");
sword result = 0;
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtExecute(svchp, stmtp, errhp, iters, rowoff, snap_in, snap_out, mode); });
return result;
}
sword swoole_oci_stmt_fetch(OCIStmt *stmtp, OCIError *errhp, ub4 nrows, ub2 orientation, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_fetch");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIStmtFetch(stmtp, errhp, nrows, orientation, mode); });
return result;
}
sword swoole_oci_stmt_fetch2(OCIStmt *stmtp, OCIError *errhp, ub4 nrows, ub2 orientation, sb4 scrollOffset, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_stmt_fetch2");
sword result = 0;
php_swoole_async(swoole_oracle_blocking,
[&]() { result = OCIStmtFetch2(stmtp, errhp, nrows, orientation, scrollOffset, mode); });
return result;
}
sword swoole_oci_trans_commit(OCISvcCtx *svchp, OCIError *errhp, ub4 flags) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_trans_commit");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCITransCommit(svchp, errhp, flags); });
return result;
}
sword swoole_oci_trans_rollback(OCISvcCtx *svchp, OCIError *errhp, ub4 flags) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_trans_rollback");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCITransRollback(svchp, errhp, flags); });
return result;
}
sword swoole_oci_ping(OCISvcCtx *svchp, OCIError *errhp, ub4 mode) {
swoole_trace_log(SW_TRACE_CO_ORACLE, "oci_ping");
sword result = 0;
php_swoole_async(swoole_oracle_blocking, [&]() { result = OCIPing(svchp, errhp, mode); });
return result;
}
const ub4 SWOOLE_PDO_OCI_INIT_MODE = OCI_DEFAULT | OCI_THREADED
#ifdef OCI_OBJECT
| OCI_OBJECT
#endif
;
OCIEnv *swoole_pdo_oci_Env = NULL;
void php_swoole_oracle_rinit() {
if (!swoole_pdo_oci_Env) {
#ifdef HAVE_OCIENVCREATE
OCIEnvCreate(&swoole_pdo_oci_Env, SWOOLE_PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL, 0, NULL);
#else
OCIInitialize(SWOOLE_PDO_OCI_INIT_MODE, NULL, NULL, NULL, NULL);
OCIEnvInit(&swoole_pdo_oci_Env, OCI_DEFAULT, 0, NULL);
#endif
}
}
void php_swoole_oracle_minit(int module_id) {
if (zend_hash_str_find(&php_pdo_get_dbh_ce()->constants_table, ZEND_STRL("OCI_ATTR_ACTION")) == nullptr) {
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_ACTION", (zend_long) PDO_OCI_ATTR_ACTION);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_INFO", (zend_long) PDO_OCI_ATTR_CLIENT_INFO);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CLIENT_IDENTIFIER", (zend_long) PDO_OCI_ATTR_CLIENT_IDENTIFIER);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_MODULE", (zend_long) PDO_OCI_ATTR_MODULE);
REGISTER_PDO_CLASS_CONST_LONG("OCI_ATTR_CALL_TIMEOUT", (zend_long) PDO_OCI_ATTR_CALL_TIMEOUT);
}
php_pdo_unregister_driver(&swoole_pdo_oci_driver);
php_pdo_register_driver(&swoole_pdo_oci_driver);
}
void php_swoole_oracle_mshutdown(void) {
php_pdo_unregister_driver(&swoole_pdo_oci_driver);
if (!swoole_pdo_oci_Env) {
OCIHandleFree((dvoid *) swoole_pdo_oci_Env, OCI_HTYPE_ENV);
}
}
#endif