SqlQueryUtils

Since: BlackBerry 10.2.0

#include <bb/cascades/datamanager/SqlQueryUtils>

To link against this class, add the following line to your .pro file: LIBS += -lbbcascadesdatamanager

Utility methods for performing common operations in SQL data queries.


Overview

Public Functions Index

SqlQueryUtils ()
virtual ~SqlQueryUtils ()
QSqlDatabaseconnection (const QUrl &source, QSqlError *error)
QStringextendQuery (const QString &query, int offset, int limit)
boolgetQueryData (QSqlDatabase &connection, const QString &query, int offset, int limit, const QVariantMap &bindValues, const QString &keyColumn, const QString &revisionColumn, QList< DataItem > *results, QSqlError *error)
boolgetSingleQueryValue (QSqlDatabase &connection, const QString &query, const QVariantMap &bindValues, const QString &resultName, QVariant *resultValue, QSqlError *error)
QList< HeaderDataItem >normalizeHeaderData (const QList< DataItem > &data)
voidprepareQuery (const QString &query, const QVariantMap &bindValues, QSqlQuery *sqlQuery)

Public Functions

SqlQueryUtils ()

Constructor.

Since:

BlackBerry 10.2.0

virtual~SqlQueryUtils ()

Destructor.

Since:

BlackBerry 10.2.0

QSqlDatabase connection (

Return an existing or new database connection for the database at the source URL.

Parameters
source

The path to the local database.

error

The error object to update with the status. Pointer must not be null. If OK, then QSqlError::type() will be QSqlError::NoError.

Return:

The QSqlDatabase object to use as an open connection to the database.

Since:

BlackBerry 10.2.0

QString extendQuery (
  • const QString &query,
  • intoffset,
  • intlimit )

Extend the given query string with offset and/or limit and return the modified string.

Offset cannot be used without limit.

For example: extendQuery("select * from contact", 100, 200); Will return: "select * from contact limit 200 offset 100"

Parameters
query

The SQL query to extend.

offset

The index offset within the view. A negative offset is ignored.

limit

The number of items to retrieve. A negative limit means both limit and offset are ignored.

Return:

Returns The query string with offset and limit parameters added.

Since:

BlackBerry 10.2.0

bool getQueryData (

Execute the supplied SQL data query after applying limit and offset and binding any values.

Parameters
connection

The open database connection.

query

The SQL data query.

offset

The index offset within the view. A negative offset is ignored.

limit

The number of items to retrieve. A negative limit means both limit and offset are ignored.

bindValues

A map used to replace any named placeholders in the query with values.

keyColumn

The key column name used in the query. May be empty.

revisionColumn

The revision column name used in the query. May be empty.

results

The list of data items which is the return data. Pointer must not be null.

error

The error object to update with the status. Pointer must not be null.

Return:

Returns true if the data could be successfully retrieved, else returns false.

Since:

BlackBerry 10.2.0

bool getSingleQueryValue (

Execute the supplied SQL query after binding any values and return a single result value.

If there are multiple rows and/or multiple columns returned by query then the first column value from the first row will be returned.

Parameters
connection

The open database connection.

query

The SQL query.

bindValues

A map used to replace any named placeholders in the query with values.

resultName

The name of the result column. If not provided then the first value is returned.

resultValue

The query result value being returned. Pointer must not be null.

error

The error object to update with the status. Pointer must not be null.

Return:

Returns true if the data could be successfully retrieved, else returns false.

Since:

BlackBerry 10.2.0

QList< HeaderDataItem > normalizeHeaderData (

Use this method to normalize DataItem into HeaderDataItem.

If the header child count is zero, the item will be removed.
Parameters
data

The list of DataItem to be normalized.

Return:

Returns A new list of HeaderDataItem.

Since:

BlackBerry 10.2.0

void prepareQuery (

Prepare the given QSqlQuery object using the query string and bindValues map.

NOTE: This currently does a better job of preparing the query and binding values than using the equivalent QT code. It will perform correctly:
  1. When a query has no parameters but bindValues is supplied.

  2. When a query uses the same named parameter more than once in query string.

Parameters
query

The SQL query string using named placeholder such as :name.

bindValues

A map of names to values for supplying values to the query.

sqlQuery

Pointer to the SQL query object to prepare.

Since:

BlackBerry 10.2.0

Last modified: 2014-03-13

comments powered by Disqus