qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) with some features associated with QxDao module of QxOrm library
QxOrm can be used with smart-pointers of boost and Qt libraries. QxOrm smart-pointer is based on QSharedPointer and provides new features with qx::dao::xxx functions of QxDao module. qx::dao::ptr<T> keeps automatically values from database. So it's possible to detect if an instance has been modified using the method isDirty() : this method can return list of properties changed. qx::dao::ptr<T> can also be used with the function qx::dao::update_optimized() to update in database only properties changed. qx::dao::ptr<T> can be used with a simple object and with many containers : stl, boost, Qt and qx::QxCollection<Key, Value>.
blog_isdirty->m_id = blog_1->m_id;
blog_isdirty->m_text = "blog property 'text' modified => blog is dirty !!!";
QStringList lstDiff;
bool bDirty = blog_isdirty.
isDirty(lstDiff);
qAssert(bDirty && (lstDiff.count() == 1) && (lstDiff.at(0) ==
"blog_text"));
if (bDirty) { qDebug("[QxOrm] test dirty 1 : blog is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
type_lst_author_test_is_dirty container_isdirty = type_lst_author_test_is_dirty(new QList<author_ptr>());
qAssert(! daoError.isValid() && ! container_isdirty.isDirty() && (container_isdirty->count() == 3));
author_ptr author_ptr_dirty = container_isdirty->at(1);
author_ptr_dirty->m_name = "author name modified at index 1 => container is dirty !!!";
bDirty = container_isdirty.isDirty(lstDiff);
qAssert(bDirty && (lstDiff.count() == 1));
if (bDirty) { qDebug("[QxOrm] test dirty 2 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
author_ptr_dirty = container_isdirty->at(2);
author_ptr_dirty->m_birthdate = QDate(1998, 03, 06);
bDirty = container_isdirty.isDirty(lstDiff);
qAssert(bDirty && (lstDiff.count() == 2));
if (bDirty) { qDebug("[QxOrm] test dirty 3 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
qAssert(! daoError.isValid() && ! container_isdirty.isDirty());
QStringList lstColumns = QStringList() << "date_creation";
list_blog lst_blog_with_only_date_creation;
qAssert(! daoError.isValid() && (lst_blog_with_only_date_creation.size() > 0));
if ((lst_blog_with_only_date_creation.size() > 0) && (lst_blog_with_only_date_creation[0] != NULL))
{
qAssert(lst_blog_with_only_date_creation[0]->m_text.isEmpty()); }
qx::dump(lst_blog_with_only_date_creation);
qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) wi...
QSqlError fetch_by_id(T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList())
Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a...
QSqlError fetch_all(T &t, QSqlDatabase *pDatabase=NULL, const QStringList &columns=QStringList())
Fetch a list of objects (retrieve all elements and properties associated) of type T (container regist...
QSqlError update_optimized(qx::dao::ptr< T > &ptr, QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Update only modified fields/properties of an element or a list of elements into database (using is di...
void dump(const T &t, bool bJsonFormat=false)
qx::dump(const T & t, bool bJsonFormat) : dump class of type T registered into QxOrm context using XM...