| 1 | #include "duckdb/main/query_result.hpp" |
| 2 | |
| 3 | using namespace duckdb; |
| 4 | using namespace std; |
| 5 | |
| 6 | QueryResult::QueryResult(QueryResultType type, StatementType statement_type) |
| 7 | : type(type), statement_type(statement_type), success(true) { |
| 8 | } |
| 9 | |
| 10 | QueryResult::QueryResult(QueryResultType type, StatementType statement_type, vector<SQLType> sql_types, |
| 11 | vector<TypeId> types, vector<string> names) |
| 12 | : type(type), statement_type(statement_type), sql_types(sql_types), types(types), names(names), success(true) { |
| 13 | assert(types.size() == names.size()); |
| 14 | } |
| 15 | |
| 16 | QueryResult::QueryResult(QueryResultType type, string error) : type(type), success(false), error(error) { |
| 17 | } |
| 18 | |
| 19 | bool QueryResult::Equals(QueryResult &other) { |
| 20 | // first compare the success state of the results |
| 21 | if (success != other.success) { |
| 22 | return false; |
| 23 | } |
| 24 | if (!success) { |
| 25 | return error == other.error; |
| 26 | } |
| 27 | // compare names |
| 28 | if (names != other.names) { |
| 29 | return false; |
| 30 | } |
| 31 | // compare types |
| 32 | if (sql_types != other.sql_types || types != other.types) { |
| 33 | return false; |
| 34 | } |
| 35 | // now compare the actual values |
| 36 | // fetch chunks |
| 37 | while (true) { |
| 38 | auto lchunk = Fetch(); |
| 39 | auto rchunk = other.Fetch(); |
| 40 | if (lchunk->size() == 0 && rchunk->size() == 0) { |
| 41 | return true; |
| 42 | } |
| 43 | if (lchunk->size() != rchunk->size()) { |
| 44 | return false; |
| 45 | } |
| 46 | assert(lchunk->column_count() == rchunk->column_count()); |
| 47 | for (idx_t col = 0; col < rchunk->column_count(); col++) { |
| 48 | for (idx_t row = 0; row < rchunk->size(); row++) { |
| 49 | auto lvalue = lchunk->GetValue(col, row); |
| 50 | auto rvalue = rchunk->GetValue(col, row); |
| 51 | if (lvalue != rvalue) { |
| 52 | return false; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void QueryResult::Print() { |
| 60 | fprintf(stderr, "%s\n" , ToString().c_str()); |
| 61 | } |
| 62 | |
| 63 | string QueryResult::() { |
| 64 | string result; |
| 65 | for (auto &name : names) { |
| 66 | result += name + "\t" ; |
| 67 | } |
| 68 | result += "\n" ; |
| 69 | for (auto &type : sql_types) { |
| 70 | result += SQLTypeToString(type) + "\t" ; |
| 71 | } |
| 72 | result += "\n" ; |
| 73 | return result; |
| 74 | } |
| 75 | |