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.

67 lines
1.5 KiB

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)
'''