写在前面:
成长记录——SQL脚本转化工具
- 工作中需要用到.xlsx格式文件转换成.db格式数据库,手动导表麻烦,而且容易出错,为方便数据库的批量导入和读取,并且完成软件部署,下面介绍一款自用批量CVS转SQL脚本工具。
#include "chiness.h"
#define GET_LINE(_inFile, _line, _lineLen, _strLine) \
memset(_line, 0, _lineLen); \
_inFile.getline(_line, _lineLen); \
_strLine = string(_line, strlen(_line)); \
removeR(_strLine)
#define ADDRESS_REGEX_MATCH(_addr, _result) \
regex _reg("[A-Z]*[0-9]*\\.{0,1}[0-9]+");\
_result = regex_match(_addr, _reg)
template<class... T>
void unused_parameter(T&&...) {
}
using namespace std;
string g_sqlPath;
string g_oneSqlFileName = "allSqls.sql";
string g_strTimestamp;
void removeR(string& source)
{
regex g("\\r");
source = regex_replace(source, g, "");
}
string GetExePath(void)
{
char szFilePath[MAX_PATH + 1] = {
0 };
GetModuleFileNameA(NULL, szFilePath, MAX_PATH);
(strrchr(szFilePath, '\\'))[0] = 0;
string path = szFilePath;
regex reg("\\\\");
path = regex_replace(path, reg, "/");
return path;
}
void removeSpace(string& source)
{
string::size_type pos1 = source.find(" ");
if (pos1 != string::npos && pos1 == 0)
{
source = source.substr(1);
}
string::size_type pos2 = source.rfind(" ");
if (pos2 != string::npos && source.length() - pos2 == 1)
{
source.pop_back();
}
if(source.find(" ") != string::npos)
removeSpace(source);
}
string findKey(const string& source, const string& key, string& buttonName)
{
string::size_type pos = source.rfind(key);
string result;
if (pos != string::npos && (source.length() - pos <= 4))
{
buttonName = source.substr(pos);
result = source.substr(0, pos);
}
return result;
}
string findName(const string& source, string& buttonName)
{
string r = findKey(source, "启动", buttonName);
if (!r.empty())
return r;
r = findKey(source, "停止", buttonName);
if (!r.empty())
return r;
r = findKey(source, "自动", buttonName);
if (!r.empty())
return r;
r = findKey(source, "手动", buttonName);
if (!r.empty())
return r;
r = findKey(source, "松开", buttonName);
if (!r.empty())
return r;
r = findKey(source, "胀紧", buttonName);
if (!r.empty())
return r;
r = findKey(source, "下降", buttonName);
if (!r.empty())
return r;
r = findKey(source, "上升", buttonName);
if (!r.empty())
return r;
r = findKey(source, "伸出", buttonName);
if (!r.empty())
return r;
r = findKey(source, "回缩", buttonName);
if (!r.empty())
return r