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).

Connection Class

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)

converter

Member

Conversion dictionary

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.

get_server_version()

Method

get_server_version() method exists for compatibility reasons. However the preferred way to retrieve server version information are the server_version and server_version_info connection attributes

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.

server_version_info

Member

Server version in tuple format

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().

Cursor Class

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().

nextset()

Method

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

rowcount

GetSet

Provides the number of rows returned by the last query. (read-only)

rownumber

GetSet

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

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)

Fieldinfo Class

Name

Type

Description

flag()

Method

Returns flag information for the given field.

type()

Method

Returns type information for the given field.

Pool Class

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.

close()

Method

Closes connection pool and all connections.

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)

pool_name

GetSet

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)

set_config()

Method

Sets the connection configuration for the connection pool. For valid connection arguments check the mariadb.connect() method.

Constants

Name

Description

CLIENT.CAN_HANDLE_EXPIRED_PASSWORDS

Connector/C CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS constant. Used to determine whether the connector is prepared to handle the expired password sandbox mode.

CLIENT.COMPRESS

Connector/C CLIENT_COMPRESS constant. Used to determine whether the connection uses compression.

CLIENT.CONNECT_ATTRS

Connector/C CLIENT_CONNECT_ATTRS constant.

CLIENT.CONNECT_WITH_DB

Connector/C CLIENT_CONNECT_WITH_DB constant. Used to determine whether the connection specifies a default database.

CLIENT.FOUND_ROWS

Connector/C CLIENT_FOUND_ROWS constant. Used to determine whether the client has found rows instead of affected rows.

CLIENT.IGNORE_SPACE

Connector/C CLIENT_IGNORE_SPACE constant. Used to determine whether the client allows spaces after function names.

CLIENT.INTERACTIVE

Connector/C CLIENT_INTERACTIVE constant. Used to determine whether the client connection is interactive.

CLIENT.LOCAL_FILES

Connector/C CLIENT_LOCAL_FILES constant. Used to determine whether to allow LOAD DATA LOCAL INFILE statements.

CLIENT.LONG_FLAG

Connector/C CLIENT_LONG_FLAG constant. Used to determine whether the client retrieved all column flags.

CLIENT.MULTI_RESULTS

Connector/C CLIENT_MULTI_RESULTS constant. Used to determine whether the client can handle multiple result-sets.

CLIENT.MULTI_STATEMENTS

Connector/C CLIENT_MULTI_STATEMENTS constant. Used to determine whether the client can use the semicolon to send multiple statements in one query.

CLIENT.MYSQL

Connector/C CLIENT_MYSQL constant.

CLIENT.NO_SCHEMA

Connector/C CLIENT_NO_SCHEMA constant. Used to determine whether the SQL parser returns an error if the query does not specify a database.

CLIENT.PLUGIN_AUTH

Connector/C CLIENT_PLUGIN_AUTH constant. Used to represent the authentication plugin used on the connection.

CLIENT.PS_MULTI_RESULTS

Connector/C CLIENT_PS_MULTI_RESULTS constant.

CLIENT.REMEMBER_OPTIONS

Connector/C CLIENT_REMEMBER_OPTIONS constant.

CLIENT.SECURE_CONNECTION

Connector/C CLIENT_SECURE_CONNECTION constant.

CLIENT.SESSION_TRACKING

Connector/C CLIENT_SESSION_TRACKING constant.

CLIENT.SSL

Connector/C CLIENT_SSL constant. Used to determine whether the client switches to TLS after the handshake.

CLIENT.SSL_VERIFY_SERVER_CERT

Connector/C CLIENT_SSL_VERIFY_SERVER_CERT constant. Used to determine whether the client should verify the TLS certificate from the Server.

CLIENT.TRANSACTIONS

Connector/C CLIENT_TRANSACTIONS constant. Used to determine whether the client is aware of transactions.

FIELD_TYPE.BIT

Connector/C MYSQL_TYPE_BIT constant. Used to represent BIT columns.

FIELD_TYPE.BLOB

Connector/C MYSQL_TYPE_BLOB constant. Used to represent BLOB columns.

FIELD_TYPE.DATE

Connector/C MYSQL_TYPE_DATE constant. Used to represent DATE columns.

FIELD_TYPE.DATETIME

Connector/C MYSQL_TYPE_DATETIME constant. Used to represent DATETIME columns.

FIELD_TYPE.DATETIME2

Connector/C MYSQL_TYPE_DATETIME2 constant.

FIELD_TYPE.DECIMAL

Connector/C MYSQL_TYPE_DECIMAL constant. Used to represent DECIMAL columns.

FIELD_TYPE.DOUBLE

Connector/C MYSQL_TYPE_DOUBLE constant. Used to represent DOUBLE columns.

FIELD_TYPE.ENUM

Connector/C MYSQL_TYPE_ENUM constant. Used to represent ENUM columns.

FIELD_TYPE.FLOAT

Connector/C MYSQL_TYPE_FLOAT constant. Used to represent FLOAT columns.

FIELD_TYPE.INT24

Connector/C MYSQL_TYPE_INT24 constant.

FIELD_TYPE.JSON

Connector/C MYSQL_TYPE_JSON constant. Used to represent JSON columns.

FIELD_TYPE.LONG

Connector/C MYSQL_TYPE_LONG constant. Used to represent LONG columns.

FIELD_TYPE.LONG_BLOB

Connector/C MYSQL_TYPE_LONG_BLOB constant. Used to represent LONGBLOB columns.

FIELD_TYPE.LONGLONG

Connector/C MYSQL_TYPE_LONGLONG constant.

FIELD_TYPE.MEDIUM_BLOB

Connector/C MYSQL_TYPE_MEDIUM_BLOB constant. Used to represent MEDIUMBLOB columns.

FIELD_TYPE.NEWDATE

Connector/C MYSQL_TYPE_NEWDATE constant.

FIELD_TYPE.NEWDECIMAL

Connector/C MYSQL_TYPE_NEWDECIMAL constant.

FIELD_TYPE.NULL

Connector/C MYSQL_TYPE_NULL constant.

FIELD_TYPE.SET

Connector/C MYSQL_TYPE_SET constant.

FIELD_TYPE.SHORT

Connector/C MYSQL_TYPE_SHORT constant.

FIELD_TYPE.TIME

Connector/C MYSQL_TYPE_TIME constant. Used to represent TIME columns.

FIELD_TYPE.TIME2

Connector/C MYSQL_TYPE_TIME2 constant.

FIELD_TYPE.TIMESTAMP

Connector/C MYSQL_TYPE_TIMESTAMP constant. Used to represent TIMESTAMP columns.

FIELD_TYPE.TIMESTAMP2

Connector/C MYSQL_TYPE_TIMESTAMP2 constant.

FIELD_TYPE.TINY

Connector/C MYSQL_TYPE_TINY constant. Used to represent TINYINT columns.

FIELD_TYPE.TINY_BLOB

Connector/C MYSQL_TYPE_TINY_BLOB constant. Used to represent TINYBLOB columns.

FIELD_TYPE.VARCHAR

Connector/C MYSQL_TYPE_VARCHAR constant. Used to represent VARCHAR columns.

FIELD_TYPE.YEAR

Connector/C MYSQL_TYPE_YEAR constant. Used to represent YEAR columns.

INDICATOR.DEFAULT

Connector/C STMT_INDICATOR_DEFAULT constant. Used to indicate that the given value is the column default.

INDICATOR.IGNORE

Connector/C STMT_INDICATOR_IGNORE constant. Used to indicate whether to ignore the given value.

INDICATOR.IGNORE_ROW

Connector/C STMT_INDICATOR_IGNORE_ROW constant. Used to indicate whether skips the current row.

INDICATOR.NULL

Connector/C STMT_INDICATOR_NULL constant. Used to indicate that the value is NULL.