Beispiel #1
0
func (this *Database) SaveObject(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var object share.DbSave
	var callbackparams share.DBParams
	if server.Check(server.ParseArgs(msg, &object, &callbackparams)) {
		return share.ERR_ARGS_ERROR, nil
	}

	reply = server.CreateMessage(callbackparams)
	sqlconn := db.sql

	err := SaveItem(sqlconn, true, object.Data.DBId, object.Data)

	if err != nil {
		return share.ERR_REPLY_FAILED, reply
	}

	return share.ERR_REPLY_SUCCEED, reply
}
Beispiel #2
0
func (this *Database) DeleteObject(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var ent string
	var dbid uint64
	var callbackparams share.DBParams
	var err error

	if server.Check(server.ParseArgs(msg, &ent, &dbid, &callbackparams)) {
		return share.ERR_ARGS_ERROR, nil
	}

	reply = server.CreateMessage(callbackparams)
	sqlconn := db.sql

	sqlstr := fmt.Sprintf("DELETE FROM `tbl_%s` WHERE `id`=?", strings.ToLower(ent))
	if _, err = sqlconn.Exec(sqlstr, dbid); err != nil {
		log.LogError("sql:", sqlstr)
		return share.ERR_REPLY_FAILED, reply
	}

	return share.ERR_REPLY_SUCCEED, reply
}
Beispiel #3
0
func (this *Database) LoadObject(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var ent string
	var dbid uint64
	var callbackparams share.DBParams
	var err error
	if server.Check(server.ParseArgs(msg, &ent, &dbid, &callbackparams)) {
		return share.ERR_ARGS_ERROR, nil
	}

	reply = server.CreateMessage(callbackparams)
	sqlconn := db.sql

	savedata := share.DbSave{}
	savedata.Data, err = LoadEntity(sqlconn, dbid, ent, 0)

	if err != nil {
		return share.ERR_REPLY_FAILED, reply
	}

	server.AppendArgs(reply, savedata)
	return share.ERR_REPLY_SUCCEED, reply
}