Skip to content

Commit

Permalink
INSERT OR REPLACE sqlite3 fix (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
chayim authored Dec 9, 2021
1 parent 38f4bf7 commit acb2af7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions rgsync/Connectors/sql_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,11 @@ def __init__(self, connection, tableName, pk, exactlyOnceTableName=None):

def PrepereQueries(self, mappings):
def GetUpdateQuery(tableName, mappings, pk):
query = 'INSERT INTO %s' % tableName
query = 'INSERT OR REPLACE INTO %s' % tableName
values = [val for kk, val in mappings.items() if not kk.startswith('_')]
values = [pk] + values
values.sort()
query = '%s (%s) VALUES (%s) ON CONFLICT(%s) DO UPDATE SET %s' % (query, ','.join(values), ','.join([':%s' % a for a in values]), pk, ','.join(['%s=values(%s)' % (a,a) for a in values]))

query = '%s(%s) values(%s)' % (query, ','.join(values), ','.join([':%s' % a for a in values]))
return query
self.addQuery = GetUpdateQuery(self.tableName, mappings, self.pk)
self.delQuery = 'delete from %s where %s=:%s' % (self.tableName, self.pk, self.pk)
Expand Down

0 comments on commit acb2af7

Please sign in to comment.