Skip to content

Commit

Permalink
Issue #120: Temporary prevention using column name as an alias name
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Dec 1, 2024
1 parent 7d030b9 commit 4e05a6d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 12 additions & 0 deletions crates/gitql-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,18 @@ fn parse_select_all_or_expressions(
)?
.to_string();

// TODO [#120, #121]: Remove this check
if env
.schema
.tables_fields_types
.contains_key(alias_name.as_str())
{
return Err(Diagnostic::error("Can't use column name as Alias")
.add_note("Until supporting `table.column` you should use different alias name")
.with_location(tokens[*position - 1].location)
.as_boxed());
}

// No need to do checks or add alias
// `SELECT C AS C` is equal to `SELECT C`
if field_name != alias_name {
Expand Down
15 changes: 11 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,18 @@ fn main() {

match command {
Command::ReplMode(arguments) => {
launch_gitql_repl(arguments);
launch_gitql_repl(&arguments);
}
Command::ScriptMode(script_file, arguments) => {
let mut reporter = diagnostic_reporter::DiagnosticReporter::default();
let git_repos_result = validate_git_repositories(&arguments.repos);
if git_repos_result.is_err() {
reporter.report_diagnostic(
"",
Diagnostic::error(git_repos_result.err().unwrap().as_str()),
);
return;
}

let repos = git_repos_result.ok().unwrap();
let schema = Schema {
Expand Down Expand Up @@ -111,7 +118,7 @@ fn main() {
}
}

fn launch_gitql_repl(arguments: Arguments) {
fn launch_gitql_repl(arguments: &Arguments) {
let mut reporter = diagnostic_reporter::DiagnosticReporter::default();
let git_repos_result = validate_git_repositories(&arguments.repos);
if git_repos_result.is_err() {
Expand Down Expand Up @@ -157,7 +164,7 @@ fn launch_gitql_repl(arguments: Arguments) {

execute_gitql_query(
input.to_owned(),
&arguments,
arguments,
&git_repositories,
&mut global_env,
&mut reporter,
Expand Down Expand Up @@ -202,7 +209,7 @@ fn launch_gitql_repl(arguments: Arguments) {

execute_gitql_query(
stdin_input.to_owned(),
&arguments,
arguments,
&git_repositories,
&mut global_env,
&mut reporter,
Expand Down

0 comments on commit 4e05a6d

Please sign in to comment.