These will be used for formatting error messages in an upcoming commit.
#include <stdlib.h>
#include "column.h"
+#include "dynamic-string.h"
#include "json.h"
#include "ovsdb-error.h"
#include "ovsdb-parser.h"
return json;
}
+/* Returns an English string listing the contents of 'set', e.g. "columns
+ * \"a\", \"b\", and \"c\"". The caller must free the string. */
+char *
+ovsdb_column_set_to_string(const struct ovsdb_column_set *set)
+{
+ if (!set->n_columns) {
+ return xstrdup("no columns");
+ } else {
+ struct ds s;
+ size_t i;
+
+ ds_init(&s);
+ ds_put_format(&s, "column%s ", set->n_columns > 1 ? "s" : "");
+ for (i = 0; i < set->n_columns; i++) {
+ const char *delimiter = english_list_delimiter(i, set->n_columns);
+ ds_put_format(&s, "%s\"%s\"", delimiter, set->columns[i]->name);
+ }
+ return ds_steal_cstr(&s);
+ }
+}
+
void
ovsdb_column_set_add(struct ovsdb_column_set *set,
const struct ovsdb_column *column)
const struct json *, const struct ovsdb_table_schema *,
struct ovsdb_column_set *);
struct json *ovsdb_column_set_to_json(const struct ovsdb_column_set *);
+char *ovsdb_column_set_to_string(const struct ovsdb_column_set *);
void ovsdb_column_set_add(struct ovsdb_column_set *,
const struct ovsdb_column *);
-/* Copyright (c) 2009, 2010 Nicira Networks
+/* Copyright (c) 2009, 2010, 2011 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <assert.h>
#include <stddef.h>
+#include "dynamic-string.h"
#include "json.h"
#include "ovsdb-error.h"
#include "shash.h"
}
}
+/* Appends the string form of the value in 'row' of each of the columns in
+ * 'columns' to 'out', e.g. "1, \"xyz\", and [1, 2, 3]". */
+void
+ovsdb_row_columns_to_string(const struct ovsdb_row *row,
+ const struct ovsdb_column_set *columns,
+ struct ds *out)
+{
+ size_t i;
+
+ for (i = 0; i < columns->n_columns; i++) {
+ const struct ovsdb_column *column = columns->columns[i];
+
+ ds_put_cstr(out, english_list_delimiter(i, columns->n_columns));
+ ovsdb_datum_to_string(&row->fields[column->index], &column->type, out);
+ }
+}
+
struct ovsdb_error *
ovsdb_row_from_json(struct ovsdb_row *row, const struct json *json,
struct ovsdb_symbol_table *symtab,
-/* Copyright (c) 2009, 2010 Nicira Networks
+/* Copyright (c) 2009, 2010, 2011 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
const struct ovsdb_column_set *);
void ovsdb_row_update_columns(struct ovsdb_row *, const struct ovsdb_row *,
const struct ovsdb_column_set *);
-
+void ovsdb_row_columns_to_string(const struct ovsdb_row *,
+ const struct ovsdb_column_set *, struct ds *);
struct ovsdb_error *ovsdb_row_from_json(struct ovsdb_row *,
const struct json *,
struct ovsdb_symbol_table *,