KDbRecordEditBuffer
#include <KDbRecordEditBuffer.h>
Public Types | |
typedef QHash< KDbQueryColumnInfo *, QVariant > | DbHash |
typedef QMap< QString, QVariant > | SimpleMap |
Public Member Functions | |
KDbRecordEditBuffer (bool dbAwareBuffer) | |
const QVariant * | at (const KDbField &field) const |
const QVariant * | at (const QString &fname) const |
const QVariant * | at (KDbQueryColumnInfo *ci, bool useDefaultValueIfPossible=true) const |
void | clear () |
KDbRecordEditBuffer::DbHash | dbBuffer () const |
bool | hasDefaultValueAt (const KDbQueryColumnInfo &ci) const |
void | insert (const QString &fname, const QVariant &val) |
void | insert (KDbQueryColumnInfo *ci, const QVariant &val) |
bool | isDBAware () const |
bool | isEmpty () const |
void | removeAt (const KDbField &field) |
void | removeAt (const KDbQueryColumnInfo &ci) |
void | removeAt (const QString &fname) |
KDbRecordEditBuffer::SimpleMap | simpleBuffer () const |
Protected Attributes | |
DbHash * | m_dbBuffer |
DbHash::Iterator * | m_dbBufferIt |
QMap< KDbQueryColumnInfo *, bool > * | m_defaultValuesDbBuffer |
QMap< KDbQueryColumnInfo *, bool >::ConstIterator * | m_defaultValuesDbBufferIt |
SimpleMap * | m_simpleBuffer |
SimpleMap::ConstIterator * | m_simpleBufferIt |
Detailed Description
provides data for single edited database record
KDbRecordEditBuffer provides data for single edited record, needed to perform update at the database backend. Its advantage over pasing e.g. KDbFieldList object is that EditBuffer contains only changed values.
EditBuffer offers two modes: db-aware and not-db-aware. Db-aware buffer addresses a field using references to KDbQueryColumnInfo object, while not-db-aware buffer addresses a field using its name.
Example usage of not-db-aware buffer: KDbQuerySchema *query = ..... EditBuffer buf; buf.insert("name", "Joe"); buf.insert("surname", "Black"); buf.at("name"); //returns "Joe" buf.at("surname"); //returns "Black" buf.at(query->field("surname")); //returns "Black" too Now you can use buf to add or edit records using KDbConnection::updateRecord(), KDbConnection::insertRecord()
Example usage of db-aware buffer: KDbQuerySchema *query = ..... KDbQueryColumnInfo *ci1 = ....... //e.g. can be obtained from QueryScehma::fieldsExpanded() KDbQueryColumnInfo *ci2 = ....... EditBuffer buf; buf.insert(*ci1, "Joe"); buf.insert(*ci2, "Black"); buf.at(*ci1); //returns "Joe" buf.at(*ci2); //returns "Black" Now you can use buf to add or edit records using KDbConnection::updateRecord(), KDbConnection::insertRecord()
You can use QMap::clear() to clear buffer contents, QMap::isEmpty() to see if buffer is empty. For more, see QMap documentation.
Notes: added fields should come from the same (common) KDbQuerySchema object. However, this isn't checked at QValue& EditBuffer::operator[]( const KDbField& f ) level.
Definition at line 76 of file KDbRecordEditBuffer.h.
Member Typedef Documentation
◆ DbHash
Definition at line 80 of file KDbRecordEditBuffer.h.
◆ SimpleMap
Definition at line 79 of file KDbRecordEditBuffer.h.
Constructor & Destructor Documentation
◆ KDbRecordEditBuffer()
|
explicit |
Definition at line 25 of file KDbRecordEditBuffer.cpp.
◆ ~KDbRecordEditBuffer()
KDbRecordEditBuffer::~KDbRecordEditBuffer | ( | ) |
Definition at line 35 of file KDbRecordEditBuffer.cpp.
Member Function Documentation
◆ at() [1/3]
Useful only for not-db-aware buffer.
- Returns
- value for field field Returns
nullptr
if there is no such field.
Definition at line 77 of file KDbRecordEditBuffer.cpp.
◆ at() [2/3]
Useful only for not-db-aware buffer.
- Returns
- value for field fname Returns
nullptr
if there is no such field.
Definition at line 91 of file KDbRecordEditBuffer.cpp.
◆ at() [3/3]
const QVariant * KDbRecordEditBuffer::at | ( | KDbQueryColumnInfo * | ci, |
bool | useDefaultValueIfPossible = true ) const |
Useful only for db-aware buffer.
- Returns
- value for column ci If there is no value assigned for the buffer, this method tries to remember and return default value obtained from ci if useDefaultValueIfPossible is true. Note that if the column is declared as unique (especially: primary key), default value will not be used. Returns
nullptr
if ci isnullptr
.
Definition at line 50 of file KDbRecordEditBuffer.cpp.
◆ clear()
void KDbRecordEditBuffer::clear | ( | ) |
Definition at line 132 of file KDbRecordEditBuffer.cpp.
◆ dbBuffer()
KDbRecordEditBuffer::DbHash KDbRecordEditBuffer::dbBuffer | ( | ) | const |
Definition at line 176 of file KDbRecordEditBuffer.cpp.
◆ hasDefaultValueAt()
bool KDbRecordEditBuffer::hasDefaultValueAt | ( | const KDbQueryColumnInfo & | ci | ) | const |
Useful only for db-aware buffer:
- Returns
- true if the value available as at( ci ) is obtained from column's default value
Definition at line 166 of file KDbRecordEditBuffer.cpp.
◆ insert() [1/2]
Inserts value val for not-db-aware buffer's column fname.
Definition at line 159 of file KDbRecordEditBuffer.cpp.
◆ insert() [2/2]
void KDbRecordEditBuffer::insert | ( | KDbQueryColumnInfo * | ci, |
const QVariant & | val ) |
Inserts value val for db-aware buffer's column ci Does nothing if ci is nullptr
.
Definition at line 151 of file KDbRecordEditBuffer.cpp.
◆ isDBAware()
bool KDbRecordEditBuffer::isDBAware | ( | ) | const |
Definition at line 45 of file KDbRecordEditBuffer.cpp.
◆ isEmpty()
bool KDbRecordEditBuffer::isEmpty | ( | ) | const |
Definition at line 142 of file KDbRecordEditBuffer.cpp.
◆ removeAt() [1/3]
void KDbRecordEditBuffer::removeAt | ( | const KDbField & | field | ) |
Removes value from not-db-aware buffer's column fname.
Definition at line 114 of file KDbRecordEditBuffer.cpp.
◆ removeAt() [2/3]
void KDbRecordEditBuffer::removeAt | ( | const KDbQueryColumnInfo & | ci | ) |
Removes value from db-aware buffer's column ci.
Definition at line 105 of file KDbRecordEditBuffer.cpp.
◆ removeAt() [3/3]
void KDbRecordEditBuffer::removeAt | ( | const QString & | fname | ) |
Removes value from not-db-aware buffer's column fname.
Definition at line 123 of file KDbRecordEditBuffer.cpp.
◆ simpleBuffer()
KDbRecordEditBuffer::SimpleMap KDbRecordEditBuffer::simpleBuffer | ( | ) | const |
Definition at line 171 of file KDbRecordEditBuffer.cpp.
Member Data Documentation
◆ m_dbBuffer
|
protected |
Definition at line 135 of file KDbRecordEditBuffer.h.
◆ m_dbBufferIt
|
protected |
Definition at line 136 of file KDbRecordEditBuffer.h.
◆ m_defaultValuesDbBuffer
|
protected |
Definition at line 137 of file KDbRecordEditBuffer.h.
◆ m_defaultValuesDbBufferIt
|
protected |
Definition at line 138 of file KDbRecordEditBuffer.h.
◆ m_simpleBuffer
|
protected |
Definition at line 133 of file KDbRecordEditBuffer.h.
◆ m_simpleBufferIt
|
protected |
Definition at line 134 of file KDbRecordEditBuffer.h.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.