This commit is contained in:
shoopea 2019-10-11 12:03:42 +08:00
parent 898846727a
commit 444f511acc

46
sql.go
View File

@ -582,39 +582,19 @@ func initDB() {
log.Println("initDB : code_obj_sub_type populated ...")
_, err = db.Exec(`CREATE VIEW obj_msg_vault_v AS
SELECT x.sender_user_id user_id
,x.item_id
,(SELECT COALESCE(SUM(omix.quantity), 0)
FROM obj ox
,obj_msg omx
,obj_msg_item omix
WHERE ox.obj_sub_type_id = ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `
AND omx.sender_user_id = x.sender_user_id
AND omx.obj_id = ox.id
AND omix.obj_id = ox.id
AND omix.item_id = x.item_id) deposit
,(SELECT coalesce(sum(omix.quantity), 0)
FROM obj ox
,obj_msg omx
,obj_msg_item omix
WHERE ox.obj_sub_type_id = ` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `
AND omx.sender_user_id = x.sender_user_id
AND omx.obj_id = ox.id
AND omix.obj_id = ox.id
AND omix.item_id = x.item_id) withdraw
FROM (SELECT DISTINCT
om.sender_user_id
,om.chat_id
,omi.item_id
FROM obj o
,obj_msg om
,obj_msg_item omi
WHERE o.id = om.obj_id
AND o.obj_type_id = ` + strconv.Itoa(objTypeMessage) + `
AND o.obj_sub_type_id in (` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `, ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `)
AND omi.obj_id = o.id) x
ORDER BY x.sender_user_id ASC
,x.item_id ASC;`)
SELECT om.sender_user_id user_id
,om.chat_id
,omi.item_id
,omi.quantity
FROM obj o
,obj_msg om
,obj_msg_item omi
WHERE o.id = om.obj_id
AND o.obj_type_id = ` + strconv.Itoa(objTypeMessage) + `
AND o.obj_sub_type_id in (` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `, ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `)
AND omi.obj_id = o.id) x
ORDER BY om.sender_user_id ASC
,omi.item_id ASC;`)
failOnError(err, "initDB : create view obj_msg_vault_v")
log.Println("initDB : obj_msg_vault_v created ...")