Commit 3c7bed8c authored by osku's avatar osku

Enhance InnoDB SQL parser:

 Add support for NOT NULL in column definitions.

 Support INTEGER as an alias for INT.

 Add pars/make_bison.sh to automate parser generation.
parent 62169573
......@@ -343,8 +343,10 @@ pars_column_def(
sym_node_t* sym_node, /* in: column node in the
symbol table */
pars_res_word_t* type, /* in: data type */
sym_node_t* len); /* in: length of column, or
sym_node_t* len, /* in: length of column, or
NULL */
void* is_not_null); /* in: if not NULL, column
is of type NOT NULL. */
/*************************************************************************
Parses a table creation operation. */
......
#!/bin/bash
#
# regenerate parser from bison input files as documented at the top of
# pars0lex.l.
set -eu
bison -d pars0grm.y
mv pars0grm.tab.c pars0grm.c
mv pars0grm.tab.h pars0grm.h
cp pars0grm.h ../include
This diff is collapsed.
......@@ -450,8 +450,8 @@ fetch_statement:
;
column_def:
PARS_ID_TOKEN type_name opt_column_len
{ $$ = pars_column_def($1, $2, $3); }
PARS_ID_TOKEN type_name opt_column_len opt_not_null
{ $$ = pars_column_def($1, $2, $3, $4); }
;
column_def_list:
......@@ -464,6 +464,14 @@ opt_column_len:
/* Nothing */ { $$ = NULL; }
| '(' PARS_INT_LIT ')'
{ $$ = $2; }
;
opt_not_null:
/* Nothing */ { $$ = NULL; }
| PARS_NOT_TOKEN PARS_NULL_LIT
{ $$ = &pars_int_token;
/* pass any non-NULL pointer */ }
;
not_fit_in_memory:
/* Nothing */ { $$ = NULL; }
......@@ -514,6 +522,7 @@ rollback_statement:
type_name:
PARS_INT_TOKEN { $$ = &pars_int_token; }
| PARS_INTEGER_TOKEN { $$ = &pars_int_token; }
| PARS_CHAR_TOKEN { $$ = &pars_char_token; }
| PARS_BINARY_TOKEN { $$ = &pars_binary_token; }
| PARS_BLOB_TOKEN { $$ = &pars_blob_token; }
......
......@@ -1081,15 +1081,24 @@ void
pars_set_dfield_type(
/*=================*/
dfield_t* dfield, /* in: dfield */
pars_res_word_t* type, /* in: pointer to a type token */
ulint len) /* in: length, or 0 */
pars_res_word_t* type, /* in: pointer to a type
token */
ulint len, /* in: length, or 0 */
ibool is_not_null) /* in: if TRUE, column is
NOT NULL. */
{
ulint flags = 0;
if (is_not_null) {
flags |= DATA_NOT_NULL;
}
if (type == &pars_int_token) {
if (len != 0) {
ut_error;
}
dtype_set(dfield_get_type(dfield), DATA_INT, 0, 4, 0);
dtype_set(dfield_get_type(dfield), DATA_INT, flags, 4, 0);
} else if (type == &pars_char_token) {
if (len != 0) {
......@@ -1097,7 +1106,21 @@ pars_set_dfield_type(
}
dtype_set(dfield_get_type(dfield), DATA_VARCHAR,
DATA_ENGLISH, 0, 0);
DATA_ENGLISH | flags, 0, 0);
} else if (type == &pars_binary_token) {
if (len == 0) {
ut_error;
}
dtype_set(dfield_get_type(dfield), DATA_FIXBINARY,
DATA_BINARY_TYPE | flags, len, 0);
} else if (type == &pars_blob_token) {
if (len != 0) {
ut_error;
}
dtype_set(dfield_get_type(dfield), DATA_BLOB,
DATA_BINARY_TYPE | flags, 0, 0);
} else if (type == &pars_binary_token) {
if (len == 0) {
ut_error;
......@@ -1134,7 +1157,7 @@ pars_variable_declaration(
node->param_type = PARS_NOT_PARAM;
pars_set_dfield_type(que_node_get_val(node), type, 0);
pars_set_dfield_type(que_node_get_val(node), type, 0, FALSE);
return(node);
}
......@@ -1503,8 +1526,10 @@ pars_column_def(
sym_node_t* sym_node, /* in: column node in the
symbol table */
pars_res_word_t* type, /* in: data type */
sym_node_t* len) /* in: length of column, or
sym_node_t* len, /* in: length of column, or
NULL */
void* is_not_null) /* in: if not NULL, column
is of type NOT NULL. */
{
ulint len2;
......@@ -1514,7 +1539,8 @@ pars_column_def(
len2 = 0;
}
pars_set_dfield_type(que_node_get_val(sym_node), type, len2);
pars_set_dfield_type(que_node_get_val(sym_node), type, len2,
is_not_null != NULL);
return(sym_node);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment