def saveItem(itemNum):
    # todo: rework the id part

    # check if item already exists
    query = database.sendQuery("SELECT * FROM items WHERE id=%i;" % (itemNum+1))
    rows = query.fetchone()

    if rows == None:
        # item doesnt exist, create it
        query = database.sendQuery("INSERT INTO items (id, name, pic, type, data1, data2, data3) \
                                                           VALUES (%i, '%s', %i, %i, %i, %i, %i);" \
                                                           % (int(itemNum+1),             \
                                                              Item[itemNum].name,  \
                                                              Item[itemNum].pic,   \
                                                              Item[itemNum].type,  \
                                                              Item[itemNum].data1, \
                                                              Item[itemNum].data2, \
                                                              Item[itemNum].data3))

    elif 0 > len(rows):
        # item already exists, so update the item
        query = database.sendQuery("UPDATE items SET name='%s', \
                                                          pic=%i, \
                                                          type=%i, \
                                                          data1=%i, \
                                                          data2=%i, \
                                                          data3=%i \
                                                          WHERE id=%i;" % (Item[itemNum].name,  \
                                                                           Item[itemNum].pic,   \
                                                                           Item[itemNum].type,  \
                                                                           Item[itemNum].data1, \
                                                                           Item[itemNum].data2, \
                                                                           Item[itemNum].data3, \
                                                                           int(itemNum+1)))

    database.saveChanges()
dataset/ETHPy150Open marcusmoller/pyorpg-server/src/database.py/saveItem/swapped operands of `>`