Skip to content

Commit

Permalink
fix date range query
Browse files Browse the repository at this point in the history
  • Loading branch information
knopkem committed Sep 27, 2020
1 parent 7ccff4c commit b55bcc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/dcmsqldb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ std::list< sQRes > DcmSQLiteDatabase::query(const std::list<DcmSmallDcmElm> & fi
std::vector < std::string > selectColumns;
std::vector < std::string > whereColumns;
std::vector < std::string > whereBindings;
std::vector <DcmTagKey> whereTag;
std::vector < std::string > whereBindingNames;


for(auto qElm: findRequestList) {
Expand All @@ -295,16 +295,20 @@ std::list< sQRes > DcmSQLiteDatabase::query(const std::list<DcmSmallDcmElm> & fi
replace(valueStr, std::string("*"), std::string("%"));
replace(valueStr, std::string("?"), std::string("_"));
whereBindings.push_back(valueStr);
whereBindingNames.push_back(std::string(":") + whereStr);
}
else if ( isDateOrTimeField(qElm.XTag()) && contains(valueStr, "-")) {
whereColumns.push_back(whereStr + std::string(" BETWEEN :" ) + whereStr);
whereBindings.push_back(firstp(valueStr) + " AND " + secondp(valueStr));
whereColumns.push_back(whereStr + std::string(" BETWEEN :" ) + whereStr + "1 AND :" + whereStr + "2");
whereBindings.push_back(firstp(valueStr));
whereBindings.push_back(secondp(valueStr));
whereBindingNames.push_back(std::string(":") + whereStr + "1");
whereBindingNames.push_back(std::string(":") + whereStr + "2");
}
else {
whereColumns.push_back(whereStr + std::string(" = :") + whereStr);
whereBindings.push_back(valueStr);
whereBindingNames.push_back(std::string(":") + whereStr);
}
whereTag.push_back(qElm.XTag());
}

selectColumns.push_back(getTagName( qElm.XTag() ));
Expand All @@ -320,16 +324,17 @@ std::list< sQRes > DcmSQLiteDatabase::query(const std::list<DcmSmallDcmElm> & fi
+ std::string(" WHERE ") + join(whereColumns, " AND ");

sqlite3pp::query query(*d->db, prepare.c_str());

// DCMNET_WARN(prepare);
for (int i = 0; i < whereBindings.size(); ++i) {
const std::string bindValue = whereBindings.at(i);
if (i == whereBindings.size() -1) {
query.bind(":referenceId", std::stoi(bindValue));
// DCMNET_WARN("ref : " + bindValue);
}
else {
const std::string bindName = ":" + getTagName(whereTag.at(i));
const std::string bindName = whereBindingNames.at(i);
query.bind(bindName.c_str(), bindValue, sqlite3pp::copy);
DCMNET_WARN(bindName + bindValue);
// DCMNET_WARN(bindName + " : " + bindValue);
}
}

Expand Down Expand Up @@ -414,7 +419,7 @@ std::string DcmSQLiteDatabase::secondp( const std::string& value ) const
DCMNET_WARN("no range sign found");
return value;
}
return value.substr(pos, value.length()-1);
return value.substr(pos + 1, value.length()-1);
}

//--------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/dcmsqlhdl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,11 @@ OFCondition DcmQueryRetrieveSQLiteDatabaseHandle::startFindRequest( const char *

d->determineLevelBoundaries(d->handle->rootLevel, qLevel, lLevel);

/*
if (d->testRequestList(d->handle->findRequestList, d->handle->queryLevel, qLevel, lLevel).bad()) {
DCMNET_ERROR("DB_startFindRequest () : STATUS_FIND_Failed_IdentifierDoesNotMatchSOPClass - Invalid RequestList");
}
*/

std::list<DcmSmallDcmElm> findRequestList = d->convertList(d->handle->findRequestList);

Expand Down

0 comments on commit b55bcc6

Please sign in to comment.