sqlparser/select.cpp
// Convert row limits specified in SELECT
Convert row limits specified in SELECT
Convert row limits specified in SELECT
void SqlParser::SelectConvertRowlimit(Token *select, Token *from, Token *from_end, Token *where_, 
										Token *where_end, Token *pre_order, Token *order, 
										Token *rowlimit_slist, Token *rowlimit_soptions, int rowlimit, 
										bool rowlimit_percent)
{
	if(rowlimit_slist == NULL && rowlimit_soptions == NULL && rowlimit == 0)
		return;
	int limit = rowlimit;
	if(rowlimit_slist != NULL)
		limit = rowlimit_slist->GetInt();
	else
	if(rowlimit_soptions != NULL)
		limit = rowlimit_soptions->GetInt();
	if(limit == 100 && rowlimit_percent == true)
		return;
	Token *end = GetLastToken();
	if(_source != SQL_ORACLE && _target == SQL_ORACLE)
	{
		if(order == NULL)
		{
			if(where_ == NULL)
				end = Append(from_end, " WHERE ", L" WHERE ", 7, select);
			else
				end = Append(where_end, " AND ", L" AND ", 5, where_);
		}
		else		
		{
			Prepend(select, "SELECT * FROM (", L"SELECT * FROM (", 15);
			Append(end, ") WHERE ", L") WHERE ", 8, select);
		}
		AppendNoFormat(end, "rownum <= ", L"rownum <= ", 10);
		if(rowlimit_slist != NULL || rowlimit_soptions != NULL)
			AppendCopy(end, Nvl(rowlimit_slist, rowlimit_soptions));
		else
			Append(end, rowlimit);
		if(rowlimit_percent == true)
		{
			Append(end, "/100 * ", L"/100 * ", 7);
			Append(end, "\n (SELECT COUNT(*) ", L"\n (SELECT COUNT(*) ", 19, select);
			AppendCopy(end, from, pre_order);
			Append(end, ")", L")", 1);
		}
	}
}
void SqlParser :: SelectConvertRowlimit ( Token * select , Token * from , Token * from_end , Token * where_ , Token * where_end , Token * pre_order , Token * order , Token * rowlimit_slist , Token * rowlimit_soptions , int rowlimit , bool rowlimit_percent ) { if ( rowlimit_slist == NULL && rowlimit_soptions == NULL && rowlimit == 0 ) return ; int limit = rowlimit ; if ( rowlimit_slist != NULL ) limit = rowlimit_slist -> GetInt ( ) ; else if ( rowlimit_soptions != NULL ) limit = rowlimit_soptions -> GetInt ( ) ; if ( limit == 100 && rowlimit_percent == true ) return ; Token * end = GetLastToken ( ) ; if ( _source != SQL_ORACLE && _target == SQL_ORACLE ) { if ( order == NULL ) { if ( where_ == NULL ) end = Append ( from_end , " " , L" " , 7 , select ) ; else end = Append ( where_end , " " , L" " , 5 , where_ ) ; } else { Prepend ( select , " " , L" " , 15 ) ; Append ( end , " " , L" " , 8 , select ) ; } AppendNoFormat ( end , " " , L" " , 10 ) ; if ( rowlimit_slist != NULL || rowlimit_soptions != NULL ) AppendCopy ( end , Nvl ( rowlimit_slist , rowlimit_soptions ) ) ; else Append ( end , rowlimit ) ; if ( rowlimit_percent == true ) { Append ( end , " " , L" " , 7 ) ; Append ( end , " \n " , L" \n " , 19 , select ) ; AppendCopy ( end , from , pre_order ) ; Append ( end , " " , L" " , 1 ) ; } } }
Convert row limits specified in SELECT
Convert row limits specified in SELECT
// One of limits should be set // 100 percent // ROWNUM in Oracle // No ORDER BY, just add a condition to WHERE // No WHERE clause too // ORDER BY exists so a subquery must be used // Row limit in percent // Copy FROM, WHERE, UNION, GROUP BY, HAVING COUNT, but not ORDER BY