furniture.cpp
2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "furniture.h"
#include "func_rount.h"
namespace {
const char* STR_UID = "uid";
const char* STR_ID = "furniture_id";
const char* STR_X = "x";
const char* STR_Y = "y";
}
furniture_t::furniture_t( el::lib_mysql_if* db )
: el::lib_mysql_table_route10x10(db, g_gen_db_name("USER"), "t_furniture")
{
}
int furniture_t::update( USER_ID uid, uint32_t id, uint32_t x, uint32_t y )
{
GEN_SQLSTR(this->sqlstr, "insert into %s (%s, %s, %s, %s)"
"values(%" PRIu64 ",%u,%u,%u) on duplicate key update %s=%u, %s=%u",
this->get_table_name(uid),
STR_UID, STR_ID, STR_X, STR_Y,
uid, id, x, y,
STR_X, x, STR_Y, y);
return this->exec_update_sqls(this->sqlstr);
}
int furniture_t::get( USER_ID uid, db_msg::load_user_msg_res* out )
{
GEN_SQLSTR(this->sqlstr,"select %s,%s,%s from %s where %s=%" PRIu64,
STR_ID, STR_X, STR_Y,
this->get_table_name(uid),
STR_UID, uid);
PB_STD_QUERY_WHILE_BEGIN(this->sqlstr, out, add_furnitures);
uint32_t t_id = 0;
uint32_t t_x = 0;
uint32_t t_y = 0;
GET_FIELD_UINT64(t_id);
member->set_id(t_id);
GET_FIELD_UINT64(t_x);
member->set_x(t_x);
GET_FIELD_UINT64(t_y);
member->set_y(t_y);
PB_STD_QUERY_WHILE_END();
}
int furniture_t::get_type_cnt( USER_ID uid, uint32_t& type_cnt )
{
GEN_SQLSTR(this->sqlstr,"select COUNT(*) from %s where %s=%" PRIu64,
this->get_table_name(uid), STR_UID, uid);
STD_QUERY_ONE_BEGIN(this->sqlstr, el::ERR_DB::KEY_INEXIST);
uint32_t v = 0;
GET_FIELD_UINT64(v);
type_cnt = v;
STD_QUERY_ONE_END();
}
int furniture_t::get_home( USER_ID uid, share_msg::user_home_t* out )
{
GEN_SQLSTR(this->sqlstr,"select %s,%s,%s from %s where (x <> 0 or y <> 0 )and %s=%" PRIu64,
STR_ID, STR_X, STR_Y,
this->get_table_name(uid),
STR_UID, uid);
PB_STD_QUERY_WHILE_BEGIN(this->sqlstr, out, add_furniture);
uint32_t t_id = 0;
uint32_t t_x = 0;
uint32_t t_y = 0;
GET_FIELD_UINT64(t_id);
member->set_id(t_id);
GET_FIELD_UINT64(t_x);
member->set_x(t_x);
GET_FIELD_UINT64(t_y);
member->set_y(t_y);
PB_STD_QUERY_WHILE_END();
}
//////////////////////////////////////////////////////////////////////////
//
int Cfunc_route::on_update_furniture_msg(USER_ID uid, google::protobuf::Message* msg)
{
auto in = (db_msg::update_furniture_msg*)msg;
auto p = in->mutable_furniture();
this->ret = this->furniture.update(uid, p->id(), p->x(), p->y());
return this->ret;
}