18.4.  Review Questions

[ fromfile: database-questions.xml id: database-questions ]

  1. Which database is included with Qt on all platforms?

      Sqlite

  2. How can you determine what databases are supported by your version of Qt?

      QSqlDatabase::drivers()

  3. What is QSqlDatabase is an abstraction for, a file, connection, user, or table?

      It is an abstraction for a database connection, not an actual database.

  4. What is the difference between a DDL query and a regular query?

      A DDL query creates a table, or modifies its structure.

  5. Why are prepared queries preferred over regular queries?

      They are faster, because the query does not need to be parsed as often. They are safer, because they are not subject to SQL injection attacks. They are easier to use with strings because there is no need to escape the characters inside them.

  6. What would be a better name for the class, QSqlDatabase?

      QSqlConnection, because it represents a connection and not an actual database.

  7. If the database driver's hasFeature(QSqlDriver::PreparedQueries) reports false, can you use prepared queries?

      Yes, even if the server or the driver does not support them, Qt emulates prepared queries on the client side.

  8. Can a non-DDL query modify table rows?

      Yes, some SQL queries update or insert rows into a table. A "query" is more than just a select statement.