Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User
- {
- public:
- User (string username, string password)
- {
- self.username = username;
- self.password = password;
- };
- virtual ~User ();
- static User find(int id)
- {
- vector<User> res = find_where("SELECT * FROM" + tableName + "WHERE id="+ string(id));
- // Should be only one result, so return the first in the list (error checking would need to go here)
- return res[0];
- }
- static vector<User> find_where(string query)
- {
- vector<User> res;
- DatabaseResults dr;
- // We'll implement the Database as a Singleton class, so we'll need to
- // use getInstance()
- dr = Database.getInstance().executeQuery(query);
- for (int i = 0; i < dr.size; i++) {
- res.add(User.new(dr[i].column("name"), dr[i].column("password")));
- }
- return res;
- }
- public string getName()
- {
- return name;
- }
- public string getPassword()
- {
- return password
- }
- private:
- // This is a virtual class variable overwritten from the superclass 'Model'
- static const tableName = "users";
- };
Add Comment
Please, Sign In to add comment