Add CREATE FUNCTION support for SQL Server (#1808)

This commit is contained in:
Andrew Harper 2025-04-23 12:10:57 -04:00 committed by GitHub
parent 945f8e0534
commit 2eb1e7bdd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 313 additions and 50 deletions

View file

@ -16,7 +16,9 @@
// under the License.
use crate::ast::helpers::attached_token::AttachedToken;
use crate::ast::{ConditionalStatementBlock, ConditionalStatements, IfStatement, Statement};
use crate::ast::{
BeginEndStatements, ConditionalStatementBlock, ConditionalStatements, IfStatement, Statement,
};
use crate::dialect::Dialect;
use crate::keywords::{self, Keyword};
use crate::parser::{Parser, ParserError};
@ -149,11 +151,11 @@ impl MsSqlDialect {
start_token: AttachedToken(if_token),
condition: Some(condition),
then_token: None,
conditional_statements: ConditionalStatements::BeginEnd {
conditional_statements: ConditionalStatements::BeginEnd(BeginEndStatements {
begin_token: AttachedToken(begin_token),
statements,
end_token: AttachedToken(end_token),
},
}),
}
} else {
let stmt = parser.parse_statement()?;
@ -167,8 +169,10 @@ impl MsSqlDialect {
}
};
let mut prior_statement_ended_with_semi_colon = false;
while let Token::SemiColon = parser.peek_token_ref().token {
parser.advance_token();
prior_statement_ended_with_semi_colon = true;
}
let mut else_block = None;
@ -182,11 +186,11 @@ impl MsSqlDialect {
start_token: AttachedToken(else_token),
condition: None,
then_token: None,
conditional_statements: ConditionalStatements::BeginEnd {
conditional_statements: ConditionalStatements::BeginEnd(BeginEndStatements {
begin_token: AttachedToken(begin_token),
statements,
end_token: AttachedToken(end_token),
},
}),
});
} else {
let stmt = parser.parse_statement()?;
@ -199,6 +203,8 @@ impl MsSqlDialect {
},
});
}
} else if prior_statement_ended_with_semi_colon {
parser.prev_token();
}
Ok(Statement::If(IfStatement {