Skip to content

Switch Database To Dictionary Mode #141

Description

@Superior126

Problem

Currently, Ringer Server does not use dictionary mode.

Example (BAD):

cursor.execute("SELECT * FROM users")
data = cursor.fetchall()

for row in data:
     name = row[0]
     age = row[1]
     gender = row[2]

This is bad because is assumes that name, age, gender will always be in that order.

Solution

The solution to this problem is to use dictionary mode.

cursor = conn.cursor(dictionary=True)

cursor.execute("SELECT * FROM users")
data = cursor.fetchall()

for row in data:
     name = row['name']
     age = row['age']
     gender = row['gender']

This example ensures that no matter the order of the columns, we will always get the data we want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Task.

    Projects

    Status
    📝 Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions