You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.6 KiB
79 lines
2.6 KiB
import dbCommands as db
|
|
|
|
#Connect to the database
|
|
cursor = db.connect("minibase_projects")
|
|
|
|
# This list must represent what the database contains as tables.
|
|
# Chnages in the databse structure must be reflected here
|
|
tables = ["market", "project", "project_element", "segment"]
|
|
|
|
#Tables with the main element of database table.
|
|
tablesColumnNames = [] #name of each column of the table
|
|
tablesPrimaryKeys = [] #Primary key of each table
|
|
tablesForeignKeys = [] #Foreign keys of the table (this is a relational database)
|
|
|
|
#Initialise tables wiht information on the server! This will drastically hep reduce server
|
|
#Requests jus for table indformations
|
|
for table in tables:
|
|
buffer = db.getColumnNames(cursor, table)
|
|
tablesColumnNames.append(buffer)
|
|
|
|
buffer = db.getPrimaryKey(cursor, table)
|
|
tablesPrimaryKeys.append(buffer)
|
|
|
|
buffer = db.getForeignKeys(cursor, table)
|
|
tablesForeignKeys.append(buffer)
|
|
|
|
|
|
#Get the tables contained in this database
|
|
def getTables():
|
|
return tables
|
|
|
|
#Get the foreign keys list of the given table
|
|
def getForeignKeys(table):
|
|
return(tablesForeignKeys[tables.index(table)])
|
|
|
|
#Get the amount of foreign key of the given table
|
|
def getForeignKeyCount(table):
|
|
return(len(tablesForeignKeys[tables.index(table)]))
|
|
|
|
#Get the index of a foreign key's name contained in the given table
|
|
def getForeignKeyIndex(table, keyName):
|
|
return(tablesForeignKeys[tables.index(table)].index(keyName))
|
|
|
|
#Get the name of a foreign key's index contained in the given table
|
|
def getForeignKeyName(table, keyIndex):
|
|
return(tablesForeignKeys[tables.index(table)][keyIndex])
|
|
|
|
#Get the primary key's name of the given table
|
|
def getPrimaryKey(table):
|
|
return(tablesPrimaryKeys[tables.index(table)])
|
|
|
|
#Get the column Names list of the given table
|
|
def getColumnNames(table):
|
|
return(tablesColumnNames[tables.index(table)])
|
|
|
|
#Get the amount of column's of the given table
|
|
def getColumnCount(table):
|
|
return(len(tablesColumnNames[tables.index(table)]))
|
|
|
|
#Get the index of a column's name contained in the given table
|
|
def getColumnNameIndex(table, columnName):
|
|
return(tablesColumnNames[tables.index(table)].index(columnName))
|
|
|
|
#Get the name of a columns's index contained in the given table
|
|
def getColumnName(table, columnIndex):
|
|
return(tablesColumnNames[tables.index(table)][columnIndex])
|
|
|
|
def printTablesInfo():
|
|
for table in getTables():
|
|
print( "Table: " + table)
|
|
print( " - Primary Key : " + getPrimaryKey(table))
|
|
for column in getColumnNames(table):
|
|
print( " - Colum: " + column)
|
|
for key in getForeignKeys(table):
|
|
print( " - Foreign Key : " + key)
|
|
|
|
printTablesInfo()
|
|
|