I'm relatively new to Python and currently working on a 2nd tutorial, specifically working with SQLite.
In my attached code (specifically the function Update), I have 3 while loops and several breaks within just this simple function. I am thinking that this is not good practice and I am looking for advice to make it less vulnerable to crashing and/or more compact.
What are the side effects of having too many break statements?
def updateData():
global cursor
sql = 'SELECT name FROM sqlite_master WHERE type = "table" ORDER BY name'
cursor.execute(sql)
rows = cursor.fetchall()
print("These are the existing tables in the system:")
tableList = []
for row in rows:
print(row[0])
tableList.append(row[0])
while True:
table = input("Enter table to update: ")
if table in tableList:
while True:
phoneLIST = searchDB()
if len(phoneLIST) == 0:
option = tryMessage()
if not option:
break
else:
numID = int(input("Enter the ID number you want updated: "))
sql = 'PRAGMA table_info(%s)' % table
cursor.execute(sql)
rows = cursor.fetchall()
print("These are the existing columns in %s table:" % table)
colList = []
for row in rows:
print(row[1])
colList.append(row[1])
while True:
column = input("Enter the column name of ID: %d you want updated: " % numID)
column = column.upper()
if column in colList:
if column == 'BOD' or column == 'PID':
print("You can't change Birth of Date OR PID")
option = tryMessage()
if not option:
break
else:
if column == 'PHONE':
newEntry = checkPhone()
elif column == 'POSTAL':
newEntry = checkPostal()
else:
newEntry = input("Enter new information for column %s: " % column)
sql = 'UPDATE %s SET %s = "%s" WHERE PID = %d' % (table, column, newEntry, numID)
cursor.execute(sql)
displayOneEntry(numID)
commitMessage()
break
else:
print("Column not in the table")
break
break
else:
print("Table not in the database")
option = tryMessage()
if not option:
break