diff --git a/src/lib/datasrc/sqlite3_accessor.cc b/src/lib/datasrc/sqlite3_accessor.cc index 24d7b3f72a..4c8f371b35 100644 --- a/src/lib/datasrc/sqlite3_accessor.cc +++ b/src/lib/datasrc/sqlite3_accessor.cc @@ -20,6 +20,8 @@ #include +#include + #include #include #include @@ -85,7 +87,7 @@ const char* const text_statements[NUM_STATEMENTS] = { "SELECT rdtype, ttl, sigtype, rdata FROM records " // ANY "WHERE zone_id=?1 AND name=?2", "SELECT rdtype, ttl, sigtype, rdata " // ANY_SUB - "FROM records WHERE zone_id=?1 AND name LIKE (\"%.\" || ?2)", + "FROM records WHERE zone_id=?1 AND rname LIKE ?2", "BEGIN", // BEGIN "COMMIT", // COMMIT "ROLLBACK", // ROLLBACK @@ -660,17 +662,27 @@ public: statement_(NULL), name_(name) { - // Choose the statement text depending on the query type - const char* statement(NULL); + // Choose the statement text depending on the query type, and + // prepare a statement to get data from it. switch (qtype) { case QT_ANY: - statement = text_statements[ANY]; + statement_ = prepare(accessor->dbparameters_->db_, + text_statements[ANY]); + bindZoneId(id); + bindName(name_); break; case QT_SUBDOMAINS: - statement = text_statements[ANY_SUB]; + statement_ = prepare(accessor->dbparameters_->db_, + text_statements[ANY_SUB]); + bindZoneId(id); + // Done once, this should not be very inefficient. + bindName(isc::dns::Name(name_).reverse().toText() + "%"); break; case QT_NSEC3: - statement = text_statements[NSEC3]; + statement_ = prepare(accessor->dbparameters_->db_, + text_statements[NSEC3]); + bindZoneId(id); + bindName(name_); break; default: // Can Not Happen - there isn't any other type of query @@ -680,11 +692,6 @@ public: "Invalid qtype passed - unreachable code branch " "reached"); } - - // We create the statement now and then just keep getting data from it - statement_ = prepare(accessor->dbparameters_->db_, statement); - bindZoneId(id); - bindName(name_); } bool getNext(std::string (&data)[COLUMN_COUNT]) {