I have used GCP cloud SQL with dailogflow CX there is one table QuestionPageMapping_test it stored all padeId and FlowID of questions that asked by bot. It is used for redo activity. If user wants to go back to any question then user can select that question according to that question select query will fetch pageID of that question and user can start their conversation from that question again. But select query does not work properly at some instance.It work for some questions.
option=r=re.sub(r'[^\w\s]', ' ', option)
connection2 = connector.connect(os.environ['DB_Instance_Name'],"pymysql",database='bot_info',user="root",password=os.environ['DB_Password'])
cursor2 = connection2.cursor(pymysql.cursors.DictCursor)
query1= f"select * from QuestionPageMapping_test where questions ='{option}'"
print(query1)
cursor2.execute(query1)
rows = cursor2.fetchall()
print(rows)
for row in rows:
global option2
option2=row["pageId"]
connection2.close()
query="set @row_number=0;"
cursor.execute(query)
query = f"select * FROM (select *,(@row_number:=@row_number + 1) AS R_NUM from {session_id} order by timestamp) as a1 where pageId='{option2}'"
print(query)
I tried this code,in that option variable is used for to store question that is present at dailoflow cx's page. when select query fail then rows is empty that is why it is not entering into for loop and because of that I am getting NameError: name 'option2' is not defined" for next query. (https://i.stack.imgur.com/559BB.png)