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