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 |
| BpsSqlValues & | operator= (const QVariantMap &aOther) |
| | Assign other variant map to this object.
|
| BpsSqlValues & | operator= (const BpsSqlValues &aOther) |
| | Assign other sql values to this object.
|
| BpsSqlValues & | operator= (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());
}
Constructor & Destructor Documentation
Copy constructor.
- Parameters:
-
| [in] | aOther | The other object to clone |
| BpsSqlValues::BpsSqlValues |
( |
const QVariantMap & |
aMap | ) |
|
Create object from a variant map.
- Parameters:
-
| BpsSqlValues::BpsSqlValues |
( |
const QSqlRecord & |
aRec | ) |
|
Create object from a sql record.
- Parameters:
-
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] | aKey | The key to insert |
| [in] | aValue | The 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] | aOther | The other variant map to copy from. |
- Returns:
- Reference to the current object.
Assign other sql values to this object.
- Parameters:
-
| [in] | aOther | The 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] | aOther | The other sql record to copy from. |
- Returns:
- Reference to the current object.
| QString BpsSqlValues::pairs |
( |
const QString & |
aSeparator = bStr(", ") | ) |
const |
- Parameters:
-
| [in] | aSeparator | Separator 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] | aKey | The 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:
-
| 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] | aName | Name 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: