I am trying to put together a general purpose query template function using equal_list. I
want to query using different fields in the object. For example "select * from test where
fkey=1". This contrived query selects everything matching the foreign key "fkey".
The guts of the template function is:
template<class T>
vector<T> getRows(const T& object, connection)
{
Query q = conn->query();
q << "select * from object.table() <<
" where " << object.equal_list(" and ", sql_use_compare);
cerr<<query<<endl;
vector<T> res;
query.storein(res);
return res;
}
For a given SSQLS Definition say:
sql_create_4(test,1,4,
sql_int_unsigned, "id",
sql_int_unsigned, "fkey",
sql_varchar, "name",
sql_varchar, "desc")
If I want all the objects with fkey = 1 I thought I could do this:
...
test t;
t.fkey = 1;
vector vec = getRows(test, conn);
...
When I do this I see the output from the query:
select * from test where id=65434534;
(Since id is not initialized, I assume it is a garbage value).
I was expecting to see something like:
select * from test where fkey=1;
What am I doing wrong here? Any help would greatly be appreciated.
Regards,
Dan