Determine SQL Dialect from Cursor? #983
-
Hi All, Is there anyway to determine which SQL dialect(mssql, Postgres, etc...) is being used from the cursor object? The use case I have is, I have a variety of functions that take cursor as an argument, and depending on what database is being written to, those functions will obviously vary slightly depending on the dialect being used. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can use cursor.connection.getinfo to query some properties which could give you a hint what the connection is for (https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetinfo-function - see SQL_DRIVER_NAME, SQL_DBMS_NAME etc..) But I would really recommend DBMS-specific stuff be put at a different layer so you don't need to query this information in the first place. |
Beta Was this translation helpful? Give feedback.
-
I had to make a python script that has exactly the same requirement, but to decouple the script from what DB it's running on, I take the connection type from command line argument, than I have a class called ConnectionManager that has a method and depending on the argument I give, it chooses what driver class it will instantiate and return to the caller. To make it possible, I created an Interface that all DB drivers written must agree to implement, so the main script always knows what functions it can call and, independently of the returned driver, it will always have those functions to be called. It's a mini DBAL. |
Beta Was this translation helpful? Give feedback.
You can use cursor.connection.getinfo to query some properties which could give you a hint what the connection is for (https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetinfo-function - see SQL_DRIVER_NAME, SQL_DBMS_NAME etc..) But I would really recommend DBMS-specific stuff be put at a different layer so you don't need to query this information in the first place.