Skip to content

Commit

Permalink
Merge pull request #1857 from kuzudb/create-macro-trx
Browse files Browse the repository at this point in the history
Add create-macro transaction constraints
  • Loading branch information
acquamarin committed Jul 25, 2023
2 parents 186bb96 + f484315 commit 8516e87
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/include/common/statement_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ class StatementTypeUtils {
return statementType == StatementType::COPY;
}

static bool isDDLOrCopyCSV(StatementType statementType) {
return isDDL(statementType) || isCopyCSV(statementType);
static bool isCreateMacro(StatementType statementType) {
return statementType == StatementType::CREATE_MACRO;
}

static bool allowActiveTransaction(StatementType statementType) {
return isDDL(statementType) || isCopyCSV(statementType) || isCreateMacro(statementType);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/main/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void Connection::beginTransactionIfAutoCommit(PreparedStatement* preparedStateme
}
if (!preparedStatement->allowActiveTransaction() && activeTransaction) {
throw ConnectionException(
"DDL and CopyCSV statements are automatically wrapped in a "
"DDL, CopyCSV, createMacro statements are automatically wrapped in a "
"transaction and committed. As such, they cannot be part of an "
"active transaction, please commit or rollback your previous transaction and "
"issue a ddl query without opening a transaction.");
Expand Down
2 changes: 1 addition & 1 deletion src/main/prepared_statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace kuzu {
namespace main {

bool PreparedStatement::allowActiveTransaction() const {
return !common::StatementTypeUtils::isDDLOrCopyCSV(preparedSummary.statementType);
return !common::StatementTypeUtils::allowActiveTransaction(preparedSummary.statementType);
}

bool PreparedStatement::isSuccess() const {
Expand Down
6 changes: 3 additions & 3 deletions test/runner/e2e_copy_transaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ TEST_F(TinySnbCopyCSVTransactionTest, CopyCSVStatementWithActiveTransactionError
conn->beginWriteTransaction();
auto result = conn->query(copyPersonTableCMD);
ASSERT_EQ(result->getErrorMessage(),
"DDL and CopyCSV statements are automatically wrapped in a transaction and committed. "
"As such, they cannot be part of an active transaction, please commit or rollback your "
"previous transaction and issue a ddl query without opening a transaction.");
"DDL, CopyCSV, createMacro statements are automatically wrapped in a transaction and "
"committed. As such, they cannot be part of an active transaction, please commit or "
"rollback your previous transaction and issue a ddl query without opening a transaction.");
}

} // namespace testing
Expand Down
8 changes: 8 additions & 0 deletions test/runner/e2e_create_macro_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,13 @@ TEST_F(CreateMacroTestTrxTest, createMacroReadTrxError) {
"Can't execute a write query inside a read-only transaction.");
}

TEST_F(CreateMacroTestTrxTest, createMacroWithActiveTrxError) {
conn->beginWriteTransaction();
ASSERT_EQ(conn->query("CREATE MACRO var_macro(x) AS x")->getErrorMessage(),
"DDL, CopyCSV, createMacro statements are automatically wrapped in a transaction and "
"committed. As such, they cannot be part of an active transaction, please commit or "
"rollback your previous transaction and issue a ddl query without opening a transaction.");
}

} // namespace testing
} // namespace kuzu
7 changes: 4 additions & 3 deletions test/runner/e2e_ddl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ class TinySnbDDLTest : public DBTest {
auto result = conn->query(query);
ASSERT_FALSE(result->isSuccess());
ASSERT_EQ(result->getErrorMessage(),
"DDL and CopyCSV statements are automatically wrapped in a transaction and committed. "
"As such, they cannot be part of an active transaction, please commit or rollback your "
"previous transaction and issue a ddl query without opening a transaction.");
"DDL, CopyCSV, createMacro statements are automatically wrapped in a transaction and "
"committed. As such, they cannot be part of an active transaction, please commit or "
"rollback your previous transaction and issue a ddl query without opening a "
"transaction.");
}

void executeQueryWithoutCommit(std::string query) {
Expand Down

0 comments on commit 8516e87

Please sign in to comment.