# Path: simplesqlite/_func.py
# def validate_table_name(name: str) -> None:
#     """
#     :param str name: Table name to validate.
#     :raises NameValidationError: |raises_validate_table_name|
#     """
# 
#     try:
#         validate_sqlite_table_name(name)
#     except ValidationError as e:
#         if e.reason == ErrorReason.RESERVED_NAME and e.reusable_name:
#             pass
#         else:
#             raise NameValidationError(e)
# 
# Path: simplesqlite/_validator.py
# def validate_sqlite_attr_name(name: str) -> None:
#     """
#     :param str name: Name to validate.
#     :raises pathvalidate.ValidationError:
#         - If the ``name`` includes unprintable character(s).
#         - |raises_sqlite_keywords|
#     """
# 
#     if not name:
#         raise ValidationError(["null name"], reason=ErrorReason.NULL_NAME)
# 
#     if __RE_INVALID_CHARS.search(name):
#         raise ValidationError(["unprintable character found"], reason=ErrorReason.INVALID_CHARACTER)
# 
#     name = name.upper()
# 
#     if name in __SQLITE_INVALID_RESERVED_KEYWORDS_ATTR:
#         raise ValidationError(
#             [f"'{name}' is a reserved keyword by sqlite"],
#             reason=ErrorReason.RESERVED_NAME,
#             reusable_name=False,
#         )
# 
#     if name in __SQLITE_VALID_RESERVED_KEYWORDS_ATTR:
#         raise ValidationError(
#             [f"'{name}' is a reserved keyword by sqlite"],
#             reason=ErrorReason.RESERVED_NAME,
#             reusable_name=True,
#         )
# 
# Path: simplesqlite/error.py
# class SqlSyntaxError(Exception):
#     """
#     Exception raised when a SQLite query syntax is invalid.
#     """


import abc
import re
import typepy
    import hashlib
from typing import Any, List, Optional, Sequence, Union
from pathvalidate import ascii_symbols, unprintable_ascii_chars
from pathvalidate.error import ErrorReason, ValidationError
from ._func import validate_table_name
from ._validator import validate_sqlite_attr_name
from .error import SqlSyntaxError
        'key'
        >>> Attr("a+b")
        '[a+b]'
        >>> Attr("key", operation="SUM")
        'SUM(key)'
    """

    __RE_NEED_QUOTE = re.compile("[{:s}]".format(re.escape("[]_")))
    __RE_NEED_BRACKET = re.compile(
        r"[{:s}0-9\s]".format(re.escape("%(){}-+/.;:`'\"\0\\*?<>|!#&=~^@"))
    )
    __RE_SANITIZE = re.compile("[{:s}\n\r]".format(re.escape("'\",")))

    @classmethod
    def sanitize(cls, name: str) -> str:
        try:
            return cls.__RE_SANITIZE.sub("_", name)
        except TypeError:
            return str(name)

    def __init__(self, name: str, operation: str = "") -> None:
        super().__init__(name)

        self.__operation = operation

    def to_query(self) -> str:
        name = self.sanitize(self._value)
        need_quote = self.__RE_NEED_QUOTE.search(name) is not None

        try:

# Path: simplesqlite/_func.py
# def validate_table_name(name: str) -> None:
#     """
#     :param str name: Table name to validate.
#     :raises NameValidationError: |raises_validate_table_name|
#     """
# 
#     try:
#         validate_sqlite_table_name(name)
#     except ValidationError as e:
#         if e.reason == ErrorReason.RESERVED_NAME and e.reusable_name:
#             pass
#         else:
#             raise NameValidationError(e)
# 
# Path: simplesqlite/_validator.py
# def validate_sqlite_attr_name(name: str) -> None:
#     """
#     :param str name: Name to validate.
#     :raises pathvalidate.ValidationError:
#         - If the ``name`` includes unprintable character(s).
#         - |raises_sqlite_keywords|
#     """
# 
#     if not name:
#         raise ValidationError(["null name"], reason=ErrorReason.NULL_NAME)
# 
#     if __RE_INVALID_CHARS.search(name):
#         raise ValidationError(["unprintable character found"], reason=ErrorReason.INVALID_CHARACTER)
# 
#     name = name.upper()
# 
#     if name in __SQLITE_INVALID_RESERVED_KEYWORDS_ATTR:
#         raise ValidationError(
#             [f"'{name}' is a reserved keyword by sqlite"],
#             reason=ErrorReason.RESERVED_NAME,
#             reusable_name=False,
#         )
# 
#     if name in __SQLITE_VALID_RESERVED_KEYWORDS_ATTR:
#         raise ValidationError(
#             [f"'{name}' is a reserved keyword by sqlite"],
#             reason=ErrorReason.RESERVED_NAME,
#             reusable_name=True,
#         )
# 
# Path: simplesqlite/error.py
# class SqlSyntaxError(Exception):
#     """
#     Exception raised when a SQLite query syntax is invalid.
#     """


# Path: simplesqlite/query.py
import abc
import re
import typepy
    import hashlib
from typing import Any, List, Optional, Sequence, Union
from pathvalidate import ascii_symbols, unprintable_ascii_chars
from pathvalidate.error import ErrorReason, ValidationError
from ._func import validate_table_name
from ._validator import validate_sqlite_attr_name
from .error import SqlSyntaxError

        'key'
        >>> Attr("a+b")
        '[a+b]'
        >>> Attr("key", operation="SUM")
        'SUM(key)'
    """

    __RE_NEED_QUOTE = re.compile("[{:s}]".format(re.escape("[]_")))
    __RE_NEED_BRACKET = re.compile(
        r"[{:s}0-9\s]".format(re.escape("%(){}-+/.;:`'\"\0\\*?<>|!#&=~^@"))
    )
    __RE_SANITIZE = re.compile("[{:s}\n\r]".format(re.escape("'\",")))

    @classmethod
    def sanitize(cls, name: str) -> str:
        try:
            return cls.__RE_SANITIZE.sub("_", name)
        except TypeError:
            return str(name)

    def __init__(self, name: str, operation: str = "") -> None:
        super().__init__(name)

        self.__operation = operation

    def to_query(self) -> str:
        name = self.sanitize(self._value)
        need_quote = self.__RE_NEED_QUOTE.search(name) is not None

        try:

            validate_sqlite_attr_name(name)