225k views
3 votes
Your task is to develop a Web app using Python, Flask and MySQL that will act as an online SQL editor/tester. A user will be able to enter a SQL query on your webpage, hit a "Run/Submit" button and the results of the query are displayed in an HTML table. You will have to get the query from an HTML text box, pass it to Python as a string and send the query to MySQL server. You then get the data returned by MySQL in Python, and pass it to HTML, which will display the query results on a webpage (formatted as a table).

Requirements
1) A user should be able to send any type of query (e.g., INSERT INTO and SELECT FROM);
2) The result of a selection should be presented in an HTML table, displaying only the attributes (table column names) that were requested in the SELECT statement. For example, "SELECT name, age FROM Student" should result in a table with two columns "name" and "age" only, along with the content (tuples).
3) The result of INSERT INTO should be just a message to the user: "Inserted into table" or "failed".

1 Answer

4 votes

Final answer:

The student requires guidance with creating a web application that serves as an online SQL editor/tester, capable of executing user-entered SQL queries and displaying results or confirmations accordingly.

Step-by-step explanation:

The student is asking for assistance in creating a Web app using Python, Flask, and MySQL that functions as an online SQL editor/tester. To achieve this, the student needs to design a web interface that allows users to enter SQL queries and display the results. The app must handle both SELECT and INSERT INTO queries properly. For SELECT queries, results should be shown in an HTML table with only the requested columns, while for INSERT INTO queries, a confirmation message should be displayed.

Requirements and Steps:

Handle SQL query input: Create an HTML form with a text box for query input and a submit button.

Process query in Python: Use Flask to capture the query and pass it as a string to the MySQL server.

Execute and display query results: Retrieve query results and pass them into an HTML page as a table for SELECT queries or as a confirmation message for INSERT INTO queries.

It is important to sanitize the input to prevent SQL injection attacks. The system should also include error handling for failed queries and communicate these to the user in an understandable manner.

User Aman Shekhar
by
8.1k points