Browse code

Add db_oracle module and toolses for it

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3997 689a6050-402a-0410-94f2-e92a70836424

Iouri Kharon authored on 09/04/2008 15:46:09
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,66 @@
1
+#include "orasel.h"
2
+
3
+//-----------------------------------------------------------------------------
4
+void open_sess(con_t* con)
5
+{
6
+	sword status;
7
+
8
+	if (   OCIEnvCreate(&con->envhp, OCI_DEFAULT | OCI_NEW_LENGTH_SEMANTICS,
9
+			    NULL, NULL, NULL, NULL, 0, NULL) != OCI_SUCCESS
10
+	    || OCIHandleAlloc(con->envhp, (dvoid**)(dvoid*)&con->errhp,
11
+				OCI_HTYPE_ERROR, 0, NULL) != OCI_SUCCESS
12
+	    || OCIHandleAlloc(con->envhp, (dvoid**)(dvoid*)&con->srvhp,
13
+				OCI_HTYPE_SERVER, 0, NULL) != OCI_SUCCESS
14
+	    || OCIHandleAlloc(con->envhp, (dvoid**)(dvoid*)&con->svchp,
15
+				OCI_HTYPE_SVCCTX, 0, NULL) != OCI_SUCCESS
16
+	    || OCIHandleAlloc(con->envhp, (dvoid**)(dvoid*)&con->authp,
17
+				OCI_HTYPE_SESSION, 0, NULL) != OCI_SUCCESS
18
+	    || OCIHandleAlloc(con->envhp, (dvoid**)(dvoid*)&con->stmthp,
19
+				OCI_HTYPE_STMT, 0, NULL) != OCI_SUCCESS)
20
+	{
21
+		errxit("no oracle memory left");
22
+	}
23
+
24
+	status = OCIAttrSet(con->svchp, OCI_HTYPE_SVCCTX, con->srvhp, 0,
25
+			OCI_ATTR_SERVER, con->errhp);
26
+	if (status != OCI_SUCCESS) goto connect_err;
27
+	status = OCIAttrSet(con->authp, OCI_HTYPE_SESSION,
28
+			(text*)con->username->s, con->username->len,
29
+			OCI_ATTR_USERNAME, con->errhp);
30
+	if (status != OCI_SUCCESS) goto connect_err;
31
+	status = OCIAttrSet(con->authp, OCI_HTYPE_SESSION,
32
+			(text*)con->password->s, con->password->len,
33
+			OCI_ATTR_PASSWORD, con->errhp);
34
+	if (status != OCI_SUCCESS) goto connect_err;
35
+	status = OCIAttrSet(con->svchp, OCI_HTYPE_SVCCTX, con->authp, 0,
36
+			OCI_ATTR_SESSION, con->errhp);
37
+	if (status != OCI_SUCCESS) goto connect_err;
38
+	status = OCIServerAttach(con->srvhp, con->errhp, (OraText*)con->uri->s,
39
+			con->uri->len, 0);
40
+	if (status != OCI_SUCCESS) goto connect_err;
41
+	status = OCISessionBegin(con->svchp, con->errhp, con->authp,
42
+			OCI_CRED_RDBMS, OCI_DEFAULT);
43
+	if (status != OCI_SUCCESS) {
44
+connect_err:
45
+		oraxit(status, con);
46
+	}
47
+}
48
+
49
+//-----------------------------------------------------------------------------
50
+void send_req(con_t* con, const Str* req)
51
+{
52
+	sword status;
53
+
54
+	status = OCIStmtPrepare(con->stmthp, con->errhp, (text*)req->s, req->len,
55
+			OCI_NTV_SYNTAX, OCI_DEFAULT);
56
+	if (status != OCI_SUCCESS) goto request_err;
57
+	status = OCIStmtExecute(con->svchp, con->stmthp, con->errhp, 0, 0, NULL,
58
+			NULL, OCI_STMT_SCROLLABLE_READONLY);
59
+	if (status != OCI_SUCCESS) {
60
+request_err:
61
+		fprintf(stderr, "%.*s\n", req->len, req->s);
62
+		oraxit(status, con);
63
+	}
64
+}
65
+
66
+//-----------------------------------------------------------------------------