This commit is contained in:
Saturneic 2019-03-05 20:27:54 +08:00
parent 01abbffa91
commit 77f0fd3d9e
10 changed files with 136 additions and 19 deletions

View File

@ -10,6 +10,7 @@
9227C804220D6E4D00AE694C /* model.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9227C803220D6E4D00AE694C /* model.cpp */; }; 9227C804220D6E4D00AE694C /* model.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9227C803220D6E4D00AE694C /* model.cpp */; };
9227C85B220D702800AE694C /* controller.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9227C85A220D702800AE694C /* controller.cpp */; }; 9227C85B220D702800AE694C /* controller.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9227C85A220D702800AE694C /* controller.cpp */; };
9227C860220DAD9B00AE694C /* aes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9227C85F220DAD9B00AE694C /* aes.cpp */; }; 9227C860220DAD9B00AE694C /* aes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9227C85F220DAD9B00AE694C /* aes.cpp */; };
92436CB7222E68C2000443B2 /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 9277A18821FEB21D009C5F11 /* libsqlite3.dylib */; };
926E0965220B17FA00AD5D5B /* client.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 926E0964220B17FA00AD5D5B /* client.cpp */; }; 926E0965220B17FA00AD5D5B /* client.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 926E0964220B17FA00AD5D5B /* client.cpp */; };
9277A16021FD725F009C5F11 /* md5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15421FD725F009C5F11 /* md5.cpp */; }; 9277A16021FD725F009C5F11 /* md5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15421FD725F009C5F11 /* md5.cpp */; };
9277A16121FD725F009C5F11 /* cproj_cpt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15521FD725F009C5F11 /* cproj_cpt.cpp */; }; 9277A16121FD725F009C5F11 /* cproj_cpt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15521FD725F009C5F11 /* cproj_cpt.cpp */; };
@ -18,7 +19,6 @@
9277A16621FD725F009C5F11 /* cpart.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15A21FD725F009C5F11 /* cpart.cpp */; }; 9277A16621FD725F009C5F11 /* cpart.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15A21FD725F009C5F11 /* cpart.cpp */; };
9277A16721FD725F009C5F11 /* memory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15B21FD725F009C5F11 /* memory.cpp */; }; 9277A16721FD725F009C5F11 /* memory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15B21FD725F009C5F11 /* memory.cpp */; };
9277A16821FD725F009C5F11 /* clock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15C21FD725F009C5F11 /* clock.cpp */; }; 9277A16821FD725F009C5F11 /* clock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15C21FD725F009C5F11 /* clock.cpp */; };
9277A18921FEB21D009C5F11 /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 9277A18821FEB21D009C5F11 /* libsqlite3.dylib */; };
9277A18C220076EE009C5F11 /* sql.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A18A220076EE009C5F11 /* sql.cpp */; }; 9277A18C220076EE009C5F11 /* sql.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A18A220076EE009C5F11 /* sql.cpp */; };
9277A190220079DB009C5F11 /* cproj_proj.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A18F220079DB009C5F11 /* cproj_proj.cpp */; }; 9277A190220079DB009C5F11 /* cproj_proj.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A18F220079DB009C5F11 /* cproj_proj.cpp */; };
92C34C272205C63A00AB38D3 /* server.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15821FD725F009C5F11 /* server.cpp */; }; 92C34C272205C63A00AB38D3 /* server.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9277A15821FD725F009C5F11 /* server.cpp */; };
@ -90,7 +90,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
9277A18921FEB21D009C5F11 /* libsqlite3.dylib in Frameworks */, 92436CB7222E68C2000443B2 /* libsqlite3.dylib in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@ -41,6 +41,8 @@ namespace sql {
string string_type(string str); string string_type(string str);
// 输出错误信息 // 输出错误信息
void printError(sqlite3 *psql); void printError(sqlite3 *psql);
// 执行SQL语句
int exec(sqlite3 *psql, string sql);
} }
#endif /* sql_h */ #endif /* sql_h */

View File

@ -18,6 +18,8 @@ Client::Client(int port, string send_ip,int send_port):socket(port),send_socket(
sqlite3_stmt *psqlsmt; sqlite3_stmt *psqlsmt;
const char *pzTail; const char *pzTail;
sqlite3_open("info.db", &psql); sqlite3_open("info.db", &psql);
sql::exec(psql, "BEGIN DEFERRED;");
string sql_quote = "select name,tag,msqes_key from client_info where rowid = 1;"; string sql_quote = "select name,tag,msqes_key from client_info where rowid = 1;";
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
@ -25,6 +27,8 @@ Client::Client(int port, string send_ip,int send_port):socket(port),send_socket(
tag = (const char *)sqlite3_column_text(psqlsmt, 1); tag = (const char *)sqlite3_column_text(psqlsmt, 1);
sqe_key = (const char *)sqlite3_column_text(psqlsmt, 2); sqe_key = (const char *)sqlite3_column_text(psqlsmt, 2);
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
//客户端请求接收守护进程 //客户端请求接收守护进程

View File

@ -443,7 +443,7 @@ int client(string instruct, vector<string> &configs, vector<string> &lconfigs, v
//等待广场服务器回应 //等待广场服务器回应
while (if_wait == 1) { while (if_wait == 1) {
sleep(10); usleep(1000);
} }
if(!if_wait){ if(!if_wait){
#ifdef DEBUG #ifdef DEBUG
@ -584,6 +584,7 @@ int client(string instruct, vector<string> &configs, vector<string> &lconfigs, v
//成功注册 //成功注册
if (!if_wait) { if (!if_wait) {
sqlite3_stmt *psqlsmt; sqlite3_stmt *psqlsmt;
sql::exec(psql, "BEGIN IMMEDIATE;");
sql::insert_info(psql, &psqlsmt, "client_register_info", { sql::insert_info(psql, &psqlsmt, "client_register_info", {
{"name","?1"}, {"name","?1"},
{"tag","?2"}, {"tag","?2"},
@ -595,6 +596,7 @@ int client(string instruct, vector<string> &configs, vector<string> &lconfigs, v
sqlite3_bind_blob(psqlsmt, 3, nclt.post_key.GetKey(), sizeof(uint64_t) * 4, SQLITE_TRANSIENT); sqlite3_bind_blob(psqlsmt, 3, nclt.post_key.GetKey(), sizeof(uint64_t) * 4, SQLITE_TRANSIENT);
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
else if (~!if_wait) { else if (~!if_wait) {
error::printError("fail to do register."); error::printError("fail to do register.");
@ -726,6 +728,7 @@ int client(string instruct, vector<string> &configs, vector<string> &lconfigs, v
} }
else if (cmdstr == "info") { else if (cmdstr == "info") {
sqlite3_open("info.db",&psql); sqlite3_open("info.db",&psql);
sql::exec(psql, "BEGIN DEFERRED;");
string sql_quote = "SELECT * from client_register_info where rowid = 1;"; string sql_quote = "SELECT * from client_register_info where rowid = 1;";
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
@ -746,7 +749,8 @@ int client(string instruct, vector<string> &configs, vector<string> &lconfigs, v
error::printError("[NONE INFO]"); error::printError("[NONE INFO]");
} }
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
sql::exec(psql, "COMMIT;");
sqlite3_close(psql);
} }
else if (cmdstr == "quit") { else if (cmdstr == "quit") {
//关闭所有打开的文件描述符 //关闭所有打开的文件描述符

View File

@ -246,7 +246,10 @@ void Proj::write_lib_info(void){
#ifdef DEBUG #ifdef DEBUG
printf("Writing Libfiles Information Into Database.\n"); printf("Writing Libfiles Information Into Database.\n");
#endif #endif
for(auto lib : lib_index){ for(auto lib : lib_index){
sql::exec(psql, "BEGIN;");
// 链接数据 // 链接数据
sqlite3_bind_int(psqlsmt, 1, idx++); sqlite3_bind_int(psqlsmt, 1, idx++);
sqlite3_bind_text(psqlsmt, 2, lib.second.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 2, lib.second.data(), -1, SQLITE_TRANSIENT);
@ -264,8 +267,11 @@ void Proj::write_lib_info(void){
} }
sqlite3_reset(psqlsmt); sqlite3_reset(psqlsmt);
sqlite3_clear_bindings(psqlsmt); sqlite3_clear_bindings(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
} }
// 写入入口函数信息到数据库中 // 写入入口函数信息到数据库中
@ -284,6 +290,7 @@ void Proj::write_func_info(void){
for(auto func : func_index){ for(auto func : func_index){
string src_file = func.second->funcs_src.find(func.first)->second; string src_file = func.second->funcs_src.find(func.first)->second;
string lib_file = lib_index.find(src_file)->second; string lib_file = lib_index.find(src_file)->second;
sql::exec(psql, "BEGIN;");
string sql_quote = "SELECT id FROM srcfiles WHERE name = "+sql::string_type(src_file)+";"; string sql_quote = "SELECT id FROM srcfiles WHERE name = "+sql::string_type(src_file)+";";
// 查找源文件信息在数据库中的ID // 查找源文件信息在数据库中的ID
SQLCallBack *psqlcb = sql::sql_exec(psql, sql_quote); SQLCallBack *psqlcb = sql::sql_exec(psql, sql_quote);
@ -304,7 +311,9 @@ void Proj::write_func_info(void){
throw "database abnormal"; throw "database abnormal";
} }
delete psqlcb; delete psqlcb;
sql::exec(psql, "COMMIT;");
// 查找动态链接库信息在数据库中的ID // 查找动态链接库信息在数据库中的ID
sql::exec(psql, "BEGIN;");
sql_quote = "SELECT id FROM libfiles WHERE name = "+sql::string_type(lib_file)+";"; sql_quote = "SELECT id FROM libfiles WHERE name = "+sql::string_type(lib_file)+";";
psqlcb = sql::sql_exec(psql, sql_quote); psqlcb = sql::sql_exec(psql, sql_quote);
if(psqlcb->size != 1){ if(psqlcb->size != 1){
@ -324,6 +333,9 @@ void Proj::write_func_info(void){
throw "database abnormal"; throw "database abnormal";
} }
delete psqlcb; delete psqlcb;
sql::exec(psql, "COMMIT;");
sql::exec(psql, "BEGIN;");
// 链接数据 // 链接数据
sqlite3_bind_int(psqlsmt, 1, idx++); sqlite3_bind_int(psqlsmt, 1, idx++);
sqlite3_bind_text(psqlsmt, 2, func.first.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 2, func.first.data(), -1, SQLITE_TRANSIENT);
@ -344,6 +356,8 @@ void Proj::write_func_info(void){
} }
sqlite3_reset(psqlsmt); sqlite3_reset(psqlsmt);
sqlite3_clear_bindings(psqlsmt); sqlite3_clear_bindings(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
} }
@ -353,8 +367,10 @@ void Proj::write_func_info(string func_name, Cpt *pcpt){
string sql_quote2 = "SELECT * FROM functions ORDER BY id DESC limit 0,1;"; string sql_quote2 = "SELECT * FROM functions ORDER BY id DESC limit 0,1;";
const char *pzTail; const char *pzTail;
sqlite3_stmt *psqlsmt2; sqlite3_stmt *psqlsmt2;
sql::exec(psql, "BEGIN;");
sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail); sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail);
sqlite3_step(psqlsmt2); sqlite3_step(psqlsmt2);
sql::exec(psql, "COMMIT;");
int idx = sqlite3_column_int(psqlsmt2, 0); int idx = sqlite3_column_int(psqlsmt2, 0);
sqlite3_finalize(psqlsmt2); sqlite3_finalize(psqlsmt2);
@ -370,6 +386,8 @@ void Proj::write_func_info(string func_name, Cpt *pcpt){
#endif #endif
string src_file = pcpt->funcs_src.find(func_name)->second; string src_file = pcpt->funcs_src.find(func_name)->second;
string lib_file = lib_index.find(src_file)->second; string lib_file = lib_index.find(src_file)->second;
sql::exec(psql, "BEGIN;");
string sql_quote = "SELECT id FROM srcfiles WHERE name = "+sql::string_type(src_file)+";"; string sql_quote = "SELECT id FROM srcfiles WHERE name = "+sql::string_type(src_file)+";";
// 查找源文件信息在数据库中的ID // 查找源文件信息在数据库中的ID
SQLCallBack *psqlcb = sql::sql_exec(psql, sql_quote); SQLCallBack *psqlcb = sql::sql_exec(psql, sql_quote);
@ -390,6 +408,9 @@ void Proj::write_func_info(string func_name, Cpt *pcpt){
throw "database abnormal"; throw "database abnormal";
} }
delete psqlcb; delete psqlcb;
sql::exec(psql, "COMMIT;");
sql::exec(psql, "BEGIN;");
// 查找动态链接库信息在数据库中的ID // 查找动态链接库信息在数据库中的ID
sql_quote = "SELECT id FROM libfiles WHERE name = "+sql::string_type(lib_file)+";"; sql_quote = "SELECT id FROM libfiles WHERE name = "+sql::string_type(lib_file)+";";
psqlcb = sql::sql_exec(psql, sql_quote); psqlcb = sql::sql_exec(psql, sql_quote);
@ -410,6 +431,9 @@ void Proj::write_func_info(string func_name, Cpt *pcpt){
throw "database abnormal"; throw "database abnormal";
} }
delete psqlcb; delete psqlcb;
sql::exec(psql, "COMMIT;");
sql::exec(psql, "BEGIN;");
// 链接数据 // 链接数据
sqlite3_bind_int(psqlsmt, 1, ++idx); sqlite3_bind_int(psqlsmt, 1, ++idx);
sqlite3_bind_text(psqlsmt, 2, func_name.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 2, func_name.data(), -1, SQLITE_TRANSIENT);
@ -431,6 +455,7 @@ void Proj::write_func_info(string func_name, Cpt *pcpt){
sqlite3_reset(psqlsmt); sqlite3_reset(psqlsmt);
sqlite3_clear_bindings(psqlsmt); sqlite3_clear_bindings(psqlsmt);
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
//写入口函数入输入输出参数信息到数据库中 //写入口函数入输入输出参数信息到数据库中
@ -482,7 +507,10 @@ void Proj::write_args_info_no_create_table(string func_name, Cpt *pcpt){
printf("Writing Function Parameter (IN) Information Into Database (%s)\n",func_name.data()); printf("Writing Function Parameter (IN) Information Into Database (%s)\n",func_name.data());
#endif #endif
// 写入输入参数 // 写入输入参数
for(auto arg : *pfin){ for(auto arg : *pfin){
sql::exec(psql, "BEGIN;");
// 连接数据 // 连接数据
sqlite3_bind_text(psqlsmt, 1, arg.type.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 1, arg.type.data(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(psqlsmt, 2, idx++); sqlite3_bind_int(psqlsmt, 2, idx++);
@ -504,14 +532,18 @@ void Proj::write_args_info_no_create_table(string func_name, Cpt *pcpt){
} }
sqlite3_reset(psqlsmt); sqlite3_reset(psqlsmt);
sqlite3_clear_bindings(psqlsmt); sqlite3_clear_bindings(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
#ifdef DEBUG #ifdef DEBUG
printf("Writing Function Parameter (OUT) Information Into Database (%s)\n",func_name.data()); printf("Writing Function Parameter (OUT) Information Into Database (%s)\n",func_name.data());
#endif #endif
idx = 0; idx = 0;
// 写入输入参数 // 写入输入参数
for(auto arg : *pfout){ for(auto arg : *pfout){
sql::exec(psql, "BEGIN;");
// 连接数据 // 连接数据
sqlite3_bind_text(psqlsmt, 1, arg.type.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 1, arg.type.data(), -1, SQLITE_TRANSIENT);
sqlite3_bind_int(psqlsmt, 2, idx++); sqlite3_bind_int(psqlsmt, 2, idx++);
@ -534,6 +566,7 @@ void Proj::write_args_info_no_create_table(string func_name, Cpt *pcpt){
} }
sqlite3_reset(psqlsmt); sqlite3_reset(psqlsmt);
sqlite3_clear_bindings(psqlsmt); sqlite3_clear_bindings(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
} }
@ -558,6 +591,8 @@ void Proj::write_cpt_info(void){
}; };
string buff; string buff;
read_settings(treal_path, buff); read_settings(treal_path, buff);
sql::exec(psql, "BEGIN;");
sqlite3_bind_int(psqlsmt, 1, idx++); sqlite3_bind_int(psqlsmt, 1, idx++);
string md5; string md5;
ComputeFile(treal_path.data(), md5); ComputeFile(treal_path.data(), md5);
@ -578,6 +613,8 @@ void Proj::write_cpt_info(void){
} }
sqlite3_reset(psqlsmt); sqlite3_reset(psqlsmt);
sqlite3_clear_bindings(psqlsmt); sqlite3_clear_bindings(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
} }
@ -601,6 +638,8 @@ void Proj::write_proj_info(void){
sqlite3_bind_blob(psqlsmt, 2, content.data(), (int)content.size(), SQLITE_TRANSIENT); sqlite3_bind_blob(psqlsmt, 2, content.data(), (int)content.size(), SQLITE_TRANSIENT);
string md5; string md5;
ComputeFile(proj_path+"netc.proj", md5); ComputeFile(proj_path+"netc.proj", md5);
sql::exec(psql, "BEGIN;");
sqlite3_bind_text(psqlsmt, 3, md5.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 3, md5.data(), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(psqlsmt, 4, lib_path.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 4, lib_path.data(), -1, SQLITE_TRANSIENT);
// 执行SQL语句 // 执行SQL语句
@ -618,7 +657,7 @@ void Proj::write_proj_info(void){
sqlite3_reset(psqlsmt); sqlite3_reset(psqlsmt);
sqlite3_clear_bindings(psqlsmt); sqlite3_clear_bindings(psqlsmt);
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
void Proj::check_database(void){ void Proj::check_database(void){
@ -633,6 +672,7 @@ void Proj::check_database(void){
#endif #endif
const char *tables[] = {"srcfiles","cptfiles","functions","projfile","libfiles","projfile"}; const char *tables[] = {"srcfiles","cptfiles","functions","projfile","libfiles","projfile"};
for(auto strc : tables){ for(auto strc : tables){
sql::exec(psql, "BEGIN;");
sqlite3_bind_text(psqlsmt, 1, strc, -1, SQLITE_STATIC); sqlite3_bind_text(psqlsmt, 1, strc, -1, SQLITE_STATIC);
// 执行SQL语句 // 执行SQL语句
int rtn = sqlite3_step(psqlsmt); int rtn = sqlite3_step(psqlsmt);
@ -656,6 +696,7 @@ void Proj::check_database(void){
} }
sqlite3_reset(psqlsmt); sqlite3_reset(psqlsmt);
sqlite3_clear_bindings(psqlsmt); sqlite3_clear_bindings(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
@ -737,9 +778,11 @@ void Proj::check_database(void){
printf("Succeed In Checking Table Columns\n"); printf("Succeed In Checking Table Columns\n");
#endif #endif
sql::exec(psql, "BEGIN;");
sql_quote = "SELECT project_name FROM projfile;"; sql_quote = "SELECT project_name FROM projfile;";
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
string tname = (char *)sqlite3_column_text(psqlsmt, 0); string tname = (char *)sqlite3_column_text(psqlsmt, 0);
if(name != tname){ if(name != tname){
#ifdef DEBUG #ifdef DEBUG
@ -748,6 +791,8 @@ void Proj::check_database(void){
throw "database conflict"; throw "database conflict";
} }
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
#ifdef DEBUG #ifdef DEBUG
printf("Succeed In Checking Project Information\n"); printf("Succeed In Checking Project Information\n");
#endif #endif
@ -755,7 +800,9 @@ void Proj::check_database(void){
} }
void Proj::check_table(int cnum,vector<check_table_column> sctc,sqlite3_stmt *psqlsmt){ void Proj::check_table(int cnum,vector<check_table_column> sctc,sqlite3_stmt *psqlsmt){
sql::exec(psql, "BEGIN;");
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
int tcnum = sqlite3_data_count(psqlsmt); int tcnum = sqlite3_data_count(psqlsmt);
if(tcnum != 6){ if(tcnum != 6){
#ifdef DEBUG #ifdef DEBUG
@ -775,7 +822,9 @@ void Proj::check_table(int cnum,vector<check_table_column> sctc,sqlite3_stmt *ps
if(tctc.name != sctc[i-1].name || tctc.type != sctc[i-1].type || tctc.notnull != sctc[i-1].notnull || tctc.pk != sctc[i-1].pk){ if(tctc.name != sctc[i-1].name || tctc.type != sctc[i-1].type || tctc.notnull != sctc[i-1].notnull || tctc.pk != sctc[i-1].pk){
throw "table abnormal"; throw "table abnormal";
} }
sql::exec(psql, "BEGIN;");
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
} }
@ -1093,12 +1142,14 @@ void Proj::UpdateProcess(void){
CheckCptInfo(); CheckCptInfo();
BuildFuncIndex(); BuildFuncIndex();
sql::exec(psql, "BEGIN;");
// 编译新增源文件并将记录添加到数据库中 // 编译新增源文件并将记录添加到数据库中
// 查找最大id // 查找最大id
string sql_quote2 = "SELECT * FROM srcfiles ORDER BY id DESC limit 0,1;"; string sql_quote2 = "SELECT * FROM srcfiles ORDER BY id DESC limit 0,1;";
sqlite3_stmt *psqlsmt2; sqlite3_stmt *psqlsmt2;
sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail); sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail);
int rtn = sqlite3_step(psqlsmt2); int rtn = sqlite3_step(psqlsmt2);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }
@ -1109,6 +1160,7 @@ void Proj::UpdateProcess(void){
} }
int last_id = sqlite3_column_int(psqlsmt2, 0); int last_id = sqlite3_column_int(psqlsmt2, 0);
sqlite3_finalize(psqlsmt2); sqlite3_finalize(psqlsmt2);
sql::insert_info(psql, &psqlsmt2, "srcfiles", { sql::insert_info(psql, &psqlsmt2, "srcfiles", {
{"id","?1"}, {"id","?1"},
{"name","?2"}, {"name","?2"},
@ -1116,8 +1168,10 @@ void Proj::UpdateProcess(void){
{"md5","?4"} {"md5","?4"}
}); });
for(auto usrc : used_srcfiles){ for(auto usrc : used_srcfiles){
sql::exec(psql, "BEGIN;");
sqlite3_bind_text(psqlsmt, 1, usrc.first.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 1, usrc.first.data(), -1, SQLITE_TRANSIENT);
int rtn = sqlite3_step(psqlsmt); int rtn = sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }
@ -1126,9 +1180,12 @@ void Proj::UpdateProcess(void){
int errorcode = sqlite3_extended_errcode(psql); int errorcode = sqlite3_extended_errcode(psql);
printf("\033[31mSQL Error: [%d]%s\n\033[0m",errorcode,error); printf("\033[31mSQL Error: [%d]%s\n\033[0m",errorcode,error);
} }
int if_find = sqlite3_column_int(psqlsmt, 0); int if_find = sqlite3_column_int(psqlsmt, 0);
if(!if_find){ if(!if_find){
compile_srcfile(usrc.first, src_paths[usrc.second]); compile_srcfile(usrc.first, src_paths[usrc.second]);
sql::exec(psql, "BEGIN;");
sqlite3_bind_int(psqlsmt2, 1, ++last_id); sqlite3_bind_int(psqlsmt2, 1, ++last_id);
sqlite3_bind_text(psqlsmt2, 2, usrc.first.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt2, 2, usrc.first.data(), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(psqlsmt2, 3, src_paths[usrc.second].data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt2, 3, src_paths[usrc.second].data(), -1, SQLITE_TRANSIENT);
@ -1137,6 +1194,7 @@ void Proj::UpdateProcess(void){
sqlite3_bind_text(psqlsmt2, 4, md5.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt2, 4, md5.data(), -1, SQLITE_TRANSIENT);
// 添加入口函数 // 添加入口函数
int rtn = sqlite3_step(psqlsmt2); int rtn = sqlite3_step(psqlsmt2);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }
@ -1147,6 +1205,7 @@ void Proj::UpdateProcess(void){
} }
sqlite3_reset(psqlsmt2); sqlite3_reset(psqlsmt2);
sqlite3_clear_bindings(psqlsmt2); sqlite3_clear_bindings(psqlsmt2);
} }
sqlite3_reset(psqlsmt); sqlite3_reset(psqlsmt);
sqlite3_clear_bindings(psqlsmt); sqlite3_clear_bindings(psqlsmt);
@ -1154,9 +1213,11 @@ void Proj::UpdateProcess(void){
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
sqlite3_finalize(psqlsmt2); sqlite3_finalize(psqlsmt2);
sql::exec(psql, "BEGIN;");
sql_quote2 = "SELECT * FROM libfiles ORDER BY id DESC limit 0,1;"; sql_quote2 = "SELECT * FROM libfiles ORDER BY id DESC limit 0,1;";
sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail); sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail);
rtn = sqlite3_step(psqlsmt2); rtn = sqlite3_step(psqlsmt2);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }
@ -1167,16 +1228,22 @@ void Proj::UpdateProcess(void){
} }
last_id = sqlite3_column_int(psqlsmt2, 0); last_id = sqlite3_column_int(psqlsmt2, 0);
sqlite3_finalize(psqlsmt2); sqlite3_finalize(psqlsmt2);
sql::insert_info(psql, &psqlsmt2, "libfiles", { sql::insert_info(psql, &psqlsmt2, "libfiles", {
{"id","?1"}, {"id","?1"},
{"name","?2"}, {"name","?2"},
{"content","?3"} {"content","?3"}
}); });
for(auto lib : lib_index){ for(auto lib : lib_index){
sql::exec(psql, "BEGIN;");
sql_quote = "SELECT count(*) FROM libfiles WHERE name = ?1"; sql_quote = "SELECT count(*) FROM libfiles WHERE name = ?1";
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
sqlite3_bind_text(psqlsmt, 1, lib.second.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 1, lib.second.data(), -1, SQLITE_TRANSIENT);
int rtn = sqlite3_step(psqlsmt); int rtn = sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
int if_find = sqlite3_column_int(psqlsmt, 0); int if_find = sqlite3_column_int(psqlsmt, 0);
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
@ -1188,11 +1255,12 @@ void Proj::UpdateProcess(void){
printf("\033[31mSQL Error: [%d]%s\n\033[0m",errorcode,error); printf("\033[31mSQL Error: [%d]%s\n\033[0m",errorcode,error);
throw error; throw error;
} }
sql::exec(psql, "BEGIN;");
sqlite3_bind_int(psqlsmt2, 1, ++last_id); sqlite3_bind_int(psqlsmt2, 1, ++last_id);
sqlite3_bind_text(psqlsmt2, 2, lib.second.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt2, 2, lib.second.data(), -1, SQLITE_TRANSIENT);
// 添加动态链接库 // 添加动态链接库
rtn = sqlite3_step(psqlsmt2); rtn = sqlite3_step(psqlsmt2);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }
@ -1214,8 +1282,10 @@ void Proj::UpdateProcess(void){
sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail); sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail);
for(auto usrc : used_srcfiles){ for(auto usrc : used_srcfiles){
sql::exec(psql, "BEGIN;");
sqlite3_bind_text(psqlsmt, 1, usrc.first.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 1, usrc.first.data(), -1, SQLITE_TRANSIENT);
int rtn = sqlite3_step(psqlsmt); int rtn = sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }
@ -1230,11 +1300,14 @@ void Proj::UpdateProcess(void){
ComputeFile(tsrc_file.data(), tmd5); ComputeFile(tsrc_file.data(), tmd5);
if(dmd5 != tmd5){ if(dmd5 != tmd5){
compile_srcfile(usrc.first, src_paths[usrc.second]); compile_srcfile(usrc.first, src_paths[usrc.second]);
sql::exec(psql, "BEGIN;");
// 更新md5 // 更新md5
sqlite3_bind_text(psqlsmt2, 1, tmd5.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt2, 1, tmd5.data(), -1, SQLITE_TRANSIENT);
sqlite3_bind_text(psqlsmt2, 2, usrc.first.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt2, 2, usrc.first.data(), -1, SQLITE_TRANSIENT);
int rtn = sqlite3_step(psqlsmt2); int rtn = sqlite3_step(psqlsmt2);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }
@ -1258,8 +1331,10 @@ void Proj::UpdateProcess(void){
sql_quote = "SELECT count(*) FROM functions WHERE name = ?1;"; sql_quote = "SELECT count(*) FROM functions WHERE name = ?1;";
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
for(auto func : func_index){ for(auto func : func_index){
sql::exec(psql, "BEGIN;");
sqlite3_bind_text(psqlsmt, 1, func.first.data(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(psqlsmt, 1, func.first.data(), -1, SQLITE_TRANSIENT);
int rtn = sqlite3_step(psqlsmt); int rtn = sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
int if_find = sqlite3_column_int(psqlsmt, 0); int if_find = sqlite3_column_int(psqlsmt, 0);
@ -1285,8 +1360,11 @@ void Proj::UpdateProcess(void){
// 检查更新参数列表 // 检查更新参数列表
for(auto func : func_index){ for(auto func : func_index){
sql_quote = "SELECT * FROM fargs_" + func.first+";"; sql_quote = "SELECT * FROM fargs_" + func.first+";";
sql::exec(psql, "BEGIN;");
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
int rtn = sqlite3_step(psqlsmt); int rtn = sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }
@ -1318,7 +1396,9 @@ void Proj::UpdateProcess(void){
break; break;
} }
idx++; idx++;
sql::exec(psql, "BEGIN;");
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
idx = 0; idx = 0;
for(auto farg_out : func.second->fargs_out.find(func.first)->second){ for(auto farg_out : func.second->fargs_out.find(func.first)->second){
@ -1339,7 +1419,9 @@ void Proj::UpdateProcess(void){
break; break;
} }
idx++; idx++;
sql::exec(psql, "BEGIIN;");
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
if(if_changed){ if(if_changed){
@ -1347,8 +1429,10 @@ void Proj::UpdateProcess(void){
printf("\033[33mFunction Args Changed %s\n\033[0m",func.first.data()); printf("\033[33mFunction Args Changed %s\n\033[0m",func.first.data());
#endif #endif
sql_quote2 = "DELETE FROM fargs_"+func.first+";"; sql_quote2 = "DELETE FROM fargs_"+func.first+";";
sql::exec(psql, "BEGIN;");
sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail); sqlite3_prepare(psql, sql_quote2.data(), -1, &psqlsmt2, &pzTail);
sqlite3_step(psqlsmt2); sqlite3_step(psqlsmt2);
sql::exec(psql, "COMMIT;");
sqlite3_finalize(psqlsmt2); sqlite3_finalize(psqlsmt2);
write_args_info_no_create_table(func.first,func.second); write_args_info_no_create_table(func.first,func.second);
} }
@ -1356,8 +1440,10 @@ void Proj::UpdateProcess(void){
} }
sql_quote = "DELETE FROM cptfiles"; sql_quote = "DELETE FROM cptfiles";
sql::exec(psql, "BEGIN;");
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
rtn = sqlite3_step(psqlsmt); rtn = sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }
@ -1370,8 +1456,10 @@ void Proj::UpdateProcess(void){
write_cpt_info(); write_cpt_info();
sql_quote = "DELETE FROM projfile"; sql_quote = "DELETE FROM projfile";
sql::exec(psql, "BEGIN;");
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
rtn = sqlite3_step(psqlsmt); rtn = sqlite3_step(psqlsmt);
sql::exec(psql, "COMMIT;");
if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){ if(rtn == SQLITE_DONE || rtn == SQLITE_ROW){
} }

View File

@ -80,6 +80,10 @@ int main(int argc, const char *argv[]){
if (istns.update != nullptr) rtn = istns.client(instruct, config, long_config, target); if (istns.update != nullptr) rtn = istns.client(instruct, config, long_config, target);
else error::printError("Function not found."); else error::printError("Function not found.");
} }
else if (instruct == "autoinit") {
//自动配置
}
else { else {
printf("\033[33mInstruction \"%s\" doesn't make sense.\n\033[0m", instruct.data()); printf("\033[33mInstruction \"%s\" doesn't make sense.\n\033[0m", instruct.data());
} }

View File

@ -41,11 +41,13 @@ void getSQEPublicKey(respond *pres,void *args){
sqlite3 *psql = (sqlite3 *)args; sqlite3 *psql = (sqlite3 *)args;
sqlite3_stmt *psqlsmt; sqlite3_stmt *psqlsmt;
const char *pzTail; const char *pzTail;
sql::exec(psql, "BEGIN;");
string sql_quote = "update client_info set msqes_rsa_public = ?1 where rowid = 1;"; string sql_quote = "update client_info set msqes_rsa_public = ?1 where rowid = 1;";
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
sqlite3_bind_blob(psqlsmt, 1, npbc, sizeof(public_key_class), SQLITE_TRANSIENT); sqlite3_bind_blob(psqlsmt, 1, npbc, sizeof(public_key_class), SQLITE_TRANSIENT);
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
sql::exec(psql, "COMMIT;");
if_wait = 0; if_wait = 0;
} }
else if_wait = -1; else if_wait = -1;
@ -99,10 +101,11 @@ void registerSQECallback(respond *pres,void *args){
sqlite3_stmt *psqlsmt; sqlite3_stmt *psqlsmt;
const char *pzTail; const char *pzTail;
string sql_quote = "delete from client_register_info;"; string sql_quote = "delete from client_register_info;";
sql::exec(psql, "BEGIN;");
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
sqlite3_step(psqlsmt); sqlite3_step(psqlsmt);
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
sql::exec(psql, "COMMIT;");
} }
} }
if_wait = 0; if_wait = 0;
@ -163,9 +166,9 @@ void *connectionDeamon(void *args){
if (!memcmp(pcntl->write_buff, "SDAT", sizeof(uint32_t))) { if (!memcmp(pcntl->write_buff, "SDAT", sizeof(uint32_t))) {
uint32_t nsrwd_size = 0; uint32_t nsrwd_size = 0;
Byte buff[BUFSIZ]; Byte buff[BUFSIZ];
memcpy(&nsrwd_size, pcntl->write_buff + sizeof(uint32_t), sizeof(uint32_t)); memcpy(&nsrwd_size, ((Byte *)pcntl->write_buff + sizeof(uint32_t)), sizeof(uint32_t));
if (!memcmp(pcntl->write_buff + 3 * sizeof(uint32_t) + nsrwd_size, "TADS", sizeof(uint32_t))) { if (!memcmp((Byte *)pcntl->write_buff + 3 * sizeof(uint32_t) + nsrwd_size, "TADS", sizeof(uint32_t))) {
memcpy(buff, pcntl->write_buff + 3 * sizeof(uint32_t), nsrwd_size); memcpy(buff, (Byte *)pcntl->write_buff + 3 * sizeof(uint32_t), nsrwd_size);
send(pcntl->data_sfd, buff, nsrwd_size, 0); send(pcntl->data_sfd, buff, nsrwd_size, 0);
} }
else error::printError("buffer error."); else error::printError("buffer error.");
@ -307,6 +310,7 @@ void *clientServiceDeamon(void *arg) {
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
usleep(1000); usleep(1000);
} }
pthread_exit(NULL);
} }
void gets_s(char *buff, uint32_t size) { void gets_s(char *buff, uint32_t size) {

View File

@ -291,7 +291,7 @@ void Client::SendRawData(raw_data *trdt){
int Server::SentRawdata(struct raw_data *trdt){ int Server::SentRawdata(struct raw_data *trdt){
// 对大包进行拆分发送 // 对大包进行拆分发送
int rtn = 0; ssize_t rtn = 0;
if(trdt->msg_size > 256){ if(trdt->msg_size > 256){
uint64_t aidx = 0,bidx = 0; uint64_t aidx = 0,bidx = 0;
int64_t alls = trdt->msg_size; int64_t alls = trdt->msg_size;
@ -317,7 +317,7 @@ int Server::SentRawdata(struct raw_data *trdt){
else { else {
rtn = send_socket.SendRAW(trdt->msg, trdt->msg_size); rtn = send_socket.SendRAW(trdt->msg, trdt->msg_size);
} }
return rtn; return (int)rtn;
} }
void net_box::FreeNetBox(void){ void net_box::FreeNetBox(void){
@ -648,6 +648,7 @@ SQEServer::SQEServer(int port):Server(port){
sqlite3_stmt *psqlsmt; sqlite3_stmt *psqlsmt;
const char *pzTail; const char *pzTail;
sql::exec(psql, "BEGIN;");
// 从数据库获得服务器的公私钥及服务器名 // 从数据库获得服务器的公私钥及服务器名
string sql_quote = "select sqes_public,sqes_private,name from server_info where rowid = 1;"; string sql_quote = "select sqes_public,sqes_private,name from server_info where rowid = 1;";
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
@ -662,17 +663,20 @@ SQEServer::SQEServer(int port):Server(port){
memcpy(&prc, tbyt, sizeof(private_key_class)); memcpy(&prc, tbyt, sizeof(private_key_class));
name = (const char *)sqlite3_column_blob(psqlsmt, 2); name = (const char *)sqlite3_column_blob(psqlsmt, 2);
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
sql::exec(psql, "COMMIT;");
//打印关键信息 //打印关键信息
error::printSuccess("Server Name: "+name); error::printSuccess("Server Name: "+name);
error::printSuccess("Listen Port: " + std::to_string(port)); error::printSuccess("Listen Port: " + std::to_string(port));
sql::exec(psql, "BEGIN;");
sql_quote = "select count(name) from sqlite_master where name = \"register_info\""; sql_quote = "select count(name) from sqlite_master where name = \"register_info\"";
sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail); sqlite3_prepare(psql, sql_quote.data(), -1, &psqlsmt, &pzTail);
if (sqlite3_step(psqlsmt) != SQLITE_ROW) { if (sqlite3_step(psqlsmt) != SQLITE_ROW) {
sql::printError(psql); sql::printError(psql);
sql::exec(psql, "COMMIT;");
throw "database is abnormal"; throw "database is abnormal";
} }
sql::exec(psql, "COMMIT;");
int if_find = sqlite3_column_int(psqlsmt,0); int if_find = sqlite3_column_int(psqlsmt,0);
if (!if_find) { if (!if_find) {
sql::table_create(psql, "register_info", { sql::table_create(psql, "register_info", {
@ -689,6 +693,7 @@ SQEServer::SQEServer(int port):Server(port){
error::printInfo("create table register_info."); error::printInfo("create table register_info.");
} }
sqlite3_finalize(psqlsmt); sqlite3_finalize(psqlsmt);
} }
void SQEServer::Packet2Request(packet &pkt, request &req){ void SQEServer::Packet2Request(packet &pkt, request &req){
@ -863,7 +868,7 @@ void SQEServer::ProcessRequset(void){
pclr->t_addr.SetPort(sqlite3_column_int(psqlsmt, 6)); pclr->t_addr.SetPort(sqlite3_column_int(psqlsmt, 6));
pclr->psql = psql; pclr->psql = psql;
memcpy((void *)pclr->key.GetKey(), sqlite3_column_blob(psqlsmt, 3), sizeof(uint64_t) * 4); memcpy((void *)pclr->key.GetKey(), sqlite3_column_blob(psqlsmt, 3), sizeof(uint64_t) * 4);
printf("Login successfully %s[%s]:%s\n", pclr->name.data(), pclr->tag.data()); printf("Login successfully %s[%s]\n", pclr->name.data(), pclr->tag.data());
//注册客户端联络守护进程 //注册客户端联络守护进程
clock_register *pncr = new clock_register(); clock_register *pncr = new clock_register();
@ -1253,7 +1258,7 @@ void *clientListener(void *args){
free(buff); free(buff);
} }
else if(size < 0){ else if(size < 0){
pcltl->if_connected == false; pcltl->if_connected = false;
break; break;
} }
usleep(1000); usleep(1000);

View File

@ -139,7 +139,7 @@ ssize_t SocketTCPClient::SendRAW(char *buff, unsigned long size){
send(client_sfd, vbuff, 2 * sizeof(uint32_t) + nidx - idx + 1, 0); send(client_sfd, vbuff, 2 * sizeof(uint32_t) + nidx - idx + 1, 0);
int grtn = recv(client_sfd, gbuff, BUFSIZ,0); ssize_t grtn = recv(client_sfd, gbuff, BUFSIZ,0);
if (grtn > 0 && !memcmp(gbuff, "DGET", sizeof(uint32_t))); if (grtn > 0 && !memcmp(gbuff, "DGET", sizeof(uint32_t)));
else { else {
return -1; return -1;

View File

@ -71,7 +71,9 @@ namespace sql {
} }
sql_quote += ");"; sql_quote += ");";
// 执行SQL语句 // 执行SQL语句
sql::exec(psql, "BEGIN;");
SQLCallBack *pscb = sql_exec(psql, sql_quote); SQLCallBack *pscb = sql_exec(psql, sql_quote);
sql::exec(psql, "COMMIT;");
if(pscb->sql_rtn != SQLITE_OK){ if(pscb->sql_rtn != SQLITE_OK){
#ifdef DEBUG #ifdef DEBUG
printf("[Error]Fail To Create Table %s\n",name.data()); printf("[Error]Fail To Create Table %s\n",name.data());
@ -136,4 +138,8 @@ namespace sql {
} }
} }
int exec(sqlite3 *psql, string sql){
return sqlite3_exec(psql, sql.data(), NULL, NULL, NULL);
}
} }