您的位置:首页 > 移动开发 > Android开发

android SQLite数据库组装sql的源码

2015-04-29 16:40 148 查看
public static String buildQueryString(

boolean distinct, String tables, String[] columns, String where,

String groupBy, String having, String orderBy, String limit) {

if (TextUtils.isEmpty(groupBy) && !TextUtils.isEmpty(having)) {

throw new IllegalArgumentException(

"HAVING clauses are only permitted when using a groupBy clause");

}

if (!TextUtils.isEmpty(limit) && !sLimitPattern.matcher(limit).matches()) {

throw new IllegalArgumentException("invalid LIMIT clauses:" + limit);

}

StringBuilder query = new StringBuilder(120);

query.append("SELECT ");

if (distinct) {

query.append("DISTINCT ");

}

if (columns != null && columns.length != 0) {

appendColumns(query, columns);

} else {

query.append("* ");

}

query.append("FROM ");

query.append(tables);

appendClause(query, " WHERE ", where);

appendClause(query, " GROUP BY ", groupBy);

appendClause(query, " HAVING ", having);

appendClause(query, " ORDER BY ", orderBy);

appendClause(query, " LIMIT ", limit);

return query.toString();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: