/* * __wt_struct_reformat -- * Given a table and a list of columns (which could be values in a column * group or index keys), calculate the resulting new format string. * The result will be appended to the format buffer. */ int __wt_struct_reformat(WT_SESSION_IMPL *session, WT_TABLE *table, const char *columns, size_t len, const char *extra_cols, int value_only, WT_ITEM *format) { WT_CONFIG config; WT_CONFIG_ITEM k, next_k, next_v; WT_DECL_RET; WT_PACK_VALUE pv; int have_next; WT_CLEAR(pv); /* -Wuninitialized */ WT_RET(__wt_config_initn(session, &config, columns, len)); WT_RET(__wt_config_next(&config, &next_k, &next_v)); do { k = next_k; ret = __wt_config_next(&config, &next_k, &next_v); if (ret != 0 && ret != WT_NOTFOUND) return (ret); have_next = (ret == 0); if (!have_next && extra_cols != NULL) { WT_RET(__wt_config_init(session, &config, extra_cols)); WT_RET(__wt_config_next(&config, &next_k, &next_v)); have_next = 1; extra_cols = NULL; } if ((ret = __find_column_format(session, table, &k, value_only, &pv)) != 0) { if (value_only && ret == EINVAL) WT_RET_MSG(session, EINVAL, "A column group cannot store key column " "'%.*s' in its value", (int)k.len, k.str); WT_RET_MSG(session, EINVAL, "Column '%.*s' not found", (int)k.len, k.str); } /* * Check whether we're moving an unsized WT_ITEM from the end * to the middle, or vice-versa. This determines whether the * size needs to be prepended. This is the only case where the * destination size can be larger than the source size. */ if (pv.type == 'u' && !pv.havesize && have_next) pv.type = 'U'; else if (pv.type == 'U' && !have_next) pv.type = 'u'; if (pv.havesize) WT_RET(__wt_buf_catfmt( session, format, "%d%c", (int)pv.size, pv.type)); else WT_RET(__wt_buf_catfmt(session, format, "%c", pv.type)); } while (have_next); return (0); }
/* * __wt_struct_reformat -- * Given a table and a list of columns (which could be values in a column * group or index keys), calculate the resulting new format string. * The result will be appended to the format buffer. */ int __wt_struct_reformat(WT_SESSION_IMPL *session, WT_TABLE *table, const char *columns, size_t len, const char *extra_cols, bool value_only, WT_ITEM *format) { WT_CONFIG config; WT_CONFIG_ITEM k, next_k, next_v; WT_DECL_PACK_VALUE(pv); WT_DECL_RET; bool have_next; __wt_config_initn(session, &config, columns, len); /* * If an empty column list is specified, this will fail with * WT_NOTFOUND, that's okay. */ WT_RET_NOTFOUND_OK(ret = __wt_config_next(&config, &next_k, &next_v)); if (ret == WT_NOTFOUND) { if (extra_cols != NULL) { __wt_config_init(session, &config, extra_cols); WT_RET(__wt_config_next(&config, &next_k, &next_v)); extra_cols = NULL; } else if (format->size == 0) { WT_RET(__wt_buf_set(session, format, "", 1)); return (0); } } do { k = next_k; ret = __wt_config_next(&config, &next_k, &next_v); if (ret != 0 && ret != WT_NOTFOUND) return (ret); have_next = ret == 0; if (!have_next && extra_cols != NULL) { __wt_config_init(session, &config, extra_cols); WT_RET(__wt_config_next(&config, &next_k, &next_v)); have_next = true; extra_cols = NULL; } if ((ret = __find_column_format(session, table, &k, value_only, &pv)) != 0) { if (value_only && ret == EINVAL) WT_RET_MSG(session, EINVAL, "A column group cannot store key column " "'%.*s' in its value", (int)k.len, k.str); WT_RET_MSG(session, EINVAL, "Column '%.*s' not found", (int)k.len, k.str); } /* * Check whether we're moving an unsized WT_ITEM from the end * to the middle, or vice-versa. This determines whether the * size needs to be prepended. This is the only case where the * destination size can be larger than the source size. */ if (pv.type == 'u' && !pv.havesize && have_next) pv.type = 'U'; else if (pv.type == 'U' && !have_next) pv.type = 'u'; if (pv.havesize) WT_RET(__wt_buf_catfmt(session, format, "%" PRIu32 "%c", pv.size, pv.type)); else WT_RET(__wt_buf_catfmt(session, format, "%c", pv.type)); } while (have_next); return (0); }