Syntax recognize drop database

This commit is contained in:
tsthght 2018-12-12 14:54:58 +08:00
parent 405d079a68
commit 0d43ba6d9c
5 changed files with 60 additions and 1 deletions

View File

@ -114,6 +114,7 @@ cmdx ::= select_stmt.
cmdx ::= update_stmt.
cmdx ::= delete_stmt.
cmdx ::= insert_stmt.
cmdx ::= drop_database_stmt.
///////////////////// EXPLAIN syntax ////////////////////////////
cmd ::= explain fullname(X) opt_col_name. {
@ -424,7 +425,6 @@ ddl_cmd_head ::= DROP VIEW.
%token_class db_schema DATABASE|SCHEMA.
ddl_cmd_head ::= CREATE db_schema.
ddl_cmd_head ::= DROP db_schema.
ddl_cmd_head ::= ALTER db_schema.
ddl_cmd_head ::= CREATE TABLE.
@ -435,6 +435,19 @@ ddl_cmd_head ::= ALTER TABLE.
opt_unique ::= UNIQUE.
opt_unique ::= .
////////////////////////// The DROP DATABASE /////////////////////////////////////
//
drop_database_stmt ::= DROP db_schema ifexists(A) nm(B). {
sql_drop_database_t *p = sql_drop_database_new();
sql_drop_database(context, p);
p->schema_name = sql_token_dup(B);
p->ifexists = A;
}
%type ifexists {int}
ifexists(A) ::= IF EXISTS. {A = 1;}
ifexists(A) ::= . {A = 0;}
//////////////////////// The SELECT statement /////////////////////////////////
//
select_stmt ::= select(X). {

View File

@ -421,6 +421,17 @@ cmd ::= DROP TABLE ifexists nm. {
ifexists(A) ::= IF EXISTS. {A = 1;}
ifexists(A) ::= . {A = 0;}
////////////////////////// The DROP DATABASE /////////////////////////////////////
//
%token_class db_schema DATABASE|SCHEMA.
cmd ::= DROP db_schema ifexists(A) nm(B). {
sql_drop_database_t *p = sql_drop_database_new();
sql_drop_database(context, p);
p->schema_name = sql_token_dup(B);
p->ifexists = A;
}
//////////////////////// ALTER TABLE //////////////////////////////////
cmd ::= ALTER TABLE. {
context->rw_flag |= CF_WRITE;

View File

@ -672,6 +672,23 @@ sql_src_item_free(void *p)
g_free(item);
}
sql_drop_database_t *
sql_drop_database_new()
{
sql_drop_database_t *p = g_new0(sql_drop_database_t, 1);
return p;
}
void
sql_drop_database_free(sql_drop_database_t *p)
{
if(!p) return;
if(p && p->schema_name) {
g_free(p->schema_name);
}
g_free(p);
}
sql_src_list_t *
sql_src_list_append(sql_src_list_t *p, sql_token_t *tname,
sql_token_t *dbname, sql_token_t *alias, sql_select_t *subquery,

View File

@ -59,6 +59,7 @@ typedef struct sql_insert_t sql_insert_t;
typedef enum sql_stmt_type_t sql_stmt_type_t;
typedef struct sql_column_t sql_column_t;
typedef GPtrArray sql_column_list_t;
typedef struct sql_drop_database_t sql_drop_database_t;
enum sql_stmt_type_t {
STMT_UNKOWN,
@ -83,6 +84,8 @@ enum sql_stmt_type_t {
STMT_SHOW_COLUMNS,
STMT_SHOW_CREATE,
STMT_SHOW_WARNINGS,
STMT_DROP_DATABASE,
};
struct sql_token_t {
char *z; /* pointer to token text, not NUL-terminated */
@ -243,6 +246,11 @@ struct sql_src_item_t {
sql_expr_list_t *func_arg; /* Arguments to table-valued-function */
}; /* One entry for each identifier on the list */
struct sql_drop_database_t {
char *schema_name;
uint8_t ifexists;
};
typedef struct sql_set_transaction_t {
enum sql_var_scope_t scope;
enum sql_trx_feature_t rw_feature;
@ -331,6 +339,9 @@ sql_column_t *sql_column_new();
void sql_column_free(void *);
sql_drop_database_t *sql_drop_database_new();
void sql_drop_database_free(sql_drop_database_t *);
int sql_join_type(sql_token_t kw);
void sql_statement_free(void *clause, sql_stmt_type_t stmt_type);

View File

@ -106,6 +106,13 @@ sql_savepoint(sql_context_t *st, int tk, char *name)
sql_context_add_stmt(st, STMT_SAVEPOINT, name);
}
void
sql_drop_database(sql_context_t *st, sql_drop_database_t *drop_database)
{
st->rw_flag |= CF_WRITE;
sql_context_add_stmt(st, STMT_DROP_DATABASE, drop_database);
}
static gboolean
string_array_contains(const char **sa, int size, const char *str)
{