| 1623 | |
| 1624 | |
| 1625 | BlockIO InterpreterCreateQuery::doCreateOrReplaceTable(ASTCreateQuery & create, |
| 1626 | const InterpreterCreateQuery::TableProperties & properties) |
| 1627 | { |
| 1628 | auto ast_drop = std::make_shared<ASTDropQuery>(); |
| 1629 | String table_to_replace_name = create.table; |
| 1630 | bool created = false; |
| 1631 | bool replaced = false; |
| 1632 | |
| 1633 | try |
| 1634 | { |
| 1635 | [[maybe_unused]] bool done = doCreateTable(create, properties); |
| 1636 | assert(done); |
| 1637 | ast_drop->table = create.table; |
| 1638 | ast_drop->is_dictionary = create.is_dictionary; |
| 1639 | ast_drop->database = create.database; |
| 1640 | ast_drop->kind = ASTDropQuery::Drop; |
| 1641 | created = true; |
| 1642 | if (!create.replace_table) |
| 1643 | return fillTableIfNeeded(create); |
| 1644 | |
| 1645 | auto ast_rename = std::make_shared<ASTRenameQuery>(); |
| 1646 | ASTRenameQuery::Element elem |
| 1647 | { |
| 1648 | ASTRenameQuery::Table{create.database, create.table}, |
| 1649 | ASTRenameQuery::Table{create.database, table_to_replace_name} |
| 1650 | }; |
| 1651 | |
| 1652 | ast_rename->elements.push_back(std::move(elem)); |
| 1653 | ast_rename->exchange = true; |
| 1654 | ast_rename->dictionary = create.is_dictionary; |
| 1655 | |
| 1656 | InterpreterRenameQuery(ast_rename, getContext()).execute(); |
| 1657 | replaced = true; |
| 1658 | |
| 1659 | InterpreterDropQuery(ast_drop, getContext()).execute(); |
| 1660 | |
| 1661 | create.table = table_to_replace_name; |
| 1662 | |
| 1663 | return fillTableIfNeeded(create); |
| 1664 | } |
| 1665 | catch (...) |
| 1666 | { |
| 1667 | if (created && create.replace_table && !replaced) |
| 1668 | InterpreterDropQuery(ast_drop, getContext()).execute(); |
| 1669 | throw; |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | BlockIO InterpreterCreateQuery::fillTableIfNeeded(const ASTCreateQuery & create) |
| 1674 | { |
nothing calls this directly
no test coverage detected