@@ -52,6 +52,7 @@ constexpr std::string_view kConnectionOptionLoadExtensionEntrypoint =
5252// / The batch size for query results (and for initial type inference)
5353constexpr std::string_view kStatementOptionBatchRows = " adbc.sqlite.query.batch_rows" ;
5454constexpr std::string_view kStatementOptionBindByName = " adbc.statement.bind_by_name" ;
55+ constexpr int kDefaultBatchSize = 1024 ;
5556
5657std::string_view GetColumnText (sqlite3_stmt* stmt, int index) {
5758 return {
@@ -547,6 +548,15 @@ class SqliteDatabase : public driver::Database<SqliteDatabase> {
547548 return Base::ReleaseImpl ();
548549 }
549550
551+ Result<driver::Option> GetOption (std::string_view key) override {
552+ if (key == " uri" ) {
553+ return driver::Option (uri_);
554+ } else if (key == kStatementOptionBatchRows ) {
555+ return driver::Option (static_cast <int64_t >(batch_size_));
556+ }
557+ return Base::GetOption (key);
558+ }
559+
550560 Status SetOptionImpl (std::string_view key, driver::Option value) override {
551561 if (key == " uri" ) {
552562 if (lifecycle_state_ != driver::LifecycleState::kUninitialized ) {
@@ -556,13 +566,32 @@ class SqliteDatabase : public driver::Database<SqliteDatabase> {
556566 UNWRAP_RESULT (uri, value.AsString ());
557567 uri_ = std::move (uri);
558568 return status::Ok ();
569+ } else if (key == kStatementOptionBatchRows ) {
570+ if (lifecycle_state_ != driver::LifecycleState::kUninitialized ) {
571+ return status::fmt::InvalidState (
572+ " {} cannot set {} after AdbcDatabaseInit, set it directly on the statement "
573+ " instead" ,
574+ kErrorPrefix , key);
575+ }
576+ int64_t batch_size;
577+ UNWRAP_RESULT (batch_size, value.AsInt ());
578+ if (batch_size <= 0 || batch_size > std::numeric_limits<int >::max ()) {
579+ return status::fmt::InvalidArgument (
580+ " {} Invalid statement option value {}={} (value is non-positive or out of "
581+ " range of int)" ,
582+ kErrorPrefix , key, value.Format ());
583+ }
584+ batch_size_ = static_cast <int >(batch_size);
585+ return status::Ok ();
559586 }
560587 return Base::SetOptionImpl (key, value);
561588 }
562589
563590 private:
591+ friend class SqliteConnection ;
564592 std::string uri_{kDefaultUri };
565593 sqlite3* conn_ = nullptr ;
594+ int batch_size_ = kDefaultBatchSize ;
566595};
567596
568597class SqliteConnection : public driver ::Connection<SqliteConnection> {
@@ -672,6 +701,7 @@ class SqliteConnection : public driver::Connection<SqliteConnection> {
672701 Status InitImpl (void * parent) {
673702 auto & db = *reinterpret_cast <SqliteDatabase*>(parent);
674703 UNWRAP_RESULT (conn_, db.OpenConnection ());
704+ batch_size_ = db.batch_size_ ;
675705 return status::Ok ();
676706 }
677707
@@ -693,6 +723,13 @@ class SqliteConnection : public driver::Connection<SqliteConnection> {
693723 return SqliteQuery::Execute (conn_, " BEGIN" );
694724 }
695725
726+ Result<driver::Option> GetOption (std::string_view key) override {
727+ if (key == kStatementOptionBatchRows ) {
728+ return driver::Option (static_cast <int64_t >(batch_size_));
729+ }
730+ return Base::GetOption (key);
731+ }
732+
696733 Status SetOptionImpl (std::string_view key, driver::Option value) {
697734 if (key == kConnectionOptionEnableLoadExtension ) {
698735 if (!conn_ || lifecycle_state_ != driver::LifecycleState::kInitialized ) {
@@ -761,6 +798,8 @@ class SqliteConnection : public driver::Connection<SqliteConnection> {
761798 }
762799
763800 private:
801+ friend class SqliteStatement ;
802+
764803 Status CheckOpen () const {
765804 if (!conn_) {
766805 return status::InvalidState (" connection is not open" );
@@ -772,6 +811,7 @@ class SqliteConnection : public driver::Connection<SqliteConnection> {
772811 // Temporarily hold the extension path (since the path and entrypoint need
773812 // to be set separately)
774813 std::string extension_path_;
814+ int batch_size_ = kDefaultBatchSize ;
775815};
776816
777817class SqliteStatement : public driver ::Statement<SqliteStatement> {
@@ -1111,7 +1151,9 @@ class SqliteStatement : public driver::Statement<SqliteStatement> {
11111151 }
11121152
11131153 Status InitImpl (void * parent) {
1114- conn_ = reinterpret_cast <SqliteConnection*>(parent)->conn ();
1154+ auto & conn = *reinterpret_cast <SqliteConnection*>(parent);
1155+ conn_ = conn.conn ();
1156+ batch_size_ = conn.batch_size_ ;
11151157 return Statement::InitImpl (parent);
11161158 }
11171159
@@ -1151,7 +1193,16 @@ class SqliteStatement : public driver::Statement<SqliteStatement> {
11511193 return Statement::ReleaseImpl ();
11521194 }
11531195
1154- Status SetOptionImpl (std::string_view key, driver::Option value) {
1196+ Result<driver::Option> GetOption (std::string_view key) override {
1197+ if (key == kStatementOptionBatchRows ) {
1198+ return driver::Option (static_cast <int64_t >(batch_size_));
1199+ } else if (key == kStatementOptionBindByName ) {
1200+ return driver::Option (bind_by_name_ ? " true" : " false" );
1201+ }
1202+ return Base::GetOption (key);
1203+ }
1204+
1205+ Status SetOptionImpl (std::string_view key, driver::Option value) override {
11551206 if (key == kStatementOptionBatchRows ) {
11561207 int64_t batch_size;
11571208 UNWRAP_RESULT (batch_size, value.AsInt ());
@@ -1170,7 +1221,7 @@ class SqliteStatement : public driver::Statement<SqliteStatement> {
11701221 return Base::SetOptionImpl (key, std::move (value));
11711222 }
11721223
1173- int batch_size_ = 1024 ;
1224+ int batch_size_ = kDefaultBatchSize ;
11741225 bool bind_by_name_ = false ;
11751226 AdbcSqliteBinder binder_;
11761227 sqlite3* conn_ = nullptr ;
0 commit comments