parent
ae48a9ed30
commit
7fcfafffdc
@ -0,0 +1,66 @@
|
||||
import mariadb
|
||||
import sys
|
||||
|
||||
cursor = mariadb.cursors.Cursor
|
||||
|
||||
#Connects to the databse with the given user
|
||||
def connect(dbName):
|
||||
# Connect to MariaDB Platform
|
||||
try:
|
||||
conn = mariadb.connect(
|
||||
user="root",
|
||||
password="KyKvMdRt586591!*",
|
||||
host="db.keydev.me",
|
||||
port=3306,
|
||||
database=dbName
|
||||
)
|
||||
except mariadb.Error as e:
|
||||
print(f"Error connecting to MariaDB Platform: {e}")
|
||||
sys.exit(1)
|
||||
cur = conn.cursor()
|
||||
|
||||
return cur
|
||||
|
||||
def getColumnNames(cursor, table):
|
||||
command = "SHOW COLUMNS FROM " + table
|
||||
cursor.execute(command)
|
||||
colName = []
|
||||
index = 0
|
||||
for row in cursor:
|
||||
colName.append(row[0])
|
||||
return colName
|
||||
|
||||
def getForeignKeys(cursor, table):
|
||||
command = "SHOW INDEX FROM " + table
|
||||
cursor.execute(command)
|
||||
colName = []
|
||||
index = 0
|
||||
for row in cursor:
|
||||
if not row[2] == "PRIMARY":
|
||||
colName.append(row[4])
|
||||
return colName
|
||||
|
||||
def getPrimaryKey(cursor, table):
|
||||
command = "SHOW INDEX FROM " + table
|
||||
cursor.execute(command)
|
||||
index = 0
|
||||
for row in cursor:
|
||||
if row[2] == "PRIMARY":
|
||||
pk = row[4]
|
||||
return pk
|
||||
|
||||
|
||||
|
||||
'''
|
||||
tableProject = dbGetTableColNames(cursorProjects, "project")
|
||||
# Get Cursor
|
||||
curProject.execute("SELECT name, description FROM project")
|
||||
|
||||
for (name, description) in curProject:
|
||||
print(f"Name : {name}, What: {description}")
|
||||
|
||||
|
||||
cursor.execute("select * from project")
|
||||
for row in curProject:
|
||||
print(row)
|
||||
'''
|
||||
@ -0,0 +1,78 @@
|
||||
import dbCommands as db
|
||||
|
||||
#Connect to the database
|
||||
cursorProjects = 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(cursorProjects, table)
|
||||
tablesColumnNames.append(buffer)
|
||||
|
||||
buffer = db.getPrimaryKey(cursorProjects, table)
|
||||
tablesPrimaryKeys.append(buffer)
|
||||
|
||||
buffer = db.getForeignKeys(cursorProjects, 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()
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
import dbCommands as db
|
||||
|
||||
#Connect to the database
|
||||
cursor = db.connect("minibase_materials")
|
||||
|
||||
# This list must represent what the database contains as tables.
|
||||
# Chnages in the databse structure must be reflected here
|
||||
tables = ["classification", "packaging", "physical", "product"]
|
||||
|
||||
#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()
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
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()
|
||||
|
||||
@ -0,0 +1,78 @@
|
||||
import dbCommands as db
|
||||
|
||||
#Connect to the database
|
||||
cursor = db.connect("minibase_relationships")
|
||||
|
||||
# This list must represent what the database contains as tables.
|
||||
# Chnages in the databse structure must be reflected here
|
||||
tables = ["company", "company_role", "person", "person_role"]
|
||||
|
||||
#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()
|
||||
|
||||
|
Can't render this file because it is too large.
|
|
Can't render this file because it is too large.
|
|
Can't render this file because it is too large.
|
|
Can't render this file because it is too large.
|
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in new issue