sqlparser/storage.cpp
// Parse MySQL CREATE TABLE storage clause
Parse MySQL CREATE TABLE storage clause
Parse MySQL CREATE TABLE storage clause
bool SqlParser::ParseMysqlStorageClause(Token *table_name, Token **id_start, Token **comment_out)
{
	bool exists = false;
	Token *auto_start = NULL;
	while(true)
	{
		Token *next = GetNextToken();
		if(next == NULL)
			break;
		if(next->Compare("ENGINE", L"ENGINE", 6) == true)
		{
			Token *equal = GetNextCharToken('=', L'=');
			Token *type = GetNextToken();
			if(_target != SQL_MYSQL)
			{
				Token::Remove(next);
				Token::Remove(equal);
				Token::Remove(type);
			}
			exists = true;
			continue;
		}
		else
		if(next->Compare("AUTO_INCREMENT", L"AUTO_INCREMENT", 14) == true)
		{
			Token *equal = GetNextCharToken('=', L'=');
			auto_start = GetNextNumberToken();
			if(_target != SQL_MYSQL)
			{
				Token::Remove(next);
				Token::Remove(equal);
				Token::Remove(auto_start);
			}
			exists = true;
			continue;
		}
		else
		if(next->Compare("DEFAULT", L"DEFAULT", 7) == true)
		{
			Token *option = GetNextToken();
			if(option == NULL)
				break;
			if(option->Compare("CHARSET", L"CHARSET", 7) == true)
			{
				 (void) GetNextCharToken('=', L'=');
				Token *value = GetNextIdentToken();
				if(_target != SQL_MYSQL)
					Token::Remove(next, value);
			}
			else
			if(option->Compare("CHARACTER", L"CHARACTER", 9) == true)
			{
				 (void) GetNextWordToken("SET", L"SET", 3);
				 (void) GetNextCharToken('=', L'=');
				Token *value = GetNextIdentToken();
				if(_target != SQL_MYSQL)
					Token::Remove(next, value);
			}
			exists = true;
			continue;
		}
		else
		if(next->Compare("COLLATE", L"COLLATE", 7) == true)
		{
			 (void) GetNextCharToken('=', L'=');
			Token *value = GetNextIdentToken();
			if(_target != SQL_MYSQL)
				Token::Remove(next, value);
			exists = true;
			continue;
		}
		else
		if(next->Compare("COMMENT", L"COMMENT", 7) == true)
		{
			 (void) GetNextCharToken('=', L'=');
			Token *text = GetNextToken();
			if(comment_out != NULL)
				*comment_out = text;
			if(_target != SQL_MYSQL)
				Token::Remove(next, text);
			exists = true;
			continue;
		}
		else
		if(next->Compare("PACK_KEYS", L"PACK_KEYS", 9) == true)
		{
			 (void) GetNextCharToken('=', L'=');
			Token *value = GetNextToken();
			if(_target != SQL_MYSQL)
				Token::Remove(next, value);
			exists = true;
			continue;
		}
		else
		if(next->Compare("ROW_FORMAT", L"ROW_FORMAT", 10) == true)
		{
			 (void) GetNextCharToken('=', L'=');
			Token *value = GetNextToken();
			if(_target != SQL_MYSQL)
				Token::Remove(next, value);
			exists = true;
			continue;
		}
		PushBack(next);
		break;
	}
	if(id_start != NULL)
		*id_start = auto_start;
	if(auto_start != NULL && (_target == SQL_POSTGRESQL || _target == SQL_GREENPLUM))
	{
		Token *semi = GetNextCharToken(';', L';');
		Token *last = (semi != NULL) ? semi : GetLastToken();
		Append(last, "\n\nALTER SEQUENCE ", L"\n\nALTER SEQUENCE ", 17);
		Token *seq_name = AppendIdentifier(table_name, "_seq", L"_seq", 4);
		Append(last, seq_name);
		Append(last, " RESTART WITH ", L" RESTART WITH ", 14);
		AppendCopy(last, auto_start);
		Append(last, ";", L";", 1);
	}
	return exists;
}
bool SqlParser :: ParseMysqlStorageClause ( Token * table_name , Token * * id_start , Token * * comment_out ) { bool exists = false ; Token * auto_start = NULL ; while ( true ) { Token * next = GetNextToken ( ) ; if ( next == NULL ) break ; if ( next -> Compare ( " " , L" " , 6 ) == true ) { Token * equal = GetNextCharToken ( ' ' , L' ' ) ; Token * type = GetNextToken ( ) ; if ( _target != SQL_MYSQL ) { Token :: Remove ( next ) ; Token :: Remove ( equal ) ; Token :: Remove ( type ) ; } exists = true ; continue ; } else if ( next -> Compare ( " " , L" " , 14 ) == true ) { Token * equal = GetNextCharToken ( ' ' , L' ' ) ; auto_start = GetNextNumberToken ( ) ; if ( _target != SQL_MYSQL ) { Token :: Remove ( next ) ; Token :: Remove ( equal ) ; Token :: Remove ( auto_start ) ; } exists = true ; continue ; } else if ( next -> Compare ( " " , L" " , 7 ) == true ) { Token * option = GetNextToken ( ) ; if ( option == NULL ) break ; if ( option -> Compare ( " " , L" " , 7 ) == true ) { ( void ) GetNextCharToken ( ' ' , L' ' ) ; Token * value = GetNextIdentToken ( ) ; if ( _target != SQL_MYSQL ) Token :: Remove ( next , value ) ; } else if ( option -> Compare ( " " , L" " , 9 ) == true ) { ( void ) GetNextWordToken ( " " , L" " , 3 ) ; ( void ) GetNextCharToken ( ' ' , L' ' ) ; Token * value = GetNextIdentToken ( ) ; if ( _target != SQL_MYSQL ) Token :: Remove ( next , value ) ; } exists = true ; continue ; } else if ( next -> Compare ( " " , L" " , 7 ) == true ) { ( void ) GetNextCharToken ( ' ' , L' ' ) ; Token * value = GetNextIdentToken ( ) ; if ( _target != SQL_MYSQL ) Token :: Remove ( next , value ) ; exists = true ; continue ; } else if ( next -> Compare ( " " , L" " , 7 ) == true ) { ( void ) GetNextCharToken ( ' ' , L' ' ) ; Token * text = GetNextToken ( ) ; if ( comment_out != NULL ) * comment_out = text ; if ( _target != SQL_MYSQL ) Token :: Remove ( next , text ) ; exists = true ; continue ; } else if ( next -> Compare ( " " , L" " , 9 ) == true ) { ( void ) GetNextCharToken ( ' ' , L' ' ) ; Token * value = GetNextToken ( ) ; if ( _target != SQL_MYSQL ) Token :: Remove ( next , value ) ; exists = true ; continue ; } else if ( next -> Compare ( " " , L" " , 10 ) == true ) { ( void ) GetNextCharToken ( ' ' , L' ' ) ; Token * value = GetNextToken ( ) ; if ( _target != SQL_MYSQL ) Token :: Remove ( next , value ) ; exists = true ; continue ; } PushBack ( next ) ; break ; } if ( id_start != NULL ) * id_start = auto_start ; if ( auto_start != NULL && ( _target == SQL_POSTGRESQL || _target == SQL_GREENPLUM ) ) { Token * semi = GetNextCharToken ( ' ' , L' ' ) ; Token * last = ( semi != NULL ) ? semi : GetLastToken ( ) ; Append ( last , " \n \n " , L" \n \n " , 17 ) ; Token * seq_name = AppendIdentifier ( table_name , " " , L" " , 4 ) ; Append ( last , seq_name ) ; Append ( last , " " , L" " , 14 ) ; AppendCopy ( last , auto_start ) ; Append ( last , " " , L" " , 1 ) ; } return exists ; }
Parse MySQL CREATE TABLE storage clause
Parse MySQL CREATE TABLE storage clause
// Auto_increment start value // ENGINE = type // Equal sign = is optional in the clause // AUTO_INCREMENT = start table option // Equal sign = is optional in the clause // DEFAULT CHARSET // CHARSET /*Token *equal */ // CHARACTER SET /*Token *set */ /*Token *equal */ // COLLATE = value /*Token *equal */ // COMMENT = 'table comment' // Equal sign = is optional in the clause /*Token *equal */ // Remove from CREATE TABLE // PACK_KEYS = 0 | 1 | DEFAULT // Optional =  /*Token *equal */ // ROW_FORMAT = type | DEFAULT // Optional =  /*Token *equal */ // Not a MySQL stoage clause // Restart sequence for PostgreSQL and Greenplum // Try to get ; // Append ALTER SEQUENCE command // Add sequence name