added class and keywords for updates
This commit is contained in:
parent
b86bf6e7f9
commit
789a4a5b9b
|
@ -12,4 +12,6 @@ SELECT city, AVG(grade) AS average|, MIN(grade) AS best, MAX(grade) AS worst FRO
|
||||||
# UNION
|
# UNION
|
||||||
SELECT * FROM students WHERE grade = 1.3 UNION SELECT * FROM students WHERE grade = 3.7;
|
SELECT * FROM students WHERE grade = 1.3 UNION SELECT * FROM students WHERE grade = 3.7;
|
||||||
# JOIN
|
# JOIN
|
||||||
SELECT * FROM companies JOIN employees ON company_id = employee_company_id;
|
SELECT * FROM companies JOIN employees ON company_id = employee_company_id;
|
||||||
|
# INSERT
|
||||||
|
INSERT INTO students VALUES ('Max', 10101, 'Musterhausen', 3.3);
|
|
@ -15,6 +15,7 @@ typedef enum {
|
||||||
kStmtSelect,
|
kStmtSelect,
|
||||||
kStmtImport,
|
kStmtImport,
|
||||||
kStmtInsert,
|
kStmtInsert,
|
||||||
|
kStmtUpdate,
|
||||||
// Following types are planned but not supported yet
|
// Following types are planned but not supported yet
|
||||||
kStmtDelete,
|
kStmtDelete,
|
||||||
kStmtCreate,
|
kStmtCreate,
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef __UPDATE_STATEMENT_H__
|
||||||
|
#define __UPDATE_STATEMENT_H__
|
||||||
|
|
||||||
|
#include "Statement.h"
|
||||||
|
|
||||||
|
namespace hsql {
|
||||||
|
|
||||||
|
struct UpdateClause {
|
||||||
|
char* column;
|
||||||
|
Expr* value;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UpdateStatement : Statement {
|
||||||
|
UpdateStatement() :
|
||||||
|
Statement(kStmtUpdate),
|
||||||
|
table(NULL),
|
||||||
|
updates(NULL),
|
||||||
|
where(NULL) {}
|
||||||
|
|
||||||
|
virtual ~UpdateStatement(); // defined in destructors.cpp
|
||||||
|
|
||||||
|
TableRef* table;
|
||||||
|
List<UpdateClause*> updates;
|
||||||
|
Expr* where;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namsepace hsql
|
||||||
|
#endif
|
|
@ -1,10 +1,12 @@
|
||||||
|
|
||||||
#ifndef __SQLLIB_H__
|
#ifndef __SQLLIB_H__
|
||||||
#define __SQLLIB_H__
|
#define __SQLLIB_H__
|
||||||
|
|
||||||
|
|
||||||
#include "SelectStatement.h"
|
#include "SelectStatement.h"
|
||||||
#include "ImportStatement.h"
|
#include "ImportStatement.h"
|
||||||
#include "CreateStatement.h"
|
#include "CreateStatement.h"
|
||||||
#include "InsertStatement.h"
|
#include "InsertStatement.h"
|
||||||
|
#include "UpdateStatement.h"
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -107,17 +107,19 @@ typedef void* yyscan_t;
|
||||||
%token <uval> NOTEQUALS LESSEQ GREATEREQ
|
%token <uval> NOTEQUALS LESSEQ GREATEREQ
|
||||||
|
|
||||||
/* SQL Keywords */
|
/* SQL Keywords */
|
||||||
%token INTERSECT TEMPORARY DISTINCT RESTRICT TRUNCATE
|
%token PARAMETERS INTERSECT TEMPORARY TIMESTAMP DISTINCT
|
||||||
%token ANALYZE BETWEEN CASCADE COLUMNS CONTROL DEFAULT
|
%token NVARCHAR RESTRICT TRUNCATE ANALYZE BETWEEN CASCADE
|
||||||
%token EXPLAIN HISTORY NATURAL PRIMARY SCHEMAS SPATIAL
|
%token COLUMNS CONTROL DEFAULT EXPLAIN HISTORY INTEGER
|
||||||
%token BEFORE COLUMN CREATE DELETE DIRECT ESCAPE EXCEPT
|
%token NATURAL PRIMARY SCHEMAS SPATIAL VIRTUAL BEFORE COLUMN
|
||||||
%token EXISTS GLOBAL HAVING IMPORT INSERT ISNULL OFFSET
|
%token CREATE DELETE DIRECT DOUBLE ESCAPE EXCEPT EXISTS
|
||||||
%token RENAME SCHEMA SELECT SORTED TABLES UNIQUE UNLOAD
|
%token GLOBAL HAVING IMPORT INSERT ISNULL OFFSET RENAME
|
||||||
%token UPDATE VALUES AFTER ALTER CROSS GROUP INDEX INNER
|
%token SCHEMA SELECT SORTED TABLES UNIQUE UNLOAD UPDATE
|
||||||
%token LIMIT LOCAL MINUS ORDER OUTER RIGHT TABLE UNION USING
|
%token VALUES AFTER ALTER CROSS DELTA GROUP INDEX INNER
|
||||||
%token WHERE CALL DESC DROP FILE FROM FULL HASH INTO JOIN
|
%token LIMIT LOCAL MERGE MINUS ORDER OUTER RIGHT TABLE UNION
|
||||||
%token LEFT LIKE LOAD NULL PLAN SHOW WITH ADD ALL AND ASC
|
%token USING WHERE CALL DATE DESC DROP FILE FROM FULL HASH
|
||||||
%token CSV FOR KEY NOT SET TBL TOP AS BY IF IN IS ON OR TO
|
%token INTO JOIN LEFT LIKE LOAD NULL PART PLAN SHOW TEXT
|
||||||
|
%token TIME VIEW WITH ADD ALL AND ASC CSV FOR KEY NOT OFF
|
||||||
|
%token SET TBL TOP AS BY IF IN IS OF ON OR TO
|
||||||
|
|
||||||
|
|
||||||
/*********************************
|
/*********************************
|
||||||
|
|
|
@ -57,9 +57,13 @@
|
||||||
[ \t\n]+ /* skip whitespace */;
|
[ \t\n]+ /* skip whitespace */;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PARAMETERS TOKEN(PARAMETERS)
|
||||||
INTERSECT TOKEN(INTERSECT)
|
INTERSECT TOKEN(INTERSECT)
|
||||||
TEMPORARY TOKEN(TEMPORARY)
|
TEMPORARY TOKEN(TEMPORARY)
|
||||||
|
TIMESTAMP TOKEN(TIMESTAMP)
|
||||||
DISTINCT TOKEN(DISTINCT)
|
DISTINCT TOKEN(DISTINCT)
|
||||||
|
NVARCHAR TOKEN(NVARCHAR)
|
||||||
RESTRICT TOKEN(RESTRICT)
|
RESTRICT TOKEN(RESTRICT)
|
||||||
TRUNCATE TOKEN(TRUNCATE)
|
TRUNCATE TOKEN(TRUNCATE)
|
||||||
ANALYZE TOKEN(ANALYZE)
|
ANALYZE TOKEN(ANALYZE)
|
||||||
|
@ -70,15 +74,18 @@ CONTROL TOKEN(CONTROL)
|
||||||
DEFAULT TOKEN(DEFAULT)
|
DEFAULT TOKEN(DEFAULT)
|
||||||
EXPLAIN TOKEN(EXPLAIN)
|
EXPLAIN TOKEN(EXPLAIN)
|
||||||
HISTORY TOKEN(HISTORY)
|
HISTORY TOKEN(HISTORY)
|
||||||
|
INTEGER TOKEN(INTEGER)
|
||||||
NATURAL TOKEN(NATURAL)
|
NATURAL TOKEN(NATURAL)
|
||||||
PRIMARY TOKEN(PRIMARY)
|
PRIMARY TOKEN(PRIMARY)
|
||||||
SCHEMAS TOKEN(SCHEMAS)
|
SCHEMAS TOKEN(SCHEMAS)
|
||||||
SPATIAL TOKEN(SPATIAL)
|
SPATIAL TOKEN(SPATIAL)
|
||||||
|
VIRTUAL TOKEN(VIRTUAL)
|
||||||
BEFORE TOKEN(BEFORE)
|
BEFORE TOKEN(BEFORE)
|
||||||
COLUMN TOKEN(COLUMN)
|
COLUMN TOKEN(COLUMN)
|
||||||
CREATE TOKEN(CREATE)
|
CREATE TOKEN(CREATE)
|
||||||
DELETE TOKEN(DELETE)
|
DELETE TOKEN(DELETE)
|
||||||
DIRECT TOKEN(DIRECT)
|
DIRECT TOKEN(DIRECT)
|
||||||
|
DOUBLE TOKEN(DOUBLE)
|
||||||
ESCAPE TOKEN(ESCAPE)
|
ESCAPE TOKEN(ESCAPE)
|
||||||
EXCEPT TOKEN(EXCEPT)
|
EXCEPT TOKEN(EXCEPT)
|
||||||
EXISTS TOKEN(EXISTS)
|
EXISTS TOKEN(EXISTS)
|
||||||
|
@ -100,11 +107,13 @@ VALUES TOKEN(VALUES)
|
||||||
AFTER TOKEN(AFTER)
|
AFTER TOKEN(AFTER)
|
||||||
ALTER TOKEN(ALTER)
|
ALTER TOKEN(ALTER)
|
||||||
CROSS TOKEN(CROSS)
|
CROSS TOKEN(CROSS)
|
||||||
|
DELTA TOKEN(DELTA)
|
||||||
GROUP TOKEN(GROUP)
|
GROUP TOKEN(GROUP)
|
||||||
INDEX TOKEN(INDEX)
|
INDEX TOKEN(INDEX)
|
||||||
INNER TOKEN(INNER)
|
INNER TOKEN(INNER)
|
||||||
LIMIT TOKEN(LIMIT)
|
LIMIT TOKEN(LIMIT)
|
||||||
LOCAL TOKEN(LOCAL)
|
LOCAL TOKEN(LOCAL)
|
||||||
|
MERGE TOKEN(MERGE)
|
||||||
MINUS TOKEN(MINUS)
|
MINUS TOKEN(MINUS)
|
||||||
ORDER TOKEN(ORDER)
|
ORDER TOKEN(ORDER)
|
||||||
OUTER TOKEN(OUTER)
|
OUTER TOKEN(OUTER)
|
||||||
|
@ -114,6 +123,7 @@ UNION TOKEN(UNION)
|
||||||
USING TOKEN(USING)
|
USING TOKEN(USING)
|
||||||
WHERE TOKEN(WHERE)
|
WHERE TOKEN(WHERE)
|
||||||
CALL TOKEN(CALL)
|
CALL TOKEN(CALL)
|
||||||
|
DATE TOKEN(DATE)
|
||||||
DESC TOKEN(DESC)
|
DESC TOKEN(DESC)
|
||||||
DROP TOKEN(DROP)
|
DROP TOKEN(DROP)
|
||||||
FILE TOKEN(FILE)
|
FILE TOKEN(FILE)
|
||||||
|
@ -126,8 +136,12 @@ LEFT TOKEN(LEFT)
|
||||||
LIKE TOKEN(LIKE)
|
LIKE TOKEN(LIKE)
|
||||||
LOAD TOKEN(LOAD)
|
LOAD TOKEN(LOAD)
|
||||||
NULL TOKEN(NULL)
|
NULL TOKEN(NULL)
|
||||||
|
PART TOKEN(PART)
|
||||||
PLAN TOKEN(PLAN)
|
PLAN TOKEN(PLAN)
|
||||||
SHOW TOKEN(SHOW)
|
SHOW TOKEN(SHOW)
|
||||||
|
TEXT TOKEN(TEXT)
|
||||||
|
TIME TOKEN(TIME)
|
||||||
|
VIEW TOKEN(VIEW)
|
||||||
WITH TOKEN(WITH)
|
WITH TOKEN(WITH)
|
||||||
ADD TOKEN(ADD)
|
ADD TOKEN(ADD)
|
||||||
ALL TOKEN(ALL)
|
ALL TOKEN(ALL)
|
||||||
|
@ -137,6 +151,7 @@ CSV TOKEN(CSV)
|
||||||
FOR TOKEN(FOR)
|
FOR TOKEN(FOR)
|
||||||
KEY TOKEN(KEY)
|
KEY TOKEN(KEY)
|
||||||
NOT TOKEN(NOT)
|
NOT TOKEN(NOT)
|
||||||
|
OFF TOKEN(OFF)
|
||||||
SET TOKEN(SET)
|
SET TOKEN(SET)
|
||||||
TBL TOKEN(TBL)
|
TBL TOKEN(TBL)
|
||||||
TOP TOKEN(TOP)
|
TOP TOKEN(TOP)
|
||||||
|
@ -145,6 +160,7 @@ BY TOKEN(BY)
|
||||||
IF TOKEN(IF)
|
IF TOKEN(IF)
|
||||||
IN TOKEN(IN)
|
IN TOKEN(IN)
|
||||||
IS TOKEN(IS)
|
IS TOKEN(IS)
|
||||||
|
OF TOKEN(OF)
|
||||||
ON TOKEN(ON)
|
ON TOKEN(ON)
|
||||||
OR TOKEN(OR)
|
OR TOKEN(OR)
|
||||||
TO TOKEN(TO)
|
TO TOKEN(TO)
|
||||||
|
|
|
@ -29,8 +29,6 @@ with open("sql_keywords.txt", 'r') as fh:
|
||||||
|
|
||||||
#################
|
#################
|
||||||
# Bison
|
# Bison
|
||||||
|
|
||||||
|
|
||||||
line = "%token"
|
line = "%token"
|
||||||
max_len = 60
|
max_len = 60
|
||||||
|
|
||||||
|
|
|
@ -39,14 +39,15 @@ CREATE
|
||||||
TABLE
|
TABLE
|
||||||
SCHEMA
|
SCHEMA
|
||||||
INDEX
|
INDEX
|
||||||
|
VIEW
|
||||||
IF
|
IF
|
||||||
NOT
|
NOT
|
||||||
EXISTS
|
EXISTS
|
||||||
GLOBAL
|
GLOBAL
|
||||||
LOCAL
|
LOCAL
|
||||||
TEMPORARY
|
TEMPORARY
|
||||||
WITH
|
|
||||||
UNIQUE
|
UNIQUE
|
||||||
|
VIRTUAL
|
||||||
|
|
||||||
INDEX
|
INDEX
|
||||||
UNIQUE
|
UNIQUE
|
||||||
|
@ -72,7 +73,6 @@ AFTER
|
||||||
// Data Manipulation
|
// Data Manipulation
|
||||||
INSERT
|
INSERT
|
||||||
VALUES
|
VALUES
|
||||||
SET
|
|
||||||
DIRECT
|
DIRECT
|
||||||
SORTED
|
SORTED
|
||||||
|
|
||||||
|
@ -83,22 +83,30 @@ TBL
|
||||||
CONTROL
|
CONTROL
|
||||||
|
|
||||||
UPDATE
|
UPDATE
|
||||||
|
SET
|
||||||
|
|
||||||
DELETE
|
DELETE
|
||||||
HISTORY
|
HISTORY
|
||||||
|
|
||||||
TRUNCATE
|
TRUNCATE
|
||||||
|
|
||||||
|
MERGE
|
||||||
|
HISTORY
|
||||||
|
DELTA
|
||||||
|
OF
|
||||||
|
PART
|
||||||
|
|
||||||
|
LOAD
|
||||||
|
UNLOAD
|
||||||
|
|
||||||
|
DELETE
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
// other statements
|
// other statements
|
||||||
RENAME
|
RENAME
|
||||||
TO
|
|
||||||
DELETE
|
|
||||||
EXPLAIN
|
EXPLAIN
|
||||||
PLAN
|
PLAN
|
||||||
ANALYZE
|
ANALYZE
|
||||||
LOAD
|
|
||||||
UNLOAD
|
|
||||||
|
|
||||||
SHOW
|
SHOW
|
||||||
SCHEMAS
|
SCHEMAS
|
||||||
|
@ -113,6 +121,7 @@ SET
|
||||||
DEFAULT
|
DEFAULT
|
||||||
CALL
|
CALL
|
||||||
FOR
|
FOR
|
||||||
|
TO
|
||||||
|
|
||||||
|
|
||||||
// Expressions
|
// Expressions
|
||||||
|
@ -125,4 +134,19 @@ IN
|
||||||
IS
|
IS
|
||||||
ISNULL
|
ISNULL
|
||||||
BETWEEN
|
BETWEEN
|
||||||
ESCAPE
|
ESCAPE
|
||||||
|
|
||||||
|
// With
|
||||||
|
WITH
|
||||||
|
PARAMETERS
|
||||||
|
ON
|
||||||
|
OFF
|
||||||
|
|
||||||
|
// Data types
|
||||||
|
DATE
|
||||||
|
TIME
|
||||||
|
TIMESTAMP
|
||||||
|
INTEGER
|
||||||
|
DOUBLE
|
||||||
|
NVARCHAR
|
||||||
|
TEXT
|
||||||
|
|
Loading…
Reference in New Issue