package cn.hmsoft.jdbc.generator;

import cn.hmsoft.exception.develop.MethodNotImplException;
import cn.hmsoft.jdbc.entity.DateFormatType;

/**********************
 * sql server 数据库实现
 * 
 * @author zxq
 * @create 2019-05-05 20:41:58
 * @version 2.0.0
 * @email: revisit@126.com
 * @Company: www.hmsoft.cn
 */
public class SQLServerSQLGenerator extends AbstractSQLGenerator {

	@Override
	public String[] getNextSequence(String sequenceName) {
		throw new MethodNotImplException(this.getClass(), "getNextSequence");
	}

	@Override
	public String list(String sql, int start, int limit) {
		throw new MethodNotImplException(this.getClass(), "list");
	}

	@Override
	public String queryTables(String databaseName) {
		throw new MethodNotImplException(this.getClass(), "queryTables");
	}

	@Override
	public String queryColumns(String databaseName, String tableName) {
		throw new MethodNotImplException(this.getClass(), "queryColumns");
	}

	@Override
	public String queryCurrentTime() {
		return "select GETDATE() ldt01";
	}

	@Override
	public String random(String sql, int rowCount) {
		return "select top " + rowCount + " from ( " + sql + " order by NEWID())";
	}

	@Override
	public String isNull(String columnName) {
		return "isnull(" + columnName + ",?)";
	}

	@Override
	public String isNull(String columnName, String otherColumn) {
		return "isnull(" + columnName + "," + otherColumn + ")";
	}

	@Override
	public String concatValues(String columnName) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String random() {
		return " random ";
	}

	@Override
	public String formatDate(String columnName, DateFormatType format) {
		if (format == DateFormatType.LongDate)
			return " CONVERT(varchar(100), " + columnName + ", 120) ";
		else if (format == DateFormatType.ShortDate)
			return " CONVERT(varchar(100), " + columnName + ", 23) ";
		else if (format == DateFormatType.LongTime)
			return " CONVERT(varchar(100), " + columnName + ", 8) "; // substring(string, start, length)
		else if (format == DateFormatType.HourMinute)
			// 10:57:46
			return " substring(CONVERT(varchar(100), " + columnName + ", 8),0,5) ";
		else if (format == DateFormatType.MinuteSecond)
			return " substring(CONVERT(varchar(100), " + columnName + ", 8),4,5) ";
		return " CONVERT(varchar(100), " + columnName + ", 120) ";
	}

}
