###################################################################
# SQLITE - Describe table
###################################################################
import sqlite3

conn  = sqlite3.connect('/home/sultans/data/sqlite/sqlite.db')      #server database
#conn = sqlite3.connect('/sqlite/sqlite.db')                        #local database 
curs  = conn.cursor( )

sql = "SELECT * FROM pragma_table_info('student')"

curs.execute(sql)

for elem in curs.description:                   #description is a 2dim tuple metadata 
    col_name = elem[0]                          #1st element of each tuple is column name 
    col_name = col_name.upper()                 #optional uppercase
    print("%-12s" % col_name, end='')           #print column name as 12 char, left justify
print()

result = curs.fetchall()                        #get the query result

for row in result:                              #for each row
    for col in row:                             #for each column
        print("%-12s" % col, end='')            #print column as 12 char, left justify
    print()

if not result:
    print('Table does not exist')
    
curs.close()
conn.close()