" inner join cols p on c.parent_id = p.resource_id and c.iscollection = 1 \n" \
" where p.depth < 3\n" \
")\n" \
- "select * from cols\n" \
+ "select n.*, r.resource_id as [__resources__resource_id], r.* from cols r\n" \
+ "left join notebooks n on r.resource_id = n.resource_id\n" \
"order by path;"
#define SQL_NOTEBOOK_GET_NOTES \
DBUQuery *q = connection->createQuery(connection, NULL);
dbuQuerySetSQL(q, SQL_NOTEBOOK_STRUCTURE);
dbuQuerySetParamInt64(q, 1, settings_default_node_id);
- DBUObjectBuilder *builder = dbuObjectBuilder(resource_class, q, mp->allocator);
+ DBUObjectBuilder *builder = dbuObjectBuilder(notebook_class, q, mp->allocator);
CxList *collections = dbuObjectBuilderGetList(builder);
dbuObjectBuilderDestroy(builder);
store->root = NULL;
store->trash = NULL;
- // key: collection_id value: Collection*
+ // key: resource_id value: Notebook*
CxMap *collection_map = cxHashMapCreate(NULL, CX_STORE_POINTERS, cxListSize(collections) + 16);
// convert result list to tree
CxIterator i = cxListIterator(collections);
- cx_foreach(Resource *, col, i) {
+ cx_foreach(Notebook *, nb, i) {
+ // switch link between resource and notebook
+ Resource *col = nb->resource;
+ if(!col) {
+ continue; // error, should not happen
+ }
+ col->notebook = nb;
CxHashKey key = cx_hash_key(&col->resource_id, sizeof(int64_t));
cxMapPut(collection_map, key, col);
if(i.index == 0) {