cardinal_pythonlib.sqlalchemy.engine_func
Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).
This file is part of cardinal_pythonlib.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Functions to help with SQLAlchemy Engines.
- cardinal_pythonlib.sqlalchemy.engine_func.get_sqlserver_product_version(engine: Engine) Tuple[int, ...][source]
Gets SQL Server version information.
Attempted to use
dialect.server_version_info:from sqlalchemy import create_engine url = "mssql+pyodbc://USER:PASSWORD@ODBC_NAME" engine = create_engine(url, future=True) dialect = engine.dialect vi = dialect.server_version_info
Unfortunately,
vi == ()for an SQL Server 2014 instance viamssql+pyodbc. It’s alsoNonefor amysql+pymysqlconnection. So this seemsserver_version_infois a badly supported feature.So the only other way is to ask the database directly. The problem is that this requires an
Engineor similar. (The initial hope was to be able to use this from within SQL compilation hooks, to vary the SQL based on the engine version. Still, this isn’t so bad.)We could use either
SELECT @@version; -- returns a human-readable string SELECT SERVERPROPERTY('ProductVersion'); -- better
The
pyodbcinterface will fall over withODBC SQL type -150 is not yet supportedwith that last call, though, meaning that aVARIANTis coming back, so weCASTas per the source below.
- cardinal_pythonlib.sqlalchemy.engine_func.is_databricks(engine: Engine) bool[source]
Is the SQLAlchemy
Enginea Databricks database?
- cardinal_pythonlib.sqlalchemy.engine_func.is_mysql(engine: Engine) bool[source]
Is the SQLAlchemy
Enginea MySQL/MariaDB database?