All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ejlchina.searcher.dialect.MySqlDialect Maven / Gradle / Ivy

There is a newer version: 3.8.3
Show newest version
package com.ejlchina.searcher.dialect;


/**
 * MySql 方言实现
 *  
 * @author Troy.Zhou
 * 
 * */
public class MySqlDialect implements Dialect {


	
	@Override
	public void toUpperCase(StringBuilder builder, String dbField) {
		builder.append("upper").append("(").append(dbField).append(")");
	}

	@Override
	public void truncateToDateStr(StringBuilder builder, String dbField) {
		builder.append("date_format(").append(dbField).append(", '%Y-%m-%d')");
	}

	@Override
	public void truncateToDateMinuteStr(StringBuilder builder, String dbField) {
		builder.append("date_format(").append(dbField).append(", '%Y-%m-%d %H:%i')");
	}

	@Override
	public void truncateToDateSecondStr(StringBuilder builder, String dbField) {
		builder.append("date_format(").append(dbField).append(", '%Y-%m-%d %H:%i:%s')");
	}
	
	@Override
	public PaginateSql forPaginate(String fieldSelectSql, String fromWhereSql, Integer max, Long offset) {
		PaginateSql paginateSql = new PaginateSql();
		StringBuilder ret = new StringBuilder();
		ret.append(fieldSelectSql).append(fromWhereSql);
		if (max != null) {
			if (offset == null) {
				ret.append(" limit ?");
			} else {
				ret.append(" limit ?, ?");
				paginateSql.addParam(offset);
			}
			paginateSql.addParam(max);
		}
		paginateSql.setSql(ret.toString());
		return paginateSql;
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy