本文整理汇总了Python中MySQL.MySQL.delete方法的典型用法代码示例。如果您正苦于以下问题:Python MySQL.delete方法的具体用法?Python MySQL.delete怎么用?Python MySQL.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySQL.MySQL
的用法示例。
在下文中一共展示了MySQL.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_auth
# 需要导入模块: from MySQL import MySQL [as 别名]
# 或者: from MySQL.MySQL import delete [as 别名]
def user_auth(data):
db = MySQL()
userId = None
isNewUser = None
validate = db.get("SELECT * FROM `validate` WHERE `mobile`=%s and `device` = %s ORDER BY `valid_date` desc", (data['Id'], data['Device']))
if validate and (validate['code'] == data['Validate'] or '147258369' == data['Validate'] or '0147258369' == data['Validate']): # 需要验证下时间,目前后门验证码为:0147258369
#
# 手机号+验证码 登录
#
user = db.get("SELECT * FROM `user` WHERE `mobile`=%s",(data['Id']))
userId = Utils.UUID() if not user else user['id']
isNewUser = True if not user else False
if isNewUser:
# New user
# TODO: 是否需要生成默认用户名和密码?
result = db.save("INSERT INTO `user` (`id`, `mobile`) VALUES (%s,%s)", (userId, data['Id']))
db.end()
# 关联新用户数据
db.save("UPDATE `share` SET `to_user_id` = %s WHERE `to_mobile` = %s AND `to_user_id` IS NULL", (userId, data['Id']))
db.end()
else:
#
# 通过 用户名/邮箱 + 密码 方式登录
#
user = db.get("SELECT * FROM `user` WHERE (`login`=%s or `email`=%s) and password = %s",
(data['Id'], data['Id'], Utils.MD5(data['Validate'])))
if user:
userId = user['id']
isNewUser = False
else:
raise Exception("验证信息不存在或验证码错误.")
#
# create session
#
sessionId = Utils.UUID()
valid_date = datetime.now() + timedelta(days=300) # 默认登录验证有效期300天
# clear old session
db.delete("DELETE FROM `session` WHERE `user_id`=%s and `device` = %s", (userId, data['Device']))
db.end()
# insert new session
result = db.save("""INSERT INTO `session` (`id`, `user_id`, `device`, `valid_time`) VALUES (%s,%s,%s,%s)"""
, (sessionId, userId, data['Device'], valid_date.strftime('%Y-%m-%d %H:%M:%S')))
db.end()
return {
'UserKey' : sessionId,
'NewUser' : isNewUser,
'ValidityDate' : valid_date
}
示例2: video_remove
# 需要导入模块: from MySQL import MySQL [as 别名]
# 或者: from MySQL.MySQL import delete [as 别名]
def video_remove(data):
"""
删除视频
方法:
video_remove
参数:
UserKey[string] –用户登录后的会话ID。
VID[string] – 分配的视频ID
返回值:
VID[string] – 删除的视频ID
"""
userId = UserService.user_id(data['UserKey'])
db = MySQL()
videoInstance = db.get('SELECT * FROM `video` WHERE `owner_id`=%s and `id` = %s', (userId, data['VID']))
if not videoInstance:
raise Exception("视频不存在.")
db.delete("DELETE FROM `video` WHERE `owner_id`=%s and `id` = %s", (userId, data['VID']))
db.end()
return {'VID': data['VID']}
示例3: space_unauthorize
# 需要导入模块: from MySQL import MySQL [as 别名]
# 或者: from MySQL.MySQL import delete [as 别名]
def space_unauthorize(data):
userId = UserService.user_id(data['UserKey'])
spaceInstance = space_get(data.get('Id', ''))
if userId == spaceInstance['user_id']:
db = MySQL()
result = db.delete("DELETE FROM `space_authorize` WHERE `space_id`=%s AND `user_id`=%s",
(data.get('Id', ''), data.get('UserId', '')))
db.end()
if result > 0:
return {
'Id': data.get('Id', ''),
'UserId': data.get('UserId', ''),
}
else:
raise Exception('删除失败或授权不存在')
else:
raise Exception('没有权限或空间不存在')
示例4: space_res_unrelation
# 需要导入模块: from MySQL import MySQL [as 别名]
# 或者: from MySQL.MySQL import delete [as 别名]
def space_res_unrelation(data):
userId = UserService.user_id(data['UserKey'])
db = MySQL()
# TEST AUTHORIZE
if __test_auth_edit(userId, data.get('Id', '')) > 0:
result = db.delete("DELETE FROM `space_resource` WHERE `space_id`=%s AND `res_type`=%s AND `res_id`=%s",
(data.get('Id', ''), data.get('ResType', ''), data.get('ResId', '')))
db.end()
if result > 0:
return {
'Id': data.get('Id', ''),
'ResType': data.get('ResType', ''),
'ResId': data.get('ResId', ''),
}
else:
raise Exception('删除失败或资源不存在')
else:
raise Exception('没有权限或空间不存在')