Skip to content

Commit

Permalink
将blob字段改为text字段,用base64编码储存
Browse files Browse the repository at this point in the history
  • Loading branch information
SnailLee committed Sep 29, 2016
1 parent 46d19f5 commit ca34ee1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion config/server/server_misc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"server_type" : 1, //服务器架构类型 1:多进程 2:多线程
"db_type" : 1, //数据库类型 1:mongodb 2:mysql
"db_type" : 2, //数据库类型 1:mongodb 2:mysql
"server_label" : "test", //服务器标签,ps查询进程时候区分用
"lib_log_switcher" : 0, //网络库日志开关,1表示写入磁盘文件
"server_log_switcher" : 0, //服务器日志开关,1表示写入磁盘文件
Expand Down
11 changes: 6 additions & 5 deletions config/sql/game.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ CREATE TABLE `bag` (
role_id bigint(20) NOT NULL auto_increment,
copper int(11) NOT NULL default '0',
gold int(11) NOT NULL default '0',
item_map blob NOT NULL,
item_map text NOT NULL,
PRIMARY KEY (role_id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `mail`;
CREATE TABLE `mail` (
role_id bigint(20) NOT NULL auto_increment,
total_count int(11) NOT NULL default '0',
mail_map blob NOT NULL,
mail_map text NOT NULL,
PRIMARY KEY (role_id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

Expand All @@ -59,7 +59,8 @@ CREATE TABLE `guild` (
guild_name varchar(120) NOT NULL default '',
chief_id bigint(20) NOT NULL default '0',
create_time int(11) NOT NULL default '0',
member_list blob NOT NULL,
member_list text NOT NULL,
app_list text NOT NULL,
PRIMARY KEY (guild_id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

Expand All @@ -68,7 +69,7 @@ CREATE TABLE `rank` (
rank_type bigint(20) NOT NULL auto_increment,
min_value int(11) NOT NULL default '0',
min_role_id bigint(20) NOT NULL default '0',
member_map blob NOT NULL,
member_map text NOT NULL,
PRIMARY KEY (rank_type)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

Expand All @@ -78,4 +79,4 @@ CREATE TABLE `offline` (
guild_id bigint(20) NOT NULL default '0',
guild_name varchar(120) NOT NULL default '',
PRIMARY KEY (role_id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
1 change: 1 addition & 0 deletions config/struct/game_struct.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<arg type="int64" name="chief_id"/>
<arg type="int32" name="create_time"/>
<vector type="Guild_Member_Detail" name="member_list"/>
<vector type="Guild_Member_Detail" name="app_list"/>
</Guild_Info>

<Rank_Info>
Expand Down
37 changes: 15 additions & 22 deletions db_server/Mysql_Struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Mysql_Operator.h"
#include "Mysql_Struct.h"
#include "DB_Manager.h"
#include "Common_Func.h"

Mysql_Struct::Mysql_Struct(Xml &xml, TiXmlNode *node) : Base_Struct(xml, node) {}

Expand Down Expand Up @@ -84,22 +85,16 @@ void Mysql_Struct::create_data(int64_t key_index, Block_Buffer &buffer) {
Block_Buffer blob_buffer;
int field_len = create_data_vector(*iter, buffer, blob_buffer);

std::string blob_data;
blob_buffer.copy_out((char*)blob_data.c_str(), field_len);
DataBuf data_buf((char*)blob_data.c_str(), field_len);
std::istream s(&data_buf);
pstmt->setBlob(param_index, &s);
std::string blob_data = base64_encode((unsigned char *)blob_buffer.get_read_ptr(), field_len);
pstmt->setString(param_index, blob_data);
}
else if(iter->field_label == "struct") {
//blob_buffer只提供对该struct类型的初始化数据
Block_Buffer blob_buffer;
int field_len = create_data_struct(*iter, buffer, blob_buffer);

std::string blob_data;
blob_buffer.copy_out((char*)blob_data.c_str(), field_len);
DataBuf data_buf((char*)blob_data.c_str(), field_len);
std::istream s(&data_buf);
pstmt->setBlob(param_index, &s);
std::string blob_data = base64_encode((unsigned char *)blob_buffer.get_read_ptr(), field_len);
pstmt->setString(param_index, blob_data);

LOG_INFO("struct_name:%s, field_type:%s, field_name:%s, param_index:%d, field_len:%d", struct_name().c_str(),
iter->field_type.c_str(), iter->field_name.c_str(), param_index, field_len);
Expand Down Expand Up @@ -246,11 +241,9 @@ void Mysql_Struct::save_data(Block_Buffer &buffer) {
int field_len = build_len_vector(*iter, buffer);
buffer.set_read_idx(read_idx);

std::string blob_data;
buffer.copy_out((char*)blob_data.c_str(), field_len);
DataBuf data_buf((char*)blob_data.c_str(), field_len);
std::istream s(&data_buf);
pstmt->setBlob(param_index, &s);
std::string blob_data = base64_encode((unsigned char *)buffer.get_read_ptr(), field_len);
buffer.set_read_idx(read_idx + field_len);
pstmt->setString(param_index, blob_data);

LOG_INFO("struct_name:%s, fileld_label:%s, field_type:%s, field_name:%s, param_index:%d, field_len:%d, read_idx:%d", struct_name().c_str(),
iter->field_label.c_str(), iter->field_type.c_str(), iter->field_name.c_str(), param_index, field_len, buffer.get_read_idx());
Expand All @@ -260,11 +253,9 @@ void Mysql_Struct::save_data(Block_Buffer &buffer) {
int field_len = build_len_struct(*iter, buffer);
buffer.set_read_idx(read_idx);

std::string blob_data;
buffer.copy_out((char*)blob_data.c_str(), field_len);
DataBuf data_buf((char*)blob_data.c_str(), field_len);
std::istream s(&data_buf);
pstmt->setBlob(param_index, &s);
std::string blob_data = base64_encode((unsigned char *)buffer.get_read_ptr(), field_len);
buffer.set_read_idx(read_idx + field_len);
pstmt->setString(param_index, blob_data);

LOG_INFO("struct_name:%s, fileld_label:%s, field_type:%s, field_name:%s, param_index:%d, field_len:%d, read_idx:%d", struct_name().c_str(),
iter->field_label.c_str(), iter->field_type.c_str(), iter->field_name.c_str(), param_index, field_len, buffer.get_read_idx());
Expand Down Expand Up @@ -404,12 +395,14 @@ void Mysql_Struct::build_buffer_arg(const Field_Info &field_info, Block_Buffer &

void Mysql_Struct::build_buffer_vector(const Field_Info &field_info, Block_Buffer &buffer, sql::ResultSet *result) {
std::string blob_str = result->getString(field_info.field_name);
buffer.copy(blob_str);
std::string decode = base64_decode(blob_str);
buffer.copy(decode);
}

void Mysql_Struct::build_buffer_struct(const Field_Info &field_info, Block_Buffer &buffer, sql::ResultSet *result) {
std::string blob_str = result->getString(field_info.field_name);
buffer.copy(blob_str);
std::string decode = base64_decode(blob_str);
buffer.copy(decode);
}

int Mysql_Struct::build_len_arg(const Field_Info &field_info, Block_Buffer &buffer) {
Expand Down
11 changes: 10 additions & 1 deletion js/guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Guild.prototype.load_data = function(obj) {
for(var i = 0; i < obj.guild_list.length; i++) {
var guild_info = obj.guild_list[i];
print('guild_id:', guild_info.guild_id, ' guild_name:', guild_info.guild_name);
if(guild_info.member_list.length > 0)
print('member_list[0].role_id is ', guild_info.member_list[0].role_id);
else
print('member_list is empty')
if(guild_info.app_list.length > 0)
print('app_list[0].role_id is ', guild_info.app_list[0].role_id);
else
print('app_list is empty')
this.guild_map.set(guild_info.guild_id, guild_info);
}
}
Expand Down Expand Up @@ -59,6 +67,7 @@ Guild.prototype.member_join_guild = function(player, guild_detail) {
member_detail.role_name = player.player_info.role_name;
member_detail.level = player.player_info.level;
guild_detail.member_list.push(member_detail);
guild_detail.app_list.push(member_detail);
this.is_change = true;
}

Expand Down Expand Up @@ -141,4 +150,4 @@ Guild.prototype.kick_out_player = function(player, obj) {
}
player.send_error_msg(Msg.RES_GUILD_KICK_OUT, Error_Code.ERROR_CLIENT_PARAM);
this.is_change = true;
}
}
1 change: 1 addition & 0 deletions js/struct.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function Guild_Info() {
this.chief_id = 0;
this.create_time = 0;
this.member_list = new Array();
this.app_list = new Array();
}

function Rank_Info() {
Expand Down

0 comments on commit ca34ee1

Please sign in to comment.