本文整理汇总了Python中database.DatabaseManager.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.getInstance方法的具体用法?Python DatabaseManager.getInstance怎么用?Python DatabaseManager.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.getInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createCharacter
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import getInstance [as 别名]
def createCharacter(account, name, model):
if hasPlayer(name):
raise CharacterAlreadyExists()
try:
ID = idFactory.createID()
# these values are only for test puporse, must be tested and fixed
# all players stats must be saved on DB
if model == 1:
spd = 2
df = 2
fc = 2
hp = 300
elif model == 2:
spd = 1
df = 2
fc = 3
hp = 350
elif model == 3:
spd = 3
df = 1
fc = 2
hp = 250
DB.getInstance().query("INSERT INTO Players (ID, account, name, speed, defense, `force`, maxHp, hp, model)" \
"Values (%s,%s,%s,%s,%s,%s,%s,%s,%s)",(ID,account,name,spd,df,fc,hp,hp,model))
except Exception, e:
print e
return False
示例2: loadPlayer
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import getInstance [as 别名]
def loadPlayer(ID):
rs = DB.getInstance().query("SELECT * FROM Players WHERE ID = %s",ID)
if rs.next():
player = Player()
player.ID = rs.getInt('ID')
player.name = rs.getString('name')
player.speed = rs.getInt('speed')
player.defense = rs.getInt('defense')
player.force = rs.getInt('force')
player.maxHp = rs.getInt('maxHp')
player.hp = rs.getInt('hp')
player.level = rs.getInt('level')
player.x = rs.getInt('x')
player.y = rs.getInt('y')
player.exp = rs.getInt('exp')
player.model = rs.getInt('model')
player.heading = rs.getInt('heading')
return player
示例3: load
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import getInstance [as 别名]
def load(self):
rs = DB.getInstance().query("SELECT ID FROM Players")
while rs.next():
self.allocate(rs.getInt('ID'))
print "All IDs loaded"
示例4: deletePlayer
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import getInstance [as 别名]
def deletePlayer(ID):
try:
DB.getInstance().query("DELETE FROM Players WHERE ID = %s",ID)
except:
return False
return True
示例5: hasPlayer
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import getInstance [as 别名]
def hasPlayer(name):
return not DB.getInstance().query("SELECT ID FROM Players WHERE name = %s",name).empty()
示例6: getPlayer
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import getInstance [as 别名]
def getPlayer(account):
return DB.getInstance().query("SELECT * FROM Players WHERE account = %s",account)