本文整理汇总了Python中dbutils.DBConnection.last方法的典型用法代码示例。如果您正苦于以下问题:Python DBConnection.last方法的具体用法?Python DBConnection.last怎么用?Python DBConnection.last使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dbutils.DBConnection
的用法示例。
在下文中一共展示了DBConnection.last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get(city_id, dbconnection:dbutils.DBConnection=None) -> City:
if isinstance(city_id, str) and len(city_id.split(',')) > 0:
city_id = splitstrlist(city_id)
if len(city_id) == 1:
city_id = city_id[0]
if isinstance(city_id, list) and len(city_id) == 0: return list()
if isinstance(city_id, int) and city_id != 0:
dbconnection.execute("SELECT * FROM cities WHERE city_id='{}'".format(city_id), dbutils.dbfields['cities'])
elif isinstance(city_id, list):
dbconnection.execute("SELECT * FROM cities WHERE city_id IN (" + ','.join(map(str, city_id)) + ")",
dbutils.dbfields['cities'])
elif city_id == 0:
dbconnection.execute("SELECT * FROM cities", dbutils.dbfields['cities'])
if len(dbconnection.last()) == 0: return list()
cities = dbconnection.last()
cities = list(map(lambda x: City(x), cities))
if isinstance(city_id, int) and city_id != 0:
return cities[0]
elif isinstance(city_id, list) or city_id == 0:
return cities
示例2: add_game_finances
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def add_game_finances(game_id:int, dbconnection:dbutils.DBConnection=None):
finances = calc_game(game_id, dbconnection=dbconnection)
sql = "INSERT INTO finances VALUES ({})".format(', '.join(["'{}'".format(finances[i]) for i in dbutils.dbfields['finances']]))
dbconnection.execute(sql)
dbconnection.execute("SELECT percents FROM responsible_salary WHERE user_id={}".format(finances['responsible_user_id']))
if len(dbconnection.last())>0:
percents = dbconnection.last()[0][0]
dbconnection.execute("INSERT INTO responsible_games_salary VALUES ({}, {}, {}, {}, {})".format(
finances['responsible_user_id'], game_id, finances['profit'], percents, finances['responsible_salary']))
dbconnection.execute("SELECT * FROM finance_balance WHERE user_id!=0 AND YEAR(date)={} AND MONTH(date)={}".format(
finances['datetime'].date().year, finances['datetime'].date().month), dbutils.dbfields['finance_balance'])
if len(dbconnection.last())==0:
dbconnection.execute("INSERT INTO finance_balance VALUES ('Александр Горохов', 0, 3, '{year}-{month}-01', 50), ('Виталий Харченко', 0, 1, '{year}-{month}-01', 50)".format(
year=finances['datetime'].date().year, month=finances['datetime'].date().month))
owners = dbconnection.last()
balance = dbconnection.execute("SELECT * FROM finance_balance WHERE user_id=0", dbutils.dbfields['finance_balance'])[0]
for owner in owners:
percents = owner['percents']
money = round(finances['real_profit']*(percents/100))
if owner['user_id']==finances['responsible_user_id']:
money += finances['responsible_salary']
dbconnection.execute("UPDATE finance_balance SET value=value+{} WHERE user_id={} AND YEAR(date)={} AND MONTH(date)={}".format(
money, owner['user_id'], finances['datetime'].date().year, finances['datetime'].date().month))
percents = balance['percents']
money = finances['real_profit']*(percents/100)
dbconnection.execute("UPDATE finance_balance SET value=value+{} WHERE user_id=0".format(money))
示例3: get
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get(type_id, dbconnection:dbutils.DBConnection=None) -> GameType:
if isinstance(type_id, str) and len(type_id.split(',')) > 0:
type_id = splitstrlist(type_id)
if len(type_id) == 1:
type_id = type_id[0]
if isinstance(type_id, list) and len(type_id) == 0: return list()
if isinstance(type_id, int) and type_id != 0:
dbconnection.execute("SELECT * FROM game_types WHERE type_id='{}'".format(type_id),
dbutils.dbfields['game_types'])
elif isinstance(type_id, list):
dbconnection.execute(
"SELECT * FROM game_types WHERE type_id IN (" + ','.join(map(str, type_id)) + ")",
dbutils.dbfields['game_types'])
elif type_id == 0:
dbconnection.execute("SELECT * FROM game_types", dbutils.dbfields['game_types'])
if len(dbconnection.last()) == 0: return list()
game_types = dbconnection.last()
game_types = list(map(lambda x: GameType(x, dbconnection=dbconnection), game_types))
if isinstance(type_id, int) and type_id != 0:
return game_types[0]
elif isinstance(type_id, list) or type_id == 0:
return game_types
示例4: get
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get(sport_id, dbconnection:dbutils.DBConnection=None) -> list:
if isinstance(sport_id, str) and len(sport_id.split(',')) > 0:
sport_id = splitstrlist(sport_id)
if len(sport_id) == 1:
sport_id = sport_id[0]
if isinstance(sport_id, list) and len(sport_id) == 0: return list()
if isinstance(sport_id, int) and sport_id != 0:
dbconnection.execute("SELECT * FROM sport_types WHERE sport_id='{}'".format(sport_id),
dbutils.dbfields['sport_types'])
elif isinstance(sport_id, list):
dbconnection.execute(
"SELECT * FROM sport_types WHERE sport_id IN (" + ','.join(map(str, sport_id)) + ")",
dbutils.dbfields['sport_types'])
elif sport_id == 0:
dbconnection.execute("SELECT * FROM sport_types", dbutils.dbfields['sport_types'])
if len(dbconnection.last()) == 0: return list()
sport_types = dbconnection.last()
sport_types = list(map(lambda x: SportType(x), sport_types))
if isinstance(sport_id, int) and sport_id != 0:
return sport_types[0]
elif isinstance(sport_id, list) or sport_id == 0:
return sport_types
示例5: create
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def create(email:str, dbconnection:dbutils.DBConnection=None) -> str:
dbconnection.execute("SELECT activated, token FROM activation WHERE email='{}'".format(email))
if len(dbconnection.last())>0:
if dbconnection.last()[0][0]==1:
raise ValueError('{} already activated'.format(email), email, dbconnection.last()[0][1])
elif dbconnection.last()[0][0]==2:
raise KeyError('{} already registrated'.format(email), email)
else:
dbconnection.execute("DELETE FROM activation WHERE email='{}'".format(email))
token = modules.generate_token()
dbconnection.execute("INSERT INTO activation (email, token) VALUES ('{}', '{}')".format(email, token))
return token
示例6: get
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get(user_id, userlevel:int=-1, count:slice=slice(0, 20), dbconnection:dbutils.DBConnection=None) -> User:
if isinstance(user_id, str) and len(user_id.split(',')) > 0:
user_id = splitstrlist(user_id)
if len(user_id) == 1:
user_id = user_id[0]
if isinstance(user_id, list) and len(user_id) == 0: return list()
sql = "SELECT * FROM users WHERE user_id='{}'".format(user_id)
if isinstance(user_id, int) and user_id != 0:
sql = "SELECT * FROM users WHERE user_id='{}'".format(user_id)
elif isinstance(user_id, list):
sql = "SELECT * FROM users WHERE user_id IN (" + ','.join(map(str, user_id)) + ")"
elif user_id == 0:
sql = "SELECT * FROM users"
if userlevel >= 0 or isinstance(userlevel, set):
if user_id==0:
sql += ' WHERE '
else:
sql += ' AND '
if isinstance(userlevel, int):
sql += " LOCATE('|{}|', userlevel) ".format(userlevel)
else:
' AND '.join(map(lambda x: "LOCATE('|{}|', userlevel)".format(x), userlevel))
sql += " ORDER BY played_games DESC"
if user_id == 0:
sql += " LIMIT {}, {}".format(count.start if count.start else 0, count.stop)
dbconnection.execute(sql, dbutils.dbfields['users'])
if len(dbconnection.last()) == 0: return list()
users = dbconnection.last()
users = list(map(lambda x: User(x, dbconnection=dbconnection), users))
if isinstance(user_id, int) and user_id != 0:
return users[0]
elif isinstance(user_id, list) or user_id == 0:
return users
示例7: get
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get(user_id:int, all:bool=False, type:int=-1, dbconnection:dbutils.DBConnection=None) -> list:
query = "SELECT * FROM notifications WHERE datetime<NOW() AND user_id={}".format(user_id)
options = list()
if not all:
options.append("`read`=0")
if type >= 0:
options.append("type={}".format(type))
if len(options) > 0:
query += ' AND '
query += ' AND '.join(options)
query += ' ORDER BY DATETIME DESC'
if all:
query += ' LIMIT 40'
dbconnection.execute(query, dbutils.dbfields['notifications'])
if len(dbconnection.last()) == 0: return list()
notifications = dbconnection.last()
notifications = list(map(lambda x: Notification(x, dbconnection=dbconnection), notifications))
return notifications
示例8: get_comands
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get_comands(comand_id:(list, int), dbconnection:dbutils.DBConnection=None) -> Comand:
if isinstance(comand_id, list) and len(comand_id) == 0: return list()
if isinstance(comand_id, int):
dbconnection.execute("SELECT * FROM comands WHERE comand_id='{}'".format(comand_id))
elif isinstance(comand_id, list):
dbconnection.execute(
"SELECT * FROM comands WHERE comand_id IN ({})".format(','.join(list(map(str, comand_id)))))
return list(map(lambda x: Comand(x, dbconnection), dbconnection.last()))
示例9: calc_game
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def calc_game(game_id:int, dbconnection:dbutils.DBConnection=None) -> dict:
game = dbconnection.execute("SELECT * FROM games WHERE game_id={}".format(game_id), dbutils.dbfields['games'])[0]
game = Game(game, dbconnection=dbconnection)
reports = dbconnection.execute("SELECT * FROM reports WHERE game_id={}".format(game_id), dbutils.dbfields['reports'])
additional_charges = dbconnection.execute("SELECT * FROM additional_charges WHERE game_id={}".format(game_id), dbutils.dbfields['additional_charges'])
finances = dict()
finances['game_id'] = game_id
finances['datetime'] = game.datetime()
finances['capacity'] = game.capacity()
finances['cost'] = game.cost()
finances['sport_id'] = game.sport_type()
finances['responsible_user_id'] = game.responsible_user_id()
finances['created_by'] = game.created_by()
finances['visited'] = len(list(filter(lambda x: x['status']!=0, reports)))
finances['empty'] = finances['capacity']-finances['visited']
if finances['empty']<0: finances['empty']=0
finances['lost_empty'] = finances['empty']*finances['cost']
finances['notvisited'] = len(list(filter(lambda x: x['status']==0, reports)))
finances['lost_notvisited'] = finances['notvisited']*finances['cost']
finances['notpayed'] = len(list(filter(lambda x: x['status']==1, reports)))
finances['lost_notpayed'] = finances['notpayed']*finances['cost']
finances['playedpayed'] = len(list(filter(lambda x: x['status']==2, reports)))
finances['real_income'] = finances['playedpayed']*finances['cost']
finances['ideal_income'] = finances['cost']*finances['capacity'] if finances['capacity']>0 else finances['real_income']
finances['rent_charges'] = game.court_id(True).cost()*(game.duration()/60)
finances['additional_charges'] = sum([i['cost'] for i in additional_charges])
finances['profit'] = finances['real_income']-finances['additional_charges']-finances['rent_charges']
dbconnection.execute("SELECT percents FROM responsible_salary WHERE user_id={}".format(game.responsible_user_id()))
finances['responsible_salary'] = 0
if len(dbconnection.last())>0:
finances['responsible_salary'] = round((finances['profit'])*(dbconnection.last()[0][0]/100))
finances['profit'] -= finances['responsible_salary']
finances['real_profit'] = finances['profit'] + finances['rent_charges']
return finances
示例10: get
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get(amplua_id, dbconnection:dbutils.DBConnection=None) -> Amplua:
# FIXME вроде как str передается иногда
if isinstance(amplua_id, list) and len(amplua_id) == 0: return list()
if isinstance(amplua_id, int) and amplua_id != 0:
dbconnection.execute("SELECT * FROM ampluas WHERE amplua_id='{}'".format(amplua_id),
dbutils.dbfields['ampluas'])
elif isinstance(amplua_id, list):
dbconnection.execute("SELECT * FROM ampluas WHERE amplua_id IN (" + ','.join(map(str, amplua_id)) + ")",
dbutils.dbfields['ampluas'])
elif amplua_id == 0:
dbconnection.execute("SELECT * FROM ampluas", dbutils.dbfields['ampluas'])
if len(dbconnection.last()) == 0: return list()
ampluas = dbconnection.last()
ampluas = list(map(lambda x: Amplua(x, dbconnection=dbconnection), ampluas))
if isinstance(amplua_id, int) and amplua_id != 0:
return ampluas[0]
elif isinstance(amplua_id, list) or amplua_id == 0:
return ampluas
示例11: get
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get(game_id:int, dbconnection:dbutils.DBConnection=None) -> dict:
# registered: user_id:int -> status:int, unregistered: name:str -> (status:int, phone:str)
resp = {'registered': dict(), 'unregistered': dict(), 'additional':list()}
dbconnection.execute("SELECT user_id, status FROM reports WHERE user_id>0 AND game_id={}".format(game_id))
if len(dbconnection.last()) > 0:
for user in dbconnection.last():
user_id, status = user
resp['registered'][user_id] = status
dbconnection.execute("SELECT name, phone, status FROM reports WHERE user_id=0 AND game_id={}".format(game_id))
if len(dbconnection.last()) > 0:
for user in dbconnection.last():
name, phone, status = user[0], user[1], user[2]
resp['unregistered'][name] = (status, phone)
dbconnection.execute("SELECT description, cost FROM additional_charges WHERE game_id={}".format(game_id))
if len(dbconnection.last()) > 0:
for i in dbconnection.last():
resp['additional'].append(i)
return resp
示例12: get_posts_by_tags
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get_posts_by_tags(tag_ids:list, dbconnection:dbutils.DBConnection=None) -> list:
dbconnection.execute("SELECT * FROM blog.posts WHERE post_id IN (SELECT post_id FROM blog.post_tags WHERE tag_id IN ({})) AND status>=0".format(', '.join(tag_ids)), _fields['posts'])
if len(dbconnection.last())==0: return list()
return list(map(lambda x: Tag(x), dbconnection.last()))
示例13: get_tags
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get_tags(post_id:int, dbconnection:dbutils.DBConnection=None) -> list:
dbconnection.execute("SELECT * FROM blog.tags WHERE tag_id IN (SELECT tag_id FROM blog.post_tags WHERE post_id={})".format(post_id), _fields['tags'])
if len(dbconnection.last())==0: return list()
return list(map(lambda x: Tag(x), dbconnection.last()))
示例14: get_comand_ids
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get_comand_ids(game_id:int, dbconnection:dbutils.DBConnection=None) -> list:
dbconnection.execute("SELECT comand_id FROM comands WHERE game_id='{}'".format(game_id))
if len(dbconnection.last()) == 0: return list()
return list(map(lambda x: x[0], dbconnection.last()))
示例15: get_subscribed
# 需要导入模块: from dbutils import DBConnection [as 别名]
# 或者: from dbutils.DBConnection import last [as 别名]
def get_subscribed(command_id:int, dbconnection:dbutils.DBConnection=None) -> list:
dbconnection.execute("SELECT user_id FROM usergames WHERE comand_id='{}'".format(command_id))
if len(dbconnection.last()) == 0: return list()
return list(map(lambda x: x[0], dbconnection.last()))