O'Reilly logo

PySide GUI Application Development by Venkateshwaran Loganathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Executing SQL queries

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.

Executing a query

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, id ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required