53 ~Connection() =
default;
57 if (
auto status = impl().InitImpl(parent); !status.
ok()) {
58 return status.ToAdbc(error);
68 switch (autocommit_) {
69 case AutocommitState::kAutocommit:
70 return status::InvalidState(Derived::kErrorPrefix,
71 " No active transaction, cannot commit")
73 case AutocommitState::kTransaction:
74 return impl().CommitImpl().ToAdbc(error);
81 AdbcStatusCode GetInfo(
const uint32_t* info_codes,
size_t info_codes_length,
82 ArrowArrayStream* out,
AdbcError* error) {
84 RAISE_STATUS(error, status::InvalidArgument(
"out must be non-null"));
87 std::vector<uint32_t> codes(info_codes, info_codes + info_codes_length);
94 AdbcStatusCode GetObjects(
int c_depth,
const char* catalog,
const char* db_schema,
95 const char* table_name,
const char** table_type,
96 const char* column_name, ArrowArrayStream* out,
98 const auto catalog_filter =
99 catalog ? std::make_optional(std::string_view(catalog)) : std::nullopt;
100 const auto schema_filter =
101 db_schema ? std::make_optional(std::string_view(db_schema)) : std::nullopt;
102 const auto table_filter =
103 table_name ? std::make_optional(std::string_view(table_name)) : std::nullopt;
104 const auto column_filter =
105 column_name ? std::make_optional(std::string_view(column_name)) : std::nullopt;
106 std::vector<std::string_view> table_type_filter;
107 while (table_type && *table_type) {
109 table_type_filter.push_back(std::string_view(*table_type));
117 depth = GetObjectsDepth::kCatalogs;
120 depth = GetObjectsDepth::kColumns;
123 depth = GetObjectsDepth::kSchemas;
126 depth = GetObjectsDepth::kTables;
129 return status::InvalidArgument(Derived::kErrorPrefix,
130 " GetObjects: invalid depth ", c_depth)
135 auto status =
BuildGetObjects(helper.get(), depth, catalog_filter, schema_filter,
136 table_filter, column_filter, table_type_filter, out);
145 switch (autocommit_) {
146 case AutocommitState::kAutocommit:
148 case AutocommitState::kTransaction:
168 AdbcStatusCode GetStatistics(
const char* catalog,
const char* db_schema,
169 const char* table_name,
char approximate,
170 ArrowArrayStream* out,
AdbcError* error) {
180 AdbcStatusCode GetTableSchema(
const char* catalog,
const char* db_schema,
181 const char* table_name, ArrowSchema* schema,
184 return status::InvalidArgument(Derived::kErrorPrefix,
185 " GetTableSchema: must provide table_name")
188 std::memset(schema, 0,
sizeof(*schema));
189 std::optional<std::string_view> catalog_param =
190 catalog ? std::make_optional(std::string_view(catalog)) : std::nullopt;
191 std::optional<std::string_view> db_schema_param =
192 db_schema ? std::make_optional(std::string_view(db_schema)) : std::nullopt;
193 std::string_view table_name_param = table_name;
196 .GetTableSchemaImpl(catalog_param, db_schema_param, table_name_param, schema)
203 RAISE_STATUS(error, status::InvalidArgument(
"out must be non-null"));
206 RAISE_RESULT(error, std::vector<std::string> table_types, impl().GetTableTypesImpl());
213 size_t serialized_length, ArrowArrayStream* out,
220 return impl().ReleaseImpl().ToAdbc(error);
225 switch (autocommit_) {
226 case AutocommitState::kAutocommit:
227 return status::InvalidState(Derived::kErrorPrefix,
228 " No active transaction, cannot rollback")
230 case AutocommitState::kTransaction:
231 return impl().RollbackImpl().ToAdbc(error);
240 return impl().SetOptionImpl(key, value).ToAdbc(error);
250 Result<std::optional<std::string>> GetCurrentSchemaImpl() {
return std::nullopt; }
259 return std::make_unique<GetObjectsHelper>();
262 Status GetTableSchemaImpl(std::optional<std::string_view> catalog,
263 std::optional<std::string_view> db_schema,
264 std::string_view table_name, ArrowSchema* schema) {
265 return status::NotImplemented(
"GetTableSchema");
268 Result<std::vector<std::string>> GetTableTypesImpl() {
269 return std::vector<std::string>();
272 Result<std::vector<InfoValue>> InfoImpl(
const std::vector<uint32_t>& codes) {
273 return std::vector<InfoValue>{};
276 Status InitImpl(
void* parent) {
return status::Ok(); }
278 Status ReleaseImpl() {
return status::Ok(); }
280 Status RollbackImpl() {
return status::NotImplemented(
"Rollback"); }
282 Status SetOptionImpl(std::string_view key, Option value) {
285 switch (autocommit_) {
286 case AutocommitState::kAutocommit: {
289 autocommit_ = AutocommitState::kTransaction;
293 case AutocommitState::kTransaction: {
296 autocommit_ = AutocommitState::kAutocommit;
303 return status::NotImplemented(Derived::kErrorPrefix,
" Unknown connection option ",
304 key,
"=", value.Format());
307 Status ToggleAutocommitImpl(
bool enable_autocommit) {
308 return status::NotImplemented(Derived::kErrorPrefix,
" Cannot change autocommit");
315 Derived& impl() {
return static_cast<Derived&
>(*this); }
Status BuildGetObjects(GetObjectsHelper *helper, GetObjectsDepth depth, std::optional< std::string_view > catalog_filter, std::optional< std::string_view > schema_filter, std::optional< std::string_view > table_filter, std::optional< std::string_view > column_filter, const std::vector< std::string_view > &table_types, ArrowArrayStream *out)
A helper that implements GetObjects. The out/helper lifetime are caller-managed.