/ Make the document tree from a file. */ /
| 2287 | /* Make the document tree from a file. */ |
| 2288 | /***********************************************************************/ |
| 2289 | int TDBJSON::MakeDocument(PGLOBAL g) |
| 2290 | { |
| 2291 | char *p, *p1, *p2, *memory, *objpath, *key = NULL; |
| 2292 | int i = 0; |
| 2293 | size_t len; |
| 2294 | my_bool a; |
| 2295 | MODE mode = Mode; |
| 2296 | PJSON jsp; |
| 2297 | PJOB objp = NULL; |
| 2298 | PJAR arp = NULL; |
| 2299 | PJVAL val = NULL; |
| 2300 | |
| 2301 | if (Done) |
| 2302 | return RC_OK; |
| 2303 | |
| 2304 | /*********************************************************************/ |
| 2305 | /* Create the mapping file object in mode read. */ |
| 2306 | /*********************************************************************/ |
| 2307 | Mode = MODE_READ; |
| 2308 | |
| 2309 | if (!Txfp->OpenTableFile(g)) { |
| 2310 | PFBLOCK fp = Txfp->GetTo_Fb(); |
| 2311 | |
| 2312 | if (fp) { |
| 2313 | len = fp->Length; |
| 2314 | memory = fp->Memory; |
| 2315 | } else { |
| 2316 | Mode = mode; // Restore saved Mode |
| 2317 | return MakeNewDoc(g); |
| 2318 | } // endif fp |
| 2319 | |
| 2320 | } else |
| 2321 | return RC_FX; |
| 2322 | |
| 2323 | /*********************************************************************/ |
| 2324 | /* Parse the json file and allocate its tree structure. */ |
| 2325 | /*********************************************************************/ |
| 2326 | g->Message[0] = 0; |
| 2327 | jsp = Top = ParseJson(g, memory, len, &Pretty); |
| 2328 | Txfp->CloseTableFile(g, false); |
| 2329 | Mode = mode; // Restore saved Mode |
| 2330 | |
| 2331 | if (!jsp && g->Message[0]) |
| 2332 | return RC_FX; |
| 2333 | |
| 2334 | if ((objpath = PlugDup(g, Objname))) { |
| 2335 | if (*objpath == '$') objpath++; |
| 2336 | if (*objpath == '.') objpath++; |
| 2337 | p1 = (*objpath == '[') ? objpath++ : NULL; |
| 2338 | |
| 2339 | /*********************************************************************/ |
| 2340 | /* Find the table in the tree structure. */ |
| 2341 | /*********************************************************************/ |
| 2342 | for (p = objpath; jsp && p; p = (p2 ? p2 : NULL)) { |
| 2343 | a = (p1 != NULL); |
| 2344 | p1 = strchr(p, '['); |
| 2345 | p2 = strchr(p, '.'); |
| 2346 |