cursor()

Returns a new cursor object for the current connection.

See also: MariaDB Connector/Python 1.0

DETAILS

Supported parameters:

named_tuple

When set to True, each fetched row is returned as a named tuple instead of a normal tuple. This allows you to access the column values using either the name of the column (row.name) or its index position (row[0]).

cursor_type

When set to mariadb.CURSOR_TYPE_READ_ONLY a read-only cursor is created, which does not allow any changes to be made to the database.

prefetch_size

The number of rows prefetched. This option is ignored if the cursor_type is not CURSOR_TYPE_READ_ONLY.

buffered

When set to True the entire result set from a SELECT/SHOW statement is stored in client memory.

prepared

When set to True the cursor remains in a prepared state after the first execute() method is called. Further calls to execute() ignore the sql statement. This means that you will need to create a separate cursor for each statement you wish to execute.

EXAMPLES

The following gives you a cursor object that you can then use to execute() SQL statements:

import mariadb

conn = mariadb.connect(
    host = '127.0.0.1',
    user = 'root',
    password = 'secret',
    )

cursor = conn.cursor()

If you want to have the option of accessing the row data using column names (in addition to tuple index integers) change the cursor assignment to pass in the named_tuple option:

cursor = conn.cursor(named_tuple=True)