aboutsummaryrefslogtreecommitdiff
path: root/qc_app/db/species.py
blob: 7006d15d3d17b0296cec3d23c922f83a0fd6a692 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Database functions for species."""
import MySQLdb as mdb
from MySQLdb.cursors import DictCursor

def species(conn: mdb.Connection) -> tuple:
    "Retrieve the species from the database."
    with conn.cursor(cursorclass=DictCursor) as cursor:
        cursor.execute(
            "SELECT SpeciesId, SpeciesName, LOWER(Name) AS Name, MenuName "
            "FROM Species")
        return tuple(cursor.fetchall())

    return tuple()

def species_by_id(conn: mdb.Connection, speciesid) -> dict:
    "Retrieve the species from the database by id."
    with conn.cursor(cursorclass=DictCursor) as cursor:
        cursor.execute(
            (
                "SELECT "
                "SpeciesId, SpeciesName, LOWER(Name) AS Name, MenuName "
                "FROM Species WHERE SpeciesId=%s"),
            (speciesid,))
        return cursor.fetchone()