Guest User

Untitled

a guest
Jul 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class User
  2. {
  3. public:
  4. User (string username, string password)
  5. {
  6. self.username = username;
  7. self.password = password;
  8. };
  9. virtual ~User ();
  10.  
  11. static User find(int id)
  12. {
  13. vector<User> res = find_where("SELECT * FROM" + tableName + "WHERE id="+ string(id));
  14. // Should be only one result, so return the first in the list (error checking would need to go here)
  15. return res[0];
  16. }
  17.  
  18. static vector<User> find_where(string query)
  19. {
  20. vector<User> res;
  21. DatabaseResults dr;
  22. // We'll implement the Database as a Singleton class, so we'll need to
  23. // use getInstance()
  24. dr = Database.getInstance().executeQuery(query);
  25. for (int i = 0; i < dr.size; i++) {
  26. res.add(User.new(dr[i].column("name"), dr[i].column("password")));
  27. }
  28.  
  29. return res;
  30. }
  31.  
  32. public string getName()
  33. {
  34. return name;
  35. }
  36.  
  37. public string getPassword()
  38. {
  39. return password
  40. }
  41. private:
  42. // This is a virtual class variable overwritten from the superclass 'Model'
  43. static const tableName = "users";
  44. };
Add Comment
Please, Sign In to add comment