Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 54a0607

Browse files
committed
Add tests for unconvertible values
1 parent c7147aa commit 54a0607

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/sql/insert_sql_test.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,5 +570,42 @@ TEST_F(InsertSQLTests, UniqueColumn) {
570570
txn_manager.CommitTransaction(txn);
571571
}
572572

573+
TEST_F(InsertSQLTests, BadTypes) {
574+
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
575+
auto txn = txn_manager.BeginTransaction();
576+
catalog::Catalog::GetInstance()->CreateDatabase(DEFAULT_DB_NAME, txn);
577+
txn_manager.CommitTransaction(txn);
578+
std::string error_message;
579+
std::unique_ptr<optimizer::AbstractOptimizer> optimizer(
580+
new optimizer::Optimizer());
581+
582+
std::string create_table("CREATE TABLE foo (id1 int, id2 bigint,"
583+
"id3 smallint, id4 tinyint,"
584+
"id5 decimal);");
585+
TestingSQLUtil::ExecuteSQLQuery(create_table);
586+
// Insert an unconvertible int.
587+
std::string query("INSERT INTO(id) foo VALUES('h');");
588+
txn = txn_manager.BeginTransaction();
589+
EXPECT_THROW(
590+
TestingSQLUtil::GeneratePlanWithOptimizer(optimizer, query, txn),
591+
peloton::Exception);
592+
query = "INSERT INTO foo(id2) VALUES('h');";
593+
EXPECT_THROW(
594+
TestingSQLUtil::GeneratePlanWithOptimizer(optimizer, query, txn),
595+
peloton::Exception);
596+
query = "INSERT INTO foo(id3) VALUES('h');";
597+
EXPECT_THROW(
598+
TestingSQLUtil::GeneratePlanWithOptimizer(optimizer, query, txn),
599+
peloton::Exception);
600+
query = "INSERT INTO foo(id4) VALUES('h');";
601+
EXPECT_THROW(
602+
TestingSQLUtil::GeneratePlanWithOptimizer(optimizer, query, txn),
603+
peloton::Exception);
604+
query = "INSERT INTO foo(id5) VALUES('h');";
605+
EXPECT_THROW(
606+
TestingSQLUtil::GeneratePlanWithOptimizer(optimizer, query, txn),
607+
peloton::Exception);
608+
}
609+
573610
} // namespace test
574611
} // namespace peloton

0 commit comments

Comments
 (0)