Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#145] handle_insert_query 테스트 리팩토링 및 버그 수정, 테스트케이스 추가 #147

Merged
merged 9 commits into from
Aug 1, 2024
8 changes: 7 additions & 1 deletion src/ast/dml/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::ast::{types::TableName, DMLStatement, SQLStatement};

use super::{parts::insert_values::InsertValue, select::SelectQuery};

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Default)]
pub struct InsertQuery {
pub into_table: Option<TableName>,
pub columns: Vec<String>,
Expand All @@ -16,6 +16,12 @@ pub enum InsertData {
None,
}

impl Default for InsertData {
fn default() -> Self {
Self::None
}
}

impl InsertQuery {
pub fn builder() -> Self {
Self {
Expand Down
26 changes: 10 additions & 16 deletions src/parser/implements/dml/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ impl Parser {
}

// INTO 토큰 삼키기
if !self.has_next_token() {
return Err(ParsingError::wrap("E0410 need more tokens"));
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

패닉케이스 제거


let current_token = self.get_next_token();
if current_token != Token::Into {
return Err(ParsingError::wrap("E0403 expected INTO"));
Expand Down Expand Up @@ -124,8 +128,7 @@ impl Parser {
continue;
}
Token::RightParentheses => {
self.unget_next_token(current_token);
break;
return Ok(names);
}
_ => {
return Err(ParsingError::wrap(format!(
Expand All @@ -135,17 +138,6 @@ impl Parser {
}
}
}

let current_token = self.get_next_token();

if current_token != Token::RightParentheses {
return Err(ParsingError::wrap(format!(
"E0408 expected ')'. but your input word is '{:?}'",
current_token
)));
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요한 지연처리 빼고 match절에서 즉시리턴


Ok(names)
}

// Values 절 파싱
Expand Down Expand Up @@ -181,8 +173,10 @@ impl Parser {
let current_token = self.get_next_token();

if current_token != Token::LeftParentheses {
self.unget_next_token(current_token);
break;
return Err(ParsingError::wrap(format!(
"E0417 expected '('. but your input word is '{:?}'",
current_token
)));
}

if !self.has_next_token() {
Expand Down Expand Up @@ -220,7 +214,7 @@ impl Parser {
}

// 쉼표가 있으면 삼키기
if self.pick_next_token() == Token::Comma {
if self.has_next_token() && self.pick_next_token() == Token::Comma {
self.get_next_token();
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

버그 수정


Expand Down
Loading
Loading