本文整理汇总了Python中Message.Message.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python Message.serialize方法的具体用法?Python Message.serialize怎么用?Python Message.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message.Message
的用法示例。
在下文中一共展示了Message.serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_messages
# 需要导入模块: from Message import Message [as 别名]
# 或者: from Message.Message import serialize [as 别名]
def get_messages(self, ID):
connection = pymysql.connect(host=db.db_host, port=db.db_port, user=db.db_user, passwd=db.db_passwd, db=db.db_name)
cursor = connection.cursor()
#Conseguir último mensaje individual.
SQL = """SELECT MAX(SEND_INDIVIDUAL_MESSAGE.ID_MESSAGE) AS MAX_INDIVIDUAL
FROM SEND_INDIVIDUAL_MESSAGE""".replace('\n',' ')
cursor.execute(SQL)
maxI = cursor._rows[0][0]
#Conseguir último mensaje grupal.
SQL = """SELECT MAX(SEND_MESSAGE_GROUP.ID_MESSAGE) AS MAX_GROUP
FROM SEND_MESSAGE_GROUP""".replace('\n',' ')
cursor.execute(SQL)
maxG = cursor._rows[0][0]
if maxG is None:
maxG = 0
if maxI is None:
maxI = 0
#Recibir mensajes
SQL = """SELECT ID_USER_SENDER, MESSAGES.TEXT, 0 AS ID_GROUP, (SELECT U.PHONE FROM USERS U WHERE U.ID_USER = ID_USER_SENDER) AS SENDER_PHONE
FROM USERS, MESSAGES, SEND_INDIVIDUAL_MESSAGE
WHERE USERS.ID_USER = SEND_INDIVIDUAL_MESSAGE.ID_USER_RECEIVER
AND SEND_INDIVIDUAL_MESSAGE.ID_MESSAGE = MESSAGES.ID_MESSAGE
AND USERS.ID_USER = %s
AND MESSAGES.ID_MESSAGE > USERS.LAST_RECEIVED_MESSAGE_INDIVIDUAL
AND MESSAGES.ID_MESSAGE <= %s
UNION
SELECT SEND_MESSAGE_GROUP.ID_USER AS ID_USER_SENDER, MESSAGES.TEXT , BELONG.ID_GROUP, (SELECT U.PHONE FROM USERS U WHERE U.ID_USER = ID_USER_SENDER) AS SENDER_PHONE
FROM USERS , MESSAGES , SEND_MESSAGE_GROUP , BELONG
WHERE USERS.ID_USER = BELONG.ID_USER
AND BELONG.ID_GROUP = SEND_MESSAGE_GROUP.ID_GROUP
AND SEND_MESSAGE_GROUP.ID_MESSAGE = MESSAGES.ID_MESSAGE
AND USERS.ID_USER = %s
AND SEND_MESSAGE_GROUP.ID_USER != USERS.ID_USER
AND MESSAGES.ID_MESSAGE > USERS.LAST_RECEIVED_MESSAGE_GROUP
AND MESSAGES.ID_MESSAGE <= %s;""".replace('\n',' ')
SQL = SQL % (str(ID),str(maxI),str(ID),str(maxG))
cursor.execute(SQL)
messages = list()
for row in cursor:
message = Message()
message.ID_USER_SENDER = row[0]
message.TEXT = row[1]
message.ID_GROUP = row[2]
message.PHONE = row[3]
messages.append(message.serialize())
#Actualizar ultimo mensaje.
SQL = """UPDATE USERS
SET USERS.LAST_RECEIVED_MESSAGE_INDIVIDUAL = %s ,
USERS.LAST_RECEIVED_MESSAGE_GROUP = %s
WHERE USERS.ID_USER = %s ;""".replace('\n',' ').replace('\t','')
SQL = SQL % (str(maxI),str(maxG),str(ID))
cursor.execute(SQL)
connection.commit()
cursor.close()
return messages