Python: how to know which database I am connecting to?
Question:
I have a very odd problem. I am able to access a database because someone installed the right ODBC drivers on my computer, but I dont know
- what type of ODBC drivers are installed
- which flavor of SQL is it
All I can do is
import pyodbc
import pandas as pd
import numpy as np
cnxn = pyodbc.connect('DSN=MYDSN')
sql = "SELECT * FROM MASTER.PRICES"
cursor.execute(sql)
data = cursor.fetchone()
which returns some data.
But thats all I know. Which SQL command can I run to know more about this mysterious database?
Thanks!
Answers:
pyodbc
provides the getinfo
method.
>>> cnxn.getinfo(pyodbc.SQL_DBMS_NAME)
'MySQL'
>>> cnxn.getinfo(pyodbc.SQL_DBMS_VER)
'10.1.21-MariaDB'
>>> cnxn.getinfo(pyodbc.SQL_DRIVER_NAME)
'libmyodbc5w.so'
Here are just a few examples, you can find all the available constants in the documentation.
I have a very odd problem. I am able to access a database because someone installed the right ODBC drivers on my computer, but I dont know
- what type of ODBC drivers are installed
- which flavor of SQL is it
All I can do is
import pyodbc
import pandas as pd
import numpy as np
cnxn = pyodbc.connect('DSN=MYDSN')
sql = "SELECT * FROM MASTER.PRICES"
cursor.execute(sql)
data = cursor.fetchone()
which returns some data.
But thats all I know. Which SQL command can I run to know more about this mysterious database?
Thanks!
pyodbc
provides the getinfo
method.
>>> cnxn.getinfo(pyodbc.SQL_DBMS_NAME)
'MySQL'
>>> cnxn.getinfo(pyodbc.SQL_DBMS_VER)
'10.1.21-MariaDB'
>>> cnxn.getinfo(pyodbc.SQL_DRIVER_NAME)
'libmyodbc5w.so'
Here are just a few examples, you can find all the available constants in the documentation.