Comparing latest sql table entry to previous

I have table TABLE1(DATA, NAME) updating with each new entry by an operator
I'd like to compare each new value to the previous but I get an out of bounds error at line 5 for this code:

    entry = system.db.runNamedQuery('TABLE1')
    prevData = entry.getValueAt(entry.getRowCount() - 1, 'DATA')
    prevName = entry.getValueAt(entry.getRowCount() - 1, 'NAME')
    for row in range(entry.getValueAt(entry.getRowCount()):
        newData = entry.getValueAt(entry.getRowCount(), 'DATA')
        newName = entry.getValueAt(entry.getRowCount(), 'NAME')
        
        if (data != prevData) and (name != prevName):
              #open popup

Row numbers are 0 based, so the last row is actually rowCount - 1. The actual previous value would (in theory) be at rowCount - 2.

What is the real problem you're trying to solve though? Do you just wan't to open a popup if the new name and data weren't previously in the table? If so, why are you not doing that prior to actually inserting the data?

Likely your dataset starts at position 0 and the getRowCount returns with first position as 1.
Therefore the getRowCount is 1 more than the possible position of your dataset.

I only want to open the popup if the values don't match

Okay, so why loop through the dataset?

Is there nothing that identifies the rows uniquely in the table? Why not only return the rows from the database that you're concerned with?

you could just do this:

columns = ('DATA','NAME')
lastRow = entry.rowCount -1
if all(entry.getValueAt(lastRow -1,col) == entry.getValueAt(lastRow,col) for col in columns):
    #open popup