def processDelQuery(metaTb, dataSource,query): if("where" in query or "WHERE" in query): indexWhere= sqlUtils.getWhereIndex(query) wherelist= query[indexWhere+1:] tableSrc = findTableSource(query) keyList= sqlWhere.processWhereStmt(metaTb, tableSrc, dataSource[tableSrc], wherelist) # print(keyList) deleteValues(dataSource[tableSrc], keyList) # returned keys should be removed and stored back to dataSource else: # else no where clause in delete deleteAll(dataSource[findTableSource(query)])
def update(data,tb,query): tbl = query[1] # Stores the table name to tbl query = query[3:] cnt = 0 # Remove other elements in the list pk = [] if("where" in query or "WHERE" in query): # Checks if query contains the WHERE clause wIndex = sqlUtils.getWhereIndex(query) # Gets the index of the WHERE keyword pk = sqlWhere.processWhereStmt(tb, tbl, data[tbl], query[wIndex+1:]) # Gets list of rows to be updated if(not isDuplicateEntry(data,tb,tbl,query[:wIndex],query[wIndex+1:],pk) and pk): updateRows(data,tb,tbl,query,pk,wIndex) print(" ",len(pk)," row(s) affected.",end=""); elif(not pk): print(" No row(s) affected.",end=""); else: print(" ERROR: Duplicate entry for PRIMARY KEY. ",end=""); else: # No WHERE clause if(not isDuplicateEntry(data,tb,tbl,query,[],[])): cnt = updateAllRows(data,tb,tbl,query) print(" ",cnt," row(s) affected.",end=""); else: print(" ERROR: Duplicate entry for PRIMARY KEY. ",end="");