本文整理匯總了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('沒有權限或空間不存在')