From 85755de8c035c99150d874c775657076fe3219a1 Mon Sep 17 00:00:00 2001 From: Solomon Choe Date: Thu, 20 Jul 2023 11:41:30 -0700 Subject: [PATCH] Add a unit test for SqliteStatementExecuteIngest --- c/driver/sqlite/sqlite_test.cc | 42 +++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/c/driver/sqlite/sqlite_test.cc b/c/driver/sqlite/sqlite_test.cc index 3ab21fe3fa..0207c165cf 100644 --- a/c/driver/sqlite/sqlite_test.cc +++ b/c/driver/sqlite/sqlite_test.cc @@ -28,6 +28,7 @@ #include #include +#include "types.h" #include "statement_reader.h" #include "validation/adbc_validation.h" #include "validation/adbc_validation_util.h" @@ -639,6 +640,45 @@ TEST_F(SqliteReaderTest, MultiValueParams) { ASSERT_EQ(nullptr, reader.array->release); } +TEST_F(SqliteReaderTest, BulkIngestWithAutocommit) { + adbc_validation::StreamReader reader; + ASSERT_NO_FATAL_FAILURE(Exec("CREATE TABLE foo (col)")); + + // Filling out SqliteStatement explicitly to include `target_table`, which will + // make SqliteStatementExecuteQuery call SqliteStatementExecuteIngest + struct SqliteStatement sqlite_stmt; + std::memset(&sqlite_stmt, 0, sizeof(sqlite_stmt)); + + struct AdbcSqliteBinder binder; + std::memset(&binder, 0, sizeof(binder)); + sqlite_stmt.binder = binder; + + sqlite_stmt.conn = db; + sqlite_stmt.prepared = 0; + sqlite_stmt.append = 1; + sqlite_stmt.batch_size = 4; + + sqlite_stmt.target_table = strdup("foo"); + + struct AdbcStatement statement; + std::memset(&statement, 0, sizeof(statement)); + + struct AdbcConnection connection; + std::memset(&connection, 0, sizeof(connection)); + connection.private_data = db; + + AdbcStatusCode status = AdbcStatementNew(&connection, &statement, &error); + ASSERT_EQ(ADBC_STATUS_OK, status); + statement.private_data = &sqlite_stmt; + + std::string query = "INSERT INTO foo VALUES (1), (2), (3), (4)"; + status = AdbcStatementSetSqlQuery(&statement, query.c_str(), &error); + ASSERT_EQ(ADBC_STATUS_OK, status); + + ASSERT_EQ(ADBC_STATUS_OK, AdbcStatementExecuteQuery(&statement, nullptr, nullptr, &error)); + free(sqlite_stmt.target_table); +} + template class SqliteNumericParamTest : public SqliteReaderTest, public ::testing::WithParamInterface { @@ -696,4 +736,4 @@ INSTANTIATE_TEST_SUITE_P(FloatTypes, SqliteFloatParamTest, // floats (FLT_MIN/FLT_MAX isn't the right thing) // NANOARROW_TYPE_FLOAT, - NANOARROW_TYPE_DOUBLE)); + NANOARROW_TYPE_DOUBLE)); \ No newline at end of file