]> granicus.if.org Git - pdns/commitdiff
skeleton of the generic Oracle Backend as sponsored by register.com (thanks)
authorBert Hubert <bert.hubert@netherlabs.nl>
Fri, 8 Apr 2005 14:42:13 +0000 (14:42 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Fri, 8 Apr 2005 14:42:13 +0000 (14:42 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@336 d19b8d6e-7fed-0310-83ef-9ca221ded41b

modules/goraclebackend/Makefile.am [new file with mode: 0644]
modules/goraclebackend/OBJECTFILES [new file with mode: 0644]
modules/goraclebackend/OBJECTLIBS [new file with mode: 0644]
modules/goraclebackend/goraclebackend.cc [new file with mode: 0644]
modules/goraclebackend/goraclebackend.hh [new file with mode: 0644]
modules/goraclebackend/soracle.cc [new file with mode: 0644]
modules/goraclebackend/soracle.hh [new file with mode: 0644]
modules/oraclebackend/oraclebackend.cc
modules/oraclebackend/oraclebackend.hh

diff --git a/modules/goraclebackend/Makefile.am b/modules/goraclebackend/Makefile.am
new file mode 100644 (file)
index 0000000..4aab9c1
--- /dev/null
@@ -0,0 +1,23 @@
+#lib_LTLIBRARIES = libgoraclebackend.la
+bin_PROGRAMS = soracle
+
+soracle_SOURCES=soracle.cc soracle.hh
+
+EXTRA_DIST=OBJECTFILES OBJECTLIBS
+
+ORACLE_HOME    ?= /opt/oracle
+
+INCLUDES= -I$(ORACLE_HOME)/rdbms/demo \
+                 -I$(ORACLE_HOME)/rdbms/public 
+
+#libgoraclebackend_la_SOURCES=goraclebackend.cc goraclebackend.hh \
+               soracle.hh soracle.cc
+
+
+#libgoraclebackend_la_LDFLAGS=-module  -L$(ORACLE_HOME)/lib -lclient9  -lclntst9
+soracle_LDFLAGS=-module  -L$(ORACLE_HOME)/lib -lclient9  -lclntst9 -ldl -pthread
+
+#      -Wl,-Bstatic -lpq++ -lpq -Wl,-Bdynamic -lssl -lcrypt -lcrypto
+
+
+       
diff --git a/modules/goraclebackend/OBJECTFILES b/modules/goraclebackend/OBJECTFILES
new file mode 100644 (file)
index 0000000..dd954ee
--- /dev/null
@@ -0,0 +1 @@
+goraclebackend.o soracle.o
\ No newline at end of file
diff --git a/modules/goraclebackend/OBJECTLIBS b/modules/goraclebackend/OBJECTLIBS
new file mode 100644 (file)
index 0000000..afc4f00
--- /dev/null
@@ -0,0 +1 @@
+-L$(ORACLE_HOME)/lib -lclient9  -lclntst9
\ No newline at end of file
diff --git a/modules/goraclebackend/goraclebackend.cc b/modules/goraclebackend/goraclebackend.cc
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/modules/goraclebackend/goraclebackend.hh b/modules/goraclebackend/goraclebackend.hh
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/modules/goraclebackend/soracle.cc b/modules/goraclebackend/soracle.cc
new file mode 100644 (file)
index 0000000..5349c99
--- /dev/null
@@ -0,0 +1,136 @@
+/* Copyright 2005 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE 
+   for more information. */
+
+#include "soracle.hh"
+#include <string>
+#include <iostream>
+#include "pdns/misc.hh"
+#include "pdns/logger.hh"
+#include "pdns/dns.hh"
+using namespace std;
+
+bool SOracle::s_dolog;
+
+SOracle::SOracle(const string &database, const string &host, u_int16_t port, 
+                const string &msocket, const string &user, 
+                const string &password)
+{
+   d_environmentHandle = NULL;
+   d_errorHandle = NULL;
+   d_serviceContextHandle = NULL;
+   
+   int err = OCIInitialize(OCI_THREADED, 0,  NULL, NULL, NULL);
+   if (err) {
+     throw sPerrorException("OCIInitialize");
+   }
+   
+   err = OCIEnvInit(&d_environmentHandle, OCI_DEFAULT, 0, 0);
+   if (err) {
+     throw sPerrorException("OCIEnvInit");
+   }
+  
+   // Allocate an error handle
+   
+   err = OCIHandleAlloc(d_environmentHandle, (dvoid**) &d_errorHandle, OCI_HTYPE_ERROR, 0, NULL);
+   if (err) {
+     throw sPerrorException("OCIHandleAlloc");
+   }
+  
+   // Logon to the database
+   
+   const char *username = user.c_str();
+
+
+
+   err = OCILogon(d_environmentHandle, d_errorHandle, &d_serviceContextHandle, (OraText*) username, strlen(username),
+                 (OraText*) password.c_str(),  strlen(password.c_str()), (OraText*) database.c_str(), strlen(database.c_str()));
+   
+   if (err) {
+     throw sPerrorException("oops"); // mErrorHandle);
+   }
+
+
+}
+
+void SOracle::setLog(bool state)
+{
+  s_dolog=state;
+}
+
+SOracle::~SOracle()
+{
+
+}
+
+SSqlException SOracle::sPerrorException(const string &reason)
+{
+  return SSqlException(reason);
+}
+
+int SOracle::doCommand(const string &query)
+{
+  return doQuery(query);
+}
+
+int SOracle::doQuery(const string &query)
+{
+
+  return 0;
+}
+
+int SOracle::doQuery(const string &query, result_t &result)
+{
+  result.clear();
+  doQuery(query);
+
+  row_t row;
+  while(getRow(row))
+    result.push_back(row);
+
+  return result.size();
+}
+
+bool SOracle::getRow(row_t &row)
+{
+  row.clear();
+
+  return false;
+}
+
+string SOracle::escape(const string &name)
+{
+  string a;
+
+  for(string::const_iterator i=name.begin();i!=name.end();++i) {
+    if(*i=='\'' || *i=='\\')
+      a+='\\';
+    a+=*i;
+  }
+  return a;
+}
+
+
+int main()
+{
+  try {
+    SOracle s("kkfnetmail","127.0.0.1");
+    SSql::result_t juh;
+    
+    int num=s.doQuery("select *, from mboxes", juh);
+    cout<<num<<" responses"<<endl;
+    
+    for(int i=0;i<num;i++) {
+      const SSql::row_t &row=juh[i];
+
+      for(SSql::row_t::const_iterator j=row.begin();j!=row.end();++j)
+       cout <<"'"<< *j<<"', ";
+      cout<<endl;
+    }
+  }
+  catch(SSqlException &e) {
+    cerr<<e.txtReason()<<endl;
+  }
+}
+
+
+
diff --git a/modules/goraclebackend/soracle.hh b/modules/goraclebackend/soracle.hh
new file mode 100644 (file)
index 0000000..886fc5a
--- /dev/null
@@ -0,0 +1,36 @@
+/* Copyright 2005 Netherlabs BV, bert.hubert@netherlabs.nl. See LICENSE 
+   for more information. */
+
+#ifndef SORACLE_HH
+#define SORACLE_HH
+
+#include "pdns/backends/gsql/ssql.hh"
+#include "pdns/utility.hh" 
+#include <oci.h>
+
+class SOracle : public SSql
+{
+public:
+  SOracle(const string &database, const string &host="", u_int16_t port=0,
+         const string &msocket="",const string &user="", 
+         const string &password="");
+  
+  ~SOracle();
+  
+  SSqlException sPerrorException(const string &reason);
+  int doQuery(const string &query, result_t &result);
+  int doQuery(const string &query);
+  int doCommand(const string &query);
+  bool getRow(row_t &row);
+  string escape(const string &str);    
+  void setLog(bool state);
+private:
+  OCIEnv    *d_environmentHandle;
+  OCIError  *d_errorHandle;
+  OCISvcCtx *d_serviceContextHandle;
+  OCIStmt   *d_statementHandles[10];
+  
+  static bool s_dolog;
+};
+      
+#endif /* SSORACLE_HH */
index 1234fbd81b42a7b64cd76f41acb438a1f0f871bd..ca54a56c017de2f9e2960ad9198f2cf99937927f 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: oraclebackend.cc,v 1.2 2003/08/22 13:33:31 ahu Exp $
+// $Id$
 
 #include <string>
 #include <map>
index ae382a342f9763af24b2f6aed36a2302de5d7362..94fbe496c90a74e9cebcc0a71f306db1ef33f633 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: oraclebackend.hh,v 1.2 2003/08/22 13:33:31 ahu Exp $
+// $Id$
 
 #include <string>
 #include <map>
@@ -74,6 +74,7 @@ class OracleBackend : public DNSBackend
       void lookup(const QType &, const string &qdomain, DNSPacket *p=0, int zoneId=-1);
       bool list(const string &target, int domain_id);
       bool get(DNSResourceRecord &r);
+
       
       
    private: