def GetDiamondsByColor(self,request,context): logging.info("SERVER:: GetDiamondsByColor Requested") connection = self.ConnectToDataBase() cursor = connection.cursor() Query = "SELECT * from diamonds where color='" + request.type + "'" print Query cursor.execute(Query) logging.info("Query %s executed" % Query) for item in cursor.fetchall(): output = "{Carat: %f, Cut: %s, Color: %s, Clarity: %s,Depth: %f,Table: %d,Price: %d}" % (item[0],item[1],item[2],item[3],item[4],item[5],item[6]) yield diamonds_pb2.TypeResponse(type=output)
def GetDiamondsByPriceRange(self,request,context): logging.info("SERVER:: GetDiamondsByPriceRange Requested") connection = self.ConnectToDataBase() cursor = connection.cursor() Query = "SELECT * from diamonds where price between " + request.fromRange + " and " + request.toRange print Query try: cursor.execute(Query) logging.info("Query %s executed" % Query) for item in cursor.fetchall(): output = "{Carat: %f, Cut: %s, Color: %s, Clarity: %s,Depth: %f,Table: %d,Price: %d}" % (item[0],item[1],item[2],item[3],item[4],item[5],item[6]) yield diamonds_pb2.TypeResponse(type=output) except Exception: logging.error("ServerError:: Unable to RUN query %s\nInvalid Parameters" % Query)