sqlparser/postgresql.cpp
// Transform format string with parameters to concatenation expression
Transform format string with parameters to concatenation expression
Transform format string with parameters to concatenation expression
void SqlParser::PostgresFormatToConcat(Token *format, ListW &params)
{
	if(format == NULL && format->len > 0)
		return;
	ListwItem *list = params.GetFirst();
	TokenStr str("'", L"'", 1);
	size_t num = 0;
	for(size_t i = 1; i < format->len - 1; i++)
	{
		if(format->Compare('%', L'%', i) == true)
		{
			if(str.len > 1)
			{
				str.Append("' || ", L"' || ", 5); 
				if(list != NULL)
					PrependNoFormat((Token*)list->value, str.str.c_str(), str.wstr.c_str(), str.len);  
			}
			str.Set(" || '", L" || '", 5);
			num++;
			if(list != NULL)
				list = list->next;
			continue;
		}
		str.Append(format, i, 1);
	}
	if(num > 0 && Target(SQL_POSTGRESQL) == false)
	{
		if(str.len > 5)
		{
			ListwItem *last = params.GetLast();
			str.Append("'", L"'", 1);
			if(last != NULL)
				AppendNoFormat((Token*)last->value, str.str.c_str(), str.wstr.c_str(), str.len);  
		}
		Token::Remove(format);
	}
}
void SqlParser :: PostgresFormatToConcat ( Token * format , ListW & params ) { if ( format == NULL && format -> len > 0 ) return ; ListwItem * list = params . GetFirst ( ) ; TokenStr str ( " " , L" " , 1 ) ; size_t num = 0 ; for ( size_t i = 1 ; i < format -> len - 1 ; i ++ ) { if ( format -> Compare ( ' ' , L' ' , i ) == true ) { if ( str . len > 1 ) { str . Append ( " " , L" " , 5 ) ; if ( list != NULL ) PrependNoFormat ( ( Token * ) list -> value , str . str . c_str ( ) , str . wstr . c_str ( ) , str . len ) ; } str . Set ( " " , L" " , 5 ) ; num ++ ; if ( list != NULL ) list = list -> next ; continue ; } str . Append ( format , i , 1 ) ; } if ( num > 0 && Target ( SQL_POSTGRESQL ) == false ) { if ( str . len > 5 ) { ListwItem * last = params . GetLast ( ) ; str . Append ( " " , L" " , 1 ) ; if ( last != NULL ) AppendNoFormat ( ( Token * ) last -> value , str . str . c_str ( ) , str . wstr . c_str ( ) , str . len ) ; } Token :: Remove ( format ) ; } }
Transform format string with parameters to concatenation expression
Transform format string with parameters to concatenation expression
// Next placeholder % matched // Prepend the string before placeholder // List can be already empty but trail values still exist // For not PostgreSQL, remove format if a % placeholder exists // Append the trail string