Thursday, April 22, 2010

Magical FetchMode property

What does the FetchMode property on a query do? I will appreciate if someone will be able to give me very precise answer.
I know only implication of this parameter. It matters when exist/notexist joined datasources on the query are forming a tree - not a chain. If the tree of datasources is quite complex then your query has a very good chance not to work if FetchMode is not set to One2One.
To my knowledge it is related somehow to the way the kernel stores query datasources.
So, my rule of thumb is the following: if a query datasources form tree-like structure, FetchMode must be set to One2One everywhere exist/notexist join is used.

Example:
Query query;
QueryBuildDataSource qbdsInventTable;
QueryBuildDataSource qbdsInventItemGroup;
QueryBuildDataSource qbdsInventModelGroup;
;

query = new Query();
qbdsInventTable = query.addDataSource(tablenum(InventTable));

qbdsInventItemGroup = qbdsInventTable.addDataSource(tablenum(InventItemGroup));
qbdsInventItemGroup.relations(true);
qbdsInventItemGroup.joinMode(JoinMode::ExistsJoin);
qbdsInventItemGroup.fetchMode(QueryFetchMode::One2One);

qbdsInventModelGroup = qbdsInventTable.addDataSource(tablenum(InventModelGroup));
qbdsInventModelGroup.relations(true);
qbdsInventModelGroup.joinMode(JoinMode::NoExistsJoin);
qbdsInventModelGroup.fetchMode(QueryFetchMode::One2One);

11 comments:

  1. I am actually writing a tutorial post about it, but it's going slow so far...
    I would make a small change to your 'rule of thumb' - always use FetchMode::One2One, since you always actually expect a join, and not separate queries.
    I can show you move info in the office :)

    ReplyDelete
    Replies
    1. Vanya, I've been waiting some years for this blog post to show up...I can't find it on your blog.

      Delete
    2. Vanya, I've been waiting some years for this blog post to show up...I can't find it on your blog.

      Delete
  2. Here is an other usage of the fetchmode-property
    http://www.crazy-club.de/blog/2010/04/fetchmode/

    ReplyDelete
  3. The Servicemembers Civil Relief Act provides protections for military members in real estate matters. timeshare cancellation

    ReplyDelete