當前位置: 首頁>>代碼示例>>Python>>正文


Python CommonUtils.getConnect方法代碼示例

本文整理匯總了Python中CommonUtils.getConnect方法的典型用法代碼示例。如果您正苦於以下問題:Python CommonUtils.getConnect方法的具體用法?Python CommonUtils.getConnect怎麽用?Python CommonUtils.getConnect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CommonUtils的用法示例。


在下文中一共展示了CommonUtils.getConnect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: insertPlayer

# 需要導入模塊: import CommonUtils [as 別名]
# 或者: from CommonUtils import getConnect [as 別名]
def insertPlayer(players):
    insertSql = "insert into player(player_zn_name,player_eng_name,team,location,height,weight,birthday,money) " \
                "values(""?,?,?,?,?,?,?,?)"
    selectSql = "select * from player where player_eng_name = ? and birthday=?"
    updateSql = "update player set team=?,location=?,height =?,weight=?,birthday=?,money=?,player_zn_name=? where player_eng_name=? and birthday=?"

    conn = CommonUtils.getConnect()
    cu = conn.cursor()

    #cu.execute("delete from player")

    insertValues = []
    updateValues = []
    for player in players:
        # 先判斷是否存在此球員
        cu.execute(selectSql, (player.playerEngName, player.birthday))
        result = cu.fetchall()
        if(len(result) == 0):
            #若不存在,則直接插入
            insertValues.append((player.playerZnName, player.playerEngName, player.teamName, player.location, player.height, player.weight, player.birthday, player.money))
        else:
            # 若存在,則直接更新即可
            updateValues.append((player.teamName,player.location,player.height,player.weight,player.birthday,player.money,player.playerZnName,player.playerEngName,player.birthday))

    # before insert,delete data that is older
    #cu.execute("delete from player")
    # insert player data
    print "新增數據" + str(len(insertValues))
    print "更新數據" + str(len(updateValues))
    cu.executemany(insertSql,insertValues)
    cu.executemany(updateSql,updateValues)
    conn.commit()
    conn.close()
開發者ID:jinkingmanager,項目名稱:my_python_code,代碼行數:35,代碼來源:DAO.py

示例2: insertSchedules

# 需要導入模塊: import CommonUtils [as 別名]
# 或者: from CommonUtils import getConnect [as 別名]
def insertSchedules(schedules):
	insertSql = "insert into point(type,date,time,weekday,guest,home) values (?,?,?,?,?,?)"

	insertValus = []
	for point in schedules:
		schedule = (point.type,point.date,point.time,point.weekday,point.guest,point.home)
		insertValus.append(schedule)

	conn = CommonUtils.getConnect()
	cu = conn.cursor()
	cu.execute("delete from point")
	cu.executemany(insertSql,insertValus)
	conn.commit()
	conn.close()
開發者ID:jinkingmanager,項目名稱:my_python_code,代碼行數:16,代碼來源:DAO.py

示例3: insertTeam

# 需要導入模塊: import CommonUtils [as 別名]
# 或者: from CommonUtils import getConnect [as 別名]
def insertTeam(teams):
    insertSql = "insert into team(eng_name,chinese_name,city,short_name) values(?,?,?,?)"

    insertValues = []
    for team in teams:
        value = (team.engName, team.chineseName, team.city, team.shortName)
        insertValues.append(value)

    conn = CommonUtils.getConnect()
    cu = conn.cursor()
    cu.execute("delete from team")
    cu.executemany(insertSql, insertValues)
    conn.commit()
    conn.close()
開發者ID:jinkingmanager,項目名稱:my_python_code,代碼行數:16,代碼來源:DAO.py


注:本文中的CommonUtils.getConnect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。