MCPcopy Create free account
hub / github.com/duckdb/duckdb / ExecuteSQLSingleValue

Method ExecuteSQLSingleValue

tools/shell/shell.cpp:1791–1820  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1789}
1790
1791ExecuteSQLSingleValueResult 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
1822ExecuteSQLSingleValueResult ShellState::ExecuteSQLSingleValue(const string &sql, string &result_value) {
1823 return ExecuteSQLSingleValue(*conn, sql, result_value);

Callers 1

ExecuteSQLMethod · 0.80

Calls 9

QueryMethod · 0.45
HasErrorMethod · 0.45
GetErrorMethod · 0.45
CountMethod · 0.45
ColumnCountMethod · 0.45
GetValueMethod · 0.45
GetRowsMethod · 0.45
IsNullMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected