Browse Source

Adding printRows flag to turn printing of rows to be inserted/updated on or off, adding matchOnly to supress insertion of new rows to database

Andrej 1 month ago
parent
commit
5ed055e622
1 changed files with 22 additions and 3 deletions
  1. 22 3
      importXLSX.py

+ 22 - 3
importXLSX.py

@@ -416,7 +416,12 @@ def loadSafely(pars,entries,dryRun=True):
    project=pars.get('project','DCIS/Study')
    schema=pars.get('schema','demographics')
    query=pars.get('query','demographics')
+#add columns from labkey that will be checked to find a match
    matchColumns=pars.get('matchColumns',[])
+#whether to insert new entries
+   matchOnly=pars.get('matchOnly',False)
+#print rows to be inserted, debugging feature
+   printRows=pars.get('printRows',False)
    
    updateRows=[]
    insertRows=[]
@@ -437,17 +442,31 @@ def loadSafely(pars,entries,dryRun=True):
          updateRows.append(r)
       else:
          insertRows.append(entry)
-        
+   
+#update rows
+
    n=len(updateRows)
    print(f'Updating {n} entries')
 
-   print(updateRows)
+   if printRows:
+      print(updateRows)
 
    if n and not dryRun:
       printErr(db.modifyRows('update',project,schema,query,updateRows))
+
+
+#insert rows
+
    n=len(insertRows)
    print(f'Inserting {n} entries')
-   print(insertRows)
+
+   if matchOnly:
+      print('Inserting supressed by matchOnly flag')
+      return
+   
+   if printRows:
+      print(insertRows)
+   
    if n and not dryRun:
       printErr(db.modifyRows('insert',project,schema,query,insertRows))