Skip to content

Commit

Permalink
Added a function to allow multiple updates in one command, gives sign…
Browse files Browse the repository at this point in the history
…ificant speed increase but will not check and report on status on each indvidual file, may add option to run the slow version in a future update
  • Loading branch information
davve2 committed Mar 5, 2021
1 parent 3257ca0 commit afa291d
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion flextaxd/modules/database/DatabaseConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,39 @@ def update(self,data,table):
WHERE {where_column} = ?
'''.format(table=table,set_column=data["set_column"],where_column=data["where_column"])
udata = tuple([data["set_value"],data["where"]])
#logger.debug("{q} {d}".format(q=UPDATE_QUERY,d=udata))
logger.debug("{q} {d}".format(q=UPDATE_QUERY,d=udata))
res = self.query(UPDATE_QUERY,udata,error=True)
if self.rowcount() == 0:
res = self.insert({data["set_column"]:data["set_value"],data["where_column"]:data["where"]}, table)
return False
return True

def multi_update(self,data,table):
'''Update function requires table column which column to identify row with and value to replace
Parameters
list - data in form of a list with updates
table - which table to update
------
Returns
boolean - True: if rowcount of update is not zero
False if column is not set (value is inserted)
'''
UPDATE_QUERY = '''
INSERT INTO {table} ({set_column},{where_column})
VALUES {data}
ON CONFLICT({where_column}) DO UPDATE SET
{where_column} = {where_column},
{set_column} = {set_column};
'''.format(table=table,set_column=data["set_column"],where_column=data["where_column"],data=",".join(data["data"]))
#udata = tuple([data["set_value"],data["where"]])
logger.debug("{q}".format(q=UPDATE_QUERY))
#exit()
res = self.query(UPDATE_QUERY,error=True)
#if self.rowcount() == 0:
# res = self.insert({data["set_column"]:data["set_value"],data["where_column"]:data["where"]}, table)
# return False
return True

def delete(self,nodes,table):
'''Deleting a node should make sure all related data is also removed
Expand Down

0 comments on commit afa291d

Please sign in to comment.