Terarea  2
The automation project
Loading...
Searching...
No Matches
src.lib.sql.sql_connections.SQLManageConnections Class Reference
Collaboration diagram for src.lib.sql.sql_connections.SQLManageConnections:
Collaboration graph

Public Member Functions

None __init__ (self, str url, int port, str username, str password, str db_name, int success=0, int error=84, bool debug=False)
 
None show_connection_info (self, str func_name="show_connection_info")
 
int initialise_pool (self)
 
mysql.connector.pooling.PooledMySQLConnection get_connection (self)
 
mysql.connector.cursor.MySQLCursor get_cursor (self, mysql.connector.pooling.PooledMySQLConnection connection)
 
int close_cursor (self, mysql.connector.cursor.MySQLCursor cursor)
 
int return_connection (self, mysql.connector.pooling.PooledMySQLConnection connection)
 
int destroy_pool (self)
 
None release_connection_and_cursor (self, Union[mysql.connector.pooling.PooledMySQLConnection, None] connection, Union[mysql.connector.pooling.PooledMySQLConnection, None] cursor=None)
 
int run_and_commit (self, str query, Union[mysql.connector.cursor.MySQLCursor, None] cursor=None)
 
Union[int, Any] run_and_fetch_all (self, str query, Union[mysql.connector.cursor.MySQLCursor, None] cursor=None)
 
int run_editing_command (self, str sql_query, str table, str action_type="update")
 
None __del__ (self)
 
bool is_pool_active (self)
 
bool is_connection_active (self, mysql.connector.pooling.PooledMySQLConnection connection)
 
bool is_cursor_active (self, mysql.connector.cursor.MySQLCursor cursor)
 

Data Fields

int error = error
 
bool debug = debug
 
int success = success
 
str url = url
 
int port = port
 
str username = username
 
str password = password
 
str db_name = db_name
 
Disp disp
 
dict pool_parameters
 
Union[ pool
 
str pool = "ProgrammingError: The pool could not be initialized."
 

Detailed Description

_summary_

Definition at line 16 of file sql_connections.py.

Constructor & Destructor Documentation

◆ __init__()

None src.lib.sql.sql_connections.SQLManageConnections.__init__ ( self,
str url,
int port,
str username,
str password,
str db_name,
int success = 0,
int error = 84,
bool debug = False )
_summary_
    This class is in charge of managing the connections to the sql database

Args:
    url (str): _description_
    port (int): _description_
    username (str): _description_
    password (str): _description_
    db_name (str): _description_
    succes (int, optional): _description_. Defaults to 0.
    error (int, optional): _description_. Defaults to 84.
    debug (bool, optional): _description_. Defaults to False.

Definition at line 20 of file sql_connections.py.

◆ __del__()

None src.lib.sql.sql_connections.SQLManageConnections.__del__ ( self)
_summary_
    Destructor

Definition at line 497 of file sql_connections.py.

Member Function Documentation

◆ close_cursor()

int src.lib.sql.sql_connections.SQLManageConnections.close_cursor ( self,
mysql.connector.cursor.MySQLCursor cursor )
Closes the given cursor.

Args:
    cursor (mysql.connector.cursor.MySQLCursor): The cursor to close.

Definition at line 194 of file sql_connections.py.

◆ destroy_pool()

int src.lib.sql.sql_connections.SQLManageConnections.destroy_pool ( self)
_summary_
    Destroy the connection pool.

Returns:
    int: _description_

Definition at line 230 of file sql_connections.py.

◆ get_connection()

mysql.connector.pooling.PooledMySQLConnection src.lib.sql.sql_connections.SQLManageConnections.get_connection ( self)
_summary_
    Retrieves a connection from the pool.

Returns:
    mysql.connector.pooling.PooledMySQLConnection: _description_: A pooled connection

Definition at line 156 of file sql_connections.py.

◆ get_cursor()

mysql.connector.cursor.MySQLCursor src.lib.sql.sql_connections.SQLManageConnections.get_cursor ( self,
mysql.connector.pooling.PooledMySQLConnection connection )
Retrieves a cursor from the given connection.

Args:
    connection (mysql.connector.pooling.PooledMySQLConnection): The active connection.

Returns:
    mysql.connector.cursor.MySQLCursor: The cursor object.

Definition at line 180 of file sql_connections.py.

◆ initialise_pool()

int src.lib.sql.sql_connections.SQLManageConnections.initialise_pool ( self)
_summary_
    Initialise a connection to the database (but within a pool)

Raises:
    RuntimeError: _description_: A runtime error is raised if it fails.

Returns:
    int: _description_: Returns self.success if the function succeeds.

Definition at line 89 of file sql_connections.py.

◆ is_connection_active()

bool src.lib.sql.sql_connections.SQLManageConnections.is_connection_active ( self,
mysql.connector.pooling.PooledMySQLConnection connection )
Checks if the connection is active.

Args:
    connection (mysql.connector.pooling.PooledMySQLConnection): The connection to check.

Returns:
    bool: True if the connection is active, False otherwise.

Definition at line 519 of file sql_connections.py.

◆ is_cursor_active()

bool src.lib.sql.sql_connections.SQLManageConnections.is_cursor_active ( self,
mysql.connector.cursor.MySQLCursor cursor )
Checks if the cursor is active.

Args:
    cursor (mysql.connector.cursor.MySQLCursor): The cursor to check.

Returns:
    bool: True if the cursor is active, False otherwise.

Definition at line 544 of file sql_connections.py.

◆ is_pool_active()

bool src.lib.sql.sql_connections.SQLManageConnections.is_pool_active ( self)
_summary_
    Check if the connection pool is active.

Returns:
    bool: _description_

Definition at line 503 of file sql_connections.py.

◆ release_connection_and_cursor()

None src.lib.sql.sql_connections.SQLManageConnections.release_connection_and_cursor ( self,
Union[mysql.connector.pooling.PooledMySQLConnection, None] connection,
Union[mysql.connector.pooling.PooledMySQLConnection, None] cursor = None )
_summary_

Args:
    connection (Union[None]): _description_
    cursor (Union[None]): _description_

Definition at line 246 of file sql_connections.py.

◆ return_connection()

int src.lib.sql.sql_connections.SQLManageConnections.return_connection ( self,
mysql.connector.pooling.PooledMySQLConnection connection )
Returns a connection to the pool by closing it.

Args:
    connection (mysql.connector.pooling.PooledMySQLConnection): The connection to close.

Definition at line 212 of file sql_connections.py.

◆ run_and_commit()

int src.lib.sql.sql_connections.SQLManageConnections.run_and_commit ( self,
str query,
Union[mysql.connector.cursor.MySQLCursor, None] cursor = None )
Executes a query and commits changes.

Args:
    cursor (mysql.connector.cursor.MySQLCursor): The active cursor.
    query (str): The query to execute.

Definition at line 263 of file sql_connections.py.

◆ run_and_fetch_all()

Union[int, Any] src.lib.sql.sql_connections.SQLManageConnections.run_and_fetch_all ( self,
str query,
Union[mysql.connector.cursor.MySQLCursor, None] cursor = None )
Executes a query and fetches all results.

Args:
    cursor (mysql.connector.cursor.MySQLCursor): The active cursor.
    query (str): The query to execute.

Definition at line 358 of file sql_connections.py.

◆ run_editing_command()

int src.lib.sql.sql_connections.SQLManageConnections.run_editing_command ( self,
str sql_query,
str table,
str action_type = "update" )
_summary_
    Function in charge of running the execute and making sure that the connection to the database is still valid.

Args:
    command (str): _description_

Returns:
    int: _description_

Definition at line 471 of file sql_connections.py.

◆ show_connection_info()

None src.lib.sql.sql_connections.SQLManageConnections.show_connection_info ( self,
str func_name = "show_connection_info" )
    Show the connection information

Definition at line 80 of file sql_connections.py.

Field Documentation

◆ db_name

str src.lib.sql.sql_connections.SQLManageConnections.db_name = db_name

Definition at line 42 of file sql_connections.py.

◆ debug

bool src.lib.sql.sql_connections.SQLManageConnections.debug = debug

Definition at line 36 of file sql_connections.py.

◆ disp

Disp src.lib.sql.sql_connections.SQLManageConnections.disp
Initial value:
= Disp(
TOML_CONF,
SAVE_TO_FILE,
FILE_NAME,
debug=self.debug,
logger=self.__class__.__name__
)

Definition at line 44 of file sql_connections.py.

◆ error

int src.lib.sql.sql_connections.SQLManageConnections.error = error

Definition at line 35 of file sql_connections.py.

◆ password

str src.lib.sql.sql_connections.SQLManageConnections.password = password

Definition at line 41 of file sql_connections.py.

◆ pool [1/2]

Union[ src.lib.sql.sql_connections.SQLManageConnections.pool

Definition at line 75 of file sql_connections.py.

◆ pool [2/2]

str src.lib.sql.sql_connections.SQLManageConnections.pool = "ProgrammingError: The pool could not be initialized."

Definition at line 131 of file sql_connections.py.

◆ pool_parameters

dict src.lib.sql.sql_connections.SQLManageConnections.pool_parameters
Initial value:
= {
"pool_name": CONST.DATABASE_POOL_NAME,
"pool_size": CONST.DATABASE_MAX_POOL_CONNECTIONS,
"pool_reset_session": CONST.DATABASE_RESET_POOL_NODE_CONNECTION,
"user": self.username,
"password": self.password,
"host": self.url,
"port": self.port,
"database": self.db_name,
"collation": CONST.DATABASE_COLLATION,
"connection_timeout": CONST.DATABASE_CONNECTION_TIMEOUT,
"allow_local_infile": CONST.DATABASE_LOCAL_INFILE,
"init_command": CONST.DATABASE_INIT_COMMAND,
"option_files": CONST.DATABASE_DEFAULT_FILE, # type error
"autocommit": CONST.DATABASE_AUTOCOMMIT,
"ssl_disabled": not CONST.DATABASE_SSL,
"ssl_key": CONST.DATABASE_SSL_KEY,
"ssl_cert": CONST.DATABASE_SSL_CERT,
"ssl_ca": CONST.DATABASE_SSL_CA,
"ssl_cipher": CONST.DATABASE_SSL_CIPHER,
"ssl_verify_cert": CONST.DATABASE_SSL_VERIFY_CERT
}

Definition at line 52 of file sql_connections.py.

◆ port

int src.lib.sql.sql_connections.SQLManageConnections.port = port

Definition at line 39 of file sql_connections.py.

◆ success

int src.lib.sql.sql_connections.SQLManageConnections.success = success

Definition at line 37 of file sql_connections.py.

◆ url

str src.lib.sql.sql_connections.SQLManageConnections.url = url

Definition at line 38 of file sql_connections.py.

◆ username

str src.lib.sql.sql_connections.SQLManageConnections.username = username

Definition at line 40 of file sql_connections.py.


The documentation for this class was generated from the following file: