Skip to content
This repository has been archived by the owner on May 9, 2018. It is now read-only.

query bug #4

Open
hellokaton opened this issue Sep 10, 2016 · 1 comment
Open

query bug #4

hellokaton opened this issue Sep 10, 2016 · 1 comment
Assignees
Labels

Comments

@hellokaton
Copy link
Member

return db.sql("select id, title, intro, create_time from t_post").where("`status` = ?", 1).page(page, limit);
@hellokaton hellokaton added the bug label Sep 10, 2016
@hellokaton hellokaton self-assigned this Sep 10, 2016
@hellokaton
Copy link
Member Author

hellokaton commented Sep 10, 2016

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 added a commit that referenced this issue Sep 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant