一、场景:
使用PLSQL编写sql时,有时候会从excel复制一大段数据来执行 in 的操作 比如,select field from tab where field2 in (‘a’,’b’….),其中field2 是字符类型,那么我们需要给复制过来的每一项加上引号,每一项后面加上逗号。可以用插件快速解决这个问题。
PLSQL插件开发过程和文档在PLSQL安装目录plugindoc有详细文档和列子。这里列出解决上述问题的代码
二、创建菜单
char* MenuItemInterface(int Index, bool CreateMenuItem_)
{
switch (Index)
{
case 1 :
if (CreateMenuItem_) return "我的自定义插件 / &Excel 复制内容处理";
processCopiedText();
return NULL;
}
return "";
}
三、处理复制内容
void SplitString(const std::string& s, std::vector<std::string>& v, const std::string& c)
{
std::string::size_type pos1, pos2;
pos2 = s.find(c);
pos1 = 0;
while (std::string::npos != pos2)
{
v.push_back(s.substr(pos1, pos2 - pos1));
pos1 = pos2 + c.size();
pos2 = s.find(c, pos1);
}
if (pos1 != s.length())
v.push_back(s.substr(pos1));
}
void processCopiedText() {
std::stringstream ss;
std::stringstream out;
ss<<IDE_GetSelectedText();
std::vector<std::string> v;
SplitString(ss.str(), v, "\r\n");
for (std::vector<std::string>::size_type i = 0; i != v.size(); ++i) {
out << "'" << v[i] << "'";
if (i != v.size() - 1) {
out << ","<<"\r\n";
}
}
// ShowMessage(out.str().c_str());
std::string proccessedText = out.str();
IDE_SetText((char*)proccessedText.c_str());
}
四、实际效果
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!