Ejemplo n.º 1
0
def validatecolumnvaluepair(parsetree):
    metadata = Metadata(parsetree.database, parsetree.table)
    for pair in parsetree.columnvaluepair:
        column = pair.key
        if not metadata.hascolumn(column):
            raise Exception("Column '{}' does not exist in table '{}'".format(
                column, parsetree.table))
            logger.get_event_logger().warning(
                "Column '{}' does not exist in table '{}'".format(
                    column, parsetree.table))
Ejemplo n.º 2
0
def validatecolumns(parsetree):

    if len(parsetree.columns) == 1 and parsetree.columns[0] == "*":
        parsetree.columns = None
        return
    metadata = Metadata(parsetree.database, parsetree.table)

    for column in parsetree.columns:
        if not metadata.hascolumn(column):
            raise Exception("Column '{}' does not exist in table '{}'".format(
                column, parsetree.table))
            logger.get_event_logger().warning(
                "Column '{}' does not exist in table '{}'".format(
                    column, parsetree.table))
Ejemplo n.º 3
0
def describe(database, query):

    pt = desc.parse(query)
    pt.database = database
    common_methods.validatetable(pt)

    metadata = Metadata(database, pt.table)
    columns = ["Column", "Type", "Length", "PK", "FK"]

    ptable = PrettyTable(columns)

    for col in metadata.columns.keys():
        data = []
        data.append(col)
        data.append(metadata.columns[col][META.COLUMNS_TYPE])
        data.append(metadata.columns[col][META.COLUMNS_LENGTH])

        if col in metadata.primarykeys:
            data.append("YES")
        else:
            data.append("-")

        if col in metadata.foreignkeys.keys():
            fk = metadata.foreignkeys[col][META.KEYS_FOREIGN_REF_TABLE]
            fk += "(" + metadata.foreignkeys[col][
                META.KEYS_FOREIGN_REF_COLUMN] + ")"
            data.append(fk)
        else:
            data.append("-")

        ptable.add_row(data)

    print(ptable)
Ejemplo n.º 4
0
def validatedata(parsetree):
    metadata = Metadata(parsetree.database, parsetree.table)

    for column in parsetree.columnvaluepair.keys():
        if not metadata.hascolumn(column):
            raise Exception("Column '{}' does not exist in table '{}'".format(
                column, parsetree.table))
            logger.get_event_logger().warning(
                "Column '{}' does not exist in table '{}'".format(
                    column, parsetree.table))

        validator.checkdatatype(metadata, column,
                                parsetree.columnvaluepair[column])
        validator.transformvalue(metadata, parsetree.columnvaluepair, column)
        validator.validatelength(metadata, column,
                                 parsetree.columnvaluepair[column])
Ejemplo n.º 5
0
def validatedata(parsetree):
    metadata = Metadata(parsetree.database,parsetree.table)

    actualcolumns = metadata.columns.keys()
    providedcolumns = parsetree.columnvaluepair.keys()

    if len(actualcolumns)!= len(providedcolumns):
        raise Exception("Column count does not match with actual columns")
        logger.get_event_logger().warning("Column count does not match with actual columns")

    for column in parsetree.columnvaluepair.keys():
        if not metadata.hascolumn(column):
            raise Exception("Column '{}' does not exist in table '{}'".format(column,parsetree.table))
            logger.get_event_logger().warning("Column '{}' does not exist in table '{}'".format(column,parsetree.table))

        validator.checkdatatype(metadata,column,parsetree.columnvaluepair[column])
        validator.transformvalue(metadata,parsetree.columnvaluepair,column)
        validator.validatelength(metadata,column,parsetree.columnvaluepair[column])
Ejemplo n.º 6
0
def validatecondition(parsetree):
    if parsetree.condition is None:
        return

    metadata = Metadata(parsetree.database, parsetree.table)

    column = list(parsetree.condition.keys())[0]
    value = parsetree.condition[column]

    if not metadata.hascolumn(column):
        raise Exception("Column '{}' does not exist in table '{}'".format(
            column, parsetree.table))
        logger.get_event_logger().warning(
            "Column '{}' does not exist in table '{}'".format(
                column, parsetree.table))

    checkdatatype(metadata, column, value)

    transformvalue(metadata, parsetree.condition, column)
    transformcomparator(parsetree)
Ejemplo n.º 7
0
    def __init__(self, database=None, tablename=None, columns=None):
        self.root = None
        self.sort_col = None
        self.tablename = tablename
        self.database = database
        self.columns = columns

        if tablename is None:
            self.metadata = Metadata()
        else:
            self.load(database, tablename)
        pass
Ejemplo n.º 8
0
    def load(self, database, tablename):

        self.metadata = Metadata(database, tablename)

        directory = database
        ext = ".json"
        file = directory + "/" + tablename + ext

        with open(file) as f:
            tabledata = json.load(f)

            for data in tabledata:
                record = Record()
                record.data = data

                self.insert(record)