implemented DEALLOCATE PREPARE

This commit is contained in:
Pedro 2015-01-07 13:42:11 +01:00
parent ab9a85704f
commit 2f110b8168
5 changed files with 29 additions and 16 deletions

View File

@ -15,7 +15,8 @@ struct DropStatement : SQLStatement {
kTable,
kSchema,
kIndex,
kView
kView,
kPreparedStatement
};

View File

@ -353,7 +353,8 @@ column_type:
/******************************
* Drop Statement
* DROP TABLE students
* DROP TABLE students;
* DEALLOCATE PREPARE stmt;
******************************/
drop_statement:
@ -361,6 +362,11 @@ drop_statement:
$$ = new DropStatement(DropStatement::kTable);
$$->name = $3;
}
| DEALLOCATE PREPARE IDENTIFIER {
$$ = new DropStatement(DropStatement::kPreparedStatement);
$$->name = $3;
}
;
/******************************
* Delete Statement / Truncate statement

View File

@ -96,26 +96,22 @@ TEST(PrepareStatementTest) {
"INSERT INTO test VALUES(?);"
"SELECT ?, test FROM test WHERE c1 = ?;"
"};"
"PREPARE stmt: SELECT * FROM data WHERE c1 = ?;";
"PREPARE stmt: SELECT * FROM data WHERE c1 = ?;"
"DEALLOCATE PREPARE stmt;";
TEST_PARSE_SQL_QUERY(query, stmt_list, 2);
TEST_PARSE_SQL_QUERY(query, stmt_list, 3);
ASSERT_EQ(stmt_list->getStatement(0)->type(), kStmtPrepare);
ASSERT_EQ(stmt_list->getStatement(1)->type(), kStmtPrepare);
PrepareStatement* prep1 = (PrepareStatement*) stmt_list->getStatement(0);
PrepareStatement* prep2 = (PrepareStatement*) stmt_list->getStatement(1);
TEST_CAST_STMT(stmt_list, 0, kStmtPrepare, PrepareStatement, prep1);
TEST_CAST_STMT(stmt_list, 1, kStmtPrepare, PrepareStatement, prep2);
TEST_CAST_STMT(stmt_list, 2, kStmtDrop, DropStatement, drop);
// Prepare Statement #1
ASSERT_STREQ(prep1->name, "test");
ASSERT_EQ(prep1->placeholders.size(), 3);
ASSERT_EQ(prep1->query->numStatements(), 2);
ASSERT_EQ(prep1->query->getStatement(0)->type(), kStmtInsert);
ASSERT_EQ(prep1->query->getStatement(1)->type(), kStmtSelect);
InsertStatement* insert = (InsertStatement*) prep1->query->getStatement(0);
SelectStatement* select = (SelectStatement*) prep1->query->getStatement(1);
TEST_CAST_STMT(prep1->query, 0, kStmtInsert, InsertStatement, insert);
TEST_CAST_STMT(prep1->query, 1, kStmtSelect, SelectStatement, select);
ASSERT(insert->values->at(0)->isType(kExprPlaceholder));
ASSERT(select->select_list->at(0)->isType(kExprPlaceholder));
@ -134,6 +130,10 @@ TEST(PrepareStatementTest) {
// Prepare Statement #2
ASSERT_STREQ(prep2->name, "stmt");
ASSERT_EQ(prep2->placeholders.size(), 1);
// Deallocate Statement
ASSERT_EQ(drop->type, DropStatement::kPreparedStatement);
ASSERT_STREQ(drop->name, "stmt");
}

View File

@ -14,4 +14,9 @@
stmt_class* output_var = (stmt_class*) stmt_list->getStatement(0);
#define TEST_CAST_STMT(stmt_list, stmt_index, stmt_type, stmt_class, output_var) \
ASSERT_EQ(stmt_list->getStatement(stmt_index)->type(), stmt_type); \
stmt_class* output_var = (stmt_class*) stmt_list->getStatement(stmt_index);
#endif

View File

@ -35,4 +35,5 @@ DROP TABLE students;
PREPARE prep_inst: INSERT INTO test VALUES (?, ?, ?);
PREPARE prep2 { INSERT INTO test VALUES (?, 0, 0); INSERT INTO test VALUES (0, ?, 0); INSERT INTO test VALUES (0, 0, ?); };
EXECUTE prep_inst(1, 2, 3);
EXECUTE prep;
EXECUTE prep;
DEALLOCATE PREPARE prep;