pystratum_mysql package

Submodules

pystratum_mysql.MySqlConnector module

class pystratum_mysql.MySqlConnector.MySqlConnector[source]

Bases: object

Interface for classes for connecting to a MySql instances.

connect() → mysql.connector.connection.MySQLConnection[source]

Connects to the MySql instance.

disconnect() → None[source]

Disconnects from the MySql instance.

is_alive() → bool[source]

Returns whether Python is (still) connected to a MySQL or MariaDB instance.

Return type:bool

pystratum_mysql.MySqlDataLayer module

class pystratum_mysql.MySqlDataLayer.MySqlDataLayer(connector: pystratum_mysql.MySqlConnector.MySqlConnector)[source]

Bases: object

Class for connecting to a MySQL instance and executing SQL statements. Also, a parent class for classes with static wrapper methods for executing stored procedures and functions.

commit() → None[source]

Commits the current transaction. See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-commit.html

connect() → None[source]

Connects to a MySQL instance. See https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html for a complete overview of all possible keys in config.

connect_if_not_alive() → None[source]

Connects or reconnects to the MySQL or MariaDB instance when Python is not (longer) connected to a MySQL or MariaDB instance. See https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html for a complete overview of all possible keys in config.

disconnect() → None[source]

Disconnects from the MySQL instance. See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-disconnect.html.

execute_multi(sql: str) → None[source]

Executes a multi query that does not select any rows.

Parameters:sql (str) – The SQL statements.
execute_none(sql: str, *params) → int[source]

Executes a query that does not select any rows. Returns the number of affected rows.

Parameters:
  • sql (str) – The SQL statement.
  • params (iterable) – The values for the statement.
Return type:

int

execute_rows(sql: str, *params) → List[Dict[str, Any]][source]

Executes a query that selects 0 or more rows. Returns the selected rows (an empty list if no rows are selected).

Parameters:
  • sql (str) – The SQL statement.
  • params (iterable) – The arguments for the statement.
Return type:

list[dict[str,*]]

execute_singleton1(sql: str, *params) → Any[source]

Executes SQL statement that selects 1 row with 1 column. Returns the value of the selected column.

Parameters:
  • sql (str) – The SQL calling the stored procedure.
  • params (iterable) – The arguments for the stored procedure.
Return type:

*:

execute_sp_bulk(bulk_handler: pystratum_middle.BulkHandler.BulkHandler, sql: str, *params) → int[source]

Executes a stored routine with designation type “bulk”. Returns the number of rows processed.

Parameters:
  • bulk_handler (BulkHandler) – The bulk handler for processing the selected rows.
  • sql (str) – The SQL statement for calling the stored routine.
  • params (iterable) – The arguments for calling the stored routine.
Return type:

int

execute_sp_log(sql: str, *params) → int[source]

Executes a stored routine with designation type “log”. Returns the number of log messages.

Parameters:
  • sql (str) – The SQL statement for calling the stored routine.
  • params (iterable) – The arguments for calling the stored routine.
Return type:

int

execute_sp_multi(sql: str, *params) → List[List[Dict[str, Any]]][source]

Executes a stored routine with designation type “multi”. Returns a list of the result sets.

Parameters:
  • sql (str) – The SQL statement for calling the stored routine.
  • params (iterable) – The arguments for calling the stored routine.
Return type:

list[list[dict[str,*]]]

execute_sp_none(sql: str, *params) → int[source]

Executes a stored routine that does not select any rows. Returns the number of affected rows.

Parameters:
  • sql (str) – The SQL calling the stored procedure.
  • params (iterable) – The arguments for the stored procedure.
Return type:

int

execute_sp_row0(sql: str, *params) → Optional[Dict[str, Any]][source]

Executes a stored procedure that selects 0 or 1 row. Returns the selected row or None.

Parameters:
  • sql (str) – The SQL call the the stored procedure.
  • params (iterable) – The arguments for the stored procedure.
Return type:

None|dict[str,*]

execute_sp_row1(sql: str, *params) → Dict[str, Any][source]

Executes a stored procedure that selects 1 row. Returns the selected row.

Parameters:
  • sql (str) – The SQL calling the the stored procedure.
  • params (iterable) – The arguments for the stored procedure.
Return type:

dict[str,*]

execute_sp_rows(sql: str, *params) → List[Dict[str, Any]][source]

Executes a stored procedure that selects 0 or more rows. Returns the selected rows (an empty list if no rows are selected).

Parameters:
  • sql (str) – The SQL statement.
  • params (iterable) – The arguments for the statement.
Return type:

list[dict[str,*]]

execute_sp_singleton0(sql: str, *params) → Any[source]

Executes a stored procedure that selects 0 or 1 row with 1 column. Returns the value of selected column or None.

Parameters:
  • sql (str) – The SQL calling the stored procedure.
  • params (iterable) – The arguments for the stored procedure.
Return type:

execute_sp_singleton1(sql: str, *params) → Any[source]

Executes a stored routine with designation type “table”, i.e a stored routine that is expected to select 1 row with 1 column.

