示例#1
0
def _make_select(objtype, pattern, database_pattern, check_body, use_regexp):
    """Generate a SELECT statement for finding an object.
    """
    options = {
        'pattern': obj2sql(pattern),
        'regex': 'REGEXP' if use_regexp else 'LIKE',
        'select_option': '',
        'field_type': "'" + objtype.upper() + "'",
    }
    try:
        options.update(_OBJMAP[objtype])
    except KeyError:
        raise UtilError("Invalid object type '{0}'. Use --help to see allowed "
                        "values.".format(objtype))

    # Build a condition for inclusion in the select
    condition = "{field_name} {regex} {pattern}".format(**options)
    if check_body and "body_field" in options:
        condition += " OR {body_field} {regex} {pattern}".format(**options)
    if database_pattern:
        options['database_pattern'] = obj2sql(database_pattern)
        condition = ("({0}) AND {schema_field} {regex} {database_pattern}"
                     "".format(condition, **options))
    options['condition'] = condition

    return _SELECT_TYPE_FRM.format(**options)
示例#2
0
def _make_select(objtype, pattern, database_pattern, check_body, use_regexp):
    """Generate a SELECT statement for finding an object.
    """
    options = {
        'pattern': obj2sql(pattern),
        'regex': 'REGEXP' if use_regexp else 'LIKE',
        'select_option': '',
        'field_type': "'" + objtype.upper() + "'",
    }
    try:
        options.update(_OBJMAP[objtype])
    except KeyError:
        raise UtilError("Invalid object type '{0}'. Use --help to see allowed "
                        "values.".format(objtype))

    # Build a condition for inclusion in the select
    condition = "{field_name} {regex} {pattern}".format(**options)
    if check_body and "body_field" in options:
        condition += " OR {body_field} {regex} {pattern}".format(**options)
    if database_pattern:
        options['database_pattern'] = obj2sql(database_pattern)
        condition = ("({0}) AND {schema_field} {regex} {database_pattern}"
                     "".format(condition, **options))
    options['condition'] = condition

    return _SELECT_TYPE_FRM.format(**options)
示例#3
0
    def __build_exclude_patterns(self, exclude_param):
        """Return a string to add to where clause to exclude objects.

        This method will add the conditions to exclude objects based on
        name if there is a dot notation or by a search pattern as specified
        by the options.

        exclude_param[in]  Name of column to check.

        Returns (string) String to add to where clause or ""
        """
        from mysql.utilities.common.options import obj2sql

        oper = "NOT REGEXP" if self.use_regexp else "NOT LIKE"
        str = ""
        for pattern in self.exclude_patterns:
            value = None
            if pattern.find(".") > 0:
                db, name = pattern.split(".")
                if db == self.db_name:
                    value = name
            else:
                value = pattern
            if value is not None:
                str += " AND {0} {1} {2}".format(exclude_param, oper, obj2sql(value))

        return str
示例#4
0
    def __build_exclude_patterns(self, exclude_param):
        """Return a string to add to where clause to exclude objects.

        This method will add the conditions to exclude objects based on
        name if there is a dot notation or by a search pattern as specified
        by the options.

        exclude_param[in]  Name of column to check.

        Returns (string) String to add to where clause or ""
        """
        from mysql.utilities.common.options import obj2sql
        
        oper = 'NOT REGEXP' if self.use_regexp else 'NOT LIKE'
        str = ""
        for pattern in self.exclude_patterns:
            value = None
            if pattern.find(".") > 0:
                db, name = pattern.split(".")
                if db == self.db_name:
                    value = name
            else:
                value = pattern
            if value is not None:
                str += " AND {0} {1} {2}".format(exclude_param, oper,
                                                 obj2sql(value))

        return str
示例#5
0
def _make_select(matches, use_regexp, conditions):
    """Generate a SELECT statement for matching the processes.
    """
    oper = 'REGEXP' if use_regexp else 'LIKE'
    for field, pattern in matches:
        conditions.append("    {0} {1} {2}"
                          "".format(field, oper, obj2sql(pattern)))
    if len(conditions) > 0:
        condition = "\nWHERE\n" + "\n  AND\n".join(conditions)
    else:
        condition = ""
    return _SELECT_PROC_FRM.format(condition=condition)
示例#6
0
def _make_select(matches, use_regexp, conditions):
    """Generate a SELECT statement for matching the processes.
    """
    oper = 'REGEXP' if use_regexp else 'LIKE'
    for field, pattern in matches:
        conditions.append("    {0} {1} {2}"
                          "".format(field, oper, obj2sql(pattern)))
    if len(conditions) > 0:
        condition = "\nWHERE\n" + "\n  AND\n".join(conditions)
    else:
        condition = ""
    return _SELECT_PROC_FRM.format(condition=condition)
示例#7
0
def _make_select(objtype, pattern, database_pattern, check_body, use_regexp):
    """Generate a SELECT statement for finding an object.
    """
    from mysql.utilities.common.options import obj2sql

    options = {
        'pattern': obj2sql(pattern),
        'regex': 'REGEXP' if use_regexp else 'LIKE',
        'select_option': '',
        'field_type': "'" + objtype.upper() + "'",
        }
    options.update(_OBJMAP[objtype])

    # Build a condition for inclusion in the select
    condition = "{field_name} {regex} {pattern}".format(**options)
    if check_body and "body_field" in options:
        condition += " OR {body_field} {regex} {pattern}".format(**options)
    if database_pattern:
        options['database_pattern'] = obj2sql(database_pattern)
        condition = "({0}) AND {schema_field} {regex} {database_pattern}".format(condition, **options)
    options['condition'] = condition

    return _SELECT_TYPE_FRM.format(**options)
示例#8
0
def _make_select(objtype, pattern, database_pattern, check_body, use_regexp):
    """Generate a SELECT statement for finding an object.
    """
    from mysql.utilities.common.options import obj2sql

    options = {
        'pattern': obj2sql(pattern),
        'regex': 'REGEXP' if use_regexp else 'LIKE',
        'select_option': '',
        'field_type': "'" + objtype.upper() + "'",
    }
    options.update(_OBJMAP[objtype])

    # Build a condition for inclusion in the select
    condition = "{field_name} {regex} {pattern}".format(**options)
    if check_body and "body_field" in options:
        condition += " OR {body_field} {regex} {pattern}".format(**options)
    if database_pattern:
        options['database_pattern'] = obj2sql(database_pattern)
        condition = "({0}) AND {schema_field} {regex} {database_pattern}".format(
            condition, **options)
    options['condition'] = condition

    return _SELECT_TYPE_FRM.format(**options)