Skip to content

Commit

Permalink
Add a unit test for SqliteStatementExecuteIngest
Browse files Browse the repository at this point in the history
  • Loading branch information
Solomon Choe committed Jul 20, 2023
1 parent bdcef38 commit 85755de
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion c/driver/sqlite/sqlite_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <gtest/gtest.h>
#include <nanoarrow/nanoarrow.h>

#include "types.h"
#include "statement_reader.h"
#include "validation/adbc_validation.h"
#include "validation/adbc_validation_util.h"
Expand Down Expand Up @@ -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 <typename CType>
class SqliteNumericParamTest : public SqliteReaderTest,
public ::testing::WithParamInterface<ArrowType> {
Expand Down Expand Up @@ -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));

0 comments on commit 85755de

Please sign in to comment.