370 auto* driver =
reinterpret_cast<AdbcDriver*
>(raw_driver);
374 driver->ErrorGetDetailCount = &CErrorGetDetailCount;
375 driver->ErrorGetDetail = &CErrorGetDetail;
377 driver->DatabaseGetOption = &CGetOption<AdbcDatabase>;
378 driver->DatabaseGetOptionBytes = &CGetOptionBytes<AdbcDatabase>;
379 driver->DatabaseGetOptionInt = &CGetOptionInt<AdbcDatabase>;
380 driver->DatabaseGetOptionDouble = &CGetOptionDouble<AdbcDatabase>;
381 driver->DatabaseSetOptionBytes = &CSetOptionBytes<AdbcDatabase>;
382 driver->DatabaseSetOptionInt = &CSetOptionInt<AdbcDatabase>;
383 driver->DatabaseSetOptionDouble = &CSetOptionDouble<AdbcDatabase>;
385 driver->ConnectionCancel = &CConnectionCancel;
386 driver->ConnectionGetOption = &CGetOption<AdbcConnection>;
387 driver->ConnectionGetOptionBytes = &CGetOptionBytes<AdbcConnection>;
388 driver->ConnectionGetOptionInt = &CGetOptionInt<AdbcConnection>;
389 driver->ConnectionGetOptionDouble = &CGetOptionDouble<AdbcConnection>;
390 driver->ConnectionGetStatistics = &CConnectionGetStatistics;
391 driver->ConnectionGetStatisticNames = &CConnectionGetStatisticNames;
392 driver->ConnectionSetOptionBytes = &CSetOptionBytes<AdbcConnection>;
393 driver->ConnectionSetOptionInt = &CSetOptionInt<AdbcConnection>;
394 driver->ConnectionSetOptionDouble = &CSetOptionDouble<AdbcConnection>;
396 driver->StatementCancel = &CStatementCancel;
397 driver->StatementExecuteSchema = &CStatementExecuteSchema;
398 driver->StatementGetOption = &CGetOption<AdbcStatement>;
399 driver->StatementGetOptionBytes = &CGetOptionBytes<AdbcStatement>;
400 driver->StatementGetOptionInt = &CGetOptionInt<AdbcStatement>;
401 driver->StatementGetOptionDouble = &CGetOptionDouble<AdbcStatement>;
402 driver->StatementSetOptionBytes = &CSetOptionBytes<AdbcStatement>;
403 driver->StatementSetOptionInt = &CSetOptionInt<AdbcStatement>;
404 driver->StatementSetOptionDouble = &CSetOptionDouble<AdbcStatement>;
409 driver->private_data =
new Driver();
410 driver->release = &CDriverRelease;
412 driver->DatabaseInit = &CDatabaseInit;
413 driver->DatabaseNew = &CNew<AdbcDatabase>;
414 driver->DatabaseRelease = &CRelease<AdbcDatabase>;
415 driver->DatabaseSetOption = &CSetOption<AdbcDatabase>;
417 driver->ConnectionCommit = &CConnectionCommit;
418 driver->ConnectionGetInfo = &CConnectionGetInfo;
419 driver->ConnectionGetObjects = &CConnectionGetObjects;
420 driver->ConnectionGetTableSchema = &CConnectionGetTableSchema;
421 driver->ConnectionGetTableTypes = &CConnectionGetTableTypes;
422 driver->ConnectionInit = &CConnectionInit;
423 driver->ConnectionNew = &CNew<AdbcConnection>;
424 driver->ConnectionRelease = &CRelease<AdbcConnection>;
425 driver->ConnectionReadPartition = &CConnectionReadPartition;
426 driver->ConnectionRollback = &CConnectionRollback;
427 driver->ConnectionSetOption = &CSetOption<AdbcConnection>;
429 driver->StatementBind = &CStatementBind;
430 driver->StatementBindStream = &CStatementBindStream;
431 driver->StatementExecutePartitions = &CStatementExecutePartitions;
432 driver->StatementExecuteQuery = &CStatementExecuteQuery;
433 driver->StatementGetParameterSchema = &CStatementGetParameterSchema;
434 driver->StatementNew = &CStatementNew;
435 driver->StatementPrepare = &CStatementPrepare;
436 driver->StatementRelease = &CRelease<AdbcStatement>;
437 driver->StatementSetOption = &CSetOption<AdbcStatement>;
438 driver->StatementSetSqlQuery = &CStatementSetSqlQuery;
439 driver->StatementSetSubstraitPlan = &CStatementSetSubstraitPlan;
447 delete driver_private;
452 static int CErrorGetDetailCount(
const AdbcError* error) {
461 return error_obj->CDetailCount();
466 return {
nullptr,
nullptr, 0};
471 return {
nullptr,
nullptr, 0};
474 return error_obj->CDetail(index);
479 template <
typename T>
481 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
482 auto private_data =
new ObjectT();
483 obj->private_data = private_data;
487 template <
typename T>
489 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
491 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
499 obj->private_data =
nullptr;
503 template <
typename T>
504 static AdbcStatusCode CSetOption(T* obj,
const char* key,
const char* value,
506 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
507 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
508 return private_data->template CSetOption<>(key, value, error);
511 template <
typename T>
512 static AdbcStatusCode CSetOptionBytes(T* obj,
const char* key,
const uint8_t* value,
514 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
515 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
516 return private_data->CSetOptionBytes(key, value, length, error);
519 template <
typename T>
520 static AdbcStatusCode CSetOptionInt(T* obj,
const char* key, int64_t value,
522 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
523 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
524 return private_data->template CSetOption<>(key, value, error);
527 template <
typename T>
528 static AdbcStatusCode CSetOptionDouble(T* obj,
const char* key,
double value,
530 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
531 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
532 return private_data->template CSetOption<>(key, value, error);
535 template <
typename T>
536 static AdbcStatusCode CGetOption(T* obj,
const char* key,
char* value,
size_t* length,
538 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
539 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
540 return private_data->template CGetOptionStringLike<>(key, value, length, error);
543 template <
typename T>
544 static AdbcStatusCode CGetOptionBytes(T* obj,
const char* key, uint8_t* value,
546 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
547 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
548 return private_data->template CGetOptionStringLike<>(key, value, length, error);
551 template <
typename T>
552 static AdbcStatusCode CGetOptionInt(T* obj,
const char* key, int64_t* value,
554 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
555 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
556 return private_data->template CGetOptionNumeric<>(key, value, error);
559 template <
typename T>
560 static AdbcStatusCode CGetOptionDouble(T* obj,
const char* key,
double* value,
562 using ObjectT = ResolveObjectT<DatabaseT, ConnectionT, StatementT, T>;
563 auto private_data =
reinterpret_cast<ObjectT*
>(obj->private_data);
564 return private_data->template CGetOptionNumeric<>(key, value, error);
567#define CHECK_INIT(DATABASE, ERROR) \
568 if (!(DATABASE) || !(DATABASE)->private_data) { \
569 return status::InvalidState("Database is uninitialized").ToAdbc(ERROR); \
574 CHECK_INIT(database, error);
575 auto private_data =
reinterpret_cast<DatabaseT*
>(database->
private_data);
576 return private_data->Init(
nullptr, error);
580#define CHECK_INIT(CONNECTION, ERROR) \
581 if (!(CONNECTION) || !(CONNECTION)->private_data) { \
582 return status::InvalidState("Connection is uninitialized").ToAdbc(ERROR); \
588 CHECK_INIT(connection, error);
590 return status::InvalidState(
"Database is uninitialized").ToAdbc(error);
592 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
593 return private_data->Init(database->
private_data, error);
597 CHECK_INIT(connection, error);
598 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
599 return private_data->Cancel(error);
603 const uint32_t* info_codes,
604 size_t info_codes_length,
605 ArrowArrayStream* out,
AdbcError* error) {
606 CHECK_INIT(connection, error);
607 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
608 return private_data->GetInfo(info_codes, info_codes_length, out, error);
612 const char* catalog,
const char* db_schema,
613 const char* table_name,
614 const char** table_type,
615 const char* column_name,
616 ArrowArrayStream* out,
AdbcError* error) {
617 CHECK_INIT(connection, error);
618 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
619 return private_data->GetObjects(depth, catalog, db_schema, table_name, table_type,
620 column_name, out, error);
624 AdbcConnection* connection,
const char* catalog,
const char* db_schema,
625 const char* table_name,
char approximate, ArrowArrayStream* out,
AdbcError* error) {
626 CHECK_INIT(connection, error);
627 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
628 return private_data->GetStatistics(catalog, db_schema, table_name, approximate, out,
633 ArrowArrayStream* out,
635 CHECK_INIT(connection, error);
636 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
637 return private_data->GetStatisticNames(out, error);
642 const char* db_schema,
643 const char* table_name,
645 CHECK_INIT(connection, error);
646 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
647 return private_data->GetTableSchema(catalog, db_schema, table_name, schema, error);
651 ArrowArrayStream* out,
653 CHECK_INIT(connection, error);
654 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
655 return private_data->GetTableTypes(out, error);
659 const uint8_t* serialized_partition,
660 size_t serialized_length,
661 ArrowArrayStream* out,
663 CHECK_INIT(connection, error);
664 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
665 return private_data->ReadPartition(serialized_partition, serialized_length, out,
670 CHECK_INIT(connection, error);
671 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
672 return private_data->Commit(error);
677 CHECK_INIT(connection, error);
678 auto private_data =
reinterpret_cast<ConnectionT*
>(connection->
private_data);
679 return private_data->Rollback(error);
683#define CHECK_INIT(STATEMENT, ERROR) \
684 if (!(STATEMENT) || !(STATEMENT)->private_data) { \
685 return status::InvalidState("Statement is uninitialized").ToAdbc(ERROR); \
692 return status::InvalidState(
"Connection is uninitialized").ToAdbc(error);
694 auto private_data =
new StatementT();
706 CHECK_INIT(statement, error);
707 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
708 return private_data->Bind(values, schema, error);
712 ArrowArrayStream* stream,
AdbcError* error) {
713 CHECK_INIT(statement, error);
714 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
715 return private_data->BindStream(stream, error);
719 CHECK_INIT(statement, error);
720 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
721 return private_data->Cancel(error);
725 struct ArrowSchema* schema,
727 int64_t* rows_affected,
729 CHECK_INIT(statement, error);
730 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
731 return private_data->ExecutePartitions(schema, partitions, rows_affected, error);
735 ArrowArrayStream* stream,
736 int64_t* rows_affected,
AdbcError* error) {
737 CHECK_INIT(statement, error);
738 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
739 return private_data->ExecuteQuery(stream, rows_affected, error);
744 CHECK_INIT(statement, error);
745 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
746 return private_data->ExecuteSchema(schema, error);
752 CHECK_INIT(statement, error);
753 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
754 return private_data->GetParameterSchema(schema, error);
758 CHECK_INIT(statement, error);
759 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
760 return private_data->Prepare(error);
765 CHECK_INIT(statement, error);
766 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
767 return private_data->SetSqlQuery(query, error);
771 const uint8_t* plan,
size_t length,
773 CHECK_INIT(statement, error);
774 auto private_data =
reinterpret_cast<StatementT*
>(statement->
private_data);
775 return private_data->SetSubstraitPlan(plan, length, error);
836 ~BaseConnection() =
default;
850 Status CancelImpl() {
return status::NotImplemented(
"Cancel"); }
855 Status CommitImpl() {
return status::NotImplemented(
"Commit"); }
858 AdbcStatusCode GetInfo(
const uint32_t* info_codes,
size_t info_codes_length,
859 ArrowArrayStream* out,
AdbcError* error) {
860 std::vector<uint32_t> codes(info_codes, info_codes + info_codes_length);
865 Status GetInfoImpl(
const std::vector<uint32_t> info_codes, ArrowArrayStream* out) {
866 return status::NotImplemented(
"GetInfo");
870 AdbcStatusCode GetObjects(
int c_depth,
const char* catalog,
const char* db_schema,
871 const char* table_name,
const char** table_type,
872 const char* column_name, ArrowArrayStream* out,
874 const auto catalog_filter =
875 catalog ? std::make_optional(std::string_view(catalog)) : std::nullopt;
876 const auto schema_filter =
877 db_schema ? std::make_optional(std::string_view(db_schema)) : std::nullopt;
878 const auto table_filter =
879 table_name ? std::make_optional(std::string_view(table_name)) : std::nullopt;
880 const auto column_filter =
881 column_name ? std::make_optional(std::string_view(column_name)) : std::nullopt;
882 std::vector<std::string_view> table_type_filter;
883 while (table_type && *table_type) {
885 table_type_filter.push_back(std::string_view(*table_type));
891 error, impl().GetObjectsImpl(c_depth, catalog_filter, schema_filter, table_filter,
892 column_filter, table_type_filter, out));
897 Status GetObjectsImpl(
int c_depth, std::optional<std::string_view> catalog_filter,
898 std::optional<std::string_view> schema_filter,
899 std::optional<std::string_view> table_filter,
900 std::optional<std::string_view> column_filter,
901 const std::vector<std::string_view>& table_types,
902 struct ArrowArrayStream* out) {
903 return status::NotImplemented(
"GetObjects");
907 AdbcStatusCode GetStatistics(
const char* catalog,
const char* db_schema,
908 const char* table_name,
char approximate,
909 ArrowArrayStream* out,
AdbcError* error) {
910 const auto catalog_filter =
911 catalog ? std::make_optional(std::string_view(catalog)) : std::nullopt;
912 const auto schema_filter =
913 db_schema ? std::make_optional(std::string_view(db_schema)) : std::nullopt;
914 const auto table_filter =
915 table_name ? std::make_optional(std::string_view(table_name)) : std::nullopt;
916 RAISE_STATUS(error, impl().GetStatisticsImpl(catalog_filter, schema_filter,
917 table_filter, approximate != 0, out));
921 Status GetStatisticsImpl(std::optional<std::string_view> catalog,
922 std::optional<std::string_view> db_schema,
923 std::optional<std::string_view> table_name,
bool approximate,
924 ArrowArrayStream* out) {
925 return status::NotImplemented(
"GetStatistics");
934 Status GetStatisticNames(ArrowArrayStream* out) {
935 return status::NotImplemented(
"GetStatisticNames");
939 AdbcStatusCode GetTableSchema(
const char* catalog,
const char* db_schema,
940 const char* table_name, ArrowSchema* schema,
943 return status::InvalidArgument(Derived::kErrorPrefix,
944 " GetTableSchema: must provide table_name")
948 std::optional<std::string_view> catalog_param =
949 catalog ? std::make_optional(std::string_view(catalog)) : std::nullopt;
950 std::optional<std::string_view> db_schema_param =
951 db_schema ? std::make_optional(std::string_view(db_schema)) : std::nullopt;
953 RAISE_STATUS(error, impl().GetTableSchemaImpl(catalog_param, db_schema_param,
954 table_name, schema));
958 Status GetTableSchemaImpl(std::optional<std::string_view> catalog,
959 std::optional<std::string_view> db_schema,
960 std::string_view table_name, ArrowSchema* out) {
961 return status::NotImplemented(
"GetTableSchema");
970 Status GetTableTypesImpl(ArrowArrayStream* out) {
971 return status::NotImplemented(
"GetTableTypes");
976 size_t serialized_length, ArrowArrayStream* out,
978 std::string_view partition(
reinterpret_cast<const char*
>(serialized_partition),
980 RAISE_STATUS(error, impl().ReadPartitionImpl(partition, out));
984 Status ReadPartitionImpl(std::string_view serialized_partition, ArrowArrayStream* out) {
985 return status::NotImplemented(
"ReadPartition");
994 Status ReleaseImpl() {
return status::Ok(); }
1002 Status RollbackImpl() {
return status::NotImplemented(
"Rollback"); }
1013 return status::NotImplemented(Derived::kErrorPrefix,
" Unknown connection option ",
1014 key,
"=", value.
Format());
1018 Derived& impl() {
return static_cast<Derived&
>(*this); }