MariaDB Connector/Python 1.0¶

A summary of the MariaDB Connector/Python API:

Name

Type

Description

Binary()

Method

Returns an object for holding a binary (long) string value.

connect()

Method

Establishes a connection to a database server and returns a connection object.

ConnectionPool()

Method

Create a connection pool and returns a connection pool object.

Date()

Method

Returns an object for holding a date value.

DateFromTicks()

Method

Returns an object for holding a date value, built from the given ticks value (seconds since the epoch).

fieldinfo()

Method

Returns a MariaDB field information object.

Time()

Method

Returns an object for holding a time value.

TimeFromTicks()

Method

Returns an object for holding a time value, built from the given ticks value (seconds since the epoch).

Timestamp()

Method

This function constructs an object holding a time stamp value

TimestampFromTicks()

Method

Returns an object for holding a timestamp value, built from the given ticks value (seconds since the epoch).

The connection class supports the following methods:

Name

Type

Description

__enter__

Method

Returns a copy of the connection. (read-only)

__exit__

Method

Closes the connection.

auto_reconnect

GetSet

This connection value (read/write) enables or disables automatic reconnection to the server when the connection is lost.

autocommit

GetSet

This connection value (read/write) determines if commits occur automatically or manually. Default: False (automatic).

change_user()

Method

Changes the user and default database of the current connection. A valid username and password pair must be provided and that user must have sufficient permissions to access the desired database. If for any reason authorization fails, the current user authentication will remain.

character_set

Member

This connection value (read/write) sets the character set to use.

close()

Method

Close the connection now (instead of when the object is destroyed).

collation

Member

Returns the client character set collation for the connection. (read-only)

commit()

Method

Commit any pending transaction to the database.

connect()

Method

Establishes a connection to a database server and returns a connection object.

connection_id

GetSet

Returns the (thread) id for the current connection. (read only)

cursor()

Method

Returns a new cursor object for the current connection.

database

GetSet

Returns or sets the default database for the current connection. (read/write)

dsn

Member

The connection's data source name. (read-only)

escape_string()

Method

Returns a backslash-escaped string that can be used inside single or double quotes in an SQL statement.

kill()

Method

Asks the server to kill a database connection based on its thread ID.

ping()

Method

Checks if the connection to the database server is still available and throws an exception if it is not.

reconnect()

Method

Tries to make a connection object active again by reconnecting to the server using the same credentials which were specified in connect() method.

reset()

Method

Resets a connection object, clearing session state and pending results. All open cursors for the connection become invalid and must be recreated to be used again.

rollback()

Method

Causes any uncommitted changes on a connection to be discarded.

server_info

GetSet

This connection value (read-only) returns the alphanumeric version of connected database. See server_version for the numeric version.

server_name

Member

The server name or IP address that was used to make the connection to the database. (read-only)

server_port

Member

The port number that was used to make the connection to the database. (read-only)

server_version

GetSet

This connection value (read-only) returns the numeric version of the database in the form VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH.

tls_cipher

Member

The name of the TLS cipher used for the connection or None. (read-only)

tls_version

Member

The version of the TLS cipher used for the connection or None. (read-only)

tpc_begin()

Method

Begins a TPC transaction with the given transaction ID xid.

tpc_commit()

Method

Commit a two-phase-commit transaction that was started with tpc_begin() and validated using tpc_prepare().

tpc_prepare()

Method

Performs the verification phase of two-phase-commit transaction started with the tpc_begin() method.

tpc_recover()

Method

Returns a list of pending two-phase-commit transaction IDs for the current connection.

tpc_rollback()

Method

Aborts a two-phase-commit transaction that was started with tpc_begin(). A rollback can be done before or after the tpc_prepare() is called.

unix_socket

Member

This connection value (read-only) returns the path of the unix socket that was used for the connection or None if the connection was made via IP.

user

GetSet

Returns the user name for the current connection. (read-only)

warnings

GetSet

Returns the number of warnings from the last executed statement, or zero. (read only) Returns the number of warnings from the last executed statement, or zero. (read-only)

xid()

Method

Returns a transaction ID object suitable for passing to the two-phase-commit functions, starting with tpc_begin().

The cursor class supports the following methods:

Name

Type

Description

__enter__

Method

Returns a copy of the cursor. (read-only)

__exit__

Method

Closes the cursor. (read-only)

arraysize

Member

This cursor value (read/write) is the number of rows that fetchmany() reads per call. The default is 1.

buffered

GetSet

This cursor value (read/write) sets if the entire result-set of a SELECT or SHOW is immediately read into memory. Default: 0 (unbuffered).

callproc()

Method

Executes a stored procedure.

close()

Method

Closes the cursor. If the cursor has pending or unread results, .close() will cancel them so that further operations using the same connection can be executed.

closed

GetSet

Indicates if the cursor is closed and can't be reused. (read only)

connection

Member

Returns the connection object that was used to create the cursor. (read-only)

description

GetSet

Returns column (field) information for a statement that returns values, such as a SELECT or a SHOW. (read-only)

execute()

Method

Specifies a SQL statement to execute.

executemany()

Method

Specifies a SQL statement to execute multiple times, based on a list of argument values.

fetchall()

Method

Fetches all rows of a pending result set and returns a list of tuples.

fetchmany()

Method

Fetches the number of rows specified by the size parameter.

fetchone()

Method

Fetches next row of a pending result set and returns a tuple.

fieldcount()

Method

Returns the number of fields (columns) of a result set.

lastrowid

GetSet

Returns the automatically generated ID value from an INSERT statement on a table that has an AUTO_INCREMENT column.

next()

Method

Return the next row from the currently executing SQL statement using the same semantics as fetchone(). Returns the next row from the currently executing SQL statement.

nextset()

Method

Makes the cursor skip to the next available result-set in a query that returns multiple result-sets.

rowcount

GetSet

This read-only attribute specifies the number of rows that the last. (read only) Provides the number of rows returned by the last query. (read-only)

rownumber

GetSet

Current row number in result set. (read only) Provides the current row number in the result-set. (read-only)

scroll()

Method

Scrolls the cursor in the result-set to a new position according to mode.

setinputsizes()

Method

Required by PEP-249. Does nothing in MariaDB Connector/Python.

setoutputsize()

Method

Required by PEP-249. Does nothing in MariaDB Connector/Python.

sp_outparams

GetSet

Indicates if the current result set contains inout or out parameter (read)

statement

Member

The last executed statement. (read only) Displays the last executed SQL statement. (read-only)

warnings

GetSet

Returns the number of warnings from the last executed statement, or zero. (read only) Returns the number of warnings from the last executed statement, or zero. (read-only)

The fieldinfo class supports the following methods:

Name

Type

Description

flag()

Method

Returns flag information for the given field.

type()

Method

Returns type information for the given field.

The pool class supports the following methods:

Name

Type

Description

add_connection()

Method

Adds a connection to the connection pool. In case the pool doesn't have a free slot or is not configured a PoolError exception will be raised.

get_connection()

Method

Returns a connection from the connection pool or raises a PoolError if a connection is not available.

max_size

Member

Returns the maximum allowed size of the connection pool. (read only) Returns the maximum allowed size of the connection pool. (read-only)

pool_name

GetSet

Returns the name of the connection pool. (read only) Returns the name of the connection pool. (read-only)

pool_reset_connection

GetSet

If set to true, the connection will be reset on both client and server side. (read/write) If set to True, the connection will be reset on both client and server side. (read/write)

pool_size

GetSet

Returns the size of the connection pool. (read only) Returns the size of the connection pool. (read-only)

set_config()

Method

Sets the connection configuration for the connection pool.