# This file was generated by stubgen-pyx v0.2.18 from /Users/long2ice/Developer/long2ice/asyncmy/asyncmy/cursors.pyx
from collections.abc import Generator
from typing import Any
from typing_extensions import Self

import logging
import re

from asyncmy.connection import Connection

from . import errors

RE_INSERT_VALUES = re.compile(
    "\\s*((?:INSERT|REPLACE)\\b.+\\bVALUES?\\s*)"
    + "(\\(\\s*(?:%s|%\\(.+\\)s)\\s*(?:,\\s*(?:%s|%\\(.+\\)s)\\s*)*\\))"
    + "(\\s*(?:(?:AS|ON DUPLICATE).*)?);?\\s*\\Z",
    re.IGNORECASE | re.DOTALL,
)
logger = logging.getLogger(__package__)

class Cursor:
    """
    This is the object used to interact with the database.

    Do not create an instance of a Cursor yourself. Call
    connections.Connection.cursor().

    See `Cursor <https://www.python.org/dev/peps/pep-0249/#cursor-objects>`_ in
    the specification.
    """

    Warning = errors.Warning
    Error = errors.Error
    InterfaceError = errors.InterfaceError
    DatabaseError = errors.DatabaseError
    DataError = errors.DataError
    OperationalError = errors.OperationalError
    IntegrityError = errors.IntegrityError
    InternalError = errors.InternalError
    ProgrammingError = errors.ProgrammingError
    NotSupportedError = errors.NotSupportedError
    max_stmt_length: int
    rownumber: int
    arraysize: int
    rowcount: object
    description: tuple
    connection: Any
    lastrowid: int

    def __init__(self, connection: Connection, echo: bool = False, query_callback=None): ...
    async def close(self) -> None:
        """
        Closing a cursor just exhausts all remaining data.
        """
    def __aiter__(self): ...
    def __await__(self) -> Generator[Any, None, Self]: ...
    async def __aenter__(self) -> Self: ...
    async def __aexit__(self, exc_type, exc_val, exc_tb): ...
    async def __anext__(self): ...
    def setinputsizes(self, *args):
        """Does nothing, required by DB API."""
    def setoutputsizes(self, *args):
        """Does nothing, required by DB API."""
    async def nextset(self) -> bool | None: ...
    def mogrify(self, query, args=None) -> str:
        """
        Returns the exact string that would be sent to the database by calling the
        execute() method.

        :param query: Query to mogrify.
        :type query: str

        :param args: Parameters used with query. (optional)
        :type args: tuple, list or dict

        :return: The query with argument binding applied.
        :rtype: str

        This method follows the extension to the DB API 2.0 followed by Psycopg.
        """
    async def execute(self, query, args=None) -> int:
        """Execute a query.

        :param query: Query to execute.
        :type query: str

        :param args: Parameters used with query. (optional)
        :type args: tuple, list or dict

        :return: Number of affected rows.
        :rtype: int

        If args is a list or tuple, %s can be used as a placeholder in the query.
        If args is a dict, %(name)s can be used as a placeholder in the query.
        """
    async def executemany(self, query: str, args) -> int | None:
        """Run several data against one query.

        :param query: Query to execute.
        :type query: str

        :param args: Sequence of sequences or mappings. It is used as parameter.
        :type args: tuple or list

        :return: Number of rows affected, if any.
        :rtype: int or None

        This method improves performance on multiple-row INSERT and
        REPLACE. Otherwise it is equivalent to looping over args with
        execute().
        """
    async def callproc(self, procname, args=()):
        """Execute stored procedure procname with args.

        :param procname: Name of procedure to execute on server.
        :type procname: str

        :param args: Sequence of parameters to use with procedure.
        :type args: tuple or list

        Returns the original args.

        Compatibility warning: PEP-249 specifies that any modified
        parameters must be returned. This is currently impossible
        as they are only available by storing them in a server
        variable and then retrieved by a query. Since stored
        procedures return zero or more result sets, there is no
        reliable way to get at OUT or INOUT parameters via callproc.
        The server variables are named @_procname_n, where procname
        is the parameter above and n is the position of the parameter
        (from zero). Once all result sets generated by the procedure
        have been fetched, you can issue a SELECT @_procname_0, ...
        query using .execute() to get any OUT or INOUT values.

        Compatibility warning: The act of calling a stored procedure
        itself creates an empty result set. This appears after any
        result sets generated by the procedure. This is non-standard
        behavior with respect to the DB-API. Be sure to use nextset()
        to advance through all result sets; otherwise you may get
        disconnected.
        """
    async def fetchone(self) -> Any:
        """Fetch the next row."""
    async def fetchmany(self, size=None) -> list[Any]:
        """Fetch several rows."""
    async def fetchall(self) -> list[Any]:
        """Fetch all the rows."""
    def scroll(self, value, mode="relative"): ...

class DictCursorMixin:
    dict_type = dict

class DictCursor(DictCursorMixin, Cursor):
    """A cursor which returns results as a dictionary"""

class SSCursor(Cursor):
    """
    Unbuffered Cursor, mainly useful for queries that return a lot of data,
    or for connections to remote servers over a slow network.

    Instead of copying every row of data into a buffer, this will fetch
    rows as needed. The upside of this is the client uses much less memory,
    and rows are returned much faster when traveling over a slow network
    or if the result set is very big.

    There are limitations, though. The MySQL protocol doesn't support
    returning the total number of rows, so the only way to tell how many rows
    there are is to iterate over every row returned. Also, it currently isn't
    possible to scroll backwards, as only the current row is held in memory.
    """
    async def close(self) -> None: ...
    async def nextset(self) -> bool | None: ...
    async def read_next(self):
        """Read next row."""
    async def fetchone(self) -> Any:
        """Fetch next row."""
    async def fetchall(self) -> list[Any]:
        """
        Fetch all, as per MySQLdb. Pretty useless for large queries, as
        it is buffered. See fetchall_unbuffered(), if you want an unbuffered
        generator version of this method.
        """
    async def fetchmany(self, size=None) -> list[Any]:
        """Fetch many."""
    async def scroll(self, value, mode="relative"): ...

class SSDictCursor(DictCursorMixin, SSCursor):
    """An unbuffered cursor, which returns results as a dictionary"""
