| 530 | } |
| 531 | |
| 532 | static void init_indices(struct plugin *plugin, const struct table_desc *td) |
| 533 | { |
| 534 | struct sql *sql = sql_of(plugin); |
| 535 | |
| 536 | for (size_t i = 0; i < ARRAY_SIZE(indices); i++) { |
| 537 | char *errmsg, *cmd; |
| 538 | int err; |
| 539 | |
| 540 | if (!streq(indices[i].tablename, td->name)) |
| 541 | continue; |
| 542 | |
| 543 | cmd = tal_fmt(tmpctx, "CREATE INDEX %s_%zu_idx ON %s (%s", |
| 544 | indices[i].tablename, i, |
| 545 | indices[i].tablename, |
| 546 | indices[i].fields[0]); |
| 547 | if (indices[i].fields[1]) |
| 548 | tal_append_fmt(&cmd, ", %s", indices[i].fields[1]); |
| 549 | tal_append_fmt(&cmd, ");"); |
| 550 | err = sqlite3_exec(sql->db, cmd, NULL, NULL, &errmsg); |
| 551 | if (err != SQLITE_OK) |
| 552 | plugin_err(plugin, "Failed '%s': %s", cmd, errmsg); |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | /* Recursion */ |
| 557 | static struct command_result *refresh_tables(struct command *cmd, |
no test coverage detected