/* * dump_json_table_begin -- * Output the JSON syntax that starts a table, along with its config. */ static int dump_json_table_begin( WT_SESSION *session, WT_CURSOR *cursor, const char *uri, const char *config) { WT_DECL_RET; const char *name; char *jsonconfig, *stripped; jsonconfig = NULL; /* Get the table name. */ if ((name = strchr(uri, ':')) == NULL) { fprintf(stderr, "%s: %s: corrupted uri\n", progname, uri); return (1); } ++name; if ((ret = __wt_session_create_strip(session, config, NULL, &stripped)) != 0) return (util_err(ret, NULL)); ret = dup_json_string(stripped, &jsonconfig); free(stripped); if (ret != 0) return (util_cerr(uri, "config dup", ret)); if (printf(" \"%s\" : [\n {\n", uri) < 0) goto eio; if (printf(" \"config\" : \"%s\",\n", jsonconfig) < 0) goto eio; if ((ret = dump_json_table_cg( session, cursor, uri, name, "colgroup:", "colgroups")) == 0) { if (printf(",\n") < 0) goto eio; ret = dump_json_table_cg( session, cursor, uri, name, "index:", "indices"); } if (printf("\n },\n {\n \"data\" : [") < 0) goto eio; if (0) { eio: ret = util_err(EIO, NULL); } free(jsonconfig); return (ret); }
/* * print_config -- * Output a key/value URI pair by combining v1 and v2. */ static int print_config(WT_SESSION *session, const char *key, const char *v1, const char *v2) { WT_DECL_RET; const char *value_ret; /* * The underlying call will ignore v2 if v1 is NULL -- check here and * swap in that case. */ if (v1 == NULL) { v1 = v2; v2 = NULL; } if ((ret = __wt_session_create_strip(session, v1, v2, &value_ret)) != 0) return (util_err(ret, NULL)); ret = printf("%s\n%s\n", key, value_ret); free((char *)value_ret); if (ret < 0) return (util_err(EIO, NULL)); return (0); }
/* * dump_json_table_cg -- * Dump the column groups or indices for a table. */ static int dump_json_table_cg(WT_SESSION *session, WT_CURSOR *cursor, const char *uri, const char *name, const char *entry, const char *header) { WT_DECL_RET; const char *key, *skip, *value; int exact, once; char *jsonconfig, *stripped; static const char * const indent = " "; once = 0; if (printf(" \"%s\" : [", header) < 0) return (util_err(EIO, NULL)); /* * For table dumps, we're done. */ if (cursor == NULL) { if (printf("]") < 0) return (util_err(EIO, NULL)); else return (0); } /* * Search the file looking for column group and index key/value pairs: * for each one, look up the related source information and append it * to the base record. */ cursor->set_key(cursor, entry); if ((ret = cursor->search_near(cursor, &exact)) != 0) { if (ret == WT_NOTFOUND) return (0); return (util_cerr(uri, "search_near", ret)); } if (exact >= 0) goto match; while ((ret = cursor->next(cursor)) == 0) { match: if ((ret = cursor->get_key(cursor, &key)) != 0) return (util_cerr(uri, "get_key", ret)); /* Check if we've finished the list of entries. */ if (!WT_PREFIX_MATCH(key, entry)) break; /* Check for a table name match. */ skip = key + strlen(entry); if (strncmp( skip, name, strlen(name)) != 0 || skip[strlen(name)] != ':') continue; /* Get the value. */ if ((ret = cursor->get_value(cursor, &value)) != 0) return (util_cerr(uri, "get_value", ret)); if ((ret = __wt_session_create_strip( session, value, NULL, &stripped)) != 0) return (util_err(ret, NULL)); ret = dup_json_string(stripped, &jsonconfig); free(stripped); if (ret != 0) return (util_cerr(uri, "config dup", ret)); ret = printf("%s\n" "%s{\n" "%s \"uri\" : \"%s\",\n" "%s \"config\" : \"%s\"\n" "%s}", (once == 0 ? "" : ","), indent, indent, key, indent, jsonconfig, indent); free(jsonconfig); if (ret < 0) return (util_err(EIO, NULL)); once = 1; } if (printf("%s]", (once == 0 ? "" : "\n ")) < 0) return (util_err(EIO, NULL)); if (ret == 0 || ret == WT_NOTFOUND) return (0); return (util_cerr(uri, "next", ret)); }