blade-jdbc icon indicating copy to clipboard operation
blade-jdbc copied to clipboard

query bug

Open hellokaton opened this issue 8 years ago • 1 comments

return db.sql("select id, title, intro, create_time from t_post").where("`status` = ?", 1).page(page, limit);

hellokaton avatar Sep 10 '16 05:09 hellokaton

fix DefaultDialect line 123

@Override
public String getQueryCountSql(String sql, Model model) {
    StringBuffer sqlBuf = new StringBuffer();
    if(null != sql){
        sqlBuf.append("select count(1) from ")
        int pos = sql.indexOf("from") + 4;
        int w = sql.indexOf("where");
        int o = sql.indexOf("order by");

        if(w != -1){
            sqlBuf.append(sql.substring(pos, w));   
        } else if(o != -1){
            sqlBuf.append(sql.substring(pos, 0));   
        } else{
            sqlBuf.append(sql.substring(pos));  
        }
    } else {
        sqlBuf.append("select count(")
        .append(model.pkName())
        .append(") from ")
        .append(model.table());
    }
    sqlBuf.append(' ').append(this.whereSql(1, model));
    return sqlBuf.toString();
}

hellokaton avatar Sep 10 '16 05:09 hellokaton