def get_spell(name):
    "Returns a dictionary containing a spell's info, a list of possible matches or None"
    c = tibiaDatabase.cursor()
    try:
        c.execute('SELECT * FROM Spells WHERE words LIKE ? OR name LIKE ? ORDER BY LENGTH(name) LIMIT 15', ((('%' + name) + '%'), (('%' + name) + '%')))
        result = c.fetchall()
        if (len(result) == 0):
            return None
        elif ((result[0]['name'].lower() == name.lower()) or (result[0]['words'].lower() == name.lower()) or (len(result) == 1)):
            spell = result[0]
        else:
            return ['{name} ({words})'.format(**x) for x in result]
        spell['npcs'] = []
        c.execute('SELECT NPCs.title as name, NPCs.city, SpellNPCs.knight, SpellNPCs.paladin,\n                  SpellNPCs.sorcerer, SpellNPCs.druid FROM NPCs, SpellNPCs\n                  WHERE SpellNPCs.spellid = ? AND SpellNPCs.npcid = NPCs.id', (spell['id'],))
        result = c.fetchall()
        for npc in result:
            npc['city'] = npc['city'].title()
            spell['npcs'].append(npc)
        return spell
    finally:
        c.close()
Returns a dictionary containing a spell's info, a list of possible matches or None
def get_spell(name):
    
    c = tibiaDatabase.cursor()
    try:
        c.execute('SELECT * FROM Spells WHERE words LIKE ? OR name LIKE ? ORDER BY LENGTH(name) LIMIT 15', ((('%' + name) + '%'), (('%' + name) + '%')))
        result = c.fetchall()
        if (len(result) == 0):
            return None
        elif ((result[0]['name'].lower() == name.lower()) or (result[0]['words'].lower() == name.lower()) or (len(result) == 1)):
            spell = result[0]
        else:
            return ['{name} ({words})'.format(**x) for x in result]
        spell['npcs'] = []
        c.execute('SELECT NPCs.title as name, NPCs.city, SpellNPCs.knight, SpellNPCs.paladin,\n                  SpellNPCs.sorcerer, SpellNPCs.druid FROM NPCs, SpellNPCs\n                  WHERE SpellNPCs.spellid = ? AND SpellNPCs.npcid = NPCs.id', (spell['id'],))
        result = c.fetchall()
        for npc in result:
            npc['city'] = npc['city'].title()
            spell['npcs'].append(npc)
        return spell
    finally:
        c.close()