A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mariadb.com/docs/connectors/mariadb-connector-python/api/module below:

The MariaDB Connector/Python module | MariaDB Documentation

The MariaDB Connector/Python module | MariaDB Documentation
  1. Connector/Python
  2. API Reference
The MariaDB Connector/Python module

MariaDB Connector/Python module enables python programs to access MariaDB and MySQL databases, using an API which is compliant with the Python DB API 2.0 (PEP-249).

connect(connectionclass=mariadb.connections.Connection, **kwargs)

Creates a MariaDB Connection object.

By default, the standard connectionclass mariadb.connections.Connection will be created.

Parameter connectionclass specifies a subclass of mariadb.Connection object. If not specified, default will be used. This optional parameter was added in version 1.1.0.

Connection parameters are provided as a set of keyword arguments:

For a description of configuration file handling and settings please read the chapter Configuration files of the MariaDB Connector/C documentation.

Example:

import mariadb

with mariadb.connect(user="example_user", host="localhost", database="test", password="GHbe_Su3B8") as connection:
    print(connection.character_set)

Output:

Class defining a pool of database connections

MariaDB Connector/Python supports simple connection pooling. A connection pool holds a number of open connections and handles thread safety when providing connections to threads.

The size of a connection pool is configurable at creation time, but cannot be changed afterward. The maximum size of a connection pool is limited to 64 connections.

Keyword Arguments:

Constructs an object capable of holding a binary value.

Constructs an object holding a date value.

Constructs an object holding a date value from the given ticks value (number of seconds since the epoch). For more information see the documentation of the standard Python time module.

Time(hour, minute, second)

Constructs an object holding a time value.

Constructs an object holding a time value from the given ticks value (number of seconds since the epoch). For more information see the documentation of the standard Python time module.

Timestamp(year, month, day, hour, minute, second)

Constructs an object holding a datetime value.

TimestampFromTicks(ticks)

Constructs an object holding a datetime value from the given ticks value (number of seconds since the epoch). For more information see the documentation of the standard Python time module.

String constant stating the supported DB API level. The value for mariadb is 2.0.

Integer constant stating the level of thread safety. For mariadb the value is 1, which means threads can share the module but not the connection.

String constant stating the type of parameter marker. For mariadb the value is qmark. For compatibility reasons mariadb also supports the format and pyformat paramstyles with the limitation that they can’t be mixed inside a SQL statement.

String constant stating the version of the used MariaDB Connector/C library.

Since version 1.1.0

Returns the version of MariaDB Connector/C library in use as an integer. The number has the following format: MAJOR_VERSION * 10000 + MINOR_VERSION * 1000 + PATCH_VERSION

Since version 1.1.0 Returns the version of MariaDB Connector/C library as a tuple in the following format: (MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)

Compliant to DB API 2.0 MariaDB Connector/C provides information about errors through the following exceptions:

Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.

Exception raised for errors that are related to the database

Exception raised for errors that are related to the database interface rather than the database itself

Exception raised for important warnings like data truncations while inserting, etc

Exception raised for errors related to ConnectionPool class.

exception OperationalError

Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer.

Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails

Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore

exception ProgrammingError

Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement

exception NotSupportedError

Exception raised in case a method or database API was used which is not supported by the database

MariaDB Connector/Python type objects are immutable sets for type settings and defined in DBAPI 2.0 (PEP-249).

Example:

import mariadb
from mariadb.constants import FIELD_TYPE

print(FIELD_TYPE.GEOMETRY == mariadb.BINARY)
print(FIELD_TYPE.DATE == mariadb.DATE)
print(FIELD_TYPE.VARCHAR == mariadb.BINARY)

Output:

This type object is used to describe columns in a database that are string-based (e.g. CHAR1).

This type object is used to describe (long) binary columns in a database (e.g. LONG, RAW, BLOBs).

This type object is used to describe numeric columns in a database.

This type object is used to describe date/time columns in a database.

This type object is not supported in MariaDB Connector/Python and represents an empty set.

This page is covered by the Creative Commons Attribution 3.0 license .


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4