]> granicus.if.org Git - pdns/commitdiff
add oracle backend mode to zone2sql
authorKees Monshouwer <mind04@monshouwer.org>
Thu, 9 Jan 2014 13:30:49 +0000 (14:30 +0100)
committermind04 <mind04@monshouwer.org>
Thu, 9 Jan 2014 13:30:49 +0000 (14:30 +0100)
pdns/zone2sql.cc

index 1019fc0209fadfb7823c7b935cd758a4114ad314..3d554607123d43b4bad6ec2123e970d7b5155b4c 100644 (file)
@@ -47,7 +47,7 @@
 StatBag S;
 static bool g_doDNSSEC;
 
-enum dbmode_t {MYSQL, ORACLE, POSTGRES, SQLITE, MYDNS};
+enum dbmode_t {MYSQL, GORACLE, POSTGRES, SQLITE, MYDNS, ORACLE};
 static dbmode_t g_mode;
 static bool g_intransaction;
 static int g_numRecords;
@@ -68,7 +68,7 @@ static string stripDotContent(const string& content)
 
 static string sqlstr(const string &name)
 {
-  if(g_mode == SQLITE || g_mode==ORACLE)
+  if(g_mode == SQLITE || g_mode==GORACLE || g_mode==ORACLE)
     return "'"+boost::replace_all_copy(name, "'", "''")+"'";
   
   string a;
@@ -104,7 +104,7 @@ static void startNewTransaction()
   
   if(g_mode == MYSQL || g_mode == MYDNS)
     cout<<"BEGIN;"<<endl;
-  else if (g_mode!=ORACLE)
+  else if (g_mode!=GORACLE && g_mode!=ORACLE)
     cout<<"BEGIN TRANSACTION;"<<endl;
 }
 
@@ -113,9 +113,12 @@ static void emitDomain(const string& domain, const vector<string> *masters = 0)
     if(g_mode==POSTGRES || g_mode==MYSQL || g_mode==SQLITE) {
       cout<<"insert into domains (name,type) values ("<<toLower(sqlstr(stripDot(domain)))<<",'NATIVE');"<<endl;
     }
-    else if(g_mode==ORACLE) {
+    else if(g_mode==GORACLE) {
       cout<<"insert into domains (id,name,type) values (domains_id_sequence.nextval,"<<toLower(sqlstr(domain))<<",'NATIVE');"<<endl;
     }
+    else if(g_mode==ORACLE) {
+      cout<<"INSERT INTO Zones (id, name, type) VALUES (zones_id_seq.nextval, "<<sqlstr(toLower(domain))<<", 'NATIVE');"<<endl;
+    }
   }
   else 
   {
@@ -133,7 +136,7 @@ static void emitDomain(const string& domain, const vector<string> *masters = 0)
       else
         cout<<"insert into domains (name,type,master) values ("<<sqlstr(domain)<<",'SLAVE'"<<", '"<<mstrs<<"');"<<endl;
     }
-    else if (g_mode == ORACLE) {
+    else if (g_mode == GORACLE || g_mode==ORACLE) {
       cerr<<"Slave import mode not supported with oracle."<<endl;
     }
   }
@@ -147,7 +150,7 @@ static void emitRecord(const string& zoneName, const string &qname, const string
   if(qtype == "NSEC" || qtype == "NSEC3")
     return; // NSECs do not go in the database
 
-  if(qtype == "MX" || qtype == "SRV") { 
+  if((qtype == "MX" || qtype == "SRV") && g_mode!=ORACLE) {
     prio=atoi(content.c_str());
     
     string::size_type pos = content.find_first_not_of("0123456789");
@@ -195,13 +198,20 @@ static void emitRecord(const string& zoneName, const string &qname, const string
         " from domains where name="<<toLower(sqlstr(zoneName))<<";\n";
     }
   }
-  else if(g_mode==ORACLE) {
+  else if(g_mode==GORACLE) {
     cout<<"insert into Records (id, domain_id, name, type, content, ttl, prio) select RECORDS_ID_SEQUENCE.nextval,id ,"<<
       sqlstr(toLower(stripDot(qname)))<<", "<<
       sqlstr(qtype)<<", "<<
       sqlstr(stripDotContent(content))<<", "<<ttl<<", "<<prio<< 
       " from Domains where name="<<toLower(sqlstr(zoneName))<<";\n";
   }
+  else if(g_mode==ORACLE) {
+    cout<<"INSERT INTO Records (id, zone_id, fqdn, ttl, type, content) SELECT records_id_seq.nextval, id, "<<
+      sqlstr(toLower(stripDot(qname)))<<", "<<
+      ttl<<", "<<sqlstr(qtype)<<", "<<
+      sqlstr(stripDotContent(content))<<
+      " FROM Zones WHERE name="<<toLower(sqlstr(zoneName))<<";"<<endl;
+  }
   else if (g_mode == MYDNS) {
     string zoneNameDot = zoneName + ".";
     if (qtype == "A" || qtype == "AAAA" || qtype == "CNAME" || qtype == "HINFO" || qtype == "MX" || qtype == "NAPTR" || 
@@ -233,7 +243,7 @@ static void emitRecord(const string& zoneName, const string &qname, const string
 
 
 /* 2 modes of operation, either --named or --zone (the latter needs $ORIGIN) 
-   2 further modes: --mysql or --goracle 
+   2 further modes: --mysql, --goracle or --oracle
 */
 
 ArgvMap &arg()
@@ -256,6 +266,7 @@ try
     ::arg().setSwitch("gmysql","Output in format suitable for default gmysqlbackend")="no";
     ::arg().setSwitch("mydns","Output in format suitable for default mydnsbackend")="no";
     ::arg().setSwitch("goracle","Output in format suitable for the goraclebackend")="no";
+    ::arg().setSwitch("oracle","Output in format suitable for the oraclebackend")="no";
     ::arg().setSwitch("gsqlite","Output in format suitable for default gsqlitebackend")="no";
     ::arg().setSwitch("verbose","Verbose comments on operation")="no";
     ::arg().setSwitch("dnssec","Add DNSSEC related data")="no";
@@ -292,11 +303,10 @@ try
       g_mode=POSTGRES;
     else if(::arg().mustDo("gsqlite"))
       g_mode=SQLITE;
-    else if(::arg().mustDo("goracle")) {
+    else if(::arg().mustDo("goracle"))
+      g_mode=GORACLE;
+    else if(::arg().mustDo("oracle"))
       g_mode=ORACLE;
-      if(!::arg().mustDo("transactions"))
-        cout<<"set autocommit on;"<<endl;
-    }
     else if(::arg().mustDo("mydns"))
       g_mode=MYDNS;
     else {
@@ -306,6 +316,9 @@ try
       exit(1);
     }
 
+    if((g_mode==GORACLE || g_mode==ORACLE) && !::arg().mustDo("transactions"))
+      cout<<"set autocommit on;"<<endl;
+
     g_doDNSSEC=::arg().mustDo("dnssec");
       
     namedfile=::arg()["named-conf"];