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.
Problem
Currently, Ringer Server does not use dictionary mode.
Example (BAD):
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.
This example ensures that no matter the order of the columns, we will always get the data we want.