sqlparser/language.cpp
// Parse substring [] operator in Informix 
Parse substring [] operator in Informix
Parse substring [] operator in Informix
bool SqlParser::ParseIndexOperator(Token *first)
{
	if(first == NULL)
		return false;
	Token *open = GetNextCharToken('[', L'[');
	if(open == NULL)
		return false;
	Token *start = GetNextToken();
	if(start == NULL)
		return false;
	Token *comma = GetNextCharToken(',', L',');
	Token *end = NULL;
	if(comma != NULL)
	{
		end = GetNextToken();
		if(end == NULL)
			return false;
	}
	Token *close = GetNextCharToken(']', L']');
	if(close == NULL)
		return false;
	int s = start->GetInt();
	int e = 0;
	int len = 1;
	if(end != NULL)
	{
		e = end->GetInt();
		len = e - s + 1;
	}
	if(Target(SQL_ORACLE, SQL_SQL_SERVER) == true)
	{
		if(_target == SQL_ORACLE)
			Prepend(first, "SUBSTR(", L"SUBSTR(", 7);
		else
		if(_target == SQL_SQL_SERVER)
			Prepend(first, "SUBSTRING(", L"SUBSTRING(", 10);
		Token::Change(open, ",", L",", 1);
		if(end != NULL)
			Token::Change(end, len);
		else
			AppendNoFormat(start, ", 1", L", 1", 3);
		Token::Change(close, ")", L")", 1);
	}
	return true;
}
bool SqlParser :: ParseIndexOperator ( Token * first ) { if ( first == NULL ) return false ; Token * open = GetNextCharToken ( ' ' , L' ' ) ; if ( open == NULL ) return false ; Token * start = GetNextToken ( ) ; if ( start == NULL ) return false ; Token * comma = GetNextCharToken ( ' ' , L' ' ) ; Token * end = NULL ; if ( comma != NULL ) { end = GetNextToken ( ) ; if ( end == NULL ) return false ; } Token * close = GetNextCharToken ( ' ' , L' ' ) ; if ( close == NULL ) return false ; int s = start -> GetInt ( ) ; int e = 0 ; int len = 1 ; if ( end != NULL ) { e = end -> GetInt ( ) ; len = e - s + 1 ; } if ( Target ( SQL_ORACLE , SQL_SQL_SERVER ) == true ) { if ( _target == SQL_ORACLE ) Prepend ( first , " " , L" " , 7 ) ; else if ( _target == SQL_SQL_SERVER ) Prepend ( first , " " , L" " , 10 ) ; Token :: Change ( open , " " , L" " , 1 ) ; if ( end != NULL ) Token :: Change ( end , len ) ; else AppendNoFormat ( start , " " , L" " , 3 ) ; Token :: Change ( close , " " , L" " , 1 ) ; } return true ; }
Parse substring [] operator in Informix
Parse substring [] operator in Informix
// Start position // Optional comma and end position // End position (inclusive in Informix) // Get start and end as integer values // Define the substring length // SUBSTR in Oracle, SUBSTRING in SQL Server