2 * Copyright (c) 2009, 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 #include "command-line.h"
27 #include "dynamic-string.h"
30 #include "ovsdb-data.h"
31 #include "ovsdb-error.h"
32 #include "ovsdb-idl.h"
33 #include "ovsdb-types.h"
34 #include "ovsdb/column.h"
35 #include "ovsdb/condition.h"
36 #include "ovsdb/file.h"
37 #include "ovsdb/log.h"
38 #include "ovsdb/mutation.h"
39 #include "ovsdb/ovsdb.h"
40 #include "ovsdb/query.h"
41 #include "ovsdb/row.h"
42 #include "ovsdb/table.h"
43 #include "ovsdb/transaction.h"
44 #include "ovsdb/trigger.h"
45 #include "poll-loop.h"
48 #include "tests/idltest.h"
53 static struct command all_commands[];
55 static void usage(void) NO_RETURN;
56 static void parse_options(int argc, char *argv[]);
59 main(int argc, char *argv[])
61 set_program_name(argv[0]);
64 parse_options(argc, argv);
65 run_command(argc - optind, argv + optind, all_commands);
70 parse_options(int argc, char *argv[])
72 static struct option long_options[] = {
73 {"timeout", required_argument, 0, 't'},
74 {"verbose", optional_argument, 0, 'v'},
75 {"help", no_argument, 0, 'h'},
78 char *short_options = long_options_to_short_options(long_options);
81 unsigned long int timeout;
84 c = getopt_long(argc, argv, short_options, long_options, NULL);
91 timeout = strtoul(optarg, NULL, 10);
93 ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
104 vlog_set_verbosity(optarg);
120 printf("%s: Open vSwitch database test utility\n"
121 "usage: %s [OPTIONS] COMMAND [ARG...]\n\n"
122 " log-io FILE FLAGS COMMAND...\n"
123 " open FILE with FLAGS, run COMMANDs\n"
124 " parse-atomic-type TYPE\n"
125 " parse TYPE as OVSDB atomic type, and re-serialize\n"
127 " parse JSON as OVSDB type, and re-serialize\n"
128 " parse-atoms TYPE ATOM...\n"
129 " parse JSON ATOMs as atoms of TYPE, and re-serialize\n"
130 " parse-atom-strings TYPE ATOM...\n"
131 " parse string ATOMs as atoms of given TYPE, and re-serialize\n"
132 " sort-atoms TYPE ATOM...\n"
133 " print JSON ATOMs in sorted order\n"
134 " parse-data TYPE DATUM...\n"
135 " parse JSON DATUMs as data of given TYPE, and re-serialize\n"
136 " parse-data-strings TYPE DATUM...\n"
137 " parse string DATUMs as data of given TYPE, and re-serialize\n"
138 " parse-column NAME OBJECT\n"
139 " parse column NAME with info OBJECT, and re-serialize\n"
140 " parse-table NAME OBJECT\n"
141 " parse table NAME with info OBJECT\n"
142 " parse-row TABLE ROW..., and re-serialize\n"
143 " parse each ROW of defined TABLE\n"
144 " compare-row TABLE ROW...\n"
145 " mutually compare all of the ROWs, print those that are equal\n"
146 " parse-conditions TABLE CONDITION...\n"
147 " parse each CONDITION on TABLE, and re-serialize\n"
148 " evaluate-conditions TABLE [CONDITION,...] [ROW,...]\n"
149 " test CONDITIONS on TABLE against each ROW, print results\n"
150 " parse-mutations TABLE MUTATION...\n"
151 " parse each MUTATION on TABLE, and re-serialize\n"
152 " execute-mutations TABLE [MUTATION,...] [ROW,...]\n"
153 " execute MUTATIONS on TABLE on each ROW, print results\n"
154 " query TABLE [ROW,...] [CONDITION,...]\n"
155 " add each ROW to TABLE, then query and print the rows that\n"
156 " satisfy each CONDITION.\n"
157 " query-distinct TABLE [ROW,...] [CONDITION,...] COLUMNS\n"
158 " add each ROW to TABLE, then query and print the rows that\n"
159 " satisfy each CONDITION and have distinct COLUMNS.\n"
160 " transact COMMAND\n"
161 " execute each specified transactional COMMAND:\n"
168 " execute SCHEMA TRANSACTION...\n"
169 " executes each TRANSACTION on an initially empty database\n"
170 " the specified SCHEMA\n"
171 " trigger SCHEMA TRANSACTION...\n"
172 " executes each TRANSACTION on an initially empty database\n"
173 " the specified SCHEMA. A TRANSACTION of the form\n"
174 " [\"advance\", NUMBER] advances NUMBER milliseconds in\n"
175 " simulated time, for causing triggers to time out.\n"
176 " idl SERVER [TRANSACTION...]\n"
177 " connect to SERVER and dump the contents of the database\n"
178 " as seen initially by the IDL implementation and after\n"
179 " executing each TRANSACTION. (Each TRANSACTION must modify\n"
180 " the database or this command will hang.)\n",
181 program_name, program_name);
183 printf("\nOther options:\n"
184 " -t, --timeout=SECS give up after SECS seconds\n"
185 " -h, --help display this help message\n");
189 /* Command helper functions. */
192 parse_json(const char *s)
194 struct json *json = json_from_string(s);
195 if (json->type == JSON_STRING) {
196 ovs_fatal(0, "\"%s\": %s", s, json->u.string);
202 unbox_json(struct json *json)
204 if (json->type == JSON_ARRAY && json->u.array.n == 1) {
205 struct json *inner = json->u.array.elems[0];
206 json->u.array.elems[0] = NULL;
215 print_and_free_json(struct json *json)
217 char *string = json_to_string(json, JSSF_SORT);
224 print_and_free_ovsdb_error(struct ovsdb_error *error)
226 char *string = ovsdb_error_to_string(error);
227 ovsdb_error_destroy(error);
233 check_ovsdb_error(struct ovsdb_error *error)
236 char *s = ovsdb_error_to_string(error);
237 ovsdb_error_destroy(error);
238 ovs_fatal(0, "%s", s);
243 die_if_error(char *error)
246 ovs_fatal(0, "%s", error);
250 /* Command implementations. */
253 do_log_io(int argc, char *argv[])
255 const char *name = argv[1];
256 char *mode = argv[2];
258 struct ovsdb_error *error;
259 struct ovsdb_log *log;
260 char *save_ptr = NULL;
265 for (flags = 0, token = strtok_r(mode, " |", &save_ptr); token != NULL;
266 token = strtok_r(NULL, " |", &save_ptr))
268 if (!strcmp(token, "O_RDONLY")) {
270 } else if (!strcmp(token, "O_RDWR")) {
272 } else if (!strcmp(token, "O_TRUNC")) {
274 } else if (!strcmp(token, "O_CREAT")) {
276 } else if (!strcmp(token, "O_EXCL")) {
278 } else if (!strcmp(token, "O_TRUNC")) {
283 check_ovsdb_error(ovsdb_log_open(name, flags, &log));
284 printf("%s: open successful\n", name);
286 for (i = 3; i < argc; i++) {
287 const char *command = argv[i];
288 if (!strcmp(command, "read")) {
291 error = ovsdb_log_read(log, &json);
293 printf("%s: read: ", name);
295 print_and_free_json(json);
297 printf("end of log\n");
301 } else if (!strncmp(command, "write:", 6)) {
302 struct json *json = parse_json(command + 6);
303 error = ovsdb_log_write(log, json);
305 } else if (!strcmp(command, "commit")) {
306 error = ovsdb_log_commit(log);
308 ovs_fatal(0, "unknown log-io command \"%s\"", command);
311 char *s = ovsdb_error_to_string(error);
312 printf("%s: %s failed: %s\n", name, command, s);
314 ovsdb_error_destroy(error);
316 printf("%s: %s successful\n", name, command);
320 ovsdb_log_close(log);
324 do_parse_atomic_type(int argc UNUSED, char *argv[])
326 enum ovsdb_atomic_type type;
329 json = unbox_json(parse_json(argv[1]));
330 check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
332 print_and_free_json(ovsdb_atomic_type_to_json(type));
336 do_parse_type(int argc UNUSED, char *argv[])
338 struct ovsdb_type type;
341 json = unbox_json(parse_json(argv[1]));
342 check_ovsdb_error(ovsdb_type_from_json(&type, json));
344 print_and_free_json(ovsdb_type_to_json(&type));
348 do_parse_atoms(int argc, char *argv[])
350 enum ovsdb_atomic_type type;
354 json = unbox_json(parse_json(argv[1]));
355 check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
358 for (i = 2; i < argc; i++) {
359 union ovsdb_atom atom;
361 json = unbox_json(parse_json(argv[i]));
362 check_ovsdb_error(ovsdb_atom_from_json(&atom, type, json, NULL));
365 print_and_free_json(ovsdb_atom_to_json(&atom, type));
367 ovsdb_atom_destroy(&atom, type);
372 do_parse_atom_strings(int argc, char *argv[])
374 enum ovsdb_atomic_type type;
378 json = unbox_json(parse_json(argv[1]));
379 check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
382 for (i = 2; i < argc; i++) {
383 union ovsdb_atom atom;
386 die_if_error(ovsdb_atom_from_string(&atom, type, argv[i]));
389 ovsdb_atom_to_string(&atom, type, &out);
393 ovsdb_atom_destroy(&atom, type);
398 do_parse_data(int argc, char *argv[])
400 struct ovsdb_type type;
404 json = unbox_json(parse_json(argv[1]));
405 check_ovsdb_error(ovsdb_type_from_json(&type, json));
408 for (i = 2; i < argc; i++) {
409 struct ovsdb_datum datum;
411 json = unbox_json(parse_json(argv[i]));
412 check_ovsdb_error(ovsdb_datum_from_json(&datum, &type, json, NULL));
415 print_and_free_json(ovsdb_datum_to_json(&datum, &type));
417 ovsdb_datum_destroy(&datum, &type);
422 do_parse_data_strings(int argc, char *argv[])
424 struct ovsdb_type type;
428 json = unbox_json(parse_json(argv[1]));
429 check_ovsdb_error(ovsdb_type_from_json(&type, json));
432 for (i = 2; i < argc; i++) {
433 struct ovsdb_datum datum;
436 die_if_error(ovsdb_datum_from_string(&datum, &type, argv[i]));
439 ovsdb_datum_to_string(&datum, &type, &out);
443 ovsdb_datum_destroy(&datum, &type);
447 static enum ovsdb_atomic_type compare_atoms_atomic_type;
450 compare_atoms(const void *a_, const void *b_)
452 const union ovsdb_atom *a = a_;
453 const union ovsdb_atom *b = b_;
455 return ovsdb_atom_compare_3way(a, b, compare_atoms_atomic_type);
459 do_sort_atoms(int argc UNUSED, char *argv[])
461 enum ovsdb_atomic_type type;
462 union ovsdb_atom *atoms;
463 struct json *json, **json_atoms;
467 json = unbox_json(parse_json(argv[1]));
468 check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
471 json = unbox_json(parse_json(argv[2]));
472 if (json->type != JSON_ARRAY) {
473 ovs_fatal(0, "second argument must be array");
476 /* Convert JSON atoms to internal representation. */
477 n_atoms = json->u.array.n;
478 atoms = xmalloc(n_atoms * sizeof *atoms);
479 for (i = 0; i < n_atoms; i++) {
480 check_ovsdb_error(ovsdb_atom_from_json(&atoms[i], type,
481 json->u.array.elems[i], NULL));
486 compare_atoms_atomic_type = type;
487 qsort(atoms, n_atoms, sizeof *atoms, compare_atoms);
489 /* Convert internal representation back to JSON. */
490 json_atoms = xmalloc(n_atoms * sizeof *json_atoms);
491 for (i = 0; i < n_atoms; i++) {
492 json_atoms[i] = ovsdb_atom_to_json(&atoms[i], type);
493 ovsdb_atom_destroy(&atoms[i], type);
495 print_and_free_json(json_array_create(json_atoms, n_atoms));
500 do_parse_column(int argc UNUSED, char *argv[])
502 struct ovsdb_column *column;
505 json = parse_json(argv[2]);
506 check_ovsdb_error(ovsdb_column_from_json(json, argv[1], &column));
508 print_and_free_json(ovsdb_column_to_json(column));
509 ovsdb_column_destroy(column);
513 do_parse_table(int argc UNUSED, char *argv[])
515 struct ovsdb_table_schema *ts;
518 json = parse_json(argv[2]);
519 check_ovsdb_error(ovsdb_table_schema_from_json(json, argv[1], &ts));
521 print_and_free_json(ovsdb_table_schema_to_json(ts));
522 ovsdb_table_schema_destroy(ts);
526 do_parse_rows(int argc, char *argv[])
528 struct ovsdb_column_set all_columns;
529 struct ovsdb_table_schema *ts;
530 struct ovsdb_table *table;
534 json = unbox_json(parse_json(argv[1]));
535 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
538 table = ovsdb_table_create(ts);
539 ovsdb_column_set_init(&all_columns);
540 ovsdb_column_set_add_all(&all_columns, table);
542 for (i = 2; i < argc; i++) {
543 struct ovsdb_column_set columns;
544 struct ovsdb_row *row;
546 ovsdb_column_set_init(&columns);
547 row = ovsdb_row_create(table);
549 json = unbox_json(parse_json(argv[i]));
550 check_ovsdb_error(ovsdb_row_from_json(row, json, NULL, &columns));
553 print_and_free_json(ovsdb_row_to_json(row, &all_columns));
555 if (columns.n_columns) {
561 for (j = 0; j < columns.n_columns; j++) {
562 svec_add(&names, columns.columns[j]->name);
565 s = svec_join(&names, ", ", "");
568 svec_destroy(&names);
573 ovsdb_column_set_destroy(&columns);
574 ovsdb_row_destroy(row);
577 ovsdb_column_set_destroy(&all_columns);
578 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
582 do_compare_rows(int argc, char *argv[])
584 struct ovsdb_column_set all_columns;
585 struct ovsdb_table_schema *ts;
586 struct ovsdb_table *table;
587 struct ovsdb_row **rows;
593 json = unbox_json(parse_json(argv[1]));
594 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
597 table = ovsdb_table_create(ts);
598 ovsdb_column_set_init(&all_columns);
599 ovsdb_column_set_add_all(&all_columns, table);
602 rows = xmalloc(sizeof *rows * n_rows);
603 names = xmalloc(sizeof *names * n_rows);
604 for (i = 0; i < n_rows; i++) {
605 rows[i] = ovsdb_row_create(table);
607 json = parse_json(argv[i + 2]);
608 if (json->type != JSON_ARRAY || json->u.array.n != 2
609 || json->u.array.elems[0]->type != JSON_STRING) {
610 ovs_fatal(0, "\"%s\" does not have expected form "
611 "[\"name\", {data}]", argv[i]);
613 names[i] = xstrdup(json->u.array.elems[0]->u.string);
614 check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[1],
618 for (i = 0; i < n_rows; i++) {
619 uint32_t i_hash = ovsdb_row_hash_columns(rows[i], &all_columns, 0);
620 for (j = i + 1; j < n_rows; j++) {
621 uint32_t j_hash = ovsdb_row_hash_columns(rows[j], &all_columns, 0);
622 if (ovsdb_row_equal_columns(rows[i], rows[j], &all_columns)) {
623 printf("%s == %s\n", names[i], names[j]);
624 if (i_hash != j_hash) {
625 printf("but hash(%s) != hash(%s)\n", names[i], names[j]);
628 } else if (i_hash == j_hash) {
629 printf("hash(%s) == hash(%s)\n", names[i], names[j]);
633 for (i = 0; i < n_rows; i++) {
634 ovsdb_row_destroy(rows[i]);
640 ovsdb_column_set_destroy(&all_columns);
641 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
645 do_parse_conditions(int argc, char *argv[])
647 struct ovsdb_table_schema *ts;
652 json = unbox_json(parse_json(argv[1]));
653 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
656 for (i = 2; i < argc; i++) {
657 struct ovsdb_condition cnd;
658 struct ovsdb_error *error;
660 json = parse_json(argv[i]);
661 error = ovsdb_condition_from_json(ts, json, NULL, &cnd);
663 print_and_free_json(ovsdb_condition_to_json(&cnd));
665 char *s = ovsdb_error_to_string(error);
666 ovs_error(0, "%s", s);
668 ovsdb_error_destroy(error);
673 ovsdb_condition_destroy(&cnd);
675 ovsdb_table_schema_destroy(ts);
681 do_evaluate_conditions(int argc UNUSED, char *argv[])
683 struct ovsdb_table_schema *ts;
684 struct ovsdb_table *table;
685 struct ovsdb_condition *conditions;
687 struct ovsdb_row **rows;
692 /* Parse table schema, create table. */
693 json = unbox_json(parse_json(argv[1]));
694 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
697 table = ovsdb_table_create(ts);
699 /* Parse conditions. */
700 json = parse_json(argv[2]);
701 if (json->type != JSON_ARRAY) {
702 ovs_fatal(0, "CONDITION argument is not JSON array");
704 n_conditions = json->u.array.n;
705 conditions = xmalloc(n_conditions * sizeof *conditions);
706 for (i = 0; i < n_conditions; i++) {
707 check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
708 NULL, &conditions[i]));
713 json = parse_json(argv[3]);
714 if (json->type != JSON_ARRAY) {
715 ovs_fatal(0, "ROW argument is not JSON array");
717 n_rows = json->u.array.n;
718 rows = xmalloc(n_rows * sizeof *rows);
719 for (i = 0; i < n_rows; i++) {
720 rows[i] = ovsdb_row_create(table);
721 check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[i],
726 for (i = 0; i < n_conditions; i++) {
727 printf("condition %2d:", i);
728 for (j = 0; j < n_rows; j++) {
729 bool result = ovsdb_condition_evaluate(rows[j], &conditions[i]);
733 putchar(result ? 'T' : '-');
738 for (i = 0; i < n_conditions; i++) {
739 ovsdb_condition_destroy(&conditions[i]);
742 for (i = 0; i < n_rows; i++) {
743 ovsdb_row_destroy(rows[i]);
746 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
750 do_parse_mutations(int argc, char *argv[])
752 struct ovsdb_table_schema *ts;
757 json = unbox_json(parse_json(argv[1]));
758 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
761 for (i = 2; i < argc; i++) {
762 struct ovsdb_mutation_set set;
763 struct ovsdb_error *error;
765 json = parse_json(argv[i]);
766 error = ovsdb_mutation_set_from_json(ts, json, NULL, &set);
768 print_and_free_json(ovsdb_mutation_set_to_json(&set));
770 char *s = ovsdb_error_to_string(error);
771 ovs_error(0, "%s", s);
773 ovsdb_error_destroy(error);
778 ovsdb_mutation_set_destroy(&set);
780 ovsdb_table_schema_destroy(ts);
786 do_execute_mutations(int argc UNUSED, char *argv[])
788 struct ovsdb_table_schema *ts;
789 struct ovsdb_table *table;
790 struct ovsdb_mutation_set *sets;
792 struct ovsdb_row **rows;
797 /* Parse table schema, create table. */
798 json = unbox_json(parse_json(argv[1]));
799 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
802 table = ovsdb_table_create(ts);
804 /* Parse mutations. */
805 json = parse_json(argv[2]);
806 if (json->type != JSON_ARRAY) {
807 ovs_fatal(0, "MUTATION argument is not JSON array");
809 n_sets = json->u.array.n;
810 sets = xmalloc(n_sets * sizeof *sets);
811 for (i = 0; i < n_sets; i++) {
812 check_ovsdb_error(ovsdb_mutation_set_from_json(ts,
813 json->u.array.elems[i],
819 json = parse_json(argv[3]);
820 if (json->type != JSON_ARRAY) {
821 ovs_fatal(0, "ROW argument is not JSON array");
823 n_rows = json->u.array.n;
824 rows = xmalloc(n_rows * sizeof *rows);
825 for (i = 0; i < n_rows; i++) {
826 rows[i] = ovsdb_row_create(table);
827 check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[i],
832 for (i = 0; i < n_sets; i++) {
833 printf("mutation %2d:\n", i);
834 for (j = 0; j < n_rows; j++) {
835 struct ovsdb_error *error;
836 struct ovsdb_row *row;
838 row = ovsdb_row_clone(rows[j]);
839 error = ovsdb_mutation_set_execute(row, &sets[i]);
841 printf("row %zu: ", j);
843 print_and_free_ovsdb_error(error);
845 struct ovsdb_column_set columns;
846 struct shash_node *node;
848 ovsdb_column_set_init(&columns);
849 SHASH_FOR_EACH (node, &ts->columns) {
850 struct ovsdb_column *c = node->data;
851 if (!ovsdb_datum_equals(&row->fields[c->index],
852 &rows[j]->fields[c->index],
854 ovsdb_column_set_add(&columns, c);
857 if (columns.n_columns) {
858 print_and_free_json(ovsdb_row_to_json(row, &columns));
860 printf("no change\n");
862 ovsdb_column_set_destroy(&columns);
864 ovsdb_row_destroy(row);
869 for (i = 0; i < n_sets; i++) {
870 ovsdb_mutation_set_destroy(&sets[i]);
873 for (i = 0; i < n_rows; i++) {
874 ovsdb_row_destroy(rows[i]);
877 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
880 struct do_query_cbdata {
881 struct uuid *row_uuids;
887 do_query_cb(const struct ovsdb_row *row, void *cbdata_)
889 struct do_query_cbdata *cbdata = cbdata_;
892 for (i = 0; i < cbdata->n_rows; i++) {
893 if (uuid_equals(ovsdb_row_get_uuid(row), &cbdata->row_uuids[i])) {
902 do_query(int argc UNUSED, char *argv[])
904 struct do_query_cbdata cbdata;
905 struct ovsdb_table_schema *ts;
906 struct ovsdb_table *table;
911 /* Parse table schema, create table. */
912 json = unbox_json(parse_json(argv[1]));
913 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
916 table = ovsdb_table_create(ts);
918 /* Parse rows, add to table. */
919 json = parse_json(argv[2]);
920 if (json->type != JSON_ARRAY) {
921 ovs_fatal(0, "ROW argument is not JSON array");
923 cbdata.n_rows = json->u.array.n;
924 cbdata.row_uuids = xmalloc(cbdata.n_rows * sizeof *cbdata.row_uuids);
925 cbdata.counts = xmalloc(cbdata.n_rows * sizeof *cbdata.counts);
926 for (i = 0; i < cbdata.n_rows; i++) {
927 struct ovsdb_row *row = ovsdb_row_create(table);
928 uuid_generate(ovsdb_row_get_uuid_rw(row));
929 check_ovsdb_error(ovsdb_row_from_json(row, json->u.array.elems[i],
931 if (ovsdb_table_get_row(table, ovsdb_row_get_uuid(row))) {
932 ovs_fatal(0, "duplicate UUID "UUID_FMT" in table",
933 UUID_ARGS(ovsdb_row_get_uuid(row)));
935 cbdata.row_uuids[i] = *ovsdb_row_get_uuid(row);
936 ovsdb_table_put_row(table, row);
940 /* Parse conditions and execute queries. */
941 json = parse_json(argv[3]);
942 if (json->type != JSON_ARRAY) {
943 ovs_fatal(0, "CONDITION argument is not JSON array");
945 for (i = 0; i < json->u.array.n; i++) {
946 struct ovsdb_condition cnd;
949 check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
952 memset(cbdata.counts, 0, cbdata.n_rows * sizeof *cbdata.counts);
953 ovsdb_query(table, &cnd, do_query_cb, &cbdata);
955 printf("query %2d:", i);
956 for (j = 0; j < cbdata.n_rows; j++) {
960 if (cbdata.counts[j]) {
961 printf("%d", cbdata.counts[j]);
962 if (cbdata.counts[j] > 1) {
972 ovsdb_condition_destroy(&cnd);
976 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
981 struct do_query_distinct_class {
982 struct ovsdb_row *example;
986 struct do_query_distinct_row {
988 struct do_query_distinct_class *class;
992 do_query_distinct(int argc UNUSED, char *argv[])
994 struct ovsdb_column_set columns;
995 struct ovsdb_table_schema *ts;
996 struct ovsdb_table *table;
997 struct do_query_distinct_row *rows;
999 struct do_query_distinct_class *classes;
1005 /* Parse table schema, create table. */
1006 json = unbox_json(parse_json(argv[1]));
1007 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
1010 table = ovsdb_table_create(ts);
1012 /* Parse column set. */
1013 json = parse_json(argv[4]);
1014 check_ovsdb_error(ovsdb_column_set_from_json(json, table, &columns));
1017 /* Parse rows, add to table. */
1018 json = parse_json(argv[2]);
1019 if (json->type != JSON_ARRAY) {
1020 ovs_fatal(0, "ROW argument is not JSON array");
1022 n_rows = json->u.array.n;
1023 rows = xmalloc(n_rows * sizeof *rows);
1024 classes = xmalloc(n_rows * sizeof *classes);
1026 for (i = 0; i < n_rows; i++) {
1027 struct ovsdb_row *row;
1031 row = ovsdb_row_create(table);
1032 uuid_generate(ovsdb_row_get_uuid_rw(row));
1033 check_ovsdb_error(ovsdb_row_from_json(row, json->u.array.elems[i],
1036 /* Initialize row and find equivalence class. */
1037 rows[i].uuid = *ovsdb_row_get_uuid(row);
1038 rows[i].class = NULL;
1039 for (j = 0; j < n_classes; j++) {
1040 if (ovsdb_row_equal_columns(row, classes[j].example, &columns)) {
1041 rows[i].class = &classes[j];
1045 if (!rows[i].class) {
1046 rows[i].class = &classes[n_classes];
1047 classes[n_classes].example = ovsdb_row_clone(row);
1051 /* Add row to table. */
1052 if (ovsdb_table_get_row(table, ovsdb_row_get_uuid(row))) {
1053 ovs_fatal(0, "duplicate UUID "UUID_FMT" in table",
1054 UUID_ARGS(ovsdb_row_get_uuid(row)));
1056 ovsdb_table_put_row(table, row);
1061 /* Parse conditions and execute queries. */
1062 json = parse_json(argv[3]);
1063 if (json->type != JSON_ARRAY) {
1064 ovs_fatal(0, "CONDITION argument is not JSON array");
1066 for (i = 0; i < json->u.array.n; i++) {
1067 struct ovsdb_row_set results;
1068 struct ovsdb_condition cnd;
1070 check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
1073 for (j = 0; j < n_classes; j++) {
1074 classes[j].count = 0;
1076 ovsdb_row_set_init(&results);
1077 ovsdb_query_distinct(table, &cnd, &columns, &results);
1078 for (j = 0; j < results.n_rows; j++) {
1079 for (k = 0; k < n_rows; k++) {
1080 if (uuid_equals(ovsdb_row_get_uuid(results.rows[j]),
1082 rows[k].class->count++;
1086 ovsdb_row_set_destroy(&results);
1088 printf("query %2d:", i);
1089 for (j = 0; j < n_rows; j++) {
1090 int count = rows[j].class->count;
1097 printf("%d", count);
1099 } else if (count == 1) {
1100 putchar("abcdefghijklmnopqrstuvwxyz"[rows[j].class - classes]);
1107 ovsdb_condition_destroy(&cnd);
1111 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
1117 do_execute(int argc UNUSED, char *argv[])
1119 struct ovsdb_schema *schema;
1124 /* Create database. */
1125 json = parse_json(argv[1]);
1126 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1128 db = ovsdb_create(schema);
1130 for (i = 2; i < argc; i++) {
1131 struct json *params, *result;
1134 params = parse_json(argv[i]);
1135 result = ovsdb_execute(db, params, 0, NULL);
1136 s = json_to_string(result, JSSF_SORT);
1139 json_destroy(params);
1140 json_destroy(result);
1146 struct test_trigger {
1147 struct ovsdb_trigger trigger;
1152 do_trigger_dump(struct test_trigger *t, long long int now, const char *title)
1154 struct json *result;
1157 result = ovsdb_trigger_steal_result(&t->trigger);
1158 s = json_to_string(result, JSSF_SORT);
1159 printf("t=%lld: trigger %d (%s): %s\n", now, t->number, title, s);
1161 json_destroy(result);
1162 ovsdb_trigger_destroy(&t->trigger);
1167 do_trigger(int argc UNUSED, char *argv[])
1169 struct ovsdb_schema *schema;
1170 struct list completions;
1177 /* Create database. */
1178 json = parse_json(argv[1]);
1179 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1181 db = ovsdb_create(schema);
1183 list_init(&completions);
1186 for (i = 2; i < argc; i++) {
1187 struct json *params = parse_json(argv[i]);
1188 if (params->type == JSON_ARRAY
1189 && json_array(params)->n == 2
1190 && json_array(params)->elems[0]->type == JSON_STRING
1191 && !strcmp(json_string(json_array(params)->elems[0]), "advance")
1192 && json_array(params)->elems[1]->type == JSON_INTEGER) {
1193 now += json_integer(json_array(params)->elems[1]);
1194 json_destroy(params);
1196 struct test_trigger *t = xmalloc(sizeof *t);
1197 ovsdb_trigger_init(db, &t->trigger, params, &completions, now);
1198 t->number = number++;
1199 if (ovsdb_trigger_is_complete(&t->trigger)) {
1200 do_trigger_dump(t, now, "immediate");
1202 printf("t=%lld: new trigger %d\n", now, t->number);
1206 ovsdb_trigger_run(db, now);
1207 while (!list_is_empty(&completions)) {
1208 do_trigger_dump(CONTAINER_OF(list_pop_front(&completions),
1209 struct test_trigger, trigger.node),
1213 ovsdb_trigger_wait(db, now);
1214 poll_immediate_wake();
1222 do_help(int argc UNUSED, char *argv[] UNUSED)
1227 /* "transact" command. */
1229 static struct ovsdb *do_transact_db;
1230 static struct ovsdb_txn *do_transact_txn;
1231 static struct ovsdb_table *do_transact_table;
1234 do_transact_commit(int argc UNUSED, char *argv[] UNUSED)
1236 ovsdb_txn_commit(do_transact_txn, false);
1237 do_transact_txn = NULL;
1241 do_transact_abort(int argc UNUSED, char *argv[] UNUSED)
1243 ovsdb_txn_abort(do_transact_txn);
1244 do_transact_txn = NULL;
1248 uuid_from_integer(int integer, struct uuid *uuid)
1251 uuid->parts[3] = integer;
1254 static const struct ovsdb_row *
1255 do_transact_find_row(const char *uuid_string)
1257 const struct ovsdb_row *row;
1260 uuid_from_integer(atoi(uuid_string), &uuid);
1261 row = ovsdb_table_get_row(do_transact_table, &uuid);
1263 ovs_fatal(0, "table does not contain row with UUID "UUID_FMT,
1270 do_transact_set_integer(struct ovsdb_row *row, const char *column_name,
1273 if (integer != -1) {
1274 const struct ovsdb_column *column;
1276 column = ovsdb_table_schema_get_column(do_transact_table->schema,
1278 row->fields[column->index].keys[0].integer = integer;
1283 do_transact_get_integer(const struct ovsdb_row *row, const char *column_name)
1285 const struct ovsdb_column *column;
1287 column = ovsdb_table_schema_get_column(do_transact_table->schema,
1289 return row->fields[column->index].keys[0].integer;
1293 do_transact_set_i_j(struct ovsdb_row *row,
1294 const char *i_string, const char *j_string)
1296 do_transact_set_integer(row, "i", atoi(i_string));
1297 do_transact_set_integer(row, "j", atoi(j_string));
1301 do_transact_insert(int argc UNUSED, char *argv[] UNUSED)
1303 struct ovsdb_row *row;
1306 row = ovsdb_row_create(do_transact_table);
1309 uuid = ovsdb_row_get_uuid_rw(row);
1310 uuid_from_integer(atoi(argv[1]), uuid);
1311 if (ovsdb_table_get_row(do_transact_table, uuid)) {
1312 ovs_fatal(0, "table already contains row with UUID "UUID_FMT,
1316 do_transact_set_i_j(row, argv[2], argv[3]);
1319 ovsdb_txn_row_insert(do_transact_txn, row);
1323 do_transact_delete(int argc UNUSED, char *argv[] UNUSED)
1325 const struct ovsdb_row *row = do_transact_find_row(argv[1]);
1326 ovsdb_txn_row_delete(do_transact_txn, row);
1330 do_transact_modify(int argc UNUSED, char *argv[] UNUSED)
1332 const struct ovsdb_row *row_ro;
1333 struct ovsdb_row *row_rw;
1335 row_ro = do_transact_find_row(argv[1]);
1336 row_rw = ovsdb_txn_row_modify(do_transact_txn, row_ro);
1337 do_transact_set_i_j(row_rw, argv[2], argv[3]);
1341 compare_rows_by_uuid(const void *a_, const void *b_)
1343 struct ovsdb_row *const *ap = a_;
1344 struct ovsdb_row *const *bp = b_;
1346 return uuid_compare_3way(ovsdb_row_get_uuid(*ap), ovsdb_row_get_uuid(*bp));
1350 do_transact_print(int argc UNUSED, char *argv[] UNUSED)
1352 const struct ovsdb_row **rows;
1353 const struct ovsdb_row *row;
1357 n_rows = hmap_count(&do_transact_table->rows);
1358 rows = xmalloc(n_rows * sizeof *rows);
1360 HMAP_FOR_EACH (row, struct ovsdb_row, hmap_node,
1361 &do_transact_table->rows) {
1364 assert(i == n_rows);
1366 qsort(rows, n_rows, sizeof *rows, compare_rows_by_uuid);
1368 for (i = 0; i < n_rows; i++) {
1369 printf("\n%"PRId32": i=%d, j=%d",
1370 ovsdb_row_get_uuid(rows[i])->parts[3],
1371 do_transact_get_integer(rows[i], "i"),
1372 do_transact_get_integer(rows[i], "j"));
1379 do_transact(int argc, char *argv[])
1381 static const struct command do_transact_commands[] = {
1382 { "commit", 0, 0, do_transact_commit },
1383 { "abort", 0, 0, do_transact_abort },
1384 { "insert", 2, 3, do_transact_insert },
1385 { "delete", 1, 1, do_transact_delete },
1386 { "modify", 2, 3, do_transact_modify },
1387 { "print", 0, 0, do_transact_print },
1388 { NULL, 0, 0, NULL },
1391 struct ovsdb_schema *schema;
1396 json = parse_json("{\"name\": \"testdb\", "
1400 " {\"i\": {\"type\": \"integer\"}, "
1401 " \"j\": {\"type\": \"integer\"}}}}}");
1402 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1404 do_transact_db = ovsdb_create(schema);
1405 do_transact_table = ovsdb_get_table(do_transact_db, "mytable");
1406 assert(do_transact_table != NULL);
1408 for (i = 1; i < argc; i++) {
1409 struct json *command;
1414 command = parse_json(argv[i]);
1415 if (command->type != JSON_ARRAY) {
1416 ovs_fatal(0, "transaction %d must be JSON array "
1417 "with at least 1 element", i);
1420 n_args = command->u.array.n;
1421 args = xmalloc((n_args + 1) * sizeof *args);
1422 for (j = 0; j < n_args; j++) {
1423 struct json *s = command->u.array.elems[j];
1424 if (s->type != JSON_STRING) {
1425 ovs_fatal(0, "transaction %d argument %d must be JSON string",
1428 args[j] = xstrdup(json_string(s));
1430 args[n_args] = NULL;
1432 if (!do_transact_txn) {
1433 do_transact_txn = ovsdb_txn_create(do_transact_db);
1436 for (j = 0; j < n_args; j++) {
1440 fputs(args[j], stdout);
1443 run_command(n_args, args, do_transact_commands);
1446 for (j = 0; j < n_args; j++) {
1450 json_destroy(command);
1452 ovsdb_txn_abort(do_transact_txn);
1453 ovsdb_destroy(do_transact_db); /* Also destroys 'schema'. */
1457 compare_link1(const void *a_, const void *b_)
1459 const struct idltest_link1 *const *ap = a_;
1460 const struct idltest_link1 *const *bp = b_;
1461 const struct idltest_link1 *a = *ap;
1462 const struct idltest_link1 *b = *bp;
1464 return a->i < b->i ? -1 : a->i > b->i;
1468 print_idl(struct ovsdb_idl *idl, int step)
1470 const struct idltest_simple *s;
1471 const struct idltest_link1 *l1;
1472 const struct idltest_link2 *l2;
1475 IDLTEST_SIMPLE_FOR_EACH (s, idl) {
1478 printf("%03d: i=%"PRId64" r=%g b=%s s=%s u="UUID_FMT" ia=[",
1479 step, s->i, s->r, s->b ? "true" : "false",
1480 s->s, UUID_ARGS(&s->u));
1481 for (i = 0; i < s->n_ia; i++) {
1482 printf("%s%"PRId64, i ? " " : "", s->ia[i]);
1485 for (i = 0; i < s->n_ra; i++) {
1486 printf("%s%g", i ? " " : "", s->ra[i]);
1489 for (i = 0; i < s->n_ba; i++) {
1490 printf("%s%s", i ? " " : "", s->ba[i] ? "true" : "false");
1493 for (i = 0; i < s->n_sa; i++) {
1494 printf("%s%s", i ? " " : "", s->sa[i]);
1497 for (i = 0; i < s->n_ua; i++) {
1498 printf("%s"UUID_FMT, i ? " " : "", UUID_ARGS(&s->ua[i]));
1500 printf("] uuid="UUID_FMT"\n", UUID_ARGS(&s->header_.uuid));
1503 IDLTEST_LINK1_FOR_EACH (l1, idl) {
1504 struct idltest_link1 **links;
1507 printf("%03d: i=%"PRId64" k=", step, l1->i);
1509 printf("%"PRId64, l1->k->i);
1512 links = xmemdup(l1->ka, l1->n_ka * sizeof *l1->ka);
1513 qsort(links, l1->n_ka, sizeof *links, compare_link1);
1514 for (i = 0; i < l1->n_ka; i++) {
1515 printf("%s%"PRId64, i ? " " : "", links[i]->i);
1520 printf("%"PRId64, l1->l2->i);
1522 printf(" uuid="UUID_FMT"\n", UUID_ARGS(&l1->header_.uuid));
1525 IDLTEST_LINK2_FOR_EACH (l2, idl) {
1526 printf("%03d: i=%"PRId64" l1=", step, l2->i);
1528 printf("%"PRId64, l2->l1->i);
1530 printf(" uuid="UUID_FMT"\n", UUID_ARGS(&l2->header_.uuid));
1534 printf("%03d: empty\n", step);
1539 print_updated_idl(struct ovsdb_idl *idl, struct jsonrpc *rpc,
1540 int step, unsigned int seqno)
1543 unsigned int new_seqno;
1549 new_seqno = ovsdb_idl_get_seqno(idl);
1550 if (new_seqno != seqno) {
1551 print_idl(idl, step);
1558 ovsdb_idl_wait(idl);
1564 parse_uuids(const struct json *json, struct ovsdb_symbol_table *symtab,
1569 if (json->type == JSON_STRING && uuid_from_string(&uuid, json->u.string)) {
1570 char *name = xasprintf("#%d#", *n);
1571 fprintf(stderr, "%s = "UUID_FMT"\n", name, UUID_ARGS(&uuid));
1572 ovsdb_symbol_table_put(symtab, name, &uuid, false);
1575 } else if (json->type == JSON_ARRAY) {
1578 for (i = 0; i < json->u.array.n; i++) {
1579 parse_uuids(json->u.array.elems[i], symtab, n);
1581 } else if (json->type == JSON_OBJECT) {
1582 const struct shash_node *node;
1584 SHASH_FOR_EACH (node, json_object(json)) {
1585 parse_uuids(node->data, symtab, n);
1591 substitute_uuids(struct json *json, const struct ovsdb_symbol_table *symtab)
1593 if (json->type == JSON_STRING) {
1594 const struct ovsdb_symbol *symbol;
1596 symbol = ovsdb_symbol_table_get(symtab, json->u.string);
1598 free(json->u.string);
1599 json->u.string = xasprintf(UUID_FMT, UUID_ARGS(&symbol->uuid));
1601 } else if (json->type == JSON_ARRAY) {
1604 for (i = 0; i < json->u.array.n; i++) {
1605 substitute_uuids(json->u.array.elems[i], symtab);
1607 } else if (json->type == JSON_OBJECT) {
1608 const struct shash_node *node;
1610 SHASH_FOR_EACH (node, json_object(json)) {
1611 substitute_uuids(node->data, symtab);
1616 static const struct idltest_simple *
1617 idltest_find_simple(struct ovsdb_idl *idl, int i)
1619 const struct idltest_simple *s;
1621 IDLTEST_SIMPLE_FOR_EACH (s, idl) {
1630 idl_set(struct ovsdb_idl *idl, char *commands, int step)
1632 char *cmd, *save_ptr1 = NULL;
1633 struct ovsdb_idl_txn *txn;
1634 enum ovsdb_idl_txn_status status;
1635 bool increment = false;
1637 txn = ovsdb_idl_txn_create(idl);
1638 for (cmd = strtok_r(commands, ",", &save_ptr1); cmd;
1639 cmd = strtok_r(NULL, ",", &save_ptr1)) {
1640 char *save_ptr2 = NULL;
1641 char *name, *arg1, *arg2, *arg3;
1643 name = strtok_r(cmd, " ", &save_ptr2);
1644 arg1 = strtok_r(NULL, " ", &save_ptr2);
1645 arg2 = strtok_r(NULL, " ", &save_ptr2);
1646 arg3 = strtok_r(NULL, " ", &save_ptr2);
1648 if (!strcmp(name, "set")) {
1649 const struct idltest_simple *s;
1652 ovs_fatal(0, "\"set\" command requires 3 arguments");
1655 s = idltest_find_simple(idl, atoi(arg1));
1657 ovs_fatal(0, "\"set\" command asks for nonexistent "
1658 "i=%d", atoi(arg1));
1661 if (!strcmp(arg2, "b")) {
1662 idltest_simple_set_b(s, atoi(arg3));
1663 } else if (!strcmp(arg2, "s")) {
1664 idltest_simple_set_s(s, arg3);
1665 } else if (!strcmp(arg2, "u")) {
1667 uuid_from_string(&uuid, arg3);
1668 idltest_simple_set_u(s, uuid);
1669 } else if (!strcmp(arg2, "r")) {
1670 idltest_simple_set_r(s, atof(arg3));
1672 ovs_fatal(0, "\"set\" command asks for unknown column %s",
1675 } else if (!strcmp(name, "insert")) {
1676 struct idltest_simple *s;
1678 if (!arg1 || arg2) {
1679 ovs_fatal(0, "\"set\" command requires 1 argument");
1682 s = idltest_simple_insert(txn);
1683 idltest_simple_set_i(s, atoi(arg1));
1684 } else if (!strcmp(name, "delete")) {
1685 const struct idltest_simple *s;
1687 if (!arg1 || arg2) {
1688 ovs_fatal(0, "\"set\" command requires 1 argument");
1691 s = idltest_find_simple(idl, atoi(arg1));
1693 ovs_fatal(0, "\"set\" command asks for nonexistent "
1694 "i=%d", atoi(arg1));
1696 idltest_simple_delete(s);
1697 } else if (!strcmp(name, "increment")) {
1698 if (!arg2 || arg3) {
1699 ovs_fatal(0, "\"set\" command requires 2 arguments");
1701 ovsdb_idl_txn_increment(txn, arg1, arg2, NULL);
1704 ovs_fatal(0, "unknown command %s", name);
1708 while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) {
1710 ovsdb_idl_wait(idl);
1711 ovsdb_idl_txn_wait(txn);
1714 printf("%03d: commit, status=%s",
1715 step, ovsdb_idl_txn_status_to_string(status));
1717 printf(", increment=%"PRId64,
1718 ovsdb_idl_txn_get_increment_new_value(txn));
1721 ovsdb_idl_txn_destroy(txn);
1725 do_idl(int argc, char *argv[])
1727 struct jsonrpc *rpc;
1728 struct ovsdb_idl *idl;
1729 unsigned int seqno = 0;
1730 struct ovsdb_symbol_table *symtab;
1736 idl = ovsdb_idl_create(argv[1], &idltest_idl_class);
1738 struct stream *stream;
1740 error = stream_open_block(argv[1], &stream);
1742 ovs_fatal(error, "failed to connect to \"%s\"", argv[1]);
1744 rpc = jsonrpc_open(stream);
1749 symtab = ovsdb_symbol_table_create();
1750 for (i = 2; i < argc; i++) {
1751 struct jsonrpc_msg *request, *reply;
1754 seqno = print_updated_idl(idl, rpc, step++, seqno);
1756 if (!strcmp(argv[i], "reconnect")) {
1757 printf("%03d: reconnect\n", step++);
1758 ovsdb_idl_force_reconnect(idl);
1759 } else if (argv[i][0] != '[') {
1760 idl_set(idl, argv[i], step++);
1762 struct json *json = parse_json(argv[i]);
1763 substitute_uuids(json, symtab);
1764 request = jsonrpc_create_request("transact", json, NULL);
1765 error = jsonrpc_transact_block(rpc, request, &reply);
1767 ovs_fatal(error, "jsonrpc transaction failed");
1769 printf("%03d: ", step++);
1770 if (reply->result) {
1771 parse_uuids(reply->result, symtab, &n_uuids);
1773 json_destroy(reply->id);
1775 print_and_free_json(jsonrpc_msg_to_json(reply));
1778 ovsdb_symbol_table_destroy(symtab);
1783 print_updated_idl(idl, NULL, step++, seqno);
1784 ovsdb_idl_destroy(idl);
1785 printf("%03d: done\n", step);
1788 static struct command all_commands[] = {
1789 { "log-io", 2, INT_MAX, do_log_io },
1790 { "parse-atomic-type", 1, 1, do_parse_atomic_type },
1791 { "parse-type", 1, 1, do_parse_type },
1792 { "parse-atoms", 2, INT_MAX, do_parse_atoms },
1793 { "parse-atom-strings", 2, INT_MAX, do_parse_atom_strings },
1794 { "parse-data", 2, INT_MAX, do_parse_data },
1795 { "parse-data-strings", 2, INT_MAX, do_parse_data_strings },
1796 { "sort-atoms", 2, 2, do_sort_atoms },
1797 { "parse-column", 2, 2, do_parse_column },
1798 { "parse-table", 2, 2, do_parse_table },
1799 { "parse-rows", 2, INT_MAX, do_parse_rows },
1800 { "compare-rows", 2, INT_MAX, do_compare_rows },
1801 { "parse-conditions", 2, INT_MAX, do_parse_conditions },
1802 { "evaluate-conditions", 3, 3, do_evaluate_conditions },
1803 { "parse-mutations", 2, INT_MAX, do_parse_mutations },
1804 { "execute-mutations", 3, 3, do_execute_mutations },
1805 { "query", 3, 3, do_query },
1806 { "query-distinct", 4, 4, do_query_distinct },
1807 { "transact", 1, INT_MAX, do_transact },
1808 { "execute", 2, INT_MAX, do_execute },
1809 { "trigger", 2, INT_MAX, do_trigger },
1810 { "idl", 1, INT_MAX, do_idl },
1811 { "help", 0, INT_MAX, do_help },
1812 { NULL, 0, 0, NULL },