[svn] commit: r890 - in /branches/each-ds/src/lib/auth/cpp: TODO data_source_sqlite3.cc data_source_sqlite3.h

BIND 10 source code commits bind10-changes at lists.isc.org
Sat Feb 20 04:01:30 UTC 2010


Author: each
Date: Sat Feb 20 04:01:29 2010
New Revision: 890

Log:
- added ANY query support to SQL data source

Modified:
    branches/each-ds/src/lib/auth/cpp/TODO
    branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc
    branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h

Modified: branches/each-ds/src/lib/auth/cpp/TODO
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/TODO (original)
+++ branches/each-ds/src/lib/auth/cpp/TODO Sat Feb 20 04:01:29 2010
@@ -4,4 +4,3 @@
 SQL data source:
 - should implement findAddrs() and findReferral() directly instead of
   using the implementation in DataSrc.
-- need ANY queries

Modified: branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.cc Sat Feb 20 04:01:29 2010
@@ -76,6 +76,11 @@
     const char *c_name = s_name.c_str();
     const string s_rdtype = rdtype.toText();
     const char *c_rdtype = s_rdtype.c_str();
+    sqlite3_stmt *query = q_record;
+
+    if (rdtype == RRType::ANY()) {
+        query = q_any;
+    }
     
     flags = 0;
 
@@ -93,20 +98,23 @@
         return (0);
     }
     
-    sqlite3_reset(q_record);
-    sqlite3_clear_bindings(q_record);
-
-    rc = sqlite3_bind_int(q_record, 1, zone_id);
+    sqlite3_reset(query);
+    sqlite3_clear_bindings(query);
+
+    rc = sqlite3_bind_int(query, 1, zone_id);
     if (rc != SQLITE_OK) {
         throw("Could not bind 1 (record)");
     }
-    rc = sqlite3_bind_text(q_record, 2, c_name, -1, SQLITE_STATIC);
+    rc = sqlite3_bind_text(query, 2, c_name, -1, SQLITE_STATIC);
     if (rc != SQLITE_OK) {
         throw("Could not bind 2 (record)");
     }
-    rc = sqlite3_bind_text(q_record, 3, c_rdtype, -1, SQLITE_STATIC);
-    if (rc != SQLITE_OK) {
-        throw("Could not bind 3 (record)");
+
+    if (query == q_record) {
+        rc = sqlite3_bind_text(query, 3, c_rdtype, -1, SQLITE_STATIC);
+        if (rc != SQLITE_OK) {
+            throw("Could not bind 3 (record)");
+        }
     }
 
     // loop
@@ -115,73 +123,74 @@
     int rows = 0;
     RRsetPtr rrset;
 
-    rc = sqlite3_step(q_record);
+    rc = sqlite3_step(query);
     while (rc == SQLITE_ROW) {
-        const char *type = (const char *)sqlite3_column_text(q_record, 0);
-        int ttl = sqlite3_column_int(q_record, 1);
-        const char *sigtype = (const char *)sqlite3_column_text(q_record, 2);
-        const char *rdata = (const char *)sqlite3_column_text(q_record, 3);
+        const char *type = (const char *)sqlite3_column_text(query, 0);
+        int ttl = sqlite3_column_int(query, 1);
+        const char *sigtype = (const char *)sqlite3_column_text(query, 2);
+        const char *rdata = (const char *)sqlite3_column_text(query, 3);
 
         // looking for something else but found NS; we need to inform
         // the caller that this is a referral, but we do not return the
         // NS RRset to the caller.
-        if (strcmp(c_rdtype, "NS") != 0 &&
-            (strcmp(type, "NS") == 0 ||
-             (sigtype != NULL && strcmp(sigtype, "NS") == 0))) {
+        if ((rdtype != RRType::NS() && rdtype != RRType::ANY()) &&
+            ((strcmp(type, "NS") == 0 ||
+             (sigtype != NULL && strcmp(sigtype, "NS") == 0)))) {
             flags |= REFERRAL;
-            rc = sqlite3_step(q_record);
+            rc = sqlite3_step(query);
             continue;
         }
 
         rows++;
 
-        // found a CNAME when looking for something else (other than NSEC)
+        // found a CNAME when looking for something else (other than NSEC
+        // or ANY)
         if (strcmp(type, "CNAME") == 0 && strcmp(c_rdtype, "CNAME") != 0 &&
-            strcmp(c_rdtype, "NSEC") != 0) {
+            (rdtype != RRType::NSEC() && rdtype != RRType::ANY())) {
             flags |= CNAME_FOUND;
         }
 
-        // first time through the loop, initialize RRset
-        if (rows == 1) {
-            if (flags & CNAME_FOUND) {
-                rrset = RRsetPtr(new RRset(name, RRClass::IN(), RRType::CNAME(),
-                                           RRTTL(3600)));
-            } else {
-                rrset = RRsetPtr(new RRset(name, RRClass::IN(), rdtype,
-                                           RRTTL(3600)));
-            }
+        RRType rt(sigtype == NULL ? type : sigtype);
+        if (!target[rt]) {
+std::cerr << "looks like there was no rrset for " << rt << "\n";
+            rrset = RRsetPtr(new RRset(name, RRClass::IN(), rt, RRTTL(3600)));
+            target.addRRset(rrset);
         }
 
         if (sigtype == NULL && RRType(type) == rrset->getType()) {
             RdataPtr item = createRdata(RRType(type), RRClass("IN"), rdata);
             rrset->addRdata(item);
+std::cerr << "adding data\n";
 
             if (target_ttl == -1 || target_ttl > ttl) {
                 target_ttl = ttl;
             }
+            rrset->setTTL(RRTTL(target_ttl));
         } else if (sigtype != NULL && RRType(sigtype) == rrset->getType()) {
             RdataPtr rrsig = createRdata(RRType::RRSIG(), RRClass::IN(), rdata);
+std::cerr << "adding sig\n";
             if (rrset->getRRsig()) {
                 rrset->getRRsig()->addRdata(rrsig);
+std::cerr << "to existing rrsig\n";
             } else {
                 RRsetPtr sigs = RRsetPtr(new RRset(name, RRClass::IN(),
                                                    RRType::RRSIG(),
                                                    RRTTL(3600)));
                 sigs->addRdata(rrsig);
                 rrset->addRRsig(sigs);
+std::cerr << "to new rrsig\n";
             }
 
             if (sig_ttl == -1 || sig_ttl > ttl) {
                 sig_ttl = ttl;
             }
+            rrset->getRRsig()->setTTL(RRTTL(sig_ttl));
         }
         
-        rc = sqlite3_step(q_record);
+        rc = sqlite3_step(query);
     }
 
     if (rows > 0) {
-        rrset->setTTL(RRTTL(target_ttl));
-        target.addRRset(rrset);
         return (rows);
     }
 
@@ -277,6 +286,16 @@
         q_record = prepare(q_record_str);
     } catch (const char *e) {
         cout << e << endl << q_record_str << endl;
+        cout << sqlite3_errmsg(db) << endl;
+        throw(e);
+    }
+
+    const char *q_any_str = "SELECT rdtype, ttl, sigtype, rdata "
+                               "FROM records WHERE zone_id=?1 AND name=?2";
+    try {
+        q_any = prepare(q_any_str);
+    } catch (const char *e) {
+        cout << e << endl << q_any_str << endl;
         cout << sqlite3_errmsg(db) << endl;
         throw(e);
     }
@@ -352,6 +371,7 @@
     database_version = -1;
     q_zone = NULL;
     q_record = NULL;
+    q_any = NULL;
     q_count = NULL;
     q_previous = NULL;
 }
@@ -506,6 +526,11 @@
         q_record = NULL;
     }
 
+    if (q_any) {
+        release(q_any);
+        q_any = NULL;
+    }
+
     if (q_count) {
         release(q_count);
         q_count = NULL;

Modified: branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h
==============================================================================
--- branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h (original)
+++ branches/each-ds/src/lib/auth/cpp/data_source_sqlite3.h Sat Feb 20 04:01:29 2010
@@ -80,6 +80,7 @@
     //
     sqlite3_stmt *q_zone;
     sqlite3_stmt *q_record;
+    sqlite3_stmt *q_any;
     sqlite3_stmt *q_count;
     sqlite3_stmt *q_previous;
 };




More information about the bind10-changes mailing list