#include <boost/format.hpp>
#include <boost/scoped_ptr.hpp>
+#define ASSERT_ROW_COLUMNS(query, row, num) { if (row.size() != num) { throw PDNSException(std::string(query) + " returned wrong number of columns, expected " #num ", got " + boost::lexical_cast<std::string>(row.size())); } }
+
GSQLBackend::GSQLBackend(const string &mode, const string &suffix)
{
setArgPrefix(mode+suffix);
}
if(!d_result.empty()) {
+ ASSERT_ROW_COLUMNS("master-zone-query", d_result[0], 1);
// we can have multiple masters separated by commas
vector<string> masters;
int numanswers=d_result.size();
if(!numanswers)
return false;
-
+
+ ASSERT_ROW_COLUMNS("info-zone-query", d_result[0], 7);
+
di.id=atol(d_result[0][0].c_str());
di.zone=d_result[0][1];
stringtok(di.masters, d_result[0][2], " ,\t");
int numanswers=d_result.size();
for(int n=0;n<numanswers;++n) { // id,name,master,last_check
DomainInfo sd;
+ ASSERT_ROW_COLUMNS("info-all-slaves-query", d_result[n], 4);
sd.id=atol(d_result[n][0].c_str());
sd.zone=d_result[n][1];
stringtok(sd.masters, d_result[n][2], ", \t");
vector<DomainInfo> allMasters;
int numanswers=d_result.size();
- for(int n=0;n<numanswers;++n) { // id,name,master,last_check
+ for(int n=0;n<numanswers;++n) { // id,name,master,last_check,notified_serial
DomainInfo sd;
+ ASSERT_ROW_COLUMNS("info-all-master-query", d_result[n], 5);
sd.id=atol(d_result[n][0].c_str());
sd.zone=d_result[n][1];
sd.last_check=atol(d_result[n][3].c_str());
execute();
while(d_afterOrderQuery_stmt->hasNextRow()) {
d_afterOrderQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("get-order-after-query", row, 1);
after=row[0];
}
d_afterOrderQuery_stmt->reset();
execute();
while(d_firstOrderQuery_stmt->hasNextRow()) {
d_firstOrderQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("get-order-first-query", row, 1);
after=row[0];
}
d_firstOrderQuery_stmt->reset();
execute();
while(d_beforeOrderQuery_stmt->hasNextRow()) {
d_beforeOrderQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("get-order-before-query", row, 2);
before=row[0];
unhashed=row[1];
}
execute();
while(d_lastOrderQuery_stmt->hasNextRow()) {
d_lastOrderQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("get-order-last-query", row, 2);
before=row[0];
unhashed=row[1];
}
content->clear();
while(d_getTSIGKeyQuery_stmt->hasNextRow()) {
d_getTSIGKeyQuery_stmt->nextRow(row);
- if(row.size() >= 2 && (algorithm->empty() || *algorithm==row[0])) {
+ ASSERT_ROW_COLUMNS("get-tsig-key-query", row, 2);
+ if(algorithm->empty() || *algorithm==row[0]) {
*algorithm = row[0];
*content = row[1];
}
while(d_getTSIGKeysQuery_stmt->hasNextRow()) {
d_getTSIGKeysQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("get-tsig-keys-query", row, 3);
struct TSIGKey key;
key.name = row[0];
key.algorithm = row[1];
KeyData kd;
while(d_ListDomainKeysQuery_stmt->hasNextRow()) {
d_ListDomainKeysQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("list-domain-keys-query", row, 4);
//~ for(const auto& val: row) {
//~ cerr<<"'"<<val<<"'"<<endl;
//~ }
while(d_GetAllDomainMetadataQuery_stmt->hasNextRow()) {
d_GetAllDomainMetadataQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("get-all-domain-metadata-query", row, 2);
+
if (!isDnssecDomainMetadata(row[0]))
meta[row[0]].push_back(row[1]);
}
while(d_GetDomainMetadataQuery_stmt->hasNextRow()) {
d_GetDomainMetadataQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("get-domain-metadata-query", row, 1);
meta.push_back(row[0]);
}
try {
if(qtype.getCode()!=QType::ANY) {
if(domain_id < 0) {
+ d_query_name = "basic-query";
d_query_stmt = d_NoIdQuery_stmt;
d_query_stmt->
bind("qtype", qtype.getName())->
bind("qname", qname);
} else {
+ d_query_name = "id-query";
d_query_stmt = d_IdQuery_stmt;
d_query_stmt->
bind("qtype", qtype.getName())->
} else {
// qtype==ANY
if(domain_id < 0) {
+ d_query_name = "any-query";
d_query_stmt = d_ANYNoIdQuery_stmt;
d_query_stmt->
bind("qname", qname);
} else {
+ d_query_name = "any-id-query";
d_query_stmt = d_ANYIdQuery_stmt;
d_query_stmt->
bind("qname", qname)->
DLOG(L<<"GSQLBackend constructing handle for list of domain id '"<<domain_id<<"'"<<endl);
try {
+ d_query_name = "list-query";
d_query_stmt = d_listQuery_stmt;
d_query_stmt->
bind("include_disabled", (int)include_disabled)->
string wildzone = "%." + stripDot(zone.toString()); // tolower()?
try {
+ d_query_name = "list-subzone-query";
d_query_stmt = d_listSubZoneQuery_stmt;
d_query_stmt->
bind("zone", zone)->
if(d_query_stmt->hasNextRow()) {
try {
d_query_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS(d_query_name, row, 8);
} catch (SSqlException &e) {
throw PDNSException("GSQLBackend get: "+e.txtReason());
}
catch (SSqlException &e) {
throw PDNSException("GSQLBackend unable to search for a domain: "+e.txtReason());
}
-
+ ASSERT_ROW_COLUMNS("supermaster-query", d_result[0], 1);
if(!d_result.empty()) {
*nameserver=i->content;
*account=d_result[0][0];
SSqlStatement::row_t row;
while (d_getAllDomainsQuery_stmt->hasNextRow()) {
d_getAllDomainsQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("get-all-domains-query", row, 8);
DomainInfo di;
di.id = atol(row[0].c_str());
di.zone = row[1];
}
if (!d_result.empty()) {
+ ASSERT_ROW_COLUMNS("zone-lastchange-query", d_result[0], 1);
serial = atol(d_result[0][0].c_str());
return true;
}
bool GSQLBackend::listComments(const uint32_t domain_id)
{
try {
+ d_query_name = "list-comments-query";
d_query_stmt = d_ListCommentsQuery_stmt;
d_query_stmt->
bind("domain_id", domain_id)->
try {
d_query_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS(d_query_name, row, 6);
} catch(SSqlException &e) {
throw PDNSException("GSQLBackend comment get: "+e.txtReason());
}
SSqlStatement::row_t row;
DNSResourceRecord r;
d_SearchRecordsQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("search-records-query", row, 8);
extractRecord(row, r);
result.push_back(r);
}
while(d_SearchCommentsQuery_stmt->hasNextRow()) {
SSqlStatement::row_t row;
d_SearchCommentsQuery_stmt->nextRow(row);
+ ASSERT_ROW_COLUMNS("search-comments-query", row, 6);
Comment comment;
extractComment(row, comment);
result.push_back(comment);