|
|
|
@ -9,8 +9,9 @@
|
|
|
|
|
var codeRuleStr="((\"[\u4E00-\u9FA50-9a-z _]+\")|(\\[[\u4E00-\u9FA50-9a-z _]+\\])|(`[\u4E00-\u9FA50-9a-z _]+`)|([a-z]+[0-9]*(_[a-z]+[0-9]*)*))";
|
|
|
|
|
var codeRuleStr2="((\"[\u4E00-\u9FA50-9a-z _]+\")|(\\[[\u4E00-\u9FA50-9a-z _]+\\])|(`[\u4E00-\u9FA50-9a-z _]+`)|([a-z]+[0-9]*(_[a-z]+[0-9]*)*))";
|
|
|
|
|
var bracketRuleStr="^(\"|`|\\[)";
|
|
|
|
|
var tableRuleStr="\"%s\"|\\[%s\\]|`%s`|\\b%s";
|
|
|
|
|
var schemaTableRuleStr="\"%x\".\"%s\"|\\[%x\\].\\[%s\\]|`%x`.`%s`|%x.%s";
|
|
|
|
|
var bracketRuleClear= new RegExp("[\"`\\[\\]]+","g");
|
|
|
|
|
var tableRuleStr="\"%s\"|\\[%s\\]|`%s`|\\b%s\\b";
|
|
|
|
|
var schemaTableRuleStr= "\"\\w+\".\"%s\"|\\[\\w+\\].\\[%s\\]|`\\w+`.`%s`|\\b\\w+.%s\\b";
|
|
|
|
|
var alisaTempKey="ALISAALISAALISA";
|
|
|
|
|
var showPath=true;
|
|
|
|
|
var likeMatch=true;
|
|
|
|
@ -265,6 +266,7 @@ function markCharOrder(search, word) {
|
|
|
|
|
if(!text){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
text=text.replace(new RegExp("\\b(INSERT INTO|CREATE TABLE)\\b.*?\\)( |AS)*(?=\\bSELECT\\b)", "i")," ");
|
|
|
|
|
inputAlias = inputAlias.toLowerCase();
|
|
|
|
|
var groupdata = getNestingDepth(currTableCodes,text, currKey);
|
|
|
|
|
if(!groupdata){
|
|
|
|
@ -337,7 +339,8 @@ function markCharOrder(search, word) {
|
|
|
|
|
var fields = c.fields.match(new RegExp("(("+alisalist.join("|")+")\\."+codeRuleStr+" (AS| +) "+codeRuleStr2+" *(,|$))"+
|
|
|
|
|
"|(("+alisalist.join("|")+")\\."+codeRuleStr+"[^,]+ (AS| ) "+codeRuleStr2+" *(,|$))"+
|
|
|
|
|
"|([^,]*\\(.*?\\).*?(AS| +) "+codeRuleStr2+" *(,|$))"+
|
|
|
|
|
"|(("+alisalist.join("|")+")\\.\\* *(,|$))|(("+alisalist.join("|")+")\\."+codeRuleStr+" *(,|$))","ig"));
|
|
|
|
|
"|(("+alisalist.join("|")+")\\.\\* *(,|$))|(("+alisalist.join("|")+")\\."+codeRuleStr+" *(,|$))" +
|
|
|
|
|
"|((?<!\\.)('\\d+'|\\d+) (AS| +) " + codeRuleStr2 + " *(,|$))", "ig"));
|
|
|
|
|
if(fields && fields.length>0){
|
|
|
|
|
for (var j = 0; j < fields.length; j++) {
|
|
|
|
|
var fstr = fields[j];
|
|
|
|
@ -457,7 +460,7 @@ function markCharOrder(search, word) {
|
|
|
|
|
if(keys.length>0){
|
|
|
|
|
tables[inputAlias].push(displayHandler(fm[fm.length-1],descs.join("+"),keys.join("+")));
|
|
|
|
|
}else{
|
|
|
|
|
tables[inputAlias].push(displayHandler(fm[fm.length-1],null,factcode));
|
|
|
|
|
tables[inputAlias].push(displayHandler(fm[fm.length-1],null,null));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -615,7 +618,7 @@ function markCharOrder(search, word) {
|
|
|
|
|
if(!text1){
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
text1 = text1.replace(/'.*?'/ig,"' '").replace(/(\\n|\n|\\t|\t)/g," ")
|
|
|
|
|
text1 = clearContextValue(text1).replace(/(\\n|\n|\\t|\t)/g," ")
|
|
|
|
|
.replace(/ +/g," ").replace(regxSemicolon,"");
|
|
|
|
|
text1 = clearContentComment(text1,true);
|
|
|
|
|
return text1;
|
|
|
|
@ -624,7 +627,7 @@ function markCharOrder(search, word) {
|
|
|
|
|
if(!text){
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
text=text.replace(/'.*?'/ig,"' '").replace(/''/ig," ");
|
|
|
|
|
text= clearContextValue(text).replace(/''/ig," ");
|
|
|
|
|
var lines = text.split('\n');
|
|
|
|
|
var text2="";
|
|
|
|
|
for (var i = 0; i < lines.length; i++) {
|
|
|
|
@ -656,7 +659,7 @@ function markCharOrder(search, word) {
|
|
|
|
|
text2=text2+"\n"+linex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
text2 = text2.replace(/'.*?'/ig,"' '").replace(/(\\n|\n|\\t|\t)/g," ")
|
|
|
|
|
text2 = text2.replace(/(\\n|\n|\\t|\t)/g," ")
|
|
|
|
|
.replace(/ +/g," ");
|
|
|
|
|
return text2;
|
|
|
|
|
}
|
|
|
|
@ -685,7 +688,19 @@ function markCharOrder(search, word) {
|
|
|
|
|
}
|
|
|
|
|
return text2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearContextValue(text1) {
|
|
|
|
|
if (!text1) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
text1 = text1.replace(/ +/g, " ").replace(new RegExp("'.*?'( AS\\b)*","ig"), (match) => {
|
|
|
|
|
if (/\bAS\b/i.test(match)) {
|
|
|
|
|
return match;
|
|
|
|
|
} else {
|
|
|
|
|
return "' '";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return text1;
|
|
|
|
|
}
|
|
|
|
|
function addTableList(tables,tablesList){
|
|
|
|
|
if(!tablesList){
|
|
|
|
|
return;
|
|
|
|
@ -1201,38 +1216,46 @@ export const sqlqueryUtils = {
|
|
|
|
|
tempSqlTables={};
|
|
|
|
|
|
|
|
|
|
if(startLineStr && startLineStr.length > 10){
|
|
|
|
|
currSelectQueryStr=startLineStr;
|
|
|
|
|
currInputAlias=inputAlias;
|
|
|
|
|
|
|
|
|
|
//console.log("currSelectQueryStr",currSelectQueryStr);
|
|
|
|
|
for(var i=0,ln=alltablecodes.length;i<ln;i++){
|
|
|
|
|
var t=alltablecodes[i].tableName;
|
|
|
|
|
var t2=t;
|
|
|
|
|
var tmp=t.split(".");
|
|
|
|
|
for(var alli=0,allln=alltablecodes.length;alli<allln;alli++){
|
|
|
|
|
var key=alltablecodes[alli].tableName;
|
|
|
|
|
var tmp=key.split(".");
|
|
|
|
|
|
|
|
|
|
var regxstr1="";
|
|
|
|
|
if (tmp.length > 1) {
|
|
|
|
|
t2 = t.replace(".", "\\.") + "|" + "\\w+\\."+tmp[1] +"|"+tmp[1];
|
|
|
|
|
regxstr1 = regxstr1 + schemaTableRuleStr.replace(/%s/g, tmp[1])
|
|
|
|
|
+"|"+tableRuleStr.replace(/%s/g, tmp[1])
|
|
|
|
|
}else{
|
|
|
|
|
regxstr1 = regxstr1 + tableRuleStr.replace(/%s/g, key);
|
|
|
|
|
}
|
|
|
|
|
var mresult=startLineStr.match(new RegExp("\\b(" + t2 + ")\\b", "ig"));
|
|
|
|
|
regxstr1 = regxstr1.replace(/\./g, "\\.");
|
|
|
|
|
var mresult = startLineStr.match(new RegExp(regxstr1, "ig"));
|
|
|
|
|
if(!mresult){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
var result=false;
|
|
|
|
|
for (var mi = 0, mln = mresult.length; mi < mln; mi++) {
|
|
|
|
|
if(t.toLowerCase()===mresult[mi].toLowerCase() || tmp[1].toLowerCase()===mresult[mi].toLowerCase()){
|
|
|
|
|
for (var i = 0, ln = mresult.length; i < ln; i++) {
|
|
|
|
|
var newcode = mresult[i].replace(bracketRuleClear,"");
|
|
|
|
|
startLineStr = startLineStr.replace(new RegExp(mresult[i],"g"), newcode);
|
|
|
|
|
if(key.toLowerCase()===newcode.toLowerCase() || (tmp.length > 1 && newcode.indexOf(".")===-1
|
|
|
|
|
&& tmp[1].toLowerCase()===newcode.toLowerCase())){
|
|
|
|
|
result=true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(result){
|
|
|
|
|
tempSqlTables[t] = [];
|
|
|
|
|
currSelectTables.push(t);
|
|
|
|
|
tempSqlTables[key] = [];
|
|
|
|
|
currSelectTables.push(key);
|
|
|
|
|
}
|
|
|
|
|
if(currSelectTables.length>50){
|
|
|
|
|
//正常不应该有这么多表。也不建议所有sql放一起
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
currSelectQueryStr=startLineStr;
|
|
|
|
|
currInputAlias=inputAlias;
|
|
|
|
|
}
|
|
|
|
|
//console.log("currSelectQueryStr>>",currSelectQueryStr,currSelectTables);
|
|
|
|
|
}catch(e){
|
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
|
|
|
@ -1266,25 +1289,20 @@ export const sqlqueryUtils = {
|
|
|
|
|
|
|
|
|
|
var regxstr1;
|
|
|
|
|
for (var i = 0, ln = currSelectTables.length; i < ln; i++) {
|
|
|
|
|
regxstr1=(i==0?"":regxstr1+"|");
|
|
|
|
|
if (currSelectTables[i].indexOf(".") > -1) {
|
|
|
|
|
var ct=currSelectTables[i].split(".");
|
|
|
|
|
regxstr1 = regxstr1 + schemaTableRuleStr.replace(/%x/g, ct[0]).replace(/%s/g, ct[1])
|
|
|
|
|
+"|"+tableRuleStr.replace(/%s/g, ct[1])
|
|
|
|
|
}else{
|
|
|
|
|
regxstr1 = regxstr1 + tableRuleStr.replace(/%s/g, currSelectTables[i]);
|
|
|
|
|
}
|
|
|
|
|
regxstr1=(i==0?"":regxstr1+"|");
|
|
|
|
|
if (currSelectTables[i].indexOf(".") > -1) {
|
|
|
|
|
regxstr1 = regxstr1 + currSelectTables[i] + "|(?<!.)" + currSelectTables[i].split(".")[1];
|
|
|
|
|
}else{
|
|
|
|
|
regxstr1 = regxstr1 +"(?<!.)"+ currSelectTables[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
regxstr1=regxstr1.replace(/\./g,"\\.");
|
|
|
|
|
var tableWithAliasRegs =new RegExp("(" + regxstr1 + ") +" + alisaRuleStr + "\\b|(" + regxstr1 + ")\\b", "ig");
|
|
|
|
|
regxstr1=regxstr1.replace(/\./g,"\\.");
|
|
|
|
|
var tableWithAliasRegs = new RegExp("\\b(" + regxstr1 + ")\\b +" + alisaRuleStr + "|\\b(" + regxstr1 + ")\\b", "ig");
|
|
|
|
|
var tableWithAlias = currSelectQueryStr.match(tableWithAliasRegs);
|
|
|
|
|
|
|
|
|
|
var handlerTableAlias = function(tableAliasMap,keywords,str){
|
|
|
|
|
var t = str.split(" ");//table t1
|
|
|
|
|
if(new RegExp(bracketRuleStr).test(t[0])){
|
|
|
|
|
t[0]=t[0].substring(1, t[0].length - 1);
|
|
|
|
|
}
|
|
|
|
|
var factkey = getArrayValue(currSelectTables,t[0]);
|
|
|
|
|
if(factkey){
|
|
|
|
|
if(!tableAliasMap.hasOwnProperty(factkey)){
|
|
|
|
|