| 193 // __<table> (value ignored) |
193 // __<table> (value ignored) |
| 194 // |
194 // |
| 195 // after a column is marked as the start of the new table |
195 // after a column is marked as the start of the new table |
| 196 // all following columns will be treated as columns of this table |
196 // all following columns will be treated as columns of this table |
| 197 cxstring tabname = cx_strsubs(fieldname, 2); |
197 cxstring tabname = cx_strsubs(fieldname, 2); |
| 198 DBUClass *fcls = cxMapGet(builder->ctx->classes, tabname); |
198 cxstring remaining = cx_strstr(tabname, CX_STR("__")); |
| |
199 DBUClass *fcls = NULL; |
| |
200 if(remaining.length > 2) { |
| |
201 tabname.length = remaining.ptr - tabname.ptr; |
| |
202 |
| |
203 } |
| |
204 fcls = cxMapGet(builder->ctx->classes, tabname); |
| |
205 |
| 199 if(fcls) { |
206 if(fcls) { |
| |
207 if(remaining.length > 2) { |
| |
208 field = cxMapGet(fcls->fields, cx_strsubs(remaining, 2)); |
| |
209 } |
| |
210 field_mapping[i].cls = fcls; |
| 200 field_class = fcls; |
211 field_class = fcls; |
| 201 cxstring remaining = cx_strstr(tabname, CX_STR("__")); |
|
| 202 if(remaining.length > 2) { |
|
| 203 field = cxMapGet(cls->fields, cx_strsubs(remaining, 2)); |
|
| 204 } else { |
|
| 205 field_mapping[i].cls = fcls; |
|
| 206 } |
|
| 207 } |
212 } |
| 208 } else { |
213 } else { |
| 209 field = cxMapGet(cls->fields, fieldname); |
214 field = cxMapGet(field_class->fields, fieldname); |
| 210 } |
215 } |
| 211 |
216 |
| 212 if(field) { |
217 if(field) { |
| 213 DBUFieldMapping mapping; |
218 DBUFieldMapping mapping; |
| 214 mapping.cls = field_class; |
219 mapping.cls = field_class; |
| 234 cls->init(obj, a); |
239 cls->init(obj, a); |
| 235 } |
240 } |
| 236 |
241 |
| 237 void *current_obj = obj; |
242 void *current_obj = obj; |
| 238 void *child_obj = NULL; |
243 void *child_obj = NULL; |
| 239 DBUClass *child_cls = NULL; |
|
| 240 DBUClass *current_cls = cls; |
244 DBUClass *current_cls = cls; |
| 241 for(int i=0;i<numcols;i++) { |
245 for(int i=0;i<numcols;i++) { |
| 242 DBUFieldMapping field = field_mapping[i]; |
246 DBUFieldMapping field = field_mapping[i]; |
| 243 int isnull = result->isNull(result, i); |
247 int isnull = result->isNull(result, i); |
| 244 |
248 |
| 245 if(field.cls != current_cls) { |
249 if(field.cls && field.cls != current_cls) { |
| 246 // check if an object of this class can be added to the main obj |
250 // following columns are for this new class |
| 247 DBUField *obj_field = cxMapGet(cls->obj_fields, field.cls->name); |
251 current_cls = field.cls; |
| 248 if(obj_field && obj_field->initObjValue) { |
252 if(field.field) { |
| 249 child_obj = objresult->create(objresult, field.cls, a); |
253 // check if an object of this class can be added to the main obj |
| 250 if(!child_obj) { |
254 DBUField *obj_field = cxMapGet(cls->obj_fields, field.cls->name); |
| 251 err = 1; |
255 if(obj_field && obj_field->initObjValue) { |
| 252 break; |
256 child_obj = objresult->create(objresult, field.cls, a); |
| |
257 current_obj = child_obj; |
| |
258 if(!child_obj) { |
| |
259 err = 1; |
| |
260 break; |
| |
261 } |
| |
262 |
| |
263 if(field.cls->init) { |
| |
264 field.cls->init(child_obj, a); // TODO: check return |
| |
265 } |
| |
266 |
| |
267 obj_field->initObjValue(obj_field, a, obj, child_obj); |
| 253 } |
268 } |
| 254 |
|
| 255 if(field.cls->init) { |
|
| 256 field.cls->init(child_obj, a); // TODO: check return |
|
| 257 } |
|
| 258 |
|
| 259 obj_field->initObjValue(obj_field, a, obj, child_obj); |
|
| 260 } |
269 } |
| 261 } |
270 } |
| 262 |
271 |
| 263 DBUField *type_field = field.field; |
272 DBUField *type_field = field.field; |
| 264 if(type_field) { |
273 if(type_field) { |