UE-行文-js-20141125

function Trim(str)
{
//把str首尾的空格去掉
  var temp1 = str.replace(/(^\s*)|(\s*$)/g, "");
  //把str首尾的单引号去掉
  var temp2 = temp1.replace(/(^‘*)|(‘*$)/g, "");
  //把str首尾的双引号去掉
  var temp3 = temp2.replace(/(^"*)|("*$)/g, "");
  return temp3;
}
//数组分组
function count_str(text_all,str_f) 

    var result = ""; 
    result = text_all.split(str_f);
    //return result.length - 1; 
    return result;
}
UltraEdit.activeDocument.findReplace.regExp = true; 
var str_f = "^db"; 
var str_s = "^select"; 


//UltraEdit.activeDocument.bottom();  //跳转到文件结尾。


//==mongo.find==
UltraEdit.document[0].write("\n===========\n")
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.find(str_f);  //查找字符串 str_f
while (UltraEdit.activeDocument.isFound())  //如果找到要查询的字符串,则执行下面程序 
{
 UltraEdit.activeDocument.selectLine(); 
    line = UltraEdit.activeDocument.selection; 
    //UltraEdit.messageBox("find: "+line); 
    //var array = line.split(":");    //分成数组
    var array = count_str(line,":");
    var arr2 = array[0].split("{");  
    var arr3 = array[1].split("}");
    var arr4 = arr2[0].split(".");
    //UltraEdit.messageBox(arr4[1]+","+arr2[1]+","+arr3[0]); 
    var tab_name = arr4[1];
    var key_name2 = arr2[1];
    var key_name = Trim(key_name2)
    var key_value2 = arr3[0];
    var key_value = Trim(key_value2)
    var Filed_0 = ‘db.‘+tab_name+‘.find({"‘+key_name+‘":"‘+key_value+‘"},{"logicalDel":1}).pretty()‘;
    //var Filed_1 = ‘db.‘+db_name+‘.remove({"‘+key_name+‘":"‘+key_value+‘"})‘;
    //var Filed_2 = ‘db.‘+tab_name+‘.update({"‘+key_name+‘":"‘+key_value+‘"},{$set:{"logicalDel":NumberInt(1)}})‘;
    //UltraEdit.messageBox(Filed_0+"\n"+Filed_1); 
    //UltraEdit.messageBox(Filed_2); 
    UltraEdit.document[0].write(Filed_0+"\n");
    //UltraEdit.document[0].write(Filed_2+"\n")
    UltraEdit.activeDocument.findReplace.find(str_f); 
}
UltraEdit.document[0].write("\n===========\n")
//==mongo.update==
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.find(str_f);  //查找字符串 str_f
while (UltraEdit.activeDocument.isFound())  //如果找到要查询的字符串,则执行下面程序 
{
 UltraEdit.activeDocument.selectLine(); 
    line = UltraEdit.activeDocument.selection; 
    //UltraEdit.messageBox("find: "+line); 
    //var array = line.split(":");    //分成数组
    var array = count_str(line,":");
    var arr2 = array[0].split("{");  
    var arr3 = array[1].split("}");
    var arr4 = arr2[0].split(".");
    //UltraEdit.messageBox(arr4[1]+","+arr2[1]+","+arr3[0]); 
    var tab_name = arr4[1];
    var key_name2 = arr2[1];
    var key_name = Trim(key_name2)
    var key_value2 = arr3[0];
    var key_value = Trim(key_value2)
    //var Filed_0 = ‘db.‘+tab_name+‘.find({"‘+key_name+‘":"‘+key_value+‘"},{"logicalDel":1}).pretty()‘;
    //var Filed_1 = ‘db.‘+db_name+‘.remove({"‘+key_name+‘":"‘+key_value+‘"})‘;
    var Filed_2 = ‘db.‘+tab_name+‘.update({"‘+key_name+‘":"‘+key_value+‘"},{$set:{"logicalDel":NumberInt(1)}})‘;
    //UltraEdit.messageBox(Filed_0+"\n"+Filed_1); 
    //UltraEdit.messageBox(Filed_2); 
    //UltraEdit.document[1].write(Filed_0+"\n");
    UltraEdit.document[0].write(Filed_2+"\n")
    UltraEdit.activeDocument.findReplace.find(str_f); 
}


//==mysql.select==
UltraEdit.document[0].write("\n===========\n")
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.find(str_s);  //查找字符串 str_f
while (UltraEdit.activeDocument.isFound())  //如果找到要查询的字符串,则执行下面程序 
{
 UltraEdit.activeDocument.selectLine(); 
    line = UltraEdit.activeDocument.selection; 
    //UltraEdit.messageBox("find: "+line); 
    var arr = count_str(line," ");
    //UltraEdit.messageBox(arr[3]+","+arr[5]); 
    var table_name=Trim(arr[3]);
    var arr2 = count_str(arr[5],"=");
    //UltraEdit.messageBox(arr2[0]+","+arr2[1]); 
    var Column_name =Trim(arr2[0]);
    var Column_value2 =Trim(arr2[1]);
    var Column_value =count_str(Column_value2,"\"")
    var Filed_4 = ‘select * from ‘+table_name+‘ where ‘+Column_name+‘="‘+Column_value[0]+‘"\\G‘;
    //UltraEdit.messageBox(Filed_4); 
    UltraEdit.document[0].write(Filed_4+"\n")
    UltraEdit.activeDocument.findReplace.find(str_s);
}
//==mysql.update==
UltraEdit.document[0].write("\n===========\n")
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.find(str_s);  //查找字符串 str_f
while (UltraEdit.activeDocument.isFound())  //如果找到要查询的字符串,则执行下面程序 
{
 UltraEdit.activeDocument.selectLine(); 
    line = UltraEdit.activeDocument.selection; 
    //UltraEdit.messageBox("find: "+line); 
    var arr = count_str(line," ");
    //UltraEdit.messageBox(arr[3]+","+arr[5]); 
    var table_name=Trim(arr[3]);
    var arr2 = count_str(arr[5],"=");
    //UltraEdit.messageBox(arr2[0]+","+arr2[1]); 
    var Column_name =Trim(arr2[0]);
    var Column_value2 =Trim(arr2[1]);
    var Column_value =count_str(Column_value2,"\"")
    var Filed_4 = ‘update ‘+table_name+‘ set LogicalDel=1 where ‘+Column_name+‘="‘+Column_value[0]+‘";‘;
    //UltraEdit.messageBox(Filed_4); 
    UltraEdit.document[0].write(Filed_4+"\n")
    UltraEdit.activeDocument.findReplace.find(str_s);
    
}
UltraEdit.document[0].write("commit;\n")

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。