372 auto* driver =
reinterpret_cast<AdbcDriver*
>(raw_driver);
376 driver->ErrorGetDetailCount = &CErrorGetDetailCount;
377 driver->ErrorGetDetail = &CErrorGetDetail;
379 driver->DatabaseGetOption = &CGetOption<AdbcDatabase>;
380 driver->DatabaseGetOptionBytes = &CGetOptionBytes<AdbcDatabase>;
381 driver->DatabaseGetOptionInt = &CGetOptionInt<AdbcDatabase>;
382 driver->DatabaseGetOptionDouble = &CGetOptionDouble<AdbcDatabase>;
383 driver->DatabaseSetOptionBytes = &CSetOptionBytes<AdbcDatabase>;
384 driver->DatabaseSetOptionInt = &CSetOptionInt<AdbcDatabase>;
385 driver->DatabaseSetOptionDouble = &CSetOptionDouble<AdbcDatabase>;
387 driver->ConnectionCancel = &CConnectionCancel;
388 driver->ConnectionGetOption = &CGetOption<AdbcConnection>;
389 driver->ConnectionGetOptionBytes = &CGetOptionBytes<AdbcConnection>;
390 driver->ConnectionGetOptionInt = &CGetOptionInt<AdbcConnection>;
391 driver->ConnectionGetOptionDouble = &CGetOptionDouble<AdbcConnection>;
392 driver->ConnectionGetStatistics = &CConnectionGetStatistics;
393 driver->ConnectionGetStatisticNames = &CConnectionGetStatisticNames;
394 driver->ConnectionSetOptionBytes = &CSetOptionBytes<AdbcConnection>;
395 driver->ConnectionSetOptionInt = &CSetOptionInt<AdbcConnection>;
396 driver->ConnectionSetOptionDouble = &CSetOptionDouble<AdbcConnection>;
398 driver->StatementCancel = &CStatementCancel;
399 driver->StatementExecuteSchema = &CStatementExecuteSchema;
400 driver->StatementGetOption = &CGetOption<AdbcStatement>;
401 driver->StatementGetOptionBytes = &CGetOptionBytes<AdbcStatement>;
402 driver->StatementGetOptionInt = &CGetOptionInt<AdbcStatement>;
403 driver->StatementGetOptionDouble = &CGetOptionDouble<AdbcStatement>;
404 driver->StatementSetOptionBytes = &CSetOptionBytes<AdbcStatement>;
405 driver->StatementSetOptionInt = &CSetOptionInt<AdbcStatement>;
406 driver->StatementSetOptionDouble = &CSetOptionDouble<AdbcStatement>;
412 driver->release = &CDriverRelease;
414 driver->DatabaseInit = &CDatabaseInit;
415 driver->DatabaseNew = &CNew<AdbcDatabase>;
416 driver->DatabaseRelease = &CRelease<AdbcDatabase>;
417 driver->DatabaseSetOption = &CSetOption<AdbcDatabase>;
419 driver->ConnectionCommit = &CConnectionCommit;
420 driver->ConnectionGetInfo = &CConnectionGetInfo;
421 driver->ConnectionGetObjects = &CConnectionGetObjects;
422 driver->ConnectionGetTableSchema = &CConnectionGetTableSchema;
423 driver->ConnectionGetTableTypes = &CConnectionGetTableTypes;
424 driver->ConnectionInit = &CConnectionInit;
425 driver->ConnectionNew = &CNew<AdbcConnection>;
426 driver->ConnectionRelease = &CRelease<AdbcConnection>;
427 driver->ConnectionReadPartition = &CConnectionReadPartition;
428 driver->ConnectionRollback = &CConnectionRollback;
429 driver->ConnectionSetOption = &CSetOption<AdbcConnection>;
431 driver->StatementBind = &CStatementBind;
432 driver->StatementBindStream = &CStatementBindStream;
433 driver->StatementExecutePartitions = &CStatementExecutePartitions;
434 driver->StatementExecuteQuery = &CStatementExecuteQuery;
435 driver->StatementGetParameterSchema = &CStatementGetParameterSchema;
436 driver->StatementNew = &CStatementNew;
437 driver->StatementPrepare = &CStatementPrepare;
438 driver->StatementRelease = &CRelease<AdbcStatement>;
439 driver->StatementSetOption = &CSetOption<AdbcStatement>;
440 driver->StatementSetSqlQuery = &CStatementSetSqlQuery;
441 driver->StatementSetSubstraitPlan = &CStatementSetSubstraitPlan;
449 delete driver_private;
454 static int CErrorGetDetailCount(
const AdbcError* error) {
463 return error_obj->CDetailCount();
468 return {
nullptr,
nullptr, 0};
473 return {
nullptr,
nullptr, 0};
476 return error_obj->CDetail(index);
481 template <
typename T>
483 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
484 auto private_data =
new ObjectT();
485 obj->private_data = private_data;
489 template <
typename T>
491 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
493 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
501 obj->private_data =
nullptr;
505 template <
typename T>
506 static AdbcStatusCode CSetOption(T* obj,
const char* key,
const char* value,
508 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
509 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
510 return private_data->template CSetOption<>(key, value, error);
513 template <
typename T>
514 static AdbcStatusCode CSetOptionBytes(T* obj,
const char* key,
const uint8_t* value,
516 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
517 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
518 return private_data->CSetOptionBytes(key, value, length, error);
521 template <
typename T>
522 static AdbcStatusCode CSetOptionInt(T* obj,
const char* key, int64_t value,
524 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
525 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
526 return private_data->template CSetOption<>(key, value, error);
529 template <
typename T>
530 static AdbcStatusCode CSetOptionDouble(T* obj,
const char* key,
double value,
532 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
533 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
534 return private_data->template CSetOption<>(key, value, error);
537 template <
typename T>
538 static AdbcStatusCode CGetOption(T* obj,
const char* key,
char* value,
size_t* length,
540 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
541 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
542 return private_data->template CGetOptionStringLike<>(key, value, length, error);
545 template <
typename T>
546 static AdbcStatusCode CGetOptionBytes(T* obj,
const char* key, uint8_t* value,
548 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
549 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
550 return private_data->template CGetOptionStringLike<>(key, value, length, error);
553 template <
typename T>
554 static AdbcStatusCode CGetOptionInt(T* obj,
const char* key, int64_t* value,
556 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
557 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
558 return private_data->template CGetOptionNumeric<>(key, value, error);
561 template <
typename T>
562 static AdbcStatusCode CGetOptionDouble(T* obj,
const char* key,
double* value,
564 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
565 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
566 return private_data->template CGetOptionNumeric<>(key, value, error);
569#define CHECK_INIT(DATABASE, ERROR) \
570 if (!(DATABASE) || !(DATABASE)->private_data) { \
571 return status::InvalidState("Database is uninitialized").ToAdbc(ERROR); \
576 CHECK_INIT(database, error);
577 auto private_data =
reinterpret_cast<DatabaseT*
>(database->
private_data);
578 return private_data->Init(
nullptr, error);
582#define CHECK_INIT(CONNECTION, ERROR) \
583 if (!(CONNECTION) || !(CONNECTION)->private_data) { \
584 return status::InvalidState("Connection is uninitialized").ToAdbc(ERROR); \
590 CHECK_INIT(connection, error);
592 return status::InvalidState(
"Database is uninitialized").ToAdbc(error);
594 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
595 return private_data->Init(database->
private_data, error);
599 CHECK_INIT(connection, error);
600 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
601 return private_data->Cancel(error);
605 const uint32_t* info_codes,
606 size_t info_codes_length,
607 ArrowArrayStream* out,
AdbcError* error) {
608 CHECK_INIT(connection, error);
609 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
610 return private_data->GetInfo(info_codes, info_codes_length, out, error);
614 const char* catalog,
const char* db_schema,
615 const char* table_name,
616 const char** table_type,
617 const char* column_name,
618 ArrowArrayStream* out,
AdbcError* error) {
619 CHECK_INIT(connection, error);
620 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
621 return private_data->GetObjects(depth, catalog, db_schema, table_name, table_type,
622 column_name, out, error);
626 AdbcConnection* connection,
const char* catalog,
const char* db_schema,
627 const char* table_name,
char approximate, ArrowArrayStream* out,
AdbcError* error) {
628 CHECK_INIT(connection, error);
629 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
630 return private_data->GetStatistics(catalog, db_schema, table_name, approximate, out,
635 ArrowArrayStream* out,
637 CHECK_INIT(connection, error);
638 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
639 return private_data->GetStatisticNames(out, error);
644 const char* db_schema,
645 const char* table_name,
647 CHECK_INIT(connection, error);
648 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
649 return private_data->GetTableSchema(catalog, db_schema, table_name, schema, error);
653 ArrowArrayStream* out,
655 CHECK_INIT(connection, error);
656 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
657 return private_data->GetTableTypes(out, error);
661 const uint8_t* serialized_partition,
662 size_t serialized_length,
663 ArrowArrayStream* out,
665 CHECK_INIT(connection, error);
666 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
667 return private_data->ReadPartition(serialized_partition, serialized_length, out,
672 CHECK_INIT(connection, error);
673 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
674 return private_data->Commit(error);
679 CHECK_INIT(connection, error);
680 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
681 return private_data->Rollback(error);
685#define CHECK_INIT(STATEMENT, ERROR) \
686 if (!(STATEMENT) || !(STATEMENT)->private_data) { \
687 return status::InvalidState("Statement is uninitialized").ToAdbc(ERROR); \
694 return status::InvalidState(
"Connection is uninitialized").ToAdbc(error);
696 auto private_data =
new StatementT();
708 CHECK_INIT(statement, error);
709 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
710 return private_data->Bind(values, schema, error);
714 ArrowArrayStream* stream,
AdbcError* error) {
715 CHECK_INIT(statement, error);
716 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
717 return private_data->BindStream(stream, error);
721 CHECK_INIT(statement, error);
722 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
723 return private_data->Cancel(error);
727 struct ArrowSchema* schema,
729 int64_t* rows_affected,
731 CHECK_INIT(statement, error);
732 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
733 return private_data->ExecutePartitions(schema, partitions, rows_affected, error);
737 ArrowArrayStream* stream,
738 int64_t* rows_affected,
AdbcError* error) {
739 CHECK_INIT(statement, error);
740 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
741 return private_data->ExecuteQuery(stream, rows_affected, error);
746 CHECK_INIT(statement, error);
747 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
748 return private_data->ExecuteSchema(schema, error);
754 CHECK_INIT(statement, error);
755 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
756 return private_data->GetParameterSchema(schema, error);
760 CHECK_INIT(statement, error);
761 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
762 return private_data->Prepare(error);
767 CHECK_INIT(statement, error);
768 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
769 return private_data->SetSqlQuery(query, error);
773 const uint8_t* plan,
size_t length,
775 CHECK_INIT(statement, error);
776 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
777 return private_data->SetSubstraitPlan(plan, length, error);
838 ~BaseConnection() =
default;
852 Status CancelImpl() {
return status::NotImplemented(
"Cancel"); }
857 Status CommitImpl() {
return status::NotImplemented(
"Commit"); }
860 AdbcStatusCode GetInfo(
const uint32_t* info_codes,
size_t info_codes_length,
861 ArrowArrayStream* out,
AdbcError* error) {
862 std::vector<uint32_t> codes(info_codes, info_codes + info_codes_length);
867 Status GetInfoImpl(
const std::vector<uint32_t> info_codes, ArrowArrayStream* out) {
868 return status::NotImplemented(
"GetInfo");
872 AdbcStatusCode GetObjects(
int c_depth,
const char* catalog,
const char* db_schema,
873 const char* table_name,
const char** table_type,
874 const char* column_name, ArrowArrayStream* out,
876 const auto catalog_filter =
877 catalog ? std::make_optional(std::string_view(catalog)) : std::nullopt;
878 const auto schema_filter =
879 db_schema ? std::make_optional(std::string_view(db_schema)) : std::nullopt;
880 const auto table_filter =
881 table_name ? std::make_optional(std::string_view(table_name)) : std::nullopt;
882 const auto column_filter =
883 column_name ? std::make_optional(std::string_view(column_name)) : std::nullopt;
884 std::vector<std::string_view> table_type_filter;
885 while (table_type && *table_type) {
887 table_type_filter.push_back(std::string_view(*table_type));
893 error, impl().GetObjectsImpl(c_depth, catalog_filter, schema_filter, table_filter,
894 column_filter, table_type_filter, out));
899 Status GetObjectsImpl(
int c_depth, std::optional<std::string_view> catalog_filter,
900 std::optional<std::string_view> schema_filter,
901 std::optional<std::string_view> table_filter,
902 std::optional<std::string_view> column_filter,
903 const std::vector<std::string_view>& table_types,
904 struct ArrowArrayStream* out) {
905 return status::NotImplemented(
"GetObjects");
909 AdbcStatusCode GetStatistics(
const char* catalog,
const char* db_schema,
910 const char* table_name,
char approximate,
911 ArrowArrayStream* out,
AdbcError* error) {
912 const auto catalog_filter =
913 catalog ? std::make_optional(std::string_view(catalog)) : std::nullopt;
914 const auto schema_filter =
915 db_schema ? std::make_optional(std::string_view(db_schema)) : std::nullopt;
916 const auto table_filter =
917 table_name ? std::make_optional(std::string_view(table_name)) : std::nullopt;
918 RAISE_STATUS(error, impl().GetStatisticsImpl(catalog_filter, schema_filter,
919 table_filter, approximate != 0, out));
923 Status GetStatisticsImpl(std::optional<std::string_view> catalog,
924 std::optional<std::string_view> db_schema,
925 std::optional<std::string_view> table_name,
bool approximate,
926 ArrowArrayStream* out) {
927 return status::NotImplemented(
"GetStatistics");
936 Status GetStatisticNames(ArrowArrayStream* out) {
937 return status::NotImplemented(
"GetStatisticNames");
941 AdbcStatusCode GetTableSchema(
const char* catalog,
const char* db_schema,
942 const char* table_name, ArrowSchema* schema,
945 return status::InvalidArgument(Derived::kErrorPrefix,
946 " GetTableSchema: must provide table_name")
950 std::optional<std::string_view> catalog_param =
951 catalog ? std::make_optional(std::string_view(catalog)) : std::nullopt;
952 std::optional<std::string_view> db_schema_param =
953 db_schema ? std::make_optional(std::string_view(db_schema)) : std::nullopt;
955 RAISE_STATUS(error, impl().GetTableSchemaImpl(catalog_param, db_schema_param,
956 table_name, schema));
960 Status GetTableSchemaImpl(std::optional<std::string_view> catalog,
961 std::optional<std::string_view> db_schema,
962 std::string_view table_name, ArrowSchema* out) {
963 return status::NotImplemented(
"GetTableSchema");
972 Status GetTableTypesImpl(ArrowArrayStream* out) {
973 return status::NotImplemented(
"GetTableTypes");
978 size_t serialized_length, ArrowArrayStream* out,
980 std::string_view partition(
reinterpret_cast<const char*
>(serialized_partition),
982 RAISE_STATUS(error, impl().ReadPartitionImpl(partition, out));
986 Status ReadPartitionImpl(std::string_view serialized_partition, ArrowArrayStream* out) {
987 return status::NotImplemented(
"ReadPartition");
996 Status ReleaseImpl() {
return status::Ok(); }
1004 Status RollbackImpl() {
return status::NotImplemented(
"Rollback"); }
1015 return status::NotImplemented(Derived::kErrorPrefix,
" Unknown connection option ",
1016 key,
"=", value.
Format());
1020 Derived& impl() {
return static_cast<Derived&
>(*this); }