| 619 | } |
| 620 | |
| 621 | static bool db_sqlite3_delete_columns(struct db *db, |
| 622 | const char *tablename, |
| 623 | const char **colnames, size_t num_cols) |
| 624 | { |
| 625 | char **parts; |
| 626 | const char **coldefs, **oldcolnames; |
| 627 | size_t colnames_found = 0; |
| 628 | |
| 629 | parts = prepare_table_manip(NULL, db, tablename); |
| 630 | if (!parts) |
| 631 | return false; |
| 632 | |
| 633 | tal_steal(tmpctx, parts); |
| 634 | coldefs = tal_arr(tmpctx, const char *, 0); |
| 635 | oldcolnames = tal_arr(tmpctx, const char *, 0); |
| 636 | |
| 637 | for (size_t i = 0; parts[i]; i++) { |
| 638 | /* columnname DETAILS */ |
| 639 | size_t after_name; |
| 640 | const char *colname = find_column_name(tmpctx, parts[i], |
| 641 | &after_name); |
| 642 | |
| 643 | /* Things like "PRIMARY KEY xxx" must be copied verbatim */ |
| 644 | if (!colname) { |
| 645 | tal_arr_expand(&coldefs, parts[i]); |
| 646 | continue; |
| 647 | } |
| 648 | |
| 649 | /* Don't mention columns we're supposed to delete */ |
| 650 | if (colname_to_delete(colnames, num_cols, colname)) { |
| 651 | colnames_found++; |
| 652 | continue; |
| 653 | } |
| 654 | |
| 655 | /* Keep it as is! */ |
| 656 | tal_arr_expand(&coldefs, parts[i]); |
| 657 | tal_arr_expand(&oldcolnames, colname); |
| 658 | } |
| 659 | |
| 660 | if (colnames_found != num_cols) { |
| 661 | db->error = tal_fmt(db, "Only %zu/%zu columns found", |
| 662 | colnames_found, num_cols); |
| 663 | return false; |
| 664 | } |
| 665 | return complete_table_manip(db, tablename, coldefs, oldcolnames); |
| 666 | } |
| 667 | |
| 668 | struct db_config db_sqlite3_config = { |
| 669 | .name = "sqlite3", |
nothing calls this directly
no test coverage detected