def all(self): posts = dict() result = super(Post, self).all('posts') while True: post = result.fetch_row(1,1) if not post: break post_id = post[0]['post_id'] posts[post_id] = { 'post_id' : str(post[0]['post_id']), 'user_id' : str(post[0]['user_id']), 'lat' : str(post[0]['lat']), 'lng' : str(post[0]['lng']), 'post' : str(post[0]['post']), 'comments' : dict(), 'created_at' : post[0]['created_at'].strftime('%m/%d/%Y') } #get the comments select = SelectBuilder() select.setStatement('select *') select.setTables('from comments') select.setWhere('where post_id = ' + str(post[0]['post_id'])) comments = self._db.execute(select) while True: comment = comments.fetch_row(1,1) if not comment: break comment_id = comment[0]['comment_id'] posts[post_id]['comments'][comment_id] = { 'comment_id' : str(comment[0]['comment_id']), 'user_id' : str(comment[0]['user_id']), 'comment' : str(comment[0]['comment']), 'created_at' : comment[0]['created_at'].strftime('%m/%d/%Y') } return posts
def return_pw(self, user_name = None): password = '' if user_name: select = SelectBuilder() select.setStatement('select password') select.setTables('from users') select.setWhere('where user_name = "' + user_name + '"') result = self._db.execute(select) row = result.fetch_row(1,1) password = row[0] return password
def load(self,user_name = None): self._user_name = user_name if self._user_name: select = SelectBuilder() select.setStatement('select *') select.setTables('from users') select.setWhere('where user_name = "' + self._user_name +'"') result = self._db.execute(select) row = result.fetch_row(1,1) self._user_id = row[0]['user_id'] self._user_name = row[0]['user_name'] self._role = row[0]['role']
def all(self, tableName): select = SelectBuilder() select.setStatement('select *') select.setTables('from ' + tableName) results = self._db.execute(select) return results
#!/usr/bin/env python from database import Database from selectbuilder import SelectBuilder from insertbuilder import InsertBuilder d = Database('pannell', 'pannell', 'B00609201', 'db.cs.dal.ca') d.connect() print d.database_handle select = SelectBuilder() select.setStatement('select *') print select.getStatement() select.setTables('from users') print select.getTables() users = d.execute(select) while True: record = users.fetch_row() if not record: break print record insert = InsertBuilder()