I am trying to get records from mysql, if records found then adding success status with the mysql records and return by jsonify
function, On the other side i am getting response and then check whether the status is success or not.
This is my response format
[ { "SQL_STATUS": true }, { "id": "126","etc":"etc"} ]
i need to check whether the SQL_STATUS is true
or false
, so i tried the below method
response.SQL_STATUS
but got the below error
AttributeError: 'Response' object has no attribute 'SQL_STATUS'
These are my code
def Details(self,request):
res = self.db.SelectByConditionModel(request,self.model)
if res.SQL_STATUS == True:
response_data = SuccessResponse('','Success')
else:
response_data = ErrorResponse(res,"Database Error")
return response_data
this is the fundtion where i am doing select operation
@staticmethod
def SelectByConditionModel(request,model):
try:
where_condition = []
for key in request:
where_condition.append(key+"='"+conn.escape_string(str(request[key]))+"'")
where_condition_str = ', '.join(where_condition)
sql = ''' SELECT * from %s WHERE %s ''' %(model.TABLE, where_condition_str)
cursor.execute(sql)
row_headers=[x[0] for x in cursor.description]
conn.commit()
data = cursor.fetchall()
json_data=[]
json_data.append({"SQL_STATUS" : True})
for result in data:
json_data.append(dict(zip(row_headers,result)))
return jsonify(json_data)
except Exception as e:
return str(e)
i need to check SQL_STATUS is true or false, please help me