Beispiel #1
0
import sys
import traceback
import logging
import python_db 

mysql_username = '******'
mysql_password = '******'

try:
    python_db.open_database('localhost', mysql_username, mysql_password, mysql_username)
    teamName = sys.argv[1]
    query = """SELECT t1.TeamName AS 'Team Name', t1.Nickname, r.GameID, r.ScoreOne AS 'Team Score', 
            r.ScoreTwo AS 'Opponents Score', t2.TeamName AS 'Opponets Name', g.date, r.Winner FROM RESULT r 
            LEFT JOIN TEAM t1 ON r.TeamOneID = t1.TeamID LEFT JOIN TEAM t2 ON r.TeamTwoID = t2.TeamID 
            LEFT JOIN GAME g on r.GameID = g.GameID WHERE t1.TeamName = '""" + teamName + """' UNION 
            SELECT t2.TeamName AS 'Team Name', t2.Nickname, r.GameID, r.ScoreOne AS 'Team Score', 
            r.ScoreTwo AS 'Opponents Score', t1.TeamName AS 'Opponets Name', g.date, r.Winner FROM RESULT r 
            LEFT JOIN TEAM t1 ON r.TeamOneID = t1.TeamID LEFT JOIN TEAM t2 ON r.TeamTwoID = t2.TeamID 
            LEFT JOIN GAME g on r.GameID = g.GameID WHERE t2.TeamName = '""" + teamName + "';" 
    results = python_db.executeSelect(query)
    results = results.split('\n')
    print("<br/>" + "Games that team played in" + results[0] + "<br/>" + results[1])
    for i in range(len(results)):
        print(results[i])
    python_db.close_db()
except Exception as e:
    logging.error(traceback.format_exc())
import sys
import traceback
import logging
import python_db

mysql_username = '******'  # please change to your username
mysql_password = '******'  # please change to your MySQL password

try:
    python_db.open_database('localhost', mysql_username, mysql_password,
                            mysql_username)  # open database
    res = python_db.executeSelect('SELECT * FROM TEAM;')
    res = res.split('\n')  # split the header and data for printing
    print("<br/>" + "Table TEAM before:" + res[0] + "<br/>" + res[1])
    for i in range(len(res) - 2):
        print(res[i + 2])
    teamname = sys.argv[1]
    nickname = sys.argv[2]
    rank = sys.argv[3]
    val = "NULL" + ",'" + teamname + "','" + nickname + "','" + rank + "'"
    python_db.insert("TEAM", val)
    res = python_db.executeSelect('SELECT * FROM TEAM;')
    res = res.split('\n')  # split the header and data for printing
    print("<br/>" + "<br/>")
    print("<br/>" + "Table TEAM after:" + res[0] + "<br/>" + res[1])
    for i in range(len(res) - 2):
        print(res[i + 2])
    python_db.close_db()  # close db
except Exception as e:
    logging.error(traceback.format_exc())