Skip to content

Commit

Permalink
merged prepare_ignore into prepare_insert
Browse files Browse the repository at this point in the history
  • Loading branch information
darkmmon committed Aug 21, 2023
1 parent 871fb06 commit b3002f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/backend/mysql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ impl QueryBuilder for MysqlQueryBuilder {
// MySQL doesn't support declaring materialization in SQL for with query.
}

fn prepare_ignore(&self, on_conflict: &Option<OnConflict>, sql: &mut dyn SqlWriter) {
fn prepare_insert(
&self,
replace: bool,
on_conflict: &Option<OnConflict>,
sql: &mut dyn SqlWriter,
) {
if replace {
write!(sql, "REPLACE").unwrap();
} else {
write!(sql, "INSERT").unwrap();
}
if let Some(on_conflict) = on_conflict {
if on_conflict.action == Some(OnConflictAction::DoNothing) {
write!(sql, " IGNORE ").unwrap();
write!(sql, " IGNORE").unwrap();
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/backend/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ pub trait QueryBuilder: QuotedBuilder + EscapeBuilder + TableRefBuilder {

/// Translate [`InsertStatement`] into SQL statement.
fn prepare_insert_statement(&self, insert: &InsertStatement, sql: &mut dyn SqlWriter) {
self.prepare_insert(insert.replace, sql);

self.prepare_ignore(&insert.on_conflict, sql);
self.prepare_insert(insert.replace, &insert.on_conflict, sql);

if let Some(table) = &insert.table {
write!(sql, " INTO ").unwrap();
Expand Down Expand Up @@ -827,17 +825,14 @@ pub trait QueryBuilder: QuotedBuilder + EscapeBuilder + TableRefBuilder {
}
}

fn prepare_insert(&self, replace: bool, sql: &mut dyn SqlWriter) {
fn prepare_insert(&self, replace: bool, _: &Option<OnConflict>, sql: &mut dyn SqlWriter) {
if replace {
write!(sql, "REPLACE").unwrap();
} else {
write!(sql, "INSERT").unwrap();
}
}

/// helper function, adding IGNORE in insert statement for MySQL
fn prepare_ignore(&self, _: &Option<OnConflict>, _: &mut dyn SqlWriter) {}

fn prepare_function(&self, function: &Function, sql: &mut dyn SqlWriter) {
self.prepare_function_common(function, sql)
}
Expand Down

0 comments on commit b3002f0

Please sign in to comment.