List:MySQL++« Previous MessageNext Message »
From:Dan Cook (dancook) Date:June 20 2009 9:50pm
Subject:ssqls internals question....
View as plain text  
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);
    vector<T> res;
    return res;
For a given SSQLS Definition say:
    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.

ssqls internals question....dancook)20 Jun
  • Re: ssqls internals question....Warren Young30 Jun