I have a several postgres and mysql cursor objects exposed to me, created in some universe. How to find the database name (and other info about that db) from these cursor objects?
cursor.__dict__
gives nothing useful.
I don't know about postgres but using MySQLdb you could always use the following:
cursor.execute("select database()")
db_name = cursor.fetchone()[0]
Maybe there's a cleaner way to do this...
Edit:
for other info it depends on what exactly you're looking for but for example to fetch table names
cursor.execute("show tables")
for r in cursor.fetchall():
print r[0]
There are many other functions available... Is there anything specific you're looking for?
If you also have the connection (call it conn):
conn.info.dbname
for postgresql:-
cursor.execute("select current_database()")
db_name = cursor.fetchone()[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With