Esempio n. 1
0
func (this *MySQL5Translator) PaginateSQL(query *db.Query, sql string) string {
	sb := tk.NewStrBuffer()
	if query.GetLimit() > 0 {
		sb.Add(sql, " LIMIT :", db.OFFSET_PARAM, ", :", db.LIMIT_PARAM)
		if query.GetSkip() >= 0 {
			query.SetParameter(db.OFFSET_PARAM, query.GetSkip())
		}
		query.SetParameter(db.LIMIT_PARAM, query.GetLimit())
		return sb.String()
	}

	return sql
}
Esempio n. 2
0
func (this *OracleTranslator) PaginateSQL(query *db.Query, sql string) string {
	if query.GetSkip() > 0 {
		query.SetParameter(db.OFFSET_PARAM, query.GetSkip()+1)
		query.SetParameter(db.LIMIT_PARAM, query.GetSkip()+query.GetLimit())
		return fmt.Sprintf("select * from ( select a.*, rownum rnum from ( %s ) a where rownum <= :%s ) where rnum >= :%s",
			sql, db.LIMIT_PARAM, db.OFFSET_PARAM)
	} else if query.GetLimit() > 0 {
		query.SetParameter(db.LIMIT_PARAM, query.GetLimit())
		return fmt.Sprintf("select * from ( %s ) where rownum <= :%s", sql, db.LIMIT_PARAM)
	}

	return sql
}
Esempio n. 3
0
func (this *FirebirdSQLTranslator) PaginateSQL(query *db.Query, sql string) string {
	sb := tk.NewStrBuffer()
	if query.GetLimit() > 0 {
		sb.Add(sql, " ROWS ")
		if query.GetSkip() > 0 {
			sb.Add(":", db.OFFSET_PARAM, " TO ")
			query.SetParameter(db.OFFSET_PARAM, query.GetSkip()+1)
		}
		sb.Add(":", db.LIMIT_PARAM)
		query.SetParameter(db.LIMIT_PARAM, query.GetSkip()+query.GetLimit())

		return sb.String()
	}

	return sql
}