Parameters:
  • sql (str) – The SQL calling the the stored procedure.
  • params (iterable) – The arguments for the stored procedure.
Return type:

  • The value of the selected column.

is_alive() → bool[source]

Returns whether Python is (still) connected to a MySQL or MariaDB instance.

Return type:bool
last_sql() → str[source]

Returns the last execute SQL statement.

line_buffered = None

If True log messages from stored procedures with designation type ‘log’ are line buffered (Note: In python sys.stdout is buffered by default).

rollback() → None[source]

Rolls back the current transaction. See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-rollback.html

start_transaction(consistent_snapshot: bool = False, isolation_level: str = 'READ-COMMITTED', readonly: Optional[bool] = None) → None[source]

Starts a transaction. See https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlconnection-start-transaction.html

Parameters:
  • consistent_snapshot (bool) –
  • isolation_level (str) –
  • readonly (bool) –

pystratum_mysql.MySqlDefaultConnector module

class pystratum_mysql.MySqlDefaultConnector.MySqlDefaultConnector(params: Dict[str, Union[str, int]])[source]

Bases: pystratum_mysql.MySqlConnector.MySqlConnector

Connects to a MySQL instance using username and password.

connect() → mysql.connector.connection.MySQLConnection[source]

Connects to the MySQL instance.

disconnect() → None[source]

Disconnects from the MySQL instance.

is_alive() → bool[source]

Returns whether Python is (still) connected to a MySQL or MariaDB instance.

Return type:bool

pystratum_mysql.MySqlMetadataDataLayer module

class pystratum_mysql.MySqlMetadataDataLayer.MySqlMetadataDataLayer(io: pystratum_backend.StratumStyle.StratumStyle, connector: pystratum_mysql.MySqlConnector.MySqlConnector)[source]

Bases: pystratum_common.MetadataDataLayer.MetadataDataLayer

Data layer for retrieving metadata and loading stored routines.

call_stored_routine(routine_name: str) → int[source]

Class a stored procedure without arguments.

Parameters:routine_name (str) – The name of the procedure.
Return type:int
check_table_exists(table_name: str) → int[source]

Checks if a table exists in the current schema.

Parameters:table_name (str) – The name of the table.
Return type:int
connect() → None[source]

Connects to a MySQL instance.

describe_table(table_name: str) → List[Dict[str, Any]][source]

Describes a table.

Parameters:table_name (str) – The name of the table.
Return type:list[dict[str,*]]
disconnect() → None[source]

Disconnects from the MySQL instance.

drop_stored_routine(routine_type: str, routine_name: str) → None[source]

Drops a stored routine if it exists.

Parameters:
  • routine_type (str) – The type of the routine (i.e. PROCEDURE or FUNCTION).
  • routine_name (str) – The name of the routine.
drop_temporary_table(table_name: str) → None[source]

Drops a temporary table.

Parameters:table_name (str) – The name of the table.
execute_none(query: str) → int[source]

Executes a query that does not select any rows.

Parameters:query (str) – The query.
Return type:int
execute_rows(query: str) → List[Dict[str, Any]][source]

Executes a query that selects 0 or more rows. Returns the selected rows (an empty list if no rows are selected).

Parameters:query (str) – The query.
Return type:list[dict[str,*]]
execute_singleton1(query: str) → Any[source]

Executes SQL statement that selects 1 row with 1 column. Returns the value of the selected column.

Parameters:query (str) – The query.
Return type:
get_all_table_columns() → List[Dict[str, Union[str, int, None]]][source]

Selects metadata of all columns of all tables.

Return type:list[dict[str,*]]
get_correct_sql_mode(sql_mode: str) → str[source]

Selects the SQL mode in the order as preferred by MySQL.

Parameters:sql_mode (str) – The SQL mode.
Return type:str
get_label_tables(regex: str) → List[Dict[str, Any]][source]

Selects metadata of tables with a label column.

Parameters:regex (str) – The regular expression for columns which we want to use.
Return type:list[dict[str,*]]
get_labels_from_table(table_name: str, id_column_name: str, label_column_name: str) → List[Dict[str, Any]][source]

Selects all labels from a table with labels.

Parameters:
  • table_name (str) – The name of the table.
  • id_column_name (str) – The name of the auto increment column.
  • label_column_name (str) – The name of the column with labels.
Return type:

list[dict[str,*]]

get_routine_parameters(routine_name: str) → List[Dict[str, Any]][source]

Selects metadata of the parameters of a stored routine.

Parameters:routine_name (str) – The name of the routine.
Return type:list[dict[str,*]]
get_routines() → List[Dict[str, Any]][source]

Selects metadata of all routines in the current schema.

Return type:list[dict[str,*]]
last_sql() → str[source]

The last executed SQL statement.

Return type:str
set_character_set(character_set: str, collate: str) → None[source]

Sets the default character set and collate.

Parameters:
  • character_set (str) – The name of the character set.
  • collate (str) – The name of the collate
set_sql_mode(sql_mode: str) → None[source]

Sets the SQL mode.

Parameters:sql_mode (str) – The SQL mode.

Module contents