Skip to content

Commit

Permalink
development
Browse files Browse the repository at this point in the history
  • Loading branch information
emin100 committed Nov 3, 2023
1 parent 00fc891 commit 1168b32
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 206 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
.vscode

Cargo.lock
.cargo/
46 changes: 20 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 1 addition & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,4 @@ clap_complete = "4.4.4"
regex = "1.10.2"
serde = "1.0.189"
cargo-deb = { version = "2.0.0" }

[build-dependencies]
clap_mangen = "0.2.15"


[package.metadata.deb]
maintainer = "cargo-deb developers <[email protected]>"
copyright = "2017, cargo-deb developers."
license-file = ["LICENSE", "2"]
extended-description = "example project for cargo-deb"
depends = "$auto"
section = "utils"
priority = "optional"
assets = [
["target/release/sql_normalizer", "usr/bin/", "755"],
]
default-features = false
features = ["example_debian_build"]

[package.metadata.deb.variants.debug]
assets = [
["target/release/sql_normalizer", "usr/bin/", "755"],
]

[features]
default = ["example_non_debian_build"]
example_non_debian_build = []
example_debian_build = []
openssl = { version = "0.10.35", features = ["vendored"] }
74 changes: 40 additions & 34 deletions src/anonymize.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@

use sqlparser::ast::{Expr, Query, Select, SetExpr, Statement, Offset, Value, FunctionArg};
use log::{debug};
use sqlparser::ast::FunctionArgExpr::Expr as OtherExpr;
use crate::parser::Command;

use log::debug;
use sqlparser::ast::FunctionArgExpr::Expr as OtherExpr;
use sqlparser::ast::{Expr, FunctionArg, Offset, Query, Select, SetExpr, Statement, Value};

fn selection_changer(selection: &mut Expr) -> &mut Expr {
debug!("Selection Changer: {:?}", selection);
match selection {
Expr::BinaryOp { left, right, .. } => {
*left = Box::new(selection_changer(left).to_owned());
*right= Box::new(selection_changer(right).to_owned());
},
Expr::Like { pattern, .. } => {
*right = Box::new(selection_changer(right).to_owned());
}
Expr::Like { pattern, .. } => {
*pattern = Box::new(selection_changer(pattern).to_owned());
}
Expr::Value(value) => {
Expr::Value(value) => {
*value = Value::Placeholder("?".to_string());
}
Expr::InList { list , .. } => {
Expr::InList { list, .. } => {
*list = vec![Expr::Value(Value::Placeholder("?".to_string()))];
}
Expr::Between { low, high, .. } => {
Expand All @@ -39,20 +37,23 @@ fn selection_changer(selection: &mut Expr) -> &mut Expr {
for arg in function.args.iter_mut() {
match arg {
FunctionArg::Unnamed(ref mut f_arg) => {
let OtherExpr(f_arg_expr) = f_arg else { panic!("{}", f_arg) };
let OtherExpr(f_arg_expr) = f_arg else {
panic!("{}", f_arg)
};
{
*f_arg_expr = selection_changer(f_arg_expr).to_owned();
}
},
}
FunctionArg::Named { ref mut arg, .. } => {
let OtherExpr(f_arg_expr) = arg else { panic!("{}", arg) };
let OtherExpr(f_arg_expr) = arg else {
panic!("{}", arg)
};
{
*f_arg_expr = selection_changer(f_arg_expr).to_owned();
}
}
}
}

}
_ => {}
};
Expand All @@ -68,8 +69,7 @@ fn matcher(query: &mut Query) -> &mut Query {
for yy in xx.iter_mut() {
*yy = selection_changer(yy).to_owned();
}
};

}
}
SetExpr::Select(select) => {
let Select { selection, .. } = select.as_mut();
Expand All @@ -78,16 +78,14 @@ fn matcher(query: &mut Query) -> &mut Query {
*selection = Some(selection_changer(selection.as_mut().unwrap()).to_owned());
}
}

}
_ => ()
_ => (),
};
if query.offset.is_some() {
let Offset { value, .. } = query.offset.as_mut().unwrap();
{
*value = selection_changer(value).to_owned();
}

}

for order_by in query.order_by.iter_mut() {
Expand All @@ -104,43 +102,51 @@ fn matcher(query: &mut Query) -> &mut Query {
#[derive(Debug, Clone)]
pub struct Replaced {
pub statement_type: Command,
pub statement: Statement
pub statement: Statement,
}

pub fn rec(statement: &mut Statement) -> Replaced {
debug!("rec: {:?}", statement);
let typed ;
let typed;

match statement {
Statement::Query(query) => {
*query = Box::new(matcher(query).to_owned());
typed = Command::Query;
},
Statement::Explain { statement: explain_statement, .. } => {
}
Statement::Explain {
statement: explain_statement,
..
} => {
*explain_statement = Box::new(rec(explain_statement).statement.clone());
typed = Command::Explain;
},
Statement::Insert { source,.. } => {
}
Statement::Insert { source, .. } => {
*source = Box::new(matcher(source).to_owned());
typed = Command::Insert;
},
Statement::Update { selection,assignments, .. } => {

}
Statement::Update {
selection,
assignments,
..
} => {
*selection = Some(selection_changer(selection.as_mut().unwrap()).clone());

for assigment in assignments.iter_mut() {
assigment.value = selection_changer(&mut assigment.value).to_owned();
}

typed = Command::Update;
},
Statement::Delete { selection, limit, .. } => {

}
Statement::Delete {
selection, limit, ..
} => {
*selection = Some(selection_changer(selection.as_mut().unwrap()).clone());
*limit = Some(selection_changer(limit.as_mut().unwrap()).clone());
if limit.is_some() {
*limit = Some(selection_changer(limit.as_mut().unwrap()).clone());
}
typed = Command::Delete;

},
}
_ => {
typed = Command::Other;
}
Expand Down
Loading

0 comments on commit 1168b32

Please sign in to comment.