本文整理匯總了Python中db.DB.fetchall方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.fetchall方法的具體用法?Python DB.fetchall怎麽用?Python DB.fetchall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.fetchall方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: player_standings
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import fetchall [as 別名]
def player_standings():
"""
Returns a list of the players and their win records, sorted by wins.
The first entry in the list should be the player in first place, or a player
tied for first place if there is currently a tie.
Returns:
A list of tuples, each of which contains (id, name, wins, matches):
id: the player's unique id (assigned by the database)
name: the player's full name (as registered)
wins: the number of matches the player has won
matches: the number of matches the player has played
"""
query = 'SELECT * FROM "player_standings"'
cursor = DB().execute(query)["cursor"]
standings = cursor.fetchall()
cursor.close()
return standings
示例2: swiss_pairings
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import fetchall [as 別名]
def swiss_pairings():
"""
Returns a list of pairs of players for the next round of a match.
Assuming that there are an even number of players registered, each player
appears exactly once in the pairings. Each player is paired with another
player with an equal or nearly-equal win record, that is, a player adjacent
to him or her in the standings.
Returns:
A list of tuples, each of which contains (id1, name1, id2, name2)
id1: the first player's unique id
name1: the first player's name
id2: the second player's unique id
name2: the second player's name
"""
query = 'SELECT * FROM "swiss_pairings"'
cursor = DB().execute(query)["cursor"]
pairings = cursor.fetchall()
cursor.close()
return pairings