// extended version of User class
class UserExt{
public:
:_name(name)
,_address(address)
,_description(description) ... {
}
QString name
() const{ return _name;
} QString address
() const{ return _address;
} QString description
() const{ return _description;
} // .. other access methods
private:
...
};
// it is just a pseudocode but i think you get the idea
User myClass::GetUser(int userId)
{
q.prepare("SELECT u.name,u.address,st.description FROM User as u, user_status_tbl as st, othertable as ot, ... WHERE u.ID = :userId AND u.id=st.id AND ot.id=st.id, AND ...;");
q.bindValue(":id",userId);
if (q.next()) {
return UserExt(q.value("name").toString(), q.value("address").toString(), q.value("description").toString()...);
}
throw new NoSuchUserException; //.. or another way of reporting an error
}
// extended version of User class
class UserExt{
public:
UserExt(QString name, QString address, QString description...)
:_name(name)
,_address(address)
,_description(description) ... {
}
QString name() const{ return _name; }
QString address() const{ return _address; }
QString description() const{ return _description; }
// .. other access methods
private:
QString _name;
QString _address;
QString _description;
...
};
// it is just a pseudocode but i think you get the idea
User myClass::GetUser(int userId)
{
QSqlQuery q;
q.prepare("SELECT u.name,u.address,st.description FROM User as u, user_status_tbl as st, othertable as ot, ... WHERE u.ID = :userId AND u.id=st.id AND ot.id=st.id, AND ...;");
q.bindValue(":id",userId);
if (q.next()) {
return UserExt(q.value("name").toString(), q.value("address").toString(), q.value("description").toString()...);
}
throw new NoSuchUserException; //.. or another way of reporting an error
}
To copy to clipboard, switch view to plain text mode
Bookmarks