FIXME: sqlite3 version 3.25.0 (2018-09-15) supports ALTER TABLE RENAME */
| 570 | |
| 571 | /* FIXME: sqlite3 version 3.25.0 (2018-09-15) supports ALTER TABLE RENAME */ |
| 572 | static bool db_sqlite3_rename_column(struct db *db, |
| 573 | const char *tablename, |
| 574 | const char *from, const char *to) |
| 575 | { |
| 576 | char **parts; |
| 577 | const char **coldefs, **oldcolnames; |
| 578 | bool colname_found = false; |
| 579 | |
| 580 | parts = prepare_table_manip(NULL, db, tablename); |
| 581 | if (!parts) |
| 582 | return false; |
| 583 | |
| 584 | tal_steal(tmpctx, parts); |
| 585 | coldefs = tal_arr(tmpctx, const char *, 0); |
| 586 | oldcolnames = tal_arr(tmpctx, const char *, 0); |
| 587 | |
| 588 | for (size_t i = 0; parts[i]; i++) { |
| 589 | /* columnname DETAILS */ |
| 590 | size_t after_name; |
| 591 | const char *colname = find_column_name(tmpctx, parts[i], |
| 592 | &after_name); |
| 593 | |
| 594 | /* Things like "PRIMARY KEY xxx" must be copied verbatim */ |
| 595 | if (!colname) { |
| 596 | tal_arr_expand(&coldefs, parts[i]); |
| 597 | continue; |
| 598 | } |
| 599 | if (streq(colname, from)) { |
| 600 | char *newdef; |
| 601 | colname_found = true; |
| 602 | /* Create column with new name */ |
| 603 | newdef = tal_fmt(coldefs, |
| 604 | "%s%s", to, parts[i] + after_name); |
| 605 | tal_arr_expand(&coldefs, newdef); |
| 606 | tal_arr_expand(&oldcolnames, colname); |
| 607 | } else { |
| 608 | /* Not mentioned, keep it as is! */ |
| 609 | tal_arr_expand(&coldefs, parts[i]); |
| 610 | tal_arr_expand(&oldcolnames, colname); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | if (!colname_found) { |
| 615 | db->error = tal_fmt(db, "No column called %s", from); |
| 616 | return false; |
| 617 | } |
| 618 | return complete_table_manip(db, tablename, coldefs, oldcolnames); |
| 619 | } |
| 620 | |
| 621 | static bool db_sqlite3_delete_columns(struct db *db, |
| 622 | const char *tablename, |
nothing calls this directly
no test coverage detected