Page 1 of 1

Batch inserts/updates

PostPosted: Mon Apr 02, 2012 7:37 pm
by Davita
Hi

It would be nice if QxOrm had support of batch operations. Are you planning to implement that feature in the future? :)

Thanks

Re: Batch inserts/updates

PostPosted: Tue Apr 03, 2012 7:31 am
by QxOrm admin
Hi,

Are you planning to implement that feature in the future?

It's already done by QxOrm library if you pass a list of elements to qx::dao::insert() or qx::dao::update() functions (see below for supported list types).
For example, you can write something like this :
Code: Select all
QList<myClass> myList = ...;
QSqlError daoError = qx::dao::insert(myList);


There is only 1 prepare sql query call and then insert all elements to database (see the file ./inl/QxDao/QxDao_Insert.inl, struct QxDao_Insert_Container for more details about the process).
Moreover, a transaction is automatically created before executing the batch if you don't pass any connection to database (pDatabase parameter = NULL) => if an error occured during process, a rollback is done and no items are inserted.
If you want to manage your own transaction, you can use a session (qx::QxSession class) : see here from more details http://www.qxorm.com/qxorm_en/faq.html#faq_170
I think it's the best way for batch processing using QtSql module (but maybe I'm wrong ?).

Note : list of supported container types to pass to qx::dao::insert() or qx::dao::update() functions => STL, Qt, boost and qx::QxCollection !
For example : std::vector, std::list, QList, QVector, QHash, boost::unordered_map, qx::QxCollection, etc...

Re: Batch inserts/updates

PostPosted: Wed Apr 04, 2012 7:13 am
by Davita
Great news, thanks :)