Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanSql 方法里逻辑是不是有问题 #21

Closed
LeoMelody opened this issue Apr 26, 2021 · 1 comment · Fixed by #26 or #29
Closed

cleanSql 方法里逻辑是不是有问题 #21

LeoMelody opened this issue Apr 26, 2021 · 1 comment · Fixed by #26 or #29

Comments

@LeoMelody
Copy link

/**

  • 清除注释和前后空格
  • @param {String} sql
    */
    function cleanSql(sql: string) {
    sql.trim(); // 删除前后空格
    const tokens = lexer(sql);
    let resultSql = '';
    let startIndex = 0;
    tokens.forEach((ele: Token) => {
    if (ele.type === TokenType.Comment) {
    resultSql += sql.slice(startIndex, ele.start);
    startIndex = ele.end + 1;
    }
    });
    resultSql += sql.slice(startIndex);
    return resultSql;
    }

上面删除前后空格这段代码并不会对源sql字段生效的。是不是要改成下面这样

/**

  • 清除注释和前后空格
  • @param {String} sql
    */
    function cleanSql(origiSql: string) {
    let sql = origiSql.trim(); // 删除前后空格
    const tokens = lexer(sql);
    let resultSql = '';
    let startIndex = 0;
    tokens.forEach((ele: Token) => {
    if (ele.type === TokenType.Comment) {
    resultSql += sql.slice(startIndex, ele.start);
    startIndex = ele.end + 1;
    }
    });
    resultSql += sql.slice(startIndex);
    return resultSql;
    }
@wewoor
Copy link
Contributor

wewoor commented May 11, 2021

@LeoMelody 谢谢反馈

wewoor added a commit that referenced this issue May 11, 2021
wewoor added a commit that referenced this issue May 11, 2021
wewoor added a commit that referenced this issue May 11, 2021
wewoor added a commit that referenced this issue May 11, 2021
wewoor added a commit that referenced this issue May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants