sqlparser/sqlserver.cpp
// Parse SQL Server, Sybase ASE UPDATE statememt
Parse SQL Server, Sybase ASE UPDATE statememt
Parse SQL Server Sybase ASE UPDATE statememt
bool SqlParser::ParseSqlServerUpdateStatement(Token *update)
{
	Token *name = GetNextIdentToken(SQL_IDENT_OBJECT);
	if(name == NULL)
		return false;
	Token *set = TOKEN_GETNEXTW("SET");
	if(set == NULL)
	{
		PushBack(name);
		return false;
	}
	while(true)
	{
		Token *col = GetNextIdentToken();
		if(col == NULL)
			break;
		Token *equal = TOKEN_GETNEXT('=');
		if(equal == NULL)
			break;
		Token *open = TOKEN_GETNEXT('(');
		Token *select = NULL;
		if(open != NULL)
		{
			select = GetNextSelectStartKeyword();
			if(select != NULL)
				ParseSelectStatement(select, 0, SQL_SEL_UPDATE_SET, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
			TOKEN_GETNEXT(')');
		}
		else
		{
			Token *exp = GetNextToken();
			if(exp == NULL)
				break;
			ParseExpression(exp);
		}
		Token *comma = TOKEN_GETNEXT(',');
		if(comma == NULL)
			break;
	}
	Token *from = NULL;
	Token *from_end = NULL;
	ParseSelectFromClause(NULL, false, &from, &from_end, NULL, true, NULL);
    Token *where_ = NULL;
    Token *where_end = NULL;
	ParseWhereClause(SQL_STMT_UPDATE, &where_, &where_end, NULL);
	if(from != NULL)
	{
		if(Target(SQL_MYSQL, SQL_MARIADB))
		{
			Token::Remove(from);
			AppendCopy(name, from, from_end, false);
			Token::Remove(name);
			Token::Remove(from, from_end);
		}
	}
	if(_target == SQL_ORACLE)
		OracleContinueHandlerForUpdate(update);
	SqlServerAddStmtDelimiter();
	return true;
}
bool SqlParser :: ParseSqlServerUpdateStatement ( Token * update ) { Token * name = GetNextIdentToken ( SQL_IDENT_OBJECT ) ; if ( name == NULL ) return false ; Token * set = TOKEN_GETNEXTW ( " " ) ; if ( set == NULL ) { PushBack ( name ) ; return false ; } while ( true ) { Token * col = GetNextIdentToken ( ) ; if ( col == NULL ) break ; Token * equal = TOKEN_GETNEXT ( ' ' ) ; if ( equal == NULL ) break ; Token * open = TOKEN_GETNEXT ( ' ' ) ; Token * select = NULL ; if ( open != NULL ) { select = GetNextSelectStartKeyword ( ) ; if ( select != NULL ) ParseSelectStatement ( select , 0 , SQL_SEL_UPDATE_SET , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL ) ; TOKEN_GETNEXT ( ' ' ) ; } else { Token * exp = GetNextToken ( ) ; if ( exp == NULL ) break ; ParseExpression ( exp ) ; } Token * comma = TOKEN_GETNEXT ( ' ' ) ; if ( comma == NULL ) break ; } Token * from = NULL ; Token * from_end = NULL ; ParseSelectFromClause ( NULL , false , & from , & from_end , NULL , true , NULL ) ; Token * where_ = NULL ; Token * where_end = NULL ; ParseWhereClause ( SQL_STMT_UPDATE , & where_ , & where_end , NULL ) ; if ( from != NULL ) { if ( Target ( SQL_MYSQL , SQL_MARIADB ) ) { Token :: Remove ( from ) ; AppendCopy ( name , from , from_end , false ) ; Token :: Remove ( name ) ; Token :: Remove ( from , from_end ) ; } } if ( _target == SQL_ORACLE ) OracleContinueHandlerForUpdate ( update ) ; SqlServerAddStmtDelimiter ( ) ; return true ; }
Parse SQL Server, Sybase ASE UPDATE statememt
Parse SQL Server Sybase ASE UPDATE statememt
// Parser list of assignments: c1 = exp1, ... // Single value or (SELECT c1, c2, ...) can be specified // Check for SELECT statement // A subquery used to specify assignment values // FROM clause can include inner/outer joins // optional WHERE clause // UPDATE FROM syntax is used // MySQL, MariaDB use syntax UPDATE t1, t2 SET ... WHERE // Implement CONTINUE handler for NOT FOUND in Oracle // Add statement delimiter if not set when source is SQL Server