PyStratum SQL Server¶
A stored procedure and function loader and wrapper generator for SQL Server Python.
Licence¶
This project is licensed under the terms of the MIT-licentie.
API¶
pystratum_mssql package¶
Subpackages¶
pystratum_mssql.backend package¶
Submodules¶
pystratum_mssql.backend.MsSqlBackend module¶
-
class
pystratum_mssql.backend.MsSqlBackend.
MsSqlBackend
[source]¶ Bases:
pystratum_backend.Backend.Backend
PyStratum Backend for MS SQL Server.
-
create_constant_worker
(config: configparser.ConfigParser, io: pystratum_backend.StratumStyle.StratumStyle) → Optional[pystratum_backend.ConstantWorker.ConstantWorker][source]¶ Creates the object that does the actual execution of the constant command for the backend.
Parameters: - config (ConfigParser) – The settings from the PyStratum configuration file.
- io (StratumStyle) – The output object.
Return type: ConstantWorker|None
-
create_routine_loader_worker
(config: configparser.ConfigParser, io: pystratum_backend.StratumStyle.StratumStyle) → Optional[pystratum_backend.RoutineLoaderWorker.RoutineLoaderWorker][source]¶ Creates the object that does the actual execution of the routine loader command for the backend.
Parameters: - config (ConfigParser) – The settings from the PyStratum configuration file.
- io (StratumStyle) – The output object.
Return type: RoutineLoaderWorker|None
-
create_routine_wrapper_generator_worker
(config: configparser.ConfigParser, io: pystratum_backend.StratumStyle.StratumStyle) → Optional[pystratum_backend.RoutineWrapperGeneratorWorker.RoutineWrapperGeneratorWorker][source]¶ Creates the object that does the actual execution of the routine wrapper generator command for the backend.
Parameters: - config (ConfigParser) – The settings from the PyStratum configuration file.
- io (StratumStyle) – The output object.
Return type: RoutineWrapperGeneratorWorker|None
-
pystratum_mssql.backend.MsSqlConstantWorker module¶
PyStratum
-
class
pystratum_mssql.backend.MsSqlConstantWorker.
MsSqlConstantWorker
(io: pystratum_backend.StratumStyle.StratumStyle, config: configparser.ConfigParser)[source]¶ Bases:
pystratum_mssql.backend.MsSqlWorker.MsSqlWorker
,pystratum_common.backend.CommonConstantWorker.CommonConstantWorker
Class for creating constants based on column widths, and auto increment columns and labels for SQL Server databases.
pystratum_mssql.backend.MsSqlRoutineLoaderWorker module¶
-
class
pystratum_mssql.backend.MsSqlRoutineLoaderWorker.
MsSqlRoutineLoaderWorker
(io: pystratum_backend.StratumStyle.StratumStyle, config: configparser.ConfigParser)[source]¶ Bases:
pystratum_mssql.backend.MsSqlWorker.MsSqlWorker
,pystratum_common.backend.CommonRoutineLoaderWorker.CommonRoutineLoaderWorker
Class for loading stored routines into a SQL Server instance from pseudo SQL files.
pystratum_mssql.backend.MsSqlRoutineWrapperGeneratorWorker module¶
-
class
pystratum_mssql.backend.MsSqlRoutineWrapperGeneratorWorker.
MsSqlRoutineWrapperGeneratorWorker
(io: pystratum_backend.StratumStyle.StratumStyle, config: configparser.ConfigParser)[source]¶ Bases:
pystratum_mssql.backend.MsSqlWorker.MsSqlWorker
,pystratum_common.backend.CommonRoutineWrapperGeneratorWorker.CommonRoutineWrapperGeneratorWorker
Class for generating a class with wrapper methods for calling stored routines in a SQL Server database.
pystratum_mssql.backend.MsSqlWorker module¶
Module contents¶
pystratum_mssql.helper package¶
Submodules¶
pystratum_mssql.helper.MsSqlDataTypeHelper module¶
-
class
pystratum_mssql.helper.MsSqlDataTypeHelper.
MsSqlDataTypeHelper
[source]¶ Bases:
pystratum_common.helper.DataTypeHelper.DataTypeHelper
Utility class for deriving information based on a SQL Server data type.
pystratum_mssql.helper.MsSqlRoutineLoaderHelper module¶
-
class
pystratum_mssql.helper.MsSqlRoutineLoaderHelper.
MsSqlRoutineLoaderHelper
(io: pystratum_backend.StratumStyle.StratumStyle, dl: pystratum_mssql.MsSqlMetadataDataLayer.MsSqlMetadataDataLayer, routine_filename, routine_file_encoding, pystratum_old_metadata, replace_pairs, rdbms_old_metadata)[source]¶ Bases:
pystratum_common.helper.RoutineLoaderHelper.RoutineLoaderHelper
Class for loading a single stored routine into a SQL Server instance from a (pseudo) SQL file.
Module contents¶
pystratum_mssql.wrapper package¶
Submodules¶
pystratum_mssql.wrapper.MsSqlFunctionsWrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlFunctionsWrapper.
MsSqlFunctionsWrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
,pystratum_common.wrapper.FunctionsWrapper.FunctionsWrapper
Wrapper method generator for stored functions.
pystratum_mssql.wrapper.MsSqlLogWrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlLogWrapper.
MsSqlLogWrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
,pystratum_common.wrapper.LogWrapper.LogWrapper
Wrapper method generator for stored procedures with designation type log.
pystratum_mssql.wrapper.MsSqlNoneWrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlNoneWrapper.
MsSqlNoneWrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
,pystratum_common.wrapper.NoneWrapper.NoneWrapper
Wrapper method generator for stored procedures without any result set.
pystratum_mssql.wrapper.MsSqlRow0Wrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlRow0Wrapper.
MsSqlRow0Wrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
,pystratum_common.wrapper.Row0Wrapper.Row0Wrapper
Wrapper method generator for stored procedures that are selecting 0 or 1 row.
pystratum_mssql.wrapper.MsSqlRow1Wrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlRow1Wrapper.
MsSqlRow1Wrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
,pystratum_common.wrapper.Row1Wrapper.Row1Wrapper
Wrapper method generator for stored procedures that are selecting 1 row.
pystratum_mssql.wrapper.MsSqlRowsWithIndexWrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlRowsWithIndexWrapper.
MsSqlRowsWithIndexWrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_common.wrapper.RowsWithIndexWrapper.RowsWithIndexWrapper
,pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
Wrapper method generator for stored procedures whose result set must be returned using tree structure using a combination of non-unique columns.
pystratum_mssql.wrapper.MsSqlRowsWithKeyWrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlRowsWithKeyWrapper.
MsSqlRowsWithKeyWrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_common.wrapper.RowsWithKeyWrapper.RowsWithKeyWrapper
,pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
Wrapper method generator for stored procedures whose result set must be returned using tree structure using a combination of unique columns.
pystratum_mssql.wrapper.MsSqlRowsWrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlRowsWrapper.
MsSqlRowsWrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
,pystratum_common.wrapper.RowsWrapper.RowsWrapper
Wrapper method generator for stored procedures that are selecting 0, 1, or more rows.
pystratum_mssql.wrapper.MsSqlSingleton0Wrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlSingleton0Wrapper.
MsSqlSingleton0Wrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
,pystratum_common.wrapper.Singleton0Wrapper.Singleton0Wrapper
Wrapper method generator for stored procedures that are selecting 0 or 1 row with one column only.
pystratum_mssql.wrapper.MsSqlSingleton1Wrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlSingleton1Wrapper.
MsSqlSingleton1Wrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
,pystratum_common.wrapper.Singleton1Wrapper.Singleton1Wrapper
Wrapper method generator for stored procedures that are selecting 1 row with one column only.
pystratum_mssql.wrapper.MsSqlTableWrapper module¶
-
class
pystratum_mssql.wrapper.MsSqlTableWrapper.
MsSqlTableWrapper
(routine: Dict[str, Any], lob_as_string_flag: bool)[source]¶ Bases:
pystratum_mssql.wrapper.MsSqlWrapper.MsSqlWrapper
,pystratum_common.wrapper.TableWrapper.TableWrapper
Wrapper method generator for printing the result set of stored procedures in a table format.
pystratum_mssql.wrapper.MsSqlWrapper module¶
Submodules¶
pystratum_mssql.MsSqlConnector module¶
pystratum_mssql.MsSqlDataLayer module¶
-
class
pystratum_mssql.MsSqlDataLayer.
MsSqlDataLayer
(connector: pystratum_mssql.MsSqlConnector.MsSqlConnector)[source]¶ Bases:
object
Class for connecting to a SQL Server instance and executing SQL statements. Also, a parent class for classes with static wrapper methods for executing stored procedures and functions.
-
autocommit
(status: bool) → None[source]¶ Sets auto commit mode. See http://pymssql.org/en/stable/ref/pymssql.html#pymssql.Connection.autocommit.
Parameters: status (bool) – True: Auto commit on. False: Auto commit off.
-
commit
() → None[source]¶ Commits the current transaction. See http://pymssql.org/en/stable/ref/pymssql.html#pymssql.Connection.commit.
-
disconnect
() → None[source]¶ Disconnects from the MS SQL Server instance. See http://pymssql.org/en/stable/ref/pymssql.html#pymssql.Connection.close.
-
execute_log
(sql: str, *params) → int[source]¶ Executes a query with log statements. Returns the number of lines in the log.
Parameters: - sql (str) – The SQL statement.
- params (iterable) – The parameters.
Return type:
-
execute_none
(sql: str, *params) → None[source]¶ Executes a query that does not select any rows.
Parameters: - sql (str) – The SQL statement.
- params (iterable) – The parameters.
Return type:
-
execute_row0
(sql, *params) → Optional[Dict[str, Any]][source]¶ Executes a query that selects 0 or 1 row. Returns the selected row or None.
Parameters: - sql (str) – The SQL statement.
- params (iterable) – The parameters.
Return type: None|dict[str,*]
-
execute_row1
(sql: str, *params) → Dict[str, Any][source]¶ Executes a query that selects 1 row. Returns the selected row.
Parameters: - sql (str) – The SQL statement.
- params (iterable) – The parameters.
Return type:
-
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 parameters.
Return type:
-
execute_singleton0
(sql: str, *params) → Any[source]¶ Executes a query that selects 0 or 1 row with 1 column. Returns the value of selected column or None.
Parameters: - sql (str) – The SQL statement.
- params (iterable) – The parameters.
Return type:
-
execute_singleton1
(sql: str, *params) → Any[source]¶ Executes a query that selects 1 row with 1 column. Returns the value of the selected column.
:param str sql:The SQL statement. :param iterable params: The parameters.
Return type:
-
execute_sp_none
(sql: str, *params) → None[source]¶ Executes a stored routine that does not select any rows.
Parameters: - sql (str) – The SQL calling the stored procedure.
- params (iterable) – The parameters for the stored procedure.
Return type:
-
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 parameters 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 parameters for the stored procedure.
Return type:
-
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 calling the the stored procedure.
- params (iterable) – The parameters for the stored procedure.
Return type:
-
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 parameters 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 parameters for the stored procedure.
Return type: - The value of the selected column.
-
line_buffered
= True¶ If True log messages from stored procedures with designation type ‘log’ are line buffered (Note: In python sys.stdout is buffered by default).
Type: bool
-
rollback
() → None[source]¶ Rolls back the current transaction. See http://pymssql.org/en/stable/ref/pymssql.html#pymssql.Connection.rollback.
-
pystratum_mssql.MsSqlDefaultConnector module¶
-
class
pystratum_mssql.MsSqlDefaultConnector.
MsSqlDefaultConnector
(params: Dict[str, Union[str, int]])[source]¶ Bases:
pystratum_mssql.MsSqlConnector.MsSqlConnector
Connects to a MySQL instance using user name and password.
pystratum_mssql.MsSqlMetadataDataLayer module¶
-
class
pystratum_mssql.MsSqlMetadataDataLayer.
MsSqlMetadataDataLayer
(io: pystratum_backend.StratumStyle.StratumStyle, connector: pystratum_mssql.MsSqlConnector.MsSqlConnector)[source]¶ Bases:
pystratum_common.MetadataDataLayer.MetadataDataLayer
Data layer for retrieving metadata and loading stored routines.
-
drop_stored_routine
(routine_type: str, schema_name: str, routine_name: str) → None[source]¶ Drops a stored routine if it exists.
Parameters:
-
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) → None[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,*]]
-
get_all_table_columns
() → List[Dict[str, Any]][source]¶ Selects metadata of all columns of all tables.
Return type: list[dict[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
(database_name: str, schema_name: str, 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: Return type:
-