def saveSpell(spellNum):
    # todo: rework the id part

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

    if rows == None:
        # spell doesnt exist, create it
        query = database.sendQuery("INSERT INTO spells (id, name, pic, type, reqmp, reqclass, reqlevel, data1, data2, data3) \
                                                           VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", \
                                                             (int(spellNum+1), \
                                                              Spell[spellNum].name,  \
                                                              Spell[spellNum].pic,   \
                                                              Spell[spellNum].type,  \
                                                              Spell[spellNum].reqMp, \
                                                              Spell[spellNum].reqClass, \
                                                              Spell[spellNum].reqLevel, \
                                                              Spell[spellNum].data1, \
                                                              Spell[spellNum].data2, \
                                                              Spell[spellNum].data3))

    elif 0 > len(rows):
        # spell already exists, so update the spell
        query = database.sendQuery("UPDATE spells SET name=?, \
                                                          pic=?, \
                                                          type=?, \
                                                          reqmp=?, \
                                                          reqclass=?, \
                                                          reqlevel=?, \
                                                          data1=?, \
                                                          data2=?, \
                                                          data3=? \
                                                          WHERE id=?;", (Spell[spellNum].name,  \
                                                                           Spell[spellNum].pic,   \
                                                                           Spell[spellNum].type,  \
                                                                           Spell[spellNum].reqMp, \
                                                                           Spell[spellNum].reqClass, \
                                                                           Spell[spellNum].reqLevel, \
                                                                           Spell[spellNum].data1, \
                                                                           Spell[spellNum].data2, \
                                                                           Spell[spellNum].data3, \
                                                                           int(spellNum+1)))

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