October 2002
Intermediate to advanced
1024 pages
27h 26m
English
Has any database been selected as the current database? What is its name?
Use the DATABASE( ) function.
SELECT DATABASE( ) returns the
name of the current database, or the empty string if no database has
been selected. This Python code uses the statement to present a
status display containing information about the current connection:
cursor = conn.cursor ( )
cursor.execute ("SELECT DATABASE( )")
row = cursor.fetchone ( )
cursor.close
if row == None or len (row) == 0 or row[0] == "":
db = "(no database selected)"
else:
db = row[0]
print "Current database:", db