Documents > BPS V2 C++ API
BpsSqlValues Class Reference

Convenience class to help composing insert and update statements. More...

#include <bpssqlvalues.h>

List of all members.

Public Member Functions

 BpsSqlValues ()
 Default constructor for an empty record.
 BpsSqlValues (const BpsSqlValues &aOther)
 Copy constructor.
 BpsSqlValues (const QVariantMap &aMap)
 Create object from a variant map.
 BpsSqlValues (const QSqlRecord &aRec)
 Create object from a sql record.
void clear ()
 Clear the internal map.
QString columns () const
void insert (const QString &aKey, const QVariant &aValue)
 Insert a key/value pair.
bool isEmpty () const
QStringList keys () const
QVariantMap map () const
BpsSqlValuesoperator= (const QVariantMap &aOther)
 Assign other variant map to this object.
BpsSqlValuesoperator= (const BpsSqlValues &aOther)
 Assign other sql values to this object.
BpsSqlValuesoperator= (const QSqlRecord &aOther)
 Assign values of a sql record to this object.
QString pairs (const QString &aSeparator=bStr(", ")) const
int remove (const QString &aKey)
 Removes all the items that have the key aKey from the map.
void setMap (const QVariantMap &aMap)
 Set the internal map.
QString tags () const
QVariant value (const QString &aName) const
 Get the named columns value.
QVariantList values () const

Detailed Description

Convenience class to help composing insert and update statements.

 BpsSqlValues vals(someVariantMap);
 if (updating) {
     q.prepare(
         bStr("update t_table set %1 where c_key=?")
             .arg(vals.pairs())
     );
     q.execute(vals.values() << key);
 } else
     if (inserting) {
         q.prepare(
             bStr("insert into t_table (%1) values (%2)")
                 .arg(vals.columns())
                 .arg(vals.tags())
         );
         q.execute(vals.values());
     } // if

Constructor & Destructor Documentation

BpsSqlValues::BpsSqlValues ( const BpsSqlValues aOther)

Copy constructor.

Parameters:
[in]aOtherThe other object to clone
BpsSqlValues::BpsSqlValues ( const QVariantMap &  aMap)

Create object from a variant map.

Parameters:
[in]aMapThe variant map
BpsSqlValues::BpsSqlValues ( const QSqlRecord &  aRec)

Create object from a sql record.

Parameters:
[in]aRecThe sql record

Member Function Documentation

QString BpsSqlValues::columns ( ) const
Returns:
The column names as comma separated list.
void BpsSqlValues::insert ( const QString &  aKey,
const QVariant &  aValue 
)

Insert a key/value pair.

Parameters:
[in]aKeyThe key to insert
[in]aValueThe value to insert
bool BpsSqlValues::isEmpty ( ) const
Returns:
True if there are no columns.
QStringList BpsSqlValues::keys ( ) const
Returns:
List of the keys.
QVariantMap BpsSqlValues::map ( ) const
Returns:
The internal variant map.
BpsSqlValues& BpsSqlValues::operator= ( const QVariantMap &  aOther)

Assign other variant map to this object.

Parameters:
[in]aOtherThe other variant map to copy from.
Returns:
Reference to the current object.
BpsSqlValues& BpsSqlValues::operator= ( const BpsSqlValues aOther)

Assign other sql values to this object.

Parameters:
[in]aOtherThe other values to copy.
Returns:
Reference to the current object.
BpsSqlValues& BpsSqlValues::operator= ( const QSqlRecord &  aOther)

Assign values of a sql record to this object.

Parameters:
[in]aOtherThe other sql record to copy from.
Returns:
Reference to the current object.
QString BpsSqlValues::pairs ( const QString &  aSeparator = bStr(", ")) const
Parameters:
[in]aSeparatorSeparator to be used between the pairs. The default is comma, as used for update statements.
Returns:
Pairs column=placeholder as separated list.
int BpsSqlValues::remove ( const QString &  aKey)

Removes all the items that have the key aKey from the map.

Parameters:
[in]aKeyThe key of the pair to remove.
Returns:
Number of items removed which is usually 1 but will be 0 if the key isn't in the map.
void BpsSqlValues::setMap ( const QVariantMap &  aMap)

Set the internal map.

Parameters:
[in]aMapThe map to copy.
QString BpsSqlValues::tags ( ) const
Returns:
The value placeholders as comma separated list.
QVariant BpsSqlValues::value ( const QString &  aName) const

Get the named columns value.

Parameters:
[in]aNameName of the column to get the value for.
Returns:
The value, or QVariant() in case no such column name is found.
QVariantList BpsSqlValues::values ( ) const
Returns:
List of the values.

The documentation for this class was generated from the following file: