| 937 | } |
| 938 | |
| 939 | SuccessState ShellState::ExecuteStatement(unique_ptr<duckdb::SQLStatement> statement) { |
| 940 | if (!statement->named_param_map.empty()) { |
| 941 | PrintDatabaseError("Prepared statement parameters cannot be used directly\nTo use prepared " |
| 942 | "statement parameters, use PREPARE to prepare a statement, followed by EXECUTE"); |
| 943 | return SuccessState::FAILURE; |
| 944 | } |
| 945 | auto &con = *conn; |
| 946 | auto renderer = GetRenderer(); |
| 947 | unique_ptr<duckdb::QueryResult> result; |
| 948 | if (renderer->RequireMaterializedResult()) { |
| 949 | // we need to materialize the result prior to rendering |
| 950 | duckdb::QueryParameters parameters; |
| 951 | parameters.output_type = duckdb::QueryResultOutputType::FORCE_MATERIALIZED; |
| 952 | parameters.memory_type = duckdb::QueryResultMemoryType::BUFFER_MANAGED; |
| 953 | result = con.SendQuery(std::move(statement), parameters); |
| 954 | } else { |
| 955 | // for row-wise rendering we can use streaming results |
| 956 | result = con.SendQuery(std::move(statement)); |
| 957 | } |
| 958 | auto &res = *result; |
| 959 | if (res.HasError()) { |
| 960 | PrintDatabaseError(res.GetError()); |
| 961 | return SuccessState::FAILURE; |
| 962 | } |
| 963 | auto &properties = res.properties; |
| 964 | if (properties.return_type == duckdb::StatementReturnType::CHANGED_ROWS) { |
| 965 | auto result_chunk = res.Fetch(); |
| 966 | if (result_chunk && result_chunk->size() == 1) { |
| 967 | // update total changes |
| 968 | auto row_changes = result_chunk->GetValue(0, 0); |
| 969 | if (!row_changes.IsNull() && row_changes.DefaultTryCastAs(duckdb::LogicalType::BIGINT)) { |
| 970 | last_changes = row_changes.GetValue<int64_t>(); |
| 971 | total_changes += last_changes; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | if (properties.return_type != duckdb::StatementReturnType::QUERY_RESULT) { |
| 976 | // only SELECT statements return results that need to be rendered |
| 977 | return SuccessState::SUCCESS; |
| 978 | } |
| 979 | if (res.type == duckdb::QueryResultType::MATERIALIZED_RESULT) { |
| 980 | last_result = duckdb::unique_ptr_cast<duckdb::QueryResult, MaterializedQueryResult>(std::move(result)); |
| 981 | } |
| 982 | // analyze the query result so we know how long/wide the result will be |
| 983 | return RenderQueryResult(*renderer, res); |
| 984 | } |
| 985 | |
| 986 | /* |
| 987 | ** Execute a statement or set of statements. Print |
nothing calls this directly
no test coverage detected