Junior — Middle
Can you demonstrate how to formulate database queries?
sobes.tech AI
Answer from AI
The way to formulate database queries depends on the technology and programming language used. In QA/QA Automation, SQL queries are often used to verify data or APIs to interact with the database.
Example of a simple SQL query to fetch data:
SELECT id, name, status FROM users WHERE status = 'active';
If automation is in Python using the sqlite3 library:
import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
cursor.execute("SELECT id, name FROM users WHERE status = ?", ('active',))
rows = cursor.fetchall()
for row in rows:
print(row)
conn.close()
In QA, it is important to formulate queries so that they are understandable, parameterized (for security), and return the expected data for verification.