** Run zQuery. Use dump_callback() as the callback routine so that ** the contents of the query are output as SQL statements. ** ** If we get a SQLITE_CORRUPT error, rerun the query after appending ** "ORDER BY rowid DESC" to the end. */
| 1093 | ** "ORDER BY rowid DESC" to the end. |
| 1094 | */ |
| 1095 | void ShellState::RunSchemaDumpQuery(const string &zQuery) { |
| 1096 | auto &con = *conn; |
| 1097 | auto result = con.Query(zQuery); |
| 1098 | for (auto &row : *result) { |
| 1099 | auto zTable = row.GetValue<string>(0); |
| 1100 | auto zType = row.GetValue<string>(1); |
| 1101 | auto zSql = row.GetValue<string>(2); |
| 1102 | |
| 1103 | // print sql |
| 1104 | Print(GetSchemaLine(zSql, ";\n")); |
| 1105 | if (zType == "table") { |
| 1106 | // dump table contents |
| 1107 | string sSelect; |
| 1108 | string sTable; |
| 1109 | |
| 1110 | auto zSchema = getTableSchema(con, zTable.c_str()); |
| 1111 | auto zQualifiedName = buildQualifiedName(zSchema.c_str(), zTable.c_str()); |
| 1112 | |
| 1113 | auto table_columns = TableColumnList(zQualifiedName.c_str()); |
| 1114 | if (table_columns.empty()) { |
| 1115 | AddError(); |
| 1116 | break; |
| 1117 | } |
| 1118 | |
| 1119 | if (!zSchema.empty()) { |
| 1120 | sTable += zQualifiedName; |
| 1121 | } else { |
| 1122 | sTable += StringUtil::Format("%s", SQLIdentifier(zTable)); |
| 1123 | } |
| 1124 | |
| 1125 | /* Build an appropriate SELECT statement */ |
| 1126 | sSelect += "SELECT "; |
| 1127 | for (idx_t i = 0; i < table_columns.size(); i++) { |
| 1128 | if (i > 0) { |
| 1129 | sSelect += ", "; |
| 1130 | } |
| 1131 | sSelect += StringUtil::Format("%s", SQLIdentifier(table_columns[i])); |
| 1132 | } |
| 1133 | sSelect += " FROM "; |
| 1134 | sSelect += zQualifiedName; |
| 1135 | |
| 1136 | auto savedDestTable = zDestTable; |
| 1137 | auto savedMode = mode; |
| 1138 | zDestTable = sTable; |
| 1139 | mode = cMode = RenderMode::INSERT; |
| 1140 | auto res = ExecuteSQL(sSelect); |
| 1141 | zDestTable = savedDestTable; |
| 1142 | mode = savedMode; |
| 1143 | if (res != SuccessState::SUCCESS) { |
| 1144 | AddError(); |
| 1145 | } |
| 1146 | } |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | SuccessState ShellState::ExecuteQuery(const string &query) { |
| 1151 | auto &con = *conn; |
no test coverage detected