用pegjs重写sql分割方法
This commit is contained in:
		@ -6,7 +6,7 @@ const commentFilter = require('../core/comment');
 | 
			
		||||
 * @param {String} sql 
 | 
			
		||||
 */
 | 
			
		||||
function filterComments(sql) {
 | 
			
		||||
    return commentFilter.parse(sql)
 | 
			
		||||
    return commentFilter.parse(sql).text;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -22,36 +22,7 @@ function cleanSql(sql) {
 | 
			
		||||
 * @param {String} sqlText 
 | 
			
		||||
 */
 | 
			
		||||
function splitSql(sqlText) {
 | 
			
		||||
    sqlText=cleanSql(sqlText);
 | 
			
		||||
    if (!sqlText) {
 | 
			
		||||
        return sqlText;
 | 
			
		||||
    }
 | 
			
		||||
    sqlText = sqlText.trim();
 | 
			
		||||
    if (!endsWith(sqlText, ';')) {
 | 
			
		||||
        sqlText += ';';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let results = [];
 | 
			
		||||
    let index = 0;
 | 
			
		||||
    let tmpChar = null;
 | 
			
		||||
    for (let i = 0; i < sqlText.length; i++) {
 | 
			
		||||
        let char = sqlText[i];
 | 
			
		||||
 | 
			
		||||
        if (char == "'" || char == '"') {
 | 
			
		||||
            if (tmpChar == char) {
 | 
			
		||||
                tmpChar = null;
 | 
			
		||||
            } else {
 | 
			
		||||
                tmpChar = char;
 | 
			
		||||
            }
 | 
			
		||||
        } else if (char == ';') {
 | 
			
		||||
            if (tmpChar == null) {
 | 
			
		||||
                results.push(sqlText.substring(index, i));
 | 
			
		||||
                index = i + 1;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return results;
 | 
			
		||||
    return commentFilter.parse(sqlText).lines
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.filterComments = filterComments;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user