def get_appsys_by_no(self, no): o_type = self.order_type(no) table_name = "t_order_" + o_type.lower() #: result = db.session.execute("SELECT * FROM %s where no = '%s'" %(table_name, no)) result = db.session.execute("SELECT * FROM %s where no = :no" % table_name, {'no': no}) Record = namedtuple('Record', result.keys()) records = [Record(*r) for r in result.fetchall()] return records[0] if records else None