Users Database::fillUser() { Users u; this->query.first(); this->record = this->query.record(); u.setId(this->query.value(this->record.indexOf("id"))); u.setName(this->query.value(this->record.indexOf("name"))); return u; }
Users Database::getUsers(QString name) { Users u; u.setId(-1); this->query.prepare("Select id, name FROM Users WHERE Users.name=? LIMIT 1;"); this->query.addBindValue(QVariant(name)); if(!this->query.exec()){ this->showError(this->query.lastError()); return u; } u = this->fillUser(); return u; }
Users Database::getUsers(unsigned int id) { Users u; u.setId(-1); this->query.prepare("Select * FROM Users WHERE Users.id=? LIMIT 1;"); this->query.addBindValue(QVariant(id)); if(!this->query.exec()){ this->showError(this->query.lastError()); return u; } u = this->fillUser(); return u; }
QList<Users> Database::getAllUsers() { QList<Users> users; this->query.prepare("Select * FROM Users ORDER BY Users.name;"); if(!this->query.exec()){ this->showError(this->query.lastError()); return users; } while(this->query.next()){ Users u; u.setId(this->query.value(0)); u.setName(this->query.value(1)); users.push_back(u); } return users; }