| 1789 | } |
| 1790 | |
| 1791 | ExecuteSQLSingleValueResult ShellState::ExecuteSQLSingleValue(duckdb::Connection &con, const string &sql, |
| 1792 | string &result_value) { |
| 1793 | auto result = con.Query(sql); |
| 1794 | if (result->HasError()) { |
| 1795 | // store error in the result |
| 1796 | result_value = result->GetError(); |
| 1797 | return ExecuteSQLSingleValueResult::EXECUTION_ERROR; |
| 1798 | } |
| 1799 | auto is_query = result->properties.return_type == duckdb::StatementReturnType::QUERY_RESULT; |
| 1800 | if (!is_query) { |
| 1801 | return ExecuteSQLSingleValueResult::EMPTY_RESULT; |
| 1802 | } |
| 1803 | auto &collection = result->Collection(); |
| 1804 | if (collection.Count() == 0) { |
| 1805 | return ExecuteSQLSingleValueResult::EMPTY_RESULT; |
| 1806 | } |
| 1807 | if (collection.Count() > 1) { |
| 1808 | return ExecuteSQLSingleValueResult::MULTIPLE_ROWS; |
| 1809 | } |
| 1810 | if (collection.ColumnCount() != 1) { |
| 1811 | return ExecuteSQLSingleValueResult::MULTIPLE_COLUMNS; |
| 1812 | } |
| 1813 | |
| 1814 | auto value = collection.GetRows().GetValue(0, 0); |
| 1815 | if (value.IsNull()) { |
| 1816 | return ExecuteSQLSingleValueResult::NULL_RESULT; |
| 1817 | } |
| 1818 | result_value = value.ToString(); |
| 1819 | return ExecuteSQLSingleValueResult::SUCCESS; |
| 1820 | } |
| 1821 | |
| 1822 | ExecuteSQLSingleValueResult ShellState::ExecuteSQLSingleValue(const string &sql, string &result_value) { |
| 1823 | return ExecuteSQLSingleValue(*conn, sql, result_value); |
no test coverage detected