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( ...@@ -343,8 +343,10 @@ pars_column_def(
sym_node_t* sym_node, /* in: column node in the sym_node_t* sym_node, /* in: column node in the
symbol table */ symbol table */
pars_res_word_t* type, /* in: data type */ 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 */ NULL */
void* is_not_null); /* in: if not NULL, column
is of type NOT NULL. */
/************************************************************************* /*************************************************************************
Parses a table creation operation. */ 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: ...@@ -450,8 +450,8 @@ fetch_statement:
; ;
column_def: column_def:
PARS_ID_TOKEN type_name opt_column_len PARS_ID_TOKEN type_name opt_column_len opt_not_null
{ $$ = pars_column_def($1, $2, $3); } { $$ = pars_column_def($1, $2, $3, $4); }
; ;
column_def_list: column_def_list:
...@@ -464,6 +464,14 @@ opt_column_len: ...@@ -464,6 +464,14 @@ opt_column_len:
/* Nothing */ { $$ = NULL; } /* Nothing */ { $$ = NULL; }
| '(' PARS_INT_LIT ')' | '(' PARS_INT_LIT ')'
{ $$ = $2; } { $$ = $2; }
;
opt_not_null:
/* Nothing */ { $$ = NULL; }
| PARS_NOT_TOKEN PARS_NULL_LIT
{ $$ = &pars_int_token;
/* pass any non-NULL pointer */ }
;
not_fit_in_memory: not_fit_in_memory:
/* Nothing */ { $$ = NULL; } /* Nothing */ { $$ = NULL; }
...@@ -514,6 +522,7 @@ rollback_statement: ...@@ -514,6 +522,7 @@ rollback_statement:
type_name: type_name:
PARS_INT_TOKEN { $$ = &pars_int_token; } PARS_INT_TOKEN { $$ = &pars_int_token; }
| PARS_INTEGER_TOKEN { $$ = &pars_int_token; }
| PARS_CHAR_TOKEN { $$ = &pars_char_token; } | PARS_CHAR_TOKEN { $$ = &pars_char_token; }
| PARS_BINARY_TOKEN { $$ = &pars_binary_token; } | PARS_BINARY_TOKEN { $$ = &pars_binary_token; }
| PARS_BLOB_TOKEN { $$ = &pars_blob_token; } | PARS_BLOB_TOKEN { $$ = &pars_blob_token; }
......
...@@ -1081,15 +1081,24 @@ void ...@@ -1081,15 +1081,24 @@ void
pars_set_dfield_type( pars_set_dfield_type(
/*=================*/ /*=================*/
dfield_t* dfield, /* in: dfield */ dfield_t* dfield, /* in: dfield */
pars_res_word_t* type, /* in: pointer to a type token */ pars_res_word_t* type, /* in: pointer to a type
ulint len) /* in: length, or 0 */ 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 (type == &pars_int_token) {
if (len != 0) { if (len != 0) {
ut_error; 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) { } else if (type == &pars_char_token) {
if (len != 0) { if (len != 0) {
...@@ -1097,7 +1106,21 @@ pars_set_dfield_type( ...@@ -1097,7 +1106,21 @@ pars_set_dfield_type(
} }
dtype_set(dfield_get_type(dfield), DATA_VARCHAR, 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) { } else if (type == &pars_binary_token) {
if (len == 0) { if (len == 0) {
ut_error; ut_error;
...@@ -1134,7 +1157,7 @@ pars_variable_declaration( ...@@ -1134,7 +1157,7 @@ pars_variable_declaration(
node->param_type = PARS_NOT_PARAM; 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); return(node);
} }
...@@ -1503,8 +1526,10 @@ pars_column_def( ...@@ -1503,8 +1526,10 @@ pars_column_def(
sym_node_t* sym_node, /* in: column node in the sym_node_t* sym_node, /* in: column node in the
symbol table */ symbol table */
pars_res_word_t* type, /* in: data type */ 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 */ NULL */
void* is_not_null) /* in: if not NULL, column
is of type NOT NULL. */
{ {
ulint len2; ulint len2;
...@@ -1514,7 +1539,8 @@ pars_column_def( ...@@ -1514,7 +1539,8 @@ pars_column_def(
len2 = 0; 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); 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