After the successful connection to the database, we can execute SQL queries to perform some actions on it. If we don't specify a connection name, the default connection is taken. The
PySide.QtSql.QSqlQuery class provides a means of executing and manipulating SQL databases.
The SQL query can be executed by creating an
QSqlQuery object and calling an
exec_() function on that. As an example, we create a table named
employee and define its columns as follows:
myQuery = QSqlQuery() myQuery.exec_("""CREATE TABLE employee (id INTEGER PRIMARY KEYAUTOINCREMENT UNIQUE NOT NULL, first_name CHAR(20) NOT NULL, last_name CHAR(20), age INT, sex CHAR(1), income FLOAT)""")
This will create a table with six fields namely,