def get_tablaturecomments(self, tablature_id): """ Get comments to a tablature """ keys_on = "PRAGMA foreign_keys = ON" query = "SELECT * FROM comments WHERE tablature_id = ?" pvalue = (tablature_id,) if not self.contains_tablature(tablature_id): return None con = sqlite3.connect(self.database_name) with con: con.row_factory = sqlite3.Row cur = con.cursor() cur.execute(keys_on) cur.execute(query, pvalue) rows = cur.fetchall() if rows == []: return None comments = [] for row in rows: comments.append(CommentModel.create(row)) return comments
def get_comments_by_user(self, user_nickname): """ Returns comments. If comments doesn't exist return "None". """ keys_on = "PRAGMA foreign_keys = ON" query = "SELECT * FROM comments WHERE user_nickname = ?" pvalue = (user_nickname,) # connects (and creates if necessary) to the database. gets a connection object con = sqlite3.connect(self.database_name) with con: con.row_factory = sqlite3.Row cur = con.cursor() cur.execute(keys_on) # execute the statement cur.execute(query, pvalue) # just one result possible rows = cur.fetchall() comments = [] if rows is None: return None else: # print row.keys() for row in rows: comments.appdend(CommentModel.create(row)) return comments
def get_comment(self, comment_id): """ Returns the comment. If comment doesn't exist return "None". """ keys_on = "PRAGMA foreign_keys = ON" query = "SELECT * FROM comments WHERE comment_id = ?" pvalue = (comment_id,) # connects (and creates if necessary) to the database. gets a connection object con = sqlite3.connect(self.database_name) with con: con.row_factory = sqlite3.Row cur = con.cursor() cur.execute(keys_on) # execute the statement cur.execute(query, pvalue) # just one result possible row = cur.fetchone() if row is None: return None else: # print row.keys() return CommentModel.create(row)
def get_tablaturecomments(self, tablature_id): ''' Get comments to a tablature ''' keys_on = 'PRAGMA foreign_keys = ON' query = 'SELECT * FROM comments WHERE tablature_id = ?' pvalue = (tablature_id, ) if not self.contains_tablature(tablature_id): return None con = sqlite3.connect(self.database_name) with con: con.row_factory = sqlite3.Row cur = con.cursor() cur.execute(keys_on) cur.execute(query, pvalue) rows = cur.fetchall() if rows == []: return None comments = [] for row in rows: comments.append(CommentModel.create(row)) return comments
def get_comments_by_user(self, user_nickname): ''' Returns comments. If comments doesn't exist return "None". ''' keys_on = 'PRAGMA foreign_keys = ON' query = 'SELECT * FROM comments WHERE user_nickname = ?' pvalue = (user_nickname, ) #connects (and creates if necessary) to the database. gets a connection object con = sqlite3.connect(self.database_name) with con: con.row_factory = sqlite3.Row cur = con.cursor() cur.execute(keys_on) #execute the statement cur.execute(query, pvalue) #just one result possible rows = cur.fetchall() comments = [] if rows is None: return None else: #print row.keys() for row in rows: comments.appdend(CommentModel.create(row)) return comments
def get_comment(self, comment_id): ''' Returns the comment. If comment doesn't exist return "None". ''' keys_on = 'PRAGMA foreign_keys = ON' query = 'SELECT * FROM comments WHERE comment_id = ?' pvalue = (comment_id, ) #connects (and creates if necessary) to the database. gets a connection object con = sqlite3.connect(self.database_name) with con: con.row_factory = sqlite3.Row cur = con.cursor() cur.execute(keys_on) #execute the statement cur.execute(query, pvalue) #just one result possible row = cur.fetchone() if row is None: return None else: #print row.keys() return CommentModel.create(row)