import pymysql.cursors

debug = True

#Drop the previous tables
#drop_existing_tables(cursor)
#Load in the new data

def open():
	# Open database connection
	db = pymysql.connect(host="100.15.105.119",user="adder",password="cmsc424",db="MondialDB")
	#cursor = db.cursor()
	return db

def close(db):
	#Disconnect from server
	db.close()

def safe_execute(db, sql):
	with db.cursor() as cursor:
		try:
			# Execute the SQL command													 
			cursor.execute(sql)
			# Commit changes in the database
			db.commit()
			return cursor.fetchone()
		except:
			# Rollback in case there is any error											
			db.rollback()

def insert_cup(db, name,year):		
	"Insert one world cup edition"
	#INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);
	sql = "INSERT INTO CUP (CupYear,CupName) VALUES (" + year + "," + name + ");"
	print(sql)
	safe_execute(db, sql)
	
def retrieve_cups(db):
	sql = "SELECT * FROM CUP"
	print(sql)
	results = safe_execute(db,sql)
	print(results)
	
def drop_existing_tables(db):
	"Drop certain tables if they already exist"
	safe_execute(db,"DROP TABLE IF EXISTS CUP")
	safe_execute(db,"DROP TABLE IF EXISTS CUP_MEMBER")
	safe_execute(db,"DROP TABLE IF EXISTS TEAM_MEMBER")
	safe_execute(db,"DROP TABLE IF EXISTS TEAM")
	safe_execute(db,"DROP TABLE IF EXISTS PLAYER")
	safe_execute(db,"DROP TABLE IF EXISTS PENALTY")
	safe_execute(db,"DROP TABLE IF EXISTS GOAL")
	safe_execute(db,"DROP TABLE IF EXISTS MATCH")

def create_player_table(db):
	sql = """CREATE TABLE PLAYER (
	FIRST_NAME  CHAR(20) NOT NULL,
	LAST_NAME  CHAR(20)),
	PID INTEGER,
	PRIMARY KEY (PID)
	"""
	safe_execute(db, sql)

@@ -7,23 +7,26 @@
  pymysql
-.cursor
+%0Aimport sy
 s%0A%0Adebug
@@ -535,19 +535,198 @@
 or.fetch
-one
+all()%0A%09%09except pymysql.DataError as e:%0A%09%09%09print(%22Data Error %22 + str(e))%0A%09%09%09db.rollback()%0A%09%09except pymysql.ProgrammingError as e:%0A%09%09%09print(%22Programming Error%22 + str(e))%0A%09%09%09db.rollback
 ()%0A%09%09exc
@@ -771,26 +771,47 @@
 y error%09
+%0A
 %09%09%09
-%09%09%09%09%09%09%09
+print(%22SOMETHING HAPPENED%22)
 %0A%09%09%09db.r
@@ -997,18 +997,18 @@
 T INTO C
-UP
+up
  (CupYea
@@ -1039,16 +1039,17 @@
 ear + %22,
+'
 %22 + name
@@ -1052,16 +1052,17 @@
 name + %22
+'
 );%22%0A%09pri
@@ -1140,18 +1140,19 @@
 * FROM C
-UP
+up;
 %22%0A%09print
@@ -1157,16 +1157,37 @@
 nt(sql)%0A
+%09print(%22RESULTS---%22)%0A
 %09results

Fix capitalization and quotes