sqlparser/select.cpp
// SELECT statements options at the end of the statement
SELECT statements options at the end of the statement
SELECT statements options at the end of the statement
bool SqlParser::ParseSelectOptions(Token * , Token * , Token * , Token * , 
									Token **rowlimit_soptions, int *rowlimit)
{
	bool exists = false;
	while(true)
	{
		Token *option = GetNextToken();
		if(option == NULL)
			break;
		if(option->Compare("FOR", L"FOR", 3) == true)
		{
			Token *update = GetNextWordToken("UPDATE", L"UPDATE", 6);
			Token *read = NULL;
			if(update == NULL)
				read = GetNextWordToken("READ", L"READ", 4);
			if(update != NULL)
			{
				Token *of = GetNextWordToken("OF", L"OF", 2);
				while(of != NULL)
				{
					Token *col = GetNextIdentToken();
					if(col == NULL)
						break;
					Token *comma = GetNextCharToken(',', L',');
					if(comma == NULL)
						break;
				}
				Token *skip = GetNextWordToken("SKIP", L"SKIP", 4);
				Token *locked = NULL;
				if(skip != NULL)
					locked = GetNextWordToken("LOCKED", L"LOCKED", 6);
				Token *nowait = NULL;
				if(skip == NULL)
					nowait = TOKEN_GETNEXTW("NOWAIT");
				if(Target(SQL_MARIADB, SQL_MYSQL) && skip != NULL && locked != NULL)
					Comment(skip, locked);
			}
			else
			if(read != NULL)
			{
				Token *only = GetNextWordToken("ONLY", L"ONLY", 4);
				if(only != NULL && Target(SQL_SQL_SERVER))
					Token::Remove(option, only);
			}			
			exists = true;
			continue;
		}
		else
		if(option->Compare("WITH", L"WITH", 4) == true)
		{
			Token *value = GetNextToken();
			if(Token::Compare(value, "UR", L"UR", 2) || Token::Compare(value, "CS", L"CS", 2) ||
				Token::Compare(value, "RS", L"RS", 2) ||Token::Compare(value, "RR", L"RR", 2))
			{
				if(!Target(SQL_DB2))
					Token::Remove(option, value);
				exists = true;
				continue;
			}
			else
			{
				PushBack(option);
				break;
			}
		}
		else
		if(ParseDb2FetchFirstRowOnly(option, rowlimit_soptions, rowlimit) == true)
		{
			exists = true;
			continue;
		}
		else
		if(option->Compare("LIMIT", L"LIMIT", 5) == true)
		{
			Token *num = GetNextToken();
			if(Target(SQL_ORACLE) == true && num != NULL)
				Token::Remove(option, num);
			if(rowlimit_soptions != NULL)
				*rowlimit_soptions = num;
			exists = true;
			continue;
		}
		PushBack(option);
		break;
	}
	return exists;
}
bool SqlParser :: ParseSelectOptions ( Token * , Token * , Token * , Token * , Token * * rowlimit_soptions , int * rowlimit ) { bool exists = false ; while ( true ) { Token * option = GetNextToken ( ) ; if ( option == NULL ) break ; if ( option -> Compare ( " " , L" " , 3 ) == true ) { Token * update = GetNextWordToken ( " " , L" " , 6 ) ; Token * read = NULL ; if ( update == NULL ) read = GetNextWordToken ( " " , L" " , 4 ) ; if ( update != NULL ) { Token * of = GetNextWordToken ( " " , L" " , 2 ) ; while ( of != NULL ) { Token * col = GetNextIdentToken ( ) ; if ( col == NULL ) break ; Token * comma = GetNextCharToken ( ' ' , L' ' ) ; if ( comma == NULL ) break ; } Token * skip = GetNextWordToken ( " " , L" " , 4 ) ; Token * locked = NULL ; if ( skip != NULL ) locked = GetNextWordToken ( " " , L" " , 6 ) ; Token * nowait = NULL ; if ( skip == NULL ) nowait = TOKEN_GETNEXTW ( " " ) ; if ( Target ( SQL_MARIADB , SQL_MYSQL ) && skip != NULL && locked != NULL ) Comment ( skip , locked ) ; } else if ( read != NULL ) { Token * only = GetNextWordToken ( " " , L" " , 4 ) ; if ( only != NULL && Target ( SQL_SQL_SERVER ) ) Token :: Remove ( option , only ) ; } exists = true ; continue ; } else if ( option -> Compare ( " " , L" " , 4 ) == true ) { Token * value = GetNextToken ( ) ; if ( Token :: Compare ( value , " " , L" " , 2 ) || Token :: Compare ( value , " " , L" " , 2 ) || Token :: Compare ( value , " " , L" " , 2 ) || Token :: Compare ( value , " " , L" " , 2 ) ) { if ( ! Target ( SQL_DB2 ) ) Token :: Remove ( option , value ) ; exists = true ; continue ; } else { PushBack ( option ) ; break ; } } else if ( ParseDb2FetchFirstRowOnly ( option , rowlimit_soptions , rowlimit ) == true ) { exists = true ; continue ; } else if ( option -> Compare ( " " , L" " , 5 ) == true ) { Token * num = GetNextToken ( ) ; if ( Target ( SQL_ORACLE ) == true && num != NULL ) Token :: Remove ( option , num ) ; if ( rowlimit_soptions != NULL ) * rowlimit_soptions = num ; exists = true ; continue ; } PushBack ( option ) ; break ; } return exists ; }
SELECT statements options at the end of the statement
SELECT statements options at the end of the statement
/*select*/ /*from_end*/ /*where_*/ /*order*/ // Oracle, MySQL FOR UPDATE; DB2 FOR READ ONLY // OF column, ... clause // Oracle SKIP LOCKED // Oracle NOWAIT // MySQL does not support SKIP LOCKED, comment it // DB2 WITH UR, CS, RS, RR option // DB2 FETCH FIRST n ROWS ONLY // MySQL LIMIT num option // ROWNUM is used in Oracle