implemented drop statements
This commit is contained in:
parent
48b473e7c5
commit
4e9eebb2af
|
@ -0,0 +1,38 @@
|
|||
#ifndef __DROP_STATEMENT_H__
|
||||
#define __DROP_STATEMENT_H__
|
||||
|
||||
#include "Statement.h"
|
||||
|
||||
namespace hsql {
|
||||
|
||||
struct DropStatement : Statement {
|
||||
enum ObjectType {
|
||||
kTable,
|
||||
kSchema,
|
||||
kIndex,
|
||||
kView
|
||||
};
|
||||
|
||||
|
||||
DropStatement(ObjectType type) :
|
||||
Statement(kStmtDrop),
|
||||
obj_type(type),
|
||||
name(NULL) {}
|
||||
|
||||
|
||||
ObjectType obj_type;
|
||||
const char* name;
|
||||
|
||||
|
||||
|
||||
virtual ~DropStatement() {
|
||||
delete name;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace hsql
|
||||
#endif
|
|
@ -8,5 +8,6 @@
|
|||
#include "InsertStatement.h"
|
||||
#include "UpdateStatement.h"
|
||||
#include "DeleteStatement.h"
|
||||
#include "DropStatement.h"
|
||||
|
||||
#endif
|
|
@ -85,6 +85,7 @@ typedef void* yyscan_t;
|
|||
hsql::InsertStatement* insert_stmt;
|
||||
hsql::DeleteStatement* delete_stmt;
|
||||
hsql::UpdateStatement* update_stmt;
|
||||
hsql::DropStatement* drop_stmt;
|
||||
|
||||
hsql::TableRef* table;
|
||||
hsql::Expr* expr;
|
||||
|
@ -139,6 +140,7 @@ typedef void* yyscan_t;
|
|||
%type <insert_stmt> insert_statement
|
||||
%type <delete_stmt> delete_statement truncate_statement
|
||||
%type <update_stmt> update_statement
|
||||
%type <drop_stmt> drop_statement
|
||||
%type <sval> table_name opt_alias alias file_path
|
||||
%type <bval> opt_not_exists
|
||||
%type <uval> import_file_type opt_join_type column_type
|
||||
|
@ -205,6 +207,7 @@ statement:
|
|||
| delete_statement { $$ = $1; }
|
||||
| truncate_statement { $$ = $1; }
|
||||
| update_statement { $$ = $1; }
|
||||
| drop_statement { $$ = $1; }
|
||||
;
|
||||
|
||||
|
||||
|
@ -276,6 +279,16 @@ column_type:
|
|||
| TEXT { $$ = ColumnDefinition::TEXT; }
|
||||
;
|
||||
|
||||
/******************************
|
||||
* Drop Statement
|
||||
* DROP TABLE students
|
||||
******************************/
|
||||
|
||||
drop_statement:
|
||||
DROP TABLE table_name {
|
||||
$$ = new DropStatement(DropStatement::kTable);
|
||||
$$->name = $3;
|
||||
}
|
||||
|
||||
/******************************
|
||||
* Delete Statement / Truncate statement
|
||||
|
|
|
@ -80,3 +80,15 @@ TEST(Insert) {
|
|||
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
TEST(DropTable) {
|
||||
StatementList* stmt_list = SQLParser::parseSQLString("DROP TABLE students");
|
||||
ASSERT(stmt_list->isValid);
|
||||
ASSERT_EQ(stmt_list->size(), 1);
|
||||
ASSERT_EQ(stmt_list->at(0)->type, kStmtDrop);
|
||||
|
||||
DropStatement* stmt = (DropStatement*) stmt_list->at(0);
|
||||
ASSERT_NOTNULL(stmt->name);
|
||||
ASSERT_STREQ(stmt->name, "students");
|
||||
}
|
|
@ -28,3 +28,5 @@ TRUNCATE students
|
|||
UPDATE students SET grade = 1.3 WHERE name = 'Max Mustermann';
|
||||
UPDATE students SET grade = 1.3, name='Felix Fürstenberg' WHERE name = 'Max Mustermann';
|
||||
UPDATE students SET grade = 1.0;
|
||||
# DROP
|
||||
DROP TABLE students;
|
Loading…
Reference in New Issue