added class and keywords for updates

This commit is contained in:
Pedro 2014-11-26 12:19:33 +01:00
parent b86bf6e7f9
commit 789a4a5b9b
8 changed files with 97 additions and 22 deletions

View File

@ -13,3 +13,5 @@ SELECT city, AVG(grade) AS average|, MIN(grade) AS best, MAX(grade) AS worst FRO
SELECT * FROM students WHERE grade = 1.3 UNION SELECT * FROM students WHERE grade = 3.7;
# JOIN
SELECT * FROM companies JOIN employees ON company_id = employee_company_id;
# INSERT
INSERT INTO students VALUES ('Max', 10101, 'Musterhausen', 3.3);

View File

@ -15,6 +15,7 @@ typedef enum {
kStmtSelect,
kStmtImport,
kStmtInsert,
kStmtUpdate,
// Following types are planned but not supported yet
kStmtDelete,
kStmtCreate,

30
src/lib/UpdateStatement.h Normal file
View File

@ -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

View File

@ -1,10 +1,12 @@
#ifndef __SQLLIB_H__
#define __SQLLIB_H__
#include "SelectStatement.h"
#include "ImportStatement.h"
#include "CreateStatement.h"
#include "InsertStatement.h"
#include "UpdateStatement.h"
#endif

View File

@ -107,17 +107,19 @@ typedef void* yyscan_t;
%token <uval> NOTEQUALS LESSEQ GREATEREQ
/* SQL Keywords */
%token INTERSECT TEMPORARY DISTINCT RESTRICT TRUNCATE
%token ANALYZE BETWEEN CASCADE COLUMNS CONTROL DEFAULT
%token EXPLAIN HISTORY NATURAL PRIMARY SCHEMAS SPATIAL
%token BEFORE COLUMN CREATE DELETE DIRECT ESCAPE EXCEPT
%token EXISTS GLOBAL HAVING IMPORT INSERT ISNULL OFFSET
%token RENAME SCHEMA SELECT SORTED TABLES UNIQUE UNLOAD
%token UPDATE VALUES AFTER ALTER CROSS GROUP INDEX INNER
%token LIMIT LOCAL MINUS ORDER OUTER RIGHT TABLE UNION USING
%token WHERE CALL DESC DROP FILE FROM FULL HASH INTO JOIN
%token LEFT LIKE LOAD NULL PLAN SHOW WITH ADD ALL AND ASC
%token CSV FOR KEY NOT SET TBL TOP AS BY IF IN IS ON OR TO
%token PARAMETERS INTERSECT TEMPORARY TIMESTAMP DISTINCT
%token NVARCHAR RESTRICT TRUNCATE ANALYZE BETWEEN CASCADE
%token COLUMNS CONTROL DEFAULT EXPLAIN HISTORY INTEGER
%token NATURAL PRIMARY SCHEMAS SPATIAL VIRTUAL BEFORE COLUMN
%token CREATE DELETE DIRECT DOUBLE ESCAPE EXCEPT EXISTS
%token GLOBAL HAVING IMPORT INSERT ISNULL OFFSET RENAME
%token SCHEMA SELECT SORTED TABLES UNIQUE UNLOAD UPDATE
%token VALUES AFTER ALTER CROSS DELTA GROUP INDEX INNER
%token LIMIT LOCAL MERGE MINUS ORDER OUTER RIGHT TABLE UNION
%token USING WHERE CALL DATE DESC DROP FILE FROM FULL HASH
%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
/*********************************

View File

@ -57,9 +57,13 @@
[ \t\n]+ /* skip whitespace */;
PARAMETERS TOKEN(PARAMETERS)
INTERSECT TOKEN(INTERSECT)
TEMPORARY TOKEN(TEMPORARY)
TIMESTAMP TOKEN(TIMESTAMP)
DISTINCT TOKEN(DISTINCT)
NVARCHAR TOKEN(NVARCHAR)
RESTRICT TOKEN(RESTRICT)
TRUNCATE TOKEN(TRUNCATE)
ANALYZE TOKEN(ANALYZE)
@ -70,15 +74,18 @@ CONTROL TOKEN(CONTROL)
DEFAULT TOKEN(DEFAULT)
EXPLAIN TOKEN(EXPLAIN)
HISTORY TOKEN(HISTORY)
INTEGER TOKEN(INTEGER)
NATURAL TOKEN(NATURAL)
PRIMARY TOKEN(PRIMARY)
SCHEMAS TOKEN(SCHEMAS)
SPATIAL TOKEN(SPATIAL)
VIRTUAL TOKEN(VIRTUAL)
BEFORE TOKEN(BEFORE)
COLUMN TOKEN(COLUMN)
CREATE TOKEN(CREATE)
DELETE TOKEN(DELETE)
DIRECT TOKEN(DIRECT)
DOUBLE TOKEN(DOUBLE)
ESCAPE TOKEN(ESCAPE)
EXCEPT TOKEN(EXCEPT)
EXISTS TOKEN(EXISTS)
@ -100,11 +107,13 @@ VALUES TOKEN(VALUES)
AFTER TOKEN(AFTER)
ALTER TOKEN(ALTER)
CROSS TOKEN(CROSS)
DELTA TOKEN(DELTA)
GROUP TOKEN(GROUP)
INDEX TOKEN(INDEX)
INNER TOKEN(INNER)
LIMIT TOKEN(LIMIT)
LOCAL TOKEN(LOCAL)
MERGE TOKEN(MERGE)
MINUS TOKEN(MINUS)
ORDER TOKEN(ORDER)
OUTER TOKEN(OUTER)
@ -114,6 +123,7 @@ UNION TOKEN(UNION)
USING TOKEN(USING)
WHERE TOKEN(WHERE)
CALL TOKEN(CALL)
DATE TOKEN(DATE)
DESC TOKEN(DESC)
DROP TOKEN(DROP)
FILE TOKEN(FILE)
@ -126,8 +136,12 @@ LEFT TOKEN(LEFT)
LIKE TOKEN(LIKE)
LOAD TOKEN(LOAD)
NULL TOKEN(NULL)
PART TOKEN(PART)
PLAN TOKEN(PLAN)
SHOW TOKEN(SHOW)
TEXT TOKEN(TEXT)
TIME TOKEN(TIME)
VIEW TOKEN(VIEW)
WITH TOKEN(WITH)
ADD TOKEN(ADD)
ALL TOKEN(ALL)
@ -137,6 +151,7 @@ CSV TOKEN(CSV)
FOR TOKEN(FOR)
KEY TOKEN(KEY)
NOT TOKEN(NOT)
OFF TOKEN(OFF)
SET TOKEN(SET)
TBL TOKEN(TBL)
TOP TOKEN(TOP)
@ -145,6 +160,7 @@ BY TOKEN(BY)
IF TOKEN(IF)
IN TOKEN(IN)
IS TOKEN(IS)
OF TOKEN(OF)
ON TOKEN(ON)
OR TOKEN(OR)
TO TOKEN(TO)

View File

@ -29,8 +29,6 @@ with open("sql_keywords.txt", 'r') as fh:
#################
# Bison
line = "%token"
max_len = 60

View File

@ -39,14 +39,15 @@ CREATE
TABLE
SCHEMA
INDEX
VIEW
IF
NOT
EXISTS
GLOBAL
LOCAL
TEMPORARY
WITH
UNIQUE
VIRTUAL
INDEX
UNIQUE
@ -72,7 +73,6 @@ AFTER
// Data Manipulation
INSERT
VALUES
SET
DIRECT
SORTED
@ -83,22 +83,30 @@ TBL
CONTROL
UPDATE
SET
DELETE
HISTORY
TRUNCATE
MERGE
HISTORY
DELTA
OF
PART
LOAD
UNLOAD
DELETE
///////////////////////////////
// other statements
RENAME
TO
DELETE
EXPLAIN
PLAN
ANALYZE
LOAD
UNLOAD
SHOW
SCHEMAS
@ -113,6 +121,7 @@ SET
DEFAULT
CALL
FOR
TO
// Expressions
@ -126,3 +135,18 @@ IS
ISNULL
BETWEEN
ESCAPE
// With
WITH
PARAMETERS
ON
OFF
// Data types
DATE
TIME
TIMESTAMP
INTEGER
DOUBLE
NVARCHAR
TEXT