Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pypika/dialects.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from copy import copy

from pypika.enums import Dialects
from pypika.queries import (
Query,
Expand All @@ -21,6 +23,11 @@ def __init__(self):
super(MySQLQueryBuilder, self).__init__(quote_char='`', dialect=Dialects.MYSQL, wrap_union_queries=False)
self._duplicate_updates = []

def __copy__(self):
newone = super(MySQLQueryBuilder, self).__copy__()
newone._duplicate_updates = copy(self._duplicate_updates)
return newone

@builder
def on_duplicate_key_update(self, field, value):
field = Field(field) if not isinstance(field, Field) else field
Expand Down Expand Up @@ -101,6 +108,12 @@ def __init__(self):
self._on_conflict_do_nothing = False
self._on_conflict_updates = []

def __copy__(self):
newone = super(PostgreQueryBuilder, self).__copy__()
newone._returns = copy(self._returns)
newone._on_conflict_updates = copy(self._on_conflict_updates)
return newone

@builder
def on_conflict(self, target_field):
if not self._insert_table:
Expand Down
17 changes: 13 additions & 4 deletions pypika/queries.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import copy
from functools import reduce

from .enums import (
Expand Down Expand Up @@ -396,11 +397,19 @@ def __init__(self, quote_char='"', dialect=None, wrap_union_queries=True, wrappe
self._wrapper_cls = wrapper_cls

def __copy__(self):
newone = type(self)()
newone = type(self).__new__(type(self))
newone.__dict__.update(self.__dict__)
for key, value in self.__dict__.items():
if isinstance(value, (set, list)):
newone.__dict__[key] = type(value)(x for x in value)
newone._select_star_tables = copy(self._select_star_tables)
newone._from = copy(self._from)
newone._with = copy(self._with)
newone._selects = copy(self._selects)
newone._columns = copy(self._columns)
newone._values = copy(self._values)
newone._groupbys = copy(self._groupbys)
newone._orderbys = copy(self._orderbys)
newone._joins = copy(self._joins)
newone._unions = copy(self._unions)
newone._updates = copy(self._updates)
return newone

@builder
Expand Down