The UUIDs shown for rows created in the same \fBovs\-vsctl\fR
invocation will be wrong.
.
-.IP "\fBget \fItable record column\fR[\fB:\fIkey\fR]..."
+.IP "[\fB\-\-if\-exists\fR] \fBget \fItable record column\fR[\fB:\fIkey\fR]..."
Prints the value of each specified \fIcolumn\fR in the given
\fIrecord\fR in \fItable\fR. For map columns, a \fIkey\fR may
optionally be specified, in which case the value associated with
\fIkey\fR in the column is printed, instead of the entire map.
+.IP
+For a map column, without \fB\-\-if\-exists\fR it is an error if
+\fIkey\fR does not exist; with it, a blank line is printed. If
+\fIcolumn\fR is not a map column or if \fIkey\fR is not specified,
+\fB\-\-if\-exists\fR has no effect.
.
.IP "[\fB\-\-force\fR] \fBset \fItable record column\fR[\fB:\fIkey\fR]\fB=\fIvalue\fR..."
Sets the value of each specified \fIcolumn\fR in the given
static void
cmd_get(struct vsctl_context *ctx)
{
+ bool if_exists = shash_find(&ctx->options, "--if-exists");
const char *table_name = ctx->argv[1];
const char *record_id = ctx->argv[2];
const struct vsctl_table_class *table;
idx = ovsdb_datum_find_key(&datum, &key,
column->idl->type.key_type);
if (idx == UINT_MAX) {
- ovs_fatal(0, "no key %s in %s record \"%s\" column %s",
- key_string, table_name, record_id,
- column->idl->name);
-
+ if (!if_exists) {
+ ovs_fatal(0, "no key \"%s\" in %s record \"%s\" column %s",
+ key_string, table->class->name, record_id,
+ column->idl->name);
+ }
+ } else {
+ ovsdb_atom_to_string(&datum.values[idx],
+ column->idl->type.value_type, out);
}
- ovsdb_atom_to_string(&datum.values[idx],
- column->idl->type.value_type, out);
-
ovsdb_atom_destroy(&key, column->idl->type.key_type);
} else {
ovsdb_datum_to_string(&datum, &column->idl->type, out);
{"set-ssl", 3, 3, cmd_set_ssl, NULL, "--bootstrap"},
/* Parameter commands. */
- {"get", 3, INT_MAX, cmd_get, NULL, ""},
+ {"get", 3, INT_MAX, cmd_get, NULL, "--if-exists"},
{"list", 1, INT_MAX, cmd_list, NULL, ""},
{"set", 3, INT_MAX, cmd_set, NULL, "--force"},
{"add", 4, INT_MAX, cmd_add, NULL, "--force"},