sqlparser/select.cpp
// Resolve data types for columns in select list
Resolve data types for columns in select list
Resolve data types for columns in select list
void SqlParser::SelectSetOutColsDataTypes(ListW *out_cols, ListWM *from_table_end)
{
	if(out_cols == NULL || from_table_end == NULL)
		return;
	ListwItem *col_item = out_cols->GetFirst();
	while(col_item != NULL)
	{
		Token *col = (Token*)col_item->value;
		if(col == NULL)
			break;
		if(col->subtype == TOKEN_SUB_COLUMN_NAME)
		{
			ListwmItem *from_item = from_table_end->GetFirst();
			while(from_item != NULL)
			{
				Token *table = (Token*)from_item->value2;
				col->datatype_meta = GetMetaType(table, col);
				if(col->datatype_meta != NULL)
				{
					col->table = table;
					break;
				}
				from_item = from_item->next;
			}
		}
		else
		if(TOKEN_CMPC(col, '*') && from_table_end->GetCount() == 1)
		{
			col->table = (Token*)from_table_end->GetFirst()->value2;
		}
		col_item = col_item->next;
	}
}
void SqlParser :: SelectSetOutColsDataTypes ( ListW * out_cols , ListWM * from_table_end ) { if ( out_cols == NULL || from_table_end == NULL ) return ; ListwItem * col_item = out_cols -> GetFirst ( ) ; while ( col_item != NULL ) { Token * col = ( Token * ) col_item -> value ; if ( col == NULL ) break ; if ( col -> subtype == TOKEN_SUB_COLUMN_NAME ) { ListwmItem * from_item = from_table_end -> GetFirst ( ) ; while ( from_item != NULL ) { Token * table = ( Token * ) from_item -> value2 ; col -> datatype_meta = GetMetaType ( table , col ) ; if ( col -> datatype_meta != NULL ) { col -> table = table ; break ; } from_item = from_item -> next ; } } else if ( TOKEN_CMPC ( col , ' ' ) && from_table_end -> GetCount ( ) == 1 ) { col -> table = ( Token * ) from_table_end -> GetFirst ( ) -> value2 ; } col_item = col_item -> next ; } }
Resolve data types for columns in select list
Resolve data types for columns in select list
// Standalone column name // Find a table containing this column, and define its data type // All columns selected from single table // Save the table name