加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tools.c 1.93 KB
一键复制 编辑 原始数据 按行查看 历史
SpaceX_zhao 提交于 2023-05-18 22:23 . alopex modify
#include "head.h"
int recvn(int sockfd, void *buf, int length){
int total = 0;
char *p = (char *)buf;
while(total < length){
ssize_t sret = recv(sockfd, p+total, length-total, 0);
total += sret;
}
return 0;
}
int insertSql(const char* filename, MYSQL* usrsql, userProcess_t *usr, char *md5){
int pre_id = 0;
char path[128] = {0};
char sqlCommand[1024] = {0};
sprintf(sqlCommand, "select preid , path from vfsystem where id = %d", usr->curid);
int ret = mysql_query(usrsql, sqlCommand);
if(ret != 0){
LOGRECORD(ERROR, "mysql_query");
return ret;
}
MYSQL_RES *result = mysql_store_result(usrsql);
MYSQL_ROW row = mysql_fetch_row(result);
int row0 = atoi(row[0]);
memcpy(&pre_id, &row0, sizeof(int));
strcpy(path,row[1]);
LOGRECORD(INFO,"get preid and path");
mysql_free_result(result);
//bzero(sqlCommand,sizeof(sqlCommand));
//sprintf(sqlCommand, "select id from vfsystem where path = '%s' and preid = %d and name = '%s'",
// path, pre_id,filename);
//printf("%s\n", sqlCommand);
//ret = mysql_query(usrsql, sqlCommand);
//printf("%d\n", ret);
//
//result = mysql_store_result(usrsql);
//row = mysql_fetch_row(result);
//printf("in tools.c :%s\n",row[0]);
//if(row != NULL){
// LOGRECORD(ERROR,"filename already exist in currpath");
// mysql_free_result(result);
// return -1;
//}
bzero(sqlCommand, sizeof(sqlCommand));
sprintf(sqlCommand, "insert into vfsystem (name,type,preid,path,user,tomb,md5)"
"values ('%s','f',%d,'%s','%s',0,'%s')", filename, pre_id, path, usr->username, md5);
ret = mysql_query(usrsql, sqlCommand);
if(ret != 0){
LOGRECORD(ERROR,"mysql_query failed !");
return -1;
}
LOGRECORD(INFO,"mysql_query success");
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化