Project

General

Profile

Wt::Dbo binding question: how to add bindings to existing query

Added by John Davidson over 11 years ago

I need to perform this SQL statement:

SELECT * FROM table WHERE id IN (list)

The list can have any number of items, stored in a vector, and I have run into trouble figuring out how to do that in Wt. I imagine the statement would look like this:

SELECT t FROM table t WHERE id IN (?,? . . . .?)
.bind(v1)
.bind(v2)
...
.bind(vN)

Where I'm stuck is with needing to put a FOR loop in the middle of the session.query statement. I don't know how to add extra bindings once the initial session.query statement is closed off with a semi colon. What do I bind to? This is what I have:

typedef boost::tuple<Wt::Dbo::ptr<FileTableClass>,Wt::WString> FileData;
std::string sParams;
for(std::vector<int>::iterator i = viJobList.begin(); i != viJobList.end(); ++i) {
   sParams = sParams + ", ?";
}
sParams = sParams.substr(2,sParams.length() -2);
Wt::Dbo::Transaction transaction(*session);
FileData fileData = session->query<FileData>
   ("SELECT f, "
   "(SELECT j.path FROM jobs j WHERE j.id = f.job_id) "  
   "FROM files f")
   .where("f.job_id IN (" + sParams + ") AND f.location_id < 1 AND f.size < ?");
for(std::vector<int>::iterator i = viJobList.begin(); i != viJobList.end(); ++i) {
   session->query<FileData>.bind(*i);
}
session->query<FileData>.bind(iDiskSpace)
   .limit(1)
   .orderBy("f.size DESC");
transaction.commit();

But I can't add bindings to session->query in the loop, and nor can I add the orderBy and limit settings. How do I add them?

thanks in advance

John


Replies (1)

RE: Wt::Dbo binding question: how to add bindings to existing query - Added by Mark Petryk over 8 years ago

Does anyone have a reply to this? I have the same issue.

    (1-1/1)