当前位置: 首页>>代码示例>>Python>>正文


Python MySQL.delete方法代码示例

本文整理汇总了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
		}
开发者ID:xaccc,项目名称:videoapiserver,代码行数:56,代码来源:UserService.py

示例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']}
开发者ID:xaccc,项目名称:videoapiserver,代码行数:24,代码来源:VideoService.py

示例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('没有权限或空间不存在')
开发者ID:xaccc,项目名称:videoapiserver,代码行数:19,代码来源:SpaceService.py

示例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('没有权限或空间不存在')
开发者ID:xaccc,项目名称:videoapiserver,代码行数:21,代码来源:SpaceService.py


注:本文中的MySQL.MySQL.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。