dongluan7821 2017-02-27 12:38
浏览 554
已采纳

Golang SQL查询语法验证器

Is there any third-party tool for validate SQL query before I execute it with the database/sql pacakge or any way to check the SQL query is right without getting a panic from database/sql that the query is invalid?

  • 写回答

1条回答 默认 最新

  • dongzhi4239 2017-02-27 12:55
    关注

    Finally, I found this SQL parser package. I colud use it for validate it.

    func isSQLValid(sql string) (bool, error) {
        _, err := sqlparser.Parse(sql)
        if err != nil {
            return false, err
        }
        return true, nil
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?