| 1497 | } |
| 1498 | |
| 1499 | static void json_add_schema(struct json_stream *js, |
| 1500 | const struct table_desc *td) |
| 1501 | { |
| 1502 | bool have_indices; |
| 1503 | |
| 1504 | json_object_start(js, NULL); |
| 1505 | json_add_string(js, "tablename", td->name); |
| 1506 | /* This needs to be an array, not a dictionary, since dicts |
| 1507 | * are often treated as unordered, and order is critical! */ |
| 1508 | json_array_start(js, "columns"); |
| 1509 | if (!td->has_created_index) |
| 1510 | json_add_column(js, "rowid", "INTEGER"); |
| 1511 | if (td->parent) { |
| 1512 | json_add_column(js, "row", "INTEGER"); |
| 1513 | json_add_column(js, "arrindex", "INTEGER"); |
| 1514 | } |
| 1515 | json_add_columns(js, td); |
| 1516 | json_array_end(js); |
| 1517 | |
| 1518 | /* Don't print indices entry unless we have an index! */ |
| 1519 | have_indices = false; |
| 1520 | for (size_t i = 0; i < ARRAY_SIZE(indices); i++) { |
| 1521 | if (!streq(indices[i].tablename, td->name)) |
| 1522 | continue; |
| 1523 | if (!have_indices) { |
| 1524 | json_array_start(js, "indices"); |
| 1525 | have_indices = true; |
| 1526 | } |
| 1527 | json_array_start(js, NULL); |
| 1528 | for (size_t j = 0; j < ARRAY_SIZE(indices[i].fields); j++) { |
| 1529 | if (indices[i].fields[j]) |
| 1530 | json_add_string(js, NULL, indices[i].fields[j]); |
| 1531 | } |
| 1532 | json_array_end(js); |
| 1533 | } |
| 1534 | if (have_indices) |
| 1535 | json_array_end(js); |
| 1536 | json_object_end(js); |
| 1537 | } |
| 1538 | |
| 1539 | static bool add_one_schema(const char *member, struct table_desc *td, |
| 1540 | struct json_stream *js) |
no test coverage detected