###################################################################
# SQLITE - Select
###################################################################
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 student
'''
curs.execute(sql)

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

### Print column headers #######################################
for elem in metadata:                           #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 for better display
    print("%-15s" % col_name, end='')           #print column name as 15 char, left justify
print()

### Print column values ########################################
for row in result:                              #for each row
    for col in row:                             #for each column
        print("%-15s" % col, end='')            #print column as 15 char, left justify
    print()
    
curs.close()
conn.close()