Add DESCRIBE (#131)

This commit is contained in:
mrks 2019-09-16 11:58:05 +02:00 committed by GitHub
parent 6e730a5436
commit a4703fec5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 2447 additions and 2388 deletions

File diff suppressed because it is too large Load Diff

View File

@ -112,119 +112,120 @@ extern int hsql_debug;
SQL_SPATIAL = 284,
SQL_VARCHAR = 285,
SQL_VIRTUAL = 286,
SQL_BEFORE = 287,
SQL_COLUMN = 288,
SQL_CREATE = 289,
SQL_DELETE = 290,
SQL_DIRECT = 291,
SQL_DOUBLE = 292,
SQL_ESCAPE = 293,
SQL_EXCEPT = 294,
SQL_EXISTS = 295,
SQL_EXTRACT = 296,
SQL_GLOBAL = 297,
SQL_HAVING = 298,
SQL_IMPORT = 299,
SQL_INSERT = 300,
SQL_ISNULL = 301,
SQL_OFFSET = 302,
SQL_RENAME = 303,
SQL_SCHEMA = 304,
SQL_SELECT = 305,
SQL_SORTED = 306,
SQL_TABLES = 307,
SQL_UNIQUE = 308,
SQL_UNLOAD = 309,
SQL_UPDATE = 310,
SQL_VALUES = 311,
SQL_AFTER = 312,
SQL_ALTER = 313,
SQL_CROSS = 314,
SQL_DELTA = 315,
SQL_FLOAT = 316,
SQL_GROUP = 317,
SQL_INDEX = 318,
SQL_INNER = 319,
SQL_LIMIT = 320,
SQL_LOCAL = 321,
SQL_MERGE = 322,
SQL_MINUS = 323,
SQL_ORDER = 324,
SQL_OUTER = 325,
SQL_RIGHT = 326,
SQL_TABLE = 327,
SQL_UNION = 328,
SQL_USING = 329,
SQL_WHERE = 330,
SQL_CALL = 331,
SQL_CASE = 332,
SQL_CHAR = 333,
SQL_DATE = 334,
SQL_DESC = 335,
SQL_DROP = 336,
SQL_ELSE = 337,
SQL_FILE = 338,
SQL_FROM = 339,
SQL_FULL = 340,
SQL_HASH = 341,
SQL_HINT = 342,
SQL_INTO = 343,
SQL_JOIN = 344,
SQL_LEFT = 345,
SQL_LIKE = 346,
SQL_LOAD = 347,
SQL_LONG = 348,
SQL_NULL = 349,
SQL_PLAN = 350,
SQL_SHOW = 351,
SQL_TEXT = 352,
SQL_THEN = 353,
SQL_TIME = 354,
SQL_VIEW = 355,
SQL_WHEN = 356,
SQL_WITH = 357,
SQL_ADD = 358,
SQL_ALL = 359,
SQL_AND = 360,
SQL_ASC = 361,
SQL_CSV = 362,
SQL_END = 363,
SQL_FOR = 364,
SQL_INT = 365,
SQL_KEY = 366,
SQL_NOT = 367,
SQL_OFF = 368,
SQL_SET = 369,
SQL_TBL = 370,
SQL_TOP = 371,
SQL_AS = 372,
SQL_BY = 373,
SQL_IF = 374,
SQL_IN = 375,
SQL_IS = 376,
SQL_OF = 377,
SQL_ON = 378,
SQL_OR = 379,
SQL_TO = 380,
SQL_ARRAY = 381,
SQL_CONCAT = 382,
SQL_ILIKE = 383,
SQL_SECOND = 384,
SQL_MINUTE = 385,
SQL_HOUR = 386,
SQL_DAY = 387,
SQL_MONTH = 388,
SQL_YEAR = 389,
SQL_TRUE = 390,
SQL_FALSE = 391,
SQL_EQUALS = 392,
SQL_NOTEQUALS = 393,
SQL_LESS = 394,
SQL_GREATER = 395,
SQL_LESSEQ = 396,
SQL_GREATEREQ = 397,
SQL_NOTNULL = 398,
SQL_UMINUS = 399
SQL_DESCRIBE = 287,
SQL_BEFORE = 288,
SQL_COLUMN = 289,
SQL_CREATE = 290,
SQL_DELETE = 291,
SQL_DIRECT = 292,
SQL_DOUBLE = 293,
SQL_ESCAPE = 294,
SQL_EXCEPT = 295,
SQL_EXISTS = 296,
SQL_EXTRACT = 297,
SQL_GLOBAL = 298,
SQL_HAVING = 299,
SQL_IMPORT = 300,
SQL_INSERT = 301,
SQL_ISNULL = 302,
SQL_OFFSET = 303,
SQL_RENAME = 304,
SQL_SCHEMA = 305,
SQL_SELECT = 306,
SQL_SORTED = 307,
SQL_TABLES = 308,
SQL_UNIQUE = 309,
SQL_UNLOAD = 310,
SQL_UPDATE = 311,
SQL_VALUES = 312,
SQL_AFTER = 313,
SQL_ALTER = 314,
SQL_CROSS = 315,
SQL_DELTA = 316,
SQL_FLOAT = 317,
SQL_GROUP = 318,
SQL_INDEX = 319,
SQL_INNER = 320,
SQL_LIMIT = 321,
SQL_LOCAL = 322,
SQL_MERGE = 323,
SQL_MINUS = 324,
SQL_ORDER = 325,
SQL_OUTER = 326,
SQL_RIGHT = 327,
SQL_TABLE = 328,
SQL_UNION = 329,
SQL_USING = 330,
SQL_WHERE = 331,
SQL_CALL = 332,
SQL_CASE = 333,
SQL_CHAR = 334,
SQL_DATE = 335,
SQL_DESC = 336,
SQL_DROP = 337,
SQL_ELSE = 338,
SQL_FILE = 339,
SQL_FROM = 340,
SQL_FULL = 341,
SQL_HASH = 342,
SQL_HINT = 343,
SQL_INTO = 344,
SQL_JOIN = 345,
SQL_LEFT = 346,
SQL_LIKE = 347,
SQL_LOAD = 348,
SQL_LONG = 349,
SQL_NULL = 350,
SQL_PLAN = 351,
SQL_SHOW = 352,
SQL_TEXT = 353,
SQL_THEN = 354,
SQL_TIME = 355,
SQL_VIEW = 356,
SQL_WHEN = 357,
SQL_WITH = 358,
SQL_ADD = 359,
SQL_ALL = 360,
SQL_AND = 361,
SQL_ASC = 362,
SQL_CSV = 363,
SQL_END = 364,
SQL_FOR = 365,
SQL_INT = 366,
SQL_KEY = 367,
SQL_NOT = 368,
SQL_OFF = 369,
SQL_SET = 370,
SQL_TBL = 371,
SQL_TOP = 372,
SQL_AS = 373,
SQL_BY = 374,
SQL_IF = 375,
SQL_IN = 376,
SQL_IS = 377,
SQL_OF = 378,
SQL_ON = 379,
SQL_OR = 380,
SQL_TO = 381,
SQL_ARRAY = 382,
SQL_CONCAT = 383,
SQL_ILIKE = 384,
SQL_SECOND = 385,
SQL_MINUTE = 386,
SQL_HOUR = 387,
SQL_DAY = 388,
SQL_MONTH = 389,
SQL_YEAR = 390,
SQL_TRUE = 391,
SQL_FALSE = 392,
SQL_EQUALS = 393,
SQL_NOTEQUALS = 394,
SQL_LESS = 395,
SQL_GREATER = 396,
SQL_LESSEQ = 397,
SQL_GREATEREQ = 398,
SQL_NOTNULL = 399,
SQL_UMINUS = 400
};
#endif
@ -277,7 +278,7 @@ union HSQL_STYPE
std::vector<hsql::OrderDescription*>* order_vec;
std::vector<hsql::WithDescription*>* with_description_vec;
#line 281 "bison_parser.h" /* yacc.c:1927 */
#line 282 "bison_parser.h" /* yacc.c:1927 */
};
typedef union HSQL_STYPE HSQL_STYPE;

View File

@ -166,7 +166,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
%token DISTINCT NVARCHAR RESTRICT TRUNCATE ANALYZE BETWEEN
%token CASCADE COLUMNS CONTROL DEFAULT EXECUTE EXPLAIN
%token INTEGER NATURAL PREPARE PRIMARY SCHEMAS
%token SPATIAL VARCHAR VIRTUAL BEFORE COLUMN CREATE DELETE DIRECT
%token SPATIAL VARCHAR VIRTUAL DESCRIBE BEFORE COLUMN CREATE DELETE DIRECT
%token DOUBLE ESCAPE EXCEPT EXISTS EXTRACT GLOBAL HAVING IMPORT
%token INSERT ISNULL OFFSET RENAME SCHEMA SELECT SORTED
%token TABLES UNIQUE UNLOAD UPDATE VALUES AFTER ALTER CROSS
@ -407,6 +407,11 @@ show_statement:
$$->schema = $3.schema;
$$->name = $3.name;
}
| DESCRIBE table_name {
$$ = new ShowStatement(kShowColumns);
$$->schema = $2.schema;
$$->name = $2.name;
}
;

File diff suppressed because it is too large Load Diff

View File

@ -730,7 +730,7 @@ extern int yylex \
#undef yyTABLES_NAME
#endif
#line 235 "flex_lexer.l"
#line 236 "flex_lexer.l"
#line 736 "flex_lexer.h"

View File

@ -66,6 +66,7 @@ PARAMETERS TOKEN(PARAMETERS)
INTERSECT TOKEN(INTERSECT)
TEMPORARY TOKEN(TEMPORARY)
TIMESTAMP TOKEN(TIMESTAMP)
DESCRIBE TOKEN(DESCRIBE)
DISTINCT TOKEN(DISTINCT)
NVARCHAR TOKEN(NVARCHAR)
RESTRICT TOKEN(RESTRICT)

View File

@ -9,6 +9,7 @@
!INSERT INTO test_table VALUESd (1, 2, 'test');
!SELECT * FROM t WHERE a = ? AND b = ?;gibberish;
!SHOW COLUMNS;
!DESCRIBE;
!select a + 2 as b(spam, eggs) from B;
!WITH a AS SELECT 1 SELECT 1;
!WITH a AS (SELECT ) SELECT 1;

View File

@ -60,3 +60,4 @@ SELECT * FROM test WITH HINT(NO_CACHE, NO_SAMPLING);
SELECT * FROM test WITH HINT(NO_CACHE, SAMPLE_RATE(0.1), OMW(1.0, 'test'));
SHOW TABLES;
SHOW COLUMNS students;
DESCRIBE students;

View File

@ -192,6 +192,19 @@ TEST(ShowColumnsStatementTest) {
ASSERT_STREQ(stmt->name, "students");
}
TEST(DescribeStatementTest) {
TEST_PARSE_SINGLE_SQL(
"DESCRIBE students;",
kStmtShow,
ShowStatement,
result,
stmt);
ASSERT_EQ(stmt->type, kShowColumns);
ASSERT_NOTNULL(stmt->name);
ASSERT_STREQ(stmt->name, "students");
}
SQLParserResult parse_and_move(std::string query) {
hsql::SQLParserResult result;