瀏覽代碼

154 dtc supporting limit in dtc (#169)

* 3rdparty: update hsql.

* yaml: update yaml.

* yaml: update yaml

* core: limit supported.

* tests: add test cases.

* tests: test test case.

* tests: add test cases.

* test: add tests cases.

* test: fix test case.

* test: fix case.

* fix: test case.

* script: add update hsql script.

* yaml: update yaml.

* update hsql.

* test: fix bug.
Yang Shuang 1 年之前
父節點
當前提交
d573388dde
共有 39 個文件被更改,包括 1328 次插入1056 次删除
  1. 10 1
      .github/workflows/build-and-test.yml
  2. 12 3
      .github/workflows/release.yml
  3. 10 1
      .github/workflows/ubuntu-18.04&gcc-4.9.yml
  4. 10 1
      .github/workflows/ubuntu-20.04&gcc-4.9.yml
  5. 10 1
      .github/workflows/ubuntu-latest&gcc-4.9.yml
  6. 7 0
      script/hsql-update.sh
  7. 1 1
      src/agent/da.c
  8. 4 2
      src/agent/my/my_parse.c
  9. 34 0
      src/libs/common/my/my_request.cc
  10. 25 28
      src/libs/hsql/include/SQLParser.h
  11. 62 62
      src/libs/hsql/include/SQLParserResult.h
  12. 427 252
      src/libs/hsql/include/parser/bison_parser.h
  13. 4 4
      src/libs/hsql/include/parser/flex_lexer.h
  14. 0 3
      src/libs/hsql/include/parser/parser_typedef.h
  15. 30 31
      src/libs/hsql/include/sql/AlterStatement.h
  16. 34 42
      src/libs/hsql/include/sql/ColumnType.h
  17. 64 80
      src/libs/hsql/include/sql/CreateStatement.h
  18. 11 11
      src/libs/hsql/include/sql/DeleteStatement.h
  19. 13 20
      src/libs/hsql/include/sql/DropStatement.h
  20. 9 9
      src/libs/hsql/include/sql/ExecuteStatement.h
  21. 11 11
      src/libs/hsql/include/sql/ExportStatement.h
  22. 122 123
      src/libs/hsql/include/sql/Expr.h
  23. 16 16
      src/libs/hsql/include/sql/ImportStatement.h
  24. 14 17
      src/libs/hsql/include/sql/InsertStatement.h
  25. 10 10
      src/libs/hsql/include/sql/PrepareStatement.h
  26. 33 35
      src/libs/hsql/include/sql/SQLStatement.h
  27. 107 103
      src/libs/hsql/include/sql/SelectStatement.h
  28. 11 15
      src/libs/hsql/include/sql/ShowStatement.h
  29. 59 71
      src/libs/hsql/include/sql/Table.h
  30. 10 14
      src/libs/hsql/include/sql/TransactionStatement.h
  31. 15 15
      src/libs/hsql/include/sql/UpdateStatement.h
  32. 8 8
      src/libs/hsql/include/sql/statements.h
  33. 19 19
      src/libs/hsql/include/util/sqlhelper.h
  34. 二進制
      src/libs/hsql/libs/libsqlparser.a
  35. 二進制
      src/libs/hsql/libs/libsqlparser.so
  36. 2 2
      src/rule/rule.cc
  37. 1 1
      src/rule/rule.h
  38. 53 22
      tests/test_agent_cache_only.py
  39. 60 22
      tests/test_dtcd_cache_only.py

+ 10 - 1
.github/workflows/build-and-test.yml

@@ -23,7 +23,16 @@ jobs:
         
       - name: Install dependency
         run: |
-          sudo apt-get install -y make zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev
+          sudo apt-get install -y make zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev wget
+
+      - name: update hsql
+        run: |
+          wget https://github.com/DTC8/sql-parser/releases/download/hsql.forked-v1/hsql.forked-v1.tar.gz -O hsql.tar.gz
+          tar -zxvf hsql.tar.gz
+          cd hsql
+          cp -rf include/ ${{github.workspace}}/src/libs/hsql/
+          cp -f libs/libsqlparser.so ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.so
+          cp -f libs/libsqlparser.a ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.a
     
       - name: cmake project
         run: |

+ 12 - 3
.github/workflows/release.yml

@@ -25,6 +25,15 @@ jobs:
       - name: Install dependency
         run: |
           sudo apt-get install -y make zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev wget
+
+      - name: update hsql
+        run: |
+          wget https://github.com/DTC8/sql-parser/releases/download/hsql.forked-v1/hsql.forked-v1.tar.gz -O hsql.tar.gz
+          tar -zxvf hsql.tar.gz
+          cd hsql
+          cp -rf include/ ${{github.workspace}}/src/libs/hsql/
+          cp -f libs/libsqlparser.so ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.so
+          cp -f libs/libsqlparser.a ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.a          
     
       - name: cmake project
         run: |
@@ -83,8 +92,8 @@ jobs:
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         with:
-          tag_name: dtc-v2.0.0-rc3
-          release_name: dtc-v2.0.0-rc3
+          tag_name: dtc-v2.0.1
+          release_name: dtc-v2.0.1
           draft: false
           prerelease: true
 
@@ -96,5 +105,5 @@ jobs:
         with:
           upload_url: ${{ steps.create_release.outputs.upload_url }}
           asset_path: ${{github.workspace}}/build/dtc.tar.gz
-          asset_name: dtc-v2.0.0-rc3.tar.gz
+          asset_name: dtc-v2.0.1.tar.gz
           asset_content_type: application/gzip

+ 10 - 1
.github/workflows/ubuntu-18.04&gcc-4.9.yml

@@ -23,7 +23,16 @@ jobs:
       
     - name: install dependency
       run: |
-        sudo apt-get install -y make zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev
+        sudo apt-get install -y make zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev wget
+
+    - name: update hsql
+      run: |
+        wget https://github.com/DTC8/sql-parser/releases/download/hsql.forked-v1/hsql.forked-v1.tar.gz -O hsql.tar.gz
+        tar -zxvf hsql.tar.gz
+        cd hsql
+        cp -rf include/ ${{github.workspace}}/src/libs/hsql/
+        cp -f libs/libsqlparser.so ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.so
+        cp -f libs/libsqlparser.a ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.a
       
     - name: cmake project
       run: |

+ 10 - 1
.github/workflows/ubuntu-20.04&gcc-4.9.yml

@@ -23,7 +23,16 @@ jobs:
       
     - name: install dependency
       run: |
-        sudo apt-get install -y make zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev
+        sudo apt-get install -y make zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev wget
+
+    - name: update hsql
+      run: |
+        wget https://github.com/DTC8/sql-parser/releases/download/hsql.forked-v1/hsql.forked-v1.tar.gz -O hsql.tar.gz
+        tar -zxvf hsql.tar.gz
+        cd hsql
+        cp -rf include/ ${{github.workspace}}/src/libs/hsql/
+        cp -f libs/libsqlparser.so ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.so
+        cp -f libs/libsqlparser.a ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.a
       
     - name: cmake project
       run: |

+ 10 - 1
.github/workflows/ubuntu-latest&gcc-4.9.yml

@@ -23,7 +23,16 @@ jobs:
       
     - name: install dependency
       run: |
-        sudo apt-get install -y make zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev
+        sudo apt-get install -y make zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev wget
+        
+    - name: update hsql
+      run: |
+        wget https://github.com/DTC8/sql-parser/releases/download/hsql.forked-v1/hsql.forked-v1.tar.gz -O hsql.tar.gz
+        tar -zxvf hsql.tar.gz
+        cd hsql
+        cp -rf include/ ${{github.workspace}}/src/libs/hsql/
+        cp -f libs/libsqlparser.so ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.so
+        cp -f libs/libsqlparser.a ${{github.workspace}}/src/libs/hsql/libs/libsqlparser.a        
       
     - name: cmake project
       run: |

+ 7 - 0
script/hsql-update.sh

@@ -0,0 +1,7 @@
+wget https://github.com/DTC8/sql-parser/releases/download/hsql.forked-v1/hsql.forked-v1.tar.gz -O hsql.tar.gz
+tar -zxvf hsql.tar.gz
+cp -rf hsql/include/ ../src/libs/hsql/
+cp -f hsql/libs/libsqlparser.so ../src/libs/hsql/libs/libsqlparser.so
+cp -f hsql/libs/libsqlparser.a ../src/libs/hsql/libs/libsqlparser.a
+rm -rf hsql/
+rm -rf hsql.tar.gz

+ 1 - 1
src/agent/da.c

@@ -372,7 +372,7 @@ static bool da_test_conf(struct instance *dai) {
 }
 
 static void da_log_init(struct instance *dai) {
-	_init_log_("agent", dai->log_dir);
+	_init_log_("dtcagent", dai->log_dir);
 	_set_log_level_(dai->log_level);
 	_set_remote_log_fd_();
 }

+ 4 - 2
src/agent/my/my_parse.c

@@ -707,11 +707,13 @@ int my_get_route_key(uint8_t *sql, int sql_len, int *start_offset,
 		     int *end_offset, const char* dbname, struct msg* r)
 {
 	int i = 0;
-	struct string str;
+	struct string str, ostr;
 	int ret = 0;
 	int layer = 0;
 	string_init(&str);
 	string_copy(&str, sql, sql_len);
+	string_init(&ostr);
+	string_copy(&ostr, sql, sql_len);
 
 	if (string_empty(&str))
 		return -1;
@@ -760,7 +762,7 @@ int my_get_route_key(uint8_t *sql, int sql_len, int *start_offset,
 	log_debug("strkey type: %d", r->keytype);
 
 	//agent sql route, rule engine
-	layer = rule_sql_match(str.data, dbname, strlen(conf_path) > 0 ? conf_path : NULL);
+	layer = rule_sql_match(str.data, ostr.data, dbname, strlen(conf_path) > 0 ? conf_path : NULL);
 	log_debug("rule layer: %d", layer);
 
 	if(layer != 1)

+ 34 - 0
src/libs/common/my/my_request.cc

@@ -247,11 +247,45 @@ bool MyRequest::get_key(DTCValue *key, char *key_name)
 
 uint32_t MyRequest::get_limit_start()
 {
+	int t = m_result.getStatement(0)->type();
+	if (t != hsql::StatementType::kStmtSelect) {
+		return 0;
+	}
+	hsql::SelectStatement *stmt = get_result()->getStatement(0);
+	LimitDescription* limit = stmt->limit;
+	if(limit)
+	{
+		if(limit->offset)
+		{
+			int val = limit->offset->ival;
+			log4cplus_debug("limit- offset: %d", val);
+			if(val >= 0)
+				return val;
+		}
+	}
+
 	return 0;
 }
 
 uint32_t MyRequest::get_limit_count()
 {
+	int t = m_result.getStatement(0)->type();
+	if (t != hsql::StatementType::kStmtSelect) {
+		return 0;
+	}
+	hsql::SelectStatement *stmt = get_result()->getStatement(0);
+	LimitDescription* limit = stmt->limit;
+	if(limit)
+	{
+		if(limit->limit)
+		{
+			int val = limit->limit->ival;
+			log4cplus_debug("limit- limit: %d", val);
+			if(val >= 0)
+				return val;
+		}
+	}
+
 	return 0;
 }
 

+ 25 - 28
src/libs/hsql/include/SQLParser.h

@@ -6,33 +6,30 @@
 
 namespace hsql {
 
-  // Static methods used to parse SQL strings.
-  class SQLParser {
-   public:
-
-    // Parses a given constant character SQL string into the result object.
-    // Returns true if the lexer and parser could run without internal errors.
-    // This does NOT mean that the SQL string was valid SQL. To check that
-    // you need to check result->isValid();
-    static bool parse(const std::string& sql, SQLParserResult* result);
-
-    // Run tokenization on the given string and store the tokens in the output vector.
-    static bool tokenize(const std::string& sql, std::vector<int16_t>* tokens);
-
-    // Deprecated.
-    // Old method to parse SQL strings. Replaced by parse().
-    static bool parseSQLString(const char* sql, SQLParserResult* result);
-
-    // Deprecated.
-    // Old method to parse SQL strings. Replaced by parse().
-    static bool parseSQLString(const std::string& sql, SQLParserResult* result);
-
-   private:
-    SQLParser();
-  };
-
-
-} // namespace hsql
-
+// Static methods used to parse SQL strings.
+class SQLParser {
+ public:
+  // Parses a given constant character SQL string into the result object.
+  // Returns true if the lexer and parser could run without internal errors.
+  // This does NOT mean that the SQL string was valid SQL. To check that
+  // you need to check result->isValid();
+  static bool parse(const std::string& sql, SQLParserResult* result);
+
+  // Run tokenization on the given string and store the tokens in the output vector.
+  static bool tokenize(const std::string& sql, std::vector<int16_t>* tokens);
+
+  // Deprecated.
+  // Old method to parse SQL strings. Replaced by parse().
+  static bool parseSQLString(const char* sql, SQLParserResult* result);
+
+  // Deprecated.
+  // Old method to parse SQL strings. Replaced by parse().
+  static bool parseSQLString(const std::string& sql, SQLParserResult* result);
+
+ private:
+  SQLParser();
+};
+
+}  // namespace hsql
 
 #endif

+ 62 - 62
src/libs/hsql/include/SQLParserResult.h

@@ -4,91 +4,91 @@
 #include "sql/SQLStatement.h"
 
 namespace hsql {
-  // Represents the result of the SQLParser.
-  // If parsing was successful it contains a list of SQLStatement.
-  class SQLParserResult {
-   public:
-    // Initialize with empty statement list.
-    SQLParserResult();
+// Represents the result of the SQLParser.
+// If parsing was successful it contains a list of SQLStatement.
+class SQLParserResult {
+ public:
+  // Initialize with empty statement list.
+  SQLParserResult();
 
-    // Initialize with a single statement.
-    // Takes ownership of the statement.
-    SQLParserResult(SQLStatement* stmt);
+  // Initialize with a single statement.
+  // Takes ownership of the statement.
+  SQLParserResult(SQLStatement* stmt);
 
-    // Move constructor.
-    SQLParserResult(SQLParserResult&& moved);
-    SQLParserResult &operator=(SQLParserResult&& moved);
+  // Move constructor.
+  SQLParserResult(SQLParserResult&& moved);
+  SQLParserResult& operator=(SQLParserResult&& moved);
 
-    // Deletes all statements in the result.
-    virtual ~SQLParserResult();
+  // Deletes all statements in the result.
+  virtual ~SQLParserResult();
 
-    // Set whether parsing was successful.
-    void setIsValid(bool isValid);
+  // Set whether parsing was successful.
+  void setIsValid(bool isValid);
 
-    // Returns true if parsing was successful.
-    bool isValid() const;
+  // Returns true if parsing was successful.
+  bool isValid() const;
 
-    // Returns the number of statements in the result.
-    size_t size() const;
+  // Returns the number of statements in the result.
+  size_t size() const;
 
-    // Set the details of the error, if available.
-    // Takes ownership of errorMsg.
-    void setErrorDetails(char* errorMsg, int errorLine, int errorColumn);
+  // Set the details of the error, if available.
+  // Takes ownership of errorMsg.
+  void setErrorDetails(char* errorMsg, int errorLine, int errorColumn);
 
-    // Returns the error message, if an error occurred.
-    const char* errorMsg() const;
+  // Returns the error message, if an error occurred.
+  const char* errorMsg() const;
 
-    // Returns the line number of the occurrance of the error in the query.
-    int errorLine() const;
+  // Returns the line number of the occurrance of the error in the query.
+  int errorLine() const;
 
-    // Returns the column number of the occurrance of the error in the query.
-    int errorColumn() const;
+  // Returns the column number of the occurrance of the error in the query.
+  int errorColumn() const;
 
-    // Adds a statement to the result list of statements.
-    // SQLParserResult takes ownership of the statement.
-    void addStatement(SQLStatement* stmt);
+  // Adds a statement to the result list of statements.
+  // SQLParserResult takes ownership of the statement.
+  void addStatement(SQLStatement* stmt);
 
-    // Gets the SQL statement with the given index.
-    const SQLStatement* getStatement(size_t index) const;
+  // Gets the SQL statement with the given index.
+  const SQLStatement* getStatement(size_t index) const;
 
-    // Gets the non const SQL statement with the given index.
-    SQLStatement* getMutableStatement(size_t index);
+  // Gets the non const SQL statement with the given index.
+  SQLStatement* getMutableStatement(size_t index);
 
-    // Get the list of all statements.
-    const std::vector<SQLStatement*>& getStatements() const;
+  // Get the list of all statements.
+  const std::vector<SQLStatement*>& getStatements() const;
 
-    // Returns a copy of the list of all statements in this result.
-    // Removes them from this result.
-    std::vector<SQLStatement*> releaseStatements();
+  // Returns a copy of the list of all statements in this result.
+  // Removes them from this result.
+  std::vector<SQLStatement*> releaseStatements();
 
-    // Deletes all statements and other data within the result.
-    void reset();
+  // Deletes all statements and other data within the result.
+  void reset();
 
-    // Does NOT take ownership.
-    void addParameter(Expr* parameter);
+  // Does NOT take ownership.
+  void addParameter(Expr* parameter);
 
-    const std::vector<Expr*>& parameters();
+  const std::vector<Expr*>& parameters();
 
-   private:
-    // List of statements within the result.
-    std::vector<SQLStatement*> statements_;
+ private:
+  // List of statements within the result.
+  std::vector<SQLStatement*> statements_;
 
-    // Flag indicating the parsing was successful.
-    bool isValid_;
+  // Flag indicating the parsing was successful.
+  bool isValid_;
 
-    // Error message, if an error occurred.
-    char* errorMsg_;
+  // Error message, if an error occurred.
+  char* errorMsg_;
 
-    // Line number of the occurrance of the error in the query.
-    int errorLine_;
+  // Line number of the occurrance of the error in the query.
+  int errorLine_;
 
-    // Column number of the occurrance of the error in the query.
-    int errorColumn_;
+  // Column number of the occurrance of the error in the query.
+  int errorColumn_;
 
-    // Does NOT have ownership.
-    std::vector<Expr*> parameters_;
-  };
+  // Does NOT have ownership.
+  std::vector<Expr*> parameters_;
+};
 
-} // namespace hsql
+}  // namespace hsql
 
-#endif // SQLPARSER_SQLPARSER_RESULT_H
+#endif  // SQLPARSER_SQLPARSER_RESULT_H

+ 427 - 252
src/libs/hsql/include/parser/bison_parser.h

@@ -1,9 +1,8 @@
-/* A Bison parser, made by GNU Bison 3.8.1.  */
+/* A Bison parser, made by GNU Bison 3.0.4.  */
 
 /* Bison interface for Yacc-like parsers in C
 
-   Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
-   Inc.
+   Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -16,7 +15,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* As a special exception, you may create a larger work that contains
    part or all of the Bison parser skeleton and distribute that work
@@ -31,12 +30,8 @@
    This special exception was added by the Free Software Foundation in
    version 2.2 of Bison.  */
 
-/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
-   especially those whose name start with YY_ or yy_.  They are
-   private implementation details that can be changed or removed.  */
-
-#ifndef YY_HSQL_BISON_PARSER_H_INCLUDED
-# define YY_HSQL_BISON_PARSER_H_INCLUDED
+#ifndef YY_HSQL_BISON_PARSER_TAB_H_INCLUDED
+# define YY_HSQL_BISON_PARSER_TAB_H_INCLUDED
 /* Debug traces.  */
 #ifndef HSQL_DEBUG
 # if defined YYDEBUG
@@ -46,276 +41,458 @@
 #   define HSQL_DEBUG 0
 #  endif
 # else /* ! defined YYDEBUG */
-#  define HSQL_DEBUG 0
+#  define HSQL_DEBUG 1
 # endif /* ! defined YYDEBUG */
 #endif  /* ! defined HSQL_DEBUG */
 #if HSQL_DEBUG
 extern int hsql_debug;
 #endif
 /* "%code requires" blocks.  */
-#line 35 "bison_parser.y"
+#line 38 "bison_parser.y" /* yacc.c:1909  */
 
-// %code requires block
+  // clang-format on
+  // %code requires block
 
-#include "../sql/statements.h"
 #include "../SQLParserResult.h"
+#include "../sql/statements.h"
 #include "parser_typedef.h"
 
 // Auto update column and line number
-#define YY_USER_ACTION \
-		yylloc->first_line = yylloc->last_line; \
-		yylloc->first_column = yylloc->last_column; \
-		for(int i = 0; yytext[i] != '\0'; i++) { \
-			yylloc->total_column++; \
-			yylloc->string_length++; \
-				if(yytext[i] == '\n') { \
-						yylloc->last_line++; \
-						yylloc->last_column = 0; \
-				} \
-				else { \
-						yylloc->last_column++; \
-				} \
-		}
+#define YY_USER_ACTION                        \
+  yylloc->first_line = yylloc->last_line;     \
+  yylloc->first_column = yylloc->last_column; \
+  for (int i = 0; yytext[i] != '\0'; i++) {   \
+    yylloc->total_column++;                   \
+    yylloc->string_length++;                  \
+    if (yytext[i] == '\n') {                  \
+      yylloc->last_line++;                    \
+      yylloc->last_column = 0;                \
+    } else {                                  \
+      yylloc->last_column++;                  \
+    }                                         \
+  }
 
-#line 81 "bison_parser.h"
+#line 76 "bison_parser.tab.h" /* yacc.c:1909  */
 
-/* Token kinds.  */
+/* Token type.  */
 #ifndef HSQL_TOKENTYPE
 # define HSQL_TOKENTYPE
   enum hsql_tokentype
   {
-    SQL_HSQL_EMPTY = -2,
-    SQL_YYEOF = 0,                 /* "end of file"  */
-    SQL_HSQL_error = 256,          /* error  */
-    SQL_HSQL_UNDEF = 257,          /* "invalid token"  */
-    SQL_IDENTIFIER = 258,          /* IDENTIFIER  */
-    SQL_STRING = 259,              /* STRING  */
-    SQL_FLOATVAL = 260,            /* FLOATVAL  */
-    SQL_INTVAL = 261,              /* INTVAL  */
-    SQL_DEALLOCATE = 262,          /* DEALLOCATE  */
-    SQL_PARAMETERS = 263,          /* PARAMETERS  */
-    SQL_INTERSECT = 264,           /* INTERSECT  */
-    SQL_TEMPORARY = 265,           /* TEMPORARY  */
-    SQL_TIMESTAMP = 266,           /* TIMESTAMP  */
-    SQL_DISTINCT = 267,            /* DISTINCT  */
-    SQL_NVARCHAR = 268,            /* NVARCHAR  */
-    SQL_RESTRICT = 269,            /* RESTRICT  */
-    SQL_TRUNCATE = 270,            /* TRUNCATE  */
-    SQL_ANALYZE = 271,             /* ANALYZE  */
-    SQL_BETWEEN = 272,             /* BETWEEN  */
-    SQL_CASCADE = 273,             /* CASCADE  */
-    SQL_COLUMNS = 274,             /* COLUMNS  */
-    SQL_CONTROL = 275,             /* CONTROL  */
-    SQL_DEFAULT = 276,             /* DEFAULT  */
-    SQL_EXECUTE = 277,             /* EXECUTE  */
-    SQL_EXPLAIN = 278,             /* EXPLAIN  */
-    SQL_INTEGER = 279,             /* INTEGER  */
-    SQL_NATURAL = 280,             /* NATURAL  */
-    SQL_PREPARE = 281,             /* PREPARE  */
-    SQL_PRIMARY = 282,             /* PRIMARY  */
-    SQL_SCHEMAS = 283,             /* SCHEMAS  */
-    SQL_CHARACTER = 284,           /* CHARACTER  */
-    SQL_VARYING = 285,             /* VARYING  */
-    SQL_REAL = 286,                /* REAL  */
-    SQL_DECIMAL = 287,             /* DECIMAL  */
-    SQL_SPATIAL = 288,             /* SPATIAL  */
-    SQL_VARCHAR = 289,             /* VARCHAR  */
-    SQL_VIRTUAL = 290,             /* VIRTUAL  */
-    SQL_DESCRIBE = 291,            /* DESCRIBE  */
-    SQL_BEFORE = 292,              /* BEFORE  */
-    SQL_COLUMN = 293,              /* COLUMN  */
-    SQL_CREATE = 294,              /* CREATE  */
-    SQL_DELETE = 295,              /* DELETE  */
-    SQL_DIRECT = 296,              /* DIRECT  */
-    SQL_DOUBLE = 297,              /* DOUBLE  */
-    SQL_ESCAPE = 298,              /* ESCAPE  */
-    SQL_EXCEPT = 299,              /* EXCEPT  */
-    SQL_EXISTS = 300,              /* EXISTS  */
-    SQL_EXTRACT = 301,             /* EXTRACT  */
-    SQL_CAST = 302,                /* CAST  */
-    SQL_FORMAT = 303,              /* FORMAT  */
-    SQL_GLOBAL = 304,              /* GLOBAL  */
-    SQL_HAVING = 305,              /* HAVING  */
-    SQL_IMPORT = 306,              /* IMPORT  */
-    SQL_INSERT = 307,              /* INSERT  */
-    SQL_ISNULL = 308,              /* ISNULL  */
-    SQL_OFFSET = 309,              /* OFFSET  */
-    SQL_RENAME = 310,              /* RENAME  */
-    SQL_SCHEMA = 311,              /* SCHEMA  */
-    SQL_SELECT = 312,              /* SELECT  */
-    SQL_SORTED = 313,              /* SORTED  */
-    SQL_TABLES = 314,              /* TABLES  */
-    SQL_UNIQUE = 315,              /* UNIQUE  */
-    SQL_UNLOAD = 316,              /* UNLOAD  */
-    SQL_UPDATE = 317,              /* UPDATE  */
-    SQL_VALUES = 318,              /* VALUES  */
-    SQL_AFTER = 319,               /* AFTER  */
-    SQL_ALTER = 320,               /* ALTER  */
-    SQL_CROSS = 321,               /* CROSS  */
-    SQL_DELTA = 322,               /* DELTA  */
-    SQL_FLOAT = 323,               /* FLOAT  */
-    SQL_GROUP = 324,               /* GROUP  */
-    SQL_INDEX = 325,               /* INDEX  */
-    SQL_INNER = 326,               /* INNER  */
-    SQL_LIMIT = 327,               /* LIMIT  */
-    SQL_LOCAL = 328,               /* LOCAL  */
-    SQL_MERGE = 329,               /* MERGE  */
-    SQL_MINUS = 330,               /* MINUS  */
-    SQL_ORDER = 331,               /* ORDER  */
-    SQL_OUTER = 332,               /* OUTER  */
-    SQL_RIGHT = 333,               /* RIGHT  */
-    SQL_TABLE = 334,               /* TABLE  */
-    SQL_UNION = 335,               /* UNION  */
-    SQL_USING = 336,               /* USING  */
-    SQL_WHERE = 337,               /* WHERE  */
-    SQL_CALL = 338,                /* CALL  */
-    SQL_CASE = 339,                /* CASE  */
-    SQL_CHAR = 340,                /* CHAR  */
-    SQL_COPY = 341,                /* COPY  */
-    SQL_DATE = 342,                /* DATE  */
-    SQL_DATETIME = 343,            /* DATETIME  */
-    SQL_DESC = 344,                /* DESC  */
-    SQL_DROP = 345,                /* DROP  */
-    SQL_ELSE = 346,                /* ELSE  */
-    SQL_FILE = 347,                /* FILE  */
-    SQL_FROM = 348,                /* FROM  */
-    SQL_FULL = 349,                /* FULL  */
-    SQL_HASH = 350,                /* HASH  */
-    SQL_HINT = 351,                /* HINT  */
-    SQL_INTO = 352,                /* INTO  */
-    SQL_JOIN = 353,                /* JOIN  */
-    SQL_LEFT = 354,                /* LEFT  */
-    SQL_LIKE = 355,                /* LIKE  */
-    SQL_LOAD = 356,                /* LOAD  */
-    SQL_LONG = 357,                /* LONG  */
-    SQL_NULL = 358,                /* NULL  */
-    SQL_PLAN = 359,                /* PLAN  */
-    SQL_SHOW = 360,                /* SHOW  */
-    SQL_TEXT = 361,                /* TEXT  */
-    SQL_THEN = 362,                /* THEN  */
-    SQL_TIME = 363,                /* TIME  */
-    SQL_VIEW = 364,                /* VIEW  */
-    SQL_WHEN = 365,                /* WHEN  */
-    SQL_WITH = 366,                /* WITH  */
-    SQL_ADD = 367,                 /* ADD  */
-    SQL_ALL = 368,                 /* ALL  */
-    SQL_AND = 369,                 /* AND  */
-    SQL_ASC = 370,                 /* ASC  */
-    SQL_END = 371,                 /* END  */
-    SQL_FOR = 372,                 /* FOR  */
-    SQL_INT = 373,                 /* INT  */
-    SQL_KEY = 374,                 /* KEY  */
-    SQL_NOT = 375,                 /* NOT  */
-    SQL_OFF = 376,                 /* OFF  */
-    SQL_SET = 377,                 /* SET  */
-    SQL_TOP = 378,                 /* TOP  */
-    SQL_AS = 379,                  /* AS  */
-    SQL_BY = 380,                  /* BY  */
-    SQL_IF = 381,                  /* IF  */
-    SQL_IN = 382,                  /* IN  */
-    SQL_IS = 383,                  /* IS  */
-    SQL_OF = 384,                  /* OF  */
-    SQL_ON = 385,                  /* ON  */
-    SQL_OR = 386,                  /* OR  */
-    SQL_TO = 387,                  /* TO  */
-    SQL_ARRAY = 388,               /* ARRAY  */
-    SQL_CONCAT = 389,              /* CONCAT  */
-    SQL_ILIKE = 390,               /* ILIKE  */
-    SQL_SECOND = 391,              /* SECOND  */
-    SQL_MINUTE = 392,              /* MINUTE  */
-    SQL_HOUR = 393,                /* HOUR  */
-    SQL_DAY = 394,                 /* DAY  */
-    SQL_MONTH = 395,               /* MONTH  */
-    SQL_YEAR = 396,                /* YEAR  */
-    SQL_SECONDS = 397,             /* SECONDS  */
-    SQL_MINUTES = 398,             /* MINUTES  */
-    SQL_HOURS = 399,               /* HOURS  */
-    SQL_DAYS = 400,                /* DAYS  */
-    SQL_MONTHS = 401,              /* MONTHS  */
-    SQL_YEARS = 402,               /* YEARS  */
-    SQL_INTERVAL = 403,            /* INTERVAL  */
-    SQL_TRUE = 404,                /* TRUE  */
-    SQL_FALSE = 405,               /* FALSE  */
-    SQL_TRANSACTION = 406,         /* TRANSACTION  */
-    SQL_BEGIN = 407,               /* BEGIN  */
-    SQL_COMMIT = 408,              /* COMMIT  */
-    SQL_ROLLBACK = 409,            /* ROLLBACK  */
-    SQL_EQUALS = 410,              /* EQUALS  */
-    SQL_NOTEQUALS = 411,           /* NOTEQUALS  */
-    SQL_LESS = 412,                /* LESS  */
-    SQL_GREATER = 413,             /* GREATER  */
-    SQL_LESSEQ = 414,              /* LESSEQ  */
-    SQL_GREATEREQ = 415,           /* GREATEREQ  */
-    SQL_NOTNULL = 416,             /* NOTNULL  */
-    SQL_UMINUS = 417               /* UMINUS  */
+    SQL_IDENTIFIER = 258,
+    SQL_STRING = 259,
+    SQL_FLOATVAL = 260,
+    SQL_INTVAL = 261,
+    SQL_DEALLOCATE = 262,
+    SQL_PARAMETERS = 263,
+    SQL_INTERSECT = 264,
+    SQL_TEMPORARY = 265,
+    SQL_TIMESTAMP = 266,
+    SQL_DISTINCT = 267,
+    SQL_NVARCHAR = 268,
+    SQL_RESTRICT = 269,
+    SQL_TRUNCATE = 270,
+    SQL_ANALYZE = 271,
+    SQL_BETWEEN = 272,
+    SQL_CASCADE = 273,
+    SQL_COLUMNS = 274,
+    SQL_CONTROL = 275,
+    SQL_DEFAULT = 276,
+    SQL_EXECUTE = 277,
+    SQL_EXPLAIN = 278,
+    SQL_INTEGER = 279,
+    SQL_NATURAL = 280,
+    SQL_PREPARE = 281,
+    SQL_PRIMARY = 282,
+    SQL_SCHEMAS = 283,
+    SQL_CHARACTER_VARYING = 284,
+    SQL_REAL = 285,
+    SQL_DECIMAL = 286,
+    SQL_SMALLINT = 287,
+    SQL_BIGINT = 288,
+    SQL_SPATIAL = 289,
+    SQL_VARCHAR = 290,
+    SQL_VIRTUAL = 291,
+    SQL_DESCRIBE = 292,
+    SQL_BEFORE = 293,
+    SQL_COLUMN = 294,
+    SQL_CREATE = 295,
+    SQL_DELETE = 296,
+    SQL_DIRECT = 297,
+    SQL_DOUBLE = 298,
+    SQL_ESCAPE = 299,
+    SQL_EXCEPT = 300,
+    SQL_EXISTS = 301,
+    SQL_EXTRACT = 302,
+    SQL_CAST = 303,
+    SQL_FORMAT = 304,
+    SQL_GLOBAL = 305,
+    SQL_HAVING = 306,
+    SQL_IMPORT = 307,
+    SQL_INSERT = 308,
+    SQL_ISNULL = 309,
+    SQL_OFFSET = 310,
+    SQL_RENAME = 311,
+    SQL_SCHEMA = 312,
+    SQL_SELECT = 313,
+    SQL_SORTED = 314,
+    SQL_TABLES = 315,
+    SQL_UNIQUE = 316,
+    SQL_UNLOAD = 317,
+    SQL_UPDATE = 318,
+    SQL_VALUES = 319,
+    SQL_AFTER = 320,
+    SQL_ALTER = 321,
+    SQL_CROSS = 322,
+    SQL_DATABASES = 323,
+    SQL_DATABASE = 324,
+    SQL_DELTA = 325,
+    SQL_FLOAT = 326,
+    SQL_GROUP = 327,
+    SQL_INDEX = 328,
+    SQL_INNER = 329,
+    SQL_LIMIT = 330,
+    SQL_LOCAL = 331,
+    SQL_MERGE = 332,
+    SQL_MINUS = 333,
+    SQL_ORDER = 334,
+    SQL_OUTER = 335,
+    SQL_RIGHT = 336,
+    SQL_TABLE = 337,
+    SQL_UNION = 338,
+    SQL_USING = 339,
+    SQL_WHERE = 340,
+    SQL_CALL = 341,
+    SQL_CASE = 342,
+    SQL_CHAR = 343,
+    SQL_COPY = 344,
+    SQL_DATE = 345,
+    SQL_DATETIME = 346,
+    SQL_DESC = 347,
+    SQL_DROP = 348,
+    SQL_ELSE = 349,
+    SQL_FILE = 350,
+    SQL_FROM = 351,
+    SQL_FULL = 352,
+    SQL_HASH = 353,
+    SQL_HINT = 354,
+    SQL_INTO = 355,
+    SQL_JOIN = 356,
+    SQL_LEFT = 357,
+    SQL_LIKE = 358,
+    SQL_LOAD = 359,
+    SQL_LONG = 360,
+    SQL_NULL = 361,
+    SQL_PLAN = 362,
+    SQL_SHOW = 363,
+    SQL_TEXT = 364,
+    SQL_THEN = 365,
+    SQL_TIME = 366,
+    SQL_VIEW = 367,
+    SQL_WHEN = 368,
+    SQL_WITH = 369,
+    SQL_ADD = 370,
+    SQL_ALL = 371,
+    SQL_AND = 372,
+    SQL_ASC = 373,
+    SQL_END = 374,
+    SQL_FOR = 375,
+    SQL_INT = 376,
+    SQL_KEY = 377,
+    SQL_NOT = 378,
+    SQL_OFF = 379,
+    SQL_SET = 380,
+    SQL_TOP = 381,
+    SQL_AS = 382,
+    SQL_BY = 383,
+    SQL_IF = 384,
+    SQL_IN = 385,
+    SQL_IS = 386,
+    SQL_OF = 387,
+    SQL_ON = 388,
+    SQL_OR = 389,
+    SQL_TO = 390,
+    SQL_NO = 391,
+    SQL_ARRAY = 392,
+    SQL_CONCAT = 393,
+    SQL_ILIKE = 394,
+    SQL_SECOND = 395,
+    SQL_MINUTE = 396,
+    SQL_HOUR = 397,
+    SQL_DAY = 398,
+    SQL_MONTH = 399,
+    SQL_YEAR = 400,
+    SQL_SECONDS = 401,
+    SQL_MINUTES = 402,
+    SQL_HOURS = 403,
+    SQL_DAYS = 404,
+    SQL_MONTHS = 405,
+    SQL_YEARS = 406,
+    SQL_INTERVAL = 407,
+    SQL_TRUE = 408,
+    SQL_FALSE = 409,
+    SQL_BOOLEAN = 410,
+    SQL_TRANSACTION = 411,
+    SQL_BEGIN = 412,
+    SQL_COMMIT = 413,
+    SQL_ROLLBACK = 414,
+    SQL_NOWAIT = 415,
+    SQL_SKIP = 416,
+    SQL_LOCKED = 417,
+    SQL_SHARE = 418,
+    SQL_EQUALS = 419,
+    SQL_NOTEQUALS = 420,
+    SQL_LESS = 421,
+    SQL_GREATER = 422,
+    SQL_LESSEQ = 423,
+    SQL_GREATEREQ = 424,
+    SQL_NOTNULL = 425,
+    SQL_UMINUS = 426
   };
-  typedef enum hsql_tokentype hsql_token_kind_t;
 #endif
+/* Tokens.  */
+#define SQL_IDENTIFIER 258
+#define SQL_STRING 259
+#define SQL_FLOATVAL 260
+#define SQL_INTVAL 261
+#define SQL_DEALLOCATE 262
+#define SQL_PARAMETERS 263
+#define SQL_INTERSECT 264
+#define SQL_TEMPORARY 265
+#define SQL_TIMESTAMP 266
+#define SQL_DISTINCT 267
+#define SQL_NVARCHAR 268
+#define SQL_RESTRICT 269
+#define SQL_TRUNCATE 270
+#define SQL_ANALYZE 271
+#define SQL_BETWEEN 272
+#define SQL_CASCADE 273
+#define SQL_COLUMNS 274
+#define SQL_CONTROL 275
+#define SQL_DEFAULT 276
+#define SQL_EXECUTE 277
+#define SQL_EXPLAIN 278
+#define SQL_INTEGER 279
+#define SQL_NATURAL 280
+#define SQL_PREPARE 281
+#define SQL_PRIMARY 282
+#define SQL_SCHEMAS 283
+#define SQL_CHARACTER_VARYING 284
+#define SQL_REAL 285
+#define SQL_DECIMAL 286
+#define SQL_SMALLINT 287
+#define SQL_BIGINT 288
+#define SQL_SPATIAL 289
+#define SQL_VARCHAR 290
+#define SQL_VIRTUAL 291
+#define SQL_DESCRIBE 292
+#define SQL_BEFORE 293
+#define SQL_COLUMN 294
+#define SQL_CREATE 295
+#define SQL_DELETE 296
+#define SQL_DIRECT 297
+#define SQL_DOUBLE 298
+#define SQL_ESCAPE 299
+#define SQL_EXCEPT 300
+#define SQL_EXISTS 301
+#define SQL_EXTRACT 302
+#define SQL_CAST 303
+#define SQL_FORMAT 304
+#define SQL_GLOBAL 305
+#define SQL_HAVING 306
+#define SQL_IMPORT 307
+#define SQL_INSERT 308
+#define SQL_ISNULL 309
+#define SQL_OFFSET 310
+#define SQL_RENAME 311
+#define SQL_SCHEMA 312
+#define SQL_SELECT 313
+#define SQL_SORTED 314
+#define SQL_TABLES 315
+#define SQL_UNIQUE 316
+#define SQL_UNLOAD 317
+#define SQL_UPDATE 318
+#define SQL_VALUES 319
+#define SQL_AFTER 320
+#define SQL_ALTER 321
+#define SQL_CROSS 322
+#define SQL_DATABASES 323
+#define SQL_DATABASE 324
+#define SQL_DELTA 325
+#define SQL_FLOAT 326
+#define SQL_GROUP 327
+#define SQL_INDEX 328
+#define SQL_INNER 329
+#define SQL_LIMIT 330
+#define SQL_LOCAL 331
+#define SQL_MERGE 332
+#define SQL_MINUS 333
+#define SQL_ORDER 334
+#define SQL_OUTER 335
+#define SQL_RIGHT 336
+#define SQL_TABLE 337
+#define SQL_UNION 338
+#define SQL_USING 339
+#define SQL_WHERE 340
+#define SQL_CALL 341
+#define SQL_CASE 342
+#define SQL_CHAR 343
+#define SQL_COPY 344
+#define SQL_DATE 345
+#define SQL_DATETIME 346
+#define SQL_DESC 347
+#define SQL_DROP 348
+#define SQL_ELSE 349
+#define SQL_FILE 350
+#define SQL_FROM 351
+#define SQL_FULL 352
+#define SQL_HASH 353
+#define SQL_HINT 354
+#define SQL_INTO 355
+#define SQL_JOIN 356
+#define SQL_LEFT 357
+#define SQL_LIKE 358
+#define SQL_LOAD 359
+#define SQL_LONG 360
+#define SQL_NULL 361
+#define SQL_PLAN 362
+#define SQL_SHOW 363
+#define SQL_TEXT 364
+#define SQL_THEN 365
+#define SQL_TIME 366
+#define SQL_VIEW 367
+#define SQL_WHEN 368
+#define SQL_WITH 369
+#define SQL_ADD 370
+#define SQL_ALL 371
+#define SQL_AND 372
+#define SQL_ASC 373
+#define SQL_END 374
+#define SQL_FOR 375
+#define SQL_INT 376
+#define SQL_KEY 377
+#define SQL_NOT 378
+#define SQL_OFF 379
+#define SQL_SET 380
+#define SQL_TOP 381
+#define SQL_AS 382
+#define SQL_BY 383
+#define SQL_IF 384
+#define SQL_IN 385
+#define SQL_IS 386
+#define SQL_OF 387
+#define SQL_ON 388
+#define SQL_OR 389
+#define SQL_TO 390
+#define SQL_NO 391
+#define SQL_ARRAY 392
+#define SQL_CONCAT 393
+#define SQL_ILIKE 394
+#define SQL_SECOND 395
+#define SQL_MINUTE 396
+#define SQL_HOUR 397
+#define SQL_DAY 398
+#define SQL_MONTH 399
+#define SQL_YEAR 400
+#define SQL_SECONDS 401
+#define SQL_MINUTES 402
+#define SQL_HOURS 403
+#define SQL_DAYS 404
+#define SQL_MONTHS 405
+#define SQL_YEARS 406
+#define SQL_INTERVAL 407
+#define SQL_TRUE 408
+#define SQL_FALSE 409
+#define SQL_BOOLEAN 410
+#define SQL_TRANSACTION 411
+#define SQL_BEGIN 412
+#define SQL_COMMIT 413
+#define SQL_ROLLBACK 414
+#define SQL_NOWAIT 415
+#define SQL_SKIP 416
+#define SQL_LOCKED 417
+#define SQL_SHARE 418
+#define SQL_EQUALS 419
+#define SQL_NOTEQUALS 420
+#define SQL_LESS 421
+#define SQL_GREATER 422
+#define SQL_LESSEQ 423
+#define SQL_GREATEREQ 424
+#define SQL_NOTNULL 425
+#define SQL_UMINUS 426
 
 /* Value type.  */
 #if ! defined HSQL_STYPE && ! defined HSQL_STYPE_IS_DECLARED
+
 union HSQL_STYPE
 {
-#line 95 "bison_parser.y"
+#line 98 "bison_parser.y" /* yacc.c:1909  */
+
+  // clang-format on
+  bool bval;
+  char* sval;
+  double fval;
+  int64_t ival;
+  uintmax_t uval;
 
-	bool      bval;
-	char*     sval;
-	double    fval;
-	int64_t   ival;
-	uintmax_t uval;
+  // statements
+  hsql::AlterStatement* alter_stmt;
+  hsql::CreateStatement* create_stmt;
+  hsql::DeleteStatement* delete_stmt;
+  hsql::DropStatement* drop_stmt;
+  hsql::ExecuteStatement* exec_stmt;
+  hsql::ExportStatement* export_stmt;
+  hsql::ImportStatement* import_stmt;
+  hsql::InsertStatement* insert_stmt;
+  hsql::PrepareStatement* prep_stmt;
+  hsql::SelectStatement* select_stmt;
+  hsql::ShowStatement* show_stmt;
+  hsql::SQLStatement* statement;
+  hsql::TransactionStatement* transaction_stmt;
+  hsql::UpdateStatement* update_stmt;
 
-	// statements
-	hsql::AlterStatement*       alter_stmt;
-	hsql::CreateStatement* 	    create_stmt;
-	hsql::DeleteStatement* 	    delete_stmt;
-	hsql::DropStatement*   	    drop_stmt;
-	hsql::ExecuteStatement*     exec_stmt;
-	hsql::ExportStatement* 	    export_stmt;
-	hsql::ImportStatement* 	    import_stmt;
-	hsql::InsertStatement* 	    insert_stmt;
-	hsql::PrepareStatement*     prep_stmt;
-	hsql::SelectStatement* 	    select_stmt;
-	hsql::ShowStatement*        show_stmt;
-	hsql::SQLStatement*         statement;
-	hsql::TransactionStatement* transaction_stmt;
-	hsql::UpdateStatement* 	    update_stmt;
-    
-	hsql::Alias*              alias_t;
-	hsql::AlterAction*        alter_action_t;
-	hsql::ColumnDefinition*   column_t;
-	hsql::ColumnSpecification column_specification_t;
-	hsql::ColumnType          column_type_t;
-	hsql::ConstraintType      column_constraint_t;
-	hsql::DatetimeField       datetime_field;
-	hsql::DropColumnAction*   drop_action_t;
-	hsql::Expr*               expr;
-	hsql::GroupByDescription* group_t;
-	hsql::ImportType          import_type_t;
-	hsql::JoinType            join_type;
-	hsql::LimitDescription*   limit;
-	hsql::OrderDescription*   order;
-	hsql::OrderType           order_type;
-	hsql::SetOperation*       set_operator_t;
-	hsql::TableConstraint*    table_constraint_t;
-	hsql::TableElement*       table_element_t;
-	hsql::TableName           table_name;
-	hsql::TableRef*           table;
-	hsql::UpdateClause*       update_t;
-	hsql::WithDescription*    with_description_t;
+  hsql::Alias* alias_t;
+  hsql::AlterAction* alter_action_t;
+  hsql::ColumnDefinition* column_t;
+  hsql::ColumnType column_type_t;
+  hsql::ConstraintType column_constraint_t;
+  hsql::DatetimeField datetime_field;
+  hsql::DropColumnAction* drop_action_t;
+  hsql::Expr* expr;
+  hsql::GroupByDescription* group_t;
+  hsql::ImportType import_type_t;
+  hsql::JoinType join_type;
+  hsql::LimitDescription* limit;
+  hsql::OrderDescription* order;
+  hsql::OrderType order_type;
+  hsql::SetOperation* set_operator_t;
+  hsql::TableConstraint* table_constraint_t;
+  hsql::TableElement* table_element_t;
+  hsql::TableName table_name;
+  hsql::TableRef* table;
+  hsql::UpdateClause* update_t;
+  hsql::WithDescription* with_description_t;
+  hsql::LockingClause* locking_t;
 
-	std::vector<char*>*                   str_vec;
-	std::vector<hsql::ConstraintType>*    column_constraint_vec;
-	std::vector<hsql::Expr*>*             expr_vec;
-	std::vector<hsql::OrderDescription*>* order_vec;
-	std::vector<hsql::SQLStatement*>*     stmt_vec;
-	std::vector<hsql::TableElement*>*     table_element_vec;
-	std::vector<hsql::TableRef*>*         table_vec;
-	std::vector<hsql::UpdateClause*>*     update_vec;
-	std::vector<hsql::WithDescription*>*  with_description_vec;
+  std::vector<char*>* str_vec;
+  std::set<hsql::ConstraintType>* column_constraint_set;
+  std::vector<hsql::Expr*>* expr_vec;
+  std::vector<hsql::OrderDescription*>* order_vec;
+  std::vector<hsql::SQLStatement*>* stmt_vec;
+  std::vector<hsql::TableElement*>* table_element_vec;
+  std::vector<hsql::TableRef*>* table_vec;
+  std::vector<hsql::UpdateClause*>* update_vec;
+  std::vector<hsql::WithDescription*>* with_description_vec;
+  std::vector<hsql::LockingClause*>* locking_clause_vec;
 
-#line 317 "bison_parser.h"
+  std::pair<int64_t, int64_t>* ival_pair;
 
+  hsql::RowLockMode lock_mode_t;
+  hsql::RowLockWaitPolicy lock_wait_policy_t;
+
+#line 494 "bison_parser.tab.h" /* yacc.c:1909  */
 };
+
 typedef union HSQL_STYPE HSQL_STYPE;
 # define HSQL_STYPE_IS_TRIVIAL 1
 # define HSQL_STYPE_IS_DECLARED 1
@@ -337,8 +514,6 @@ struct HSQL_LTYPE
 
 
 
-
 int hsql_parse (hsql::SQLParserResult* result, yyscan_t scanner);
 
-
-#endif /* !YY_HSQL_BISON_PARSER_H_INCLUDED  */
+#endif /* !YY_HSQL_BISON_PARSER_TAB_H_INCLUDED  */

+ 4 - 4
src/libs/hsql/include/parser/flex_lexer.h

@@ -2,9 +2,9 @@
 #define hsql_HEADER_H 1
 #define hsql_IN_HEADER 1
 
-#line 5 "flex_lexer.h"
+#line 6 "flex_lexer.h"
 
-#line 7 "flex_lexer.h"
+#line 8 "flex_lexer.h"
 
 #define  YY_INT_ALIGNED short int
 
@@ -730,9 +730,9 @@ extern int yylex \
 #undef yyTABLES_NAME
 #endif
 
-#line 270 "flex_lexer.l"
+#line 278 "flex_lexer.l"
 
 
-#line 736 "flex_lexer.h"
+#line 737 "flex_lexer.h"
 #undef hsql_IN_HEADER
 #endif /* hsql_HEADER_H */

+ 0 - 3
src/libs/hsql/include/parser/parser_typedef.h

@@ -3,17 +3,14 @@
 
 #include <vector>
 
-
 #ifndef YYtypeDEF_YY_SCANNER_T
 #define YYtypeDEF_YY_SCANNER_T
 typedef void* yyscan_t;
 #endif
 
-
 #define YYSTYPE HSQL_STYPE
 #define YYLTYPE HSQL_LTYPE
 
-
 struct HSQL_CUST_LTYPE {
   int first_line;
   int first_column;

+ 30 - 31
src/libs/hsql/include/sql/AlterStatement.h

@@ -6,36 +6,35 @@
 // Note: Implementations of constructors and destructors can be found in statements.cpp.
 namespace hsql {
 
-  enum ActionType {
-    DropColumn,
-  };
-
-  struct AlterAction {
-    AlterAction(ActionType type);
-    ActionType type;
-    virtual ~AlterAction();
-  };
-
-  struct DropColumnAction : AlterAction {
-    DropColumnAction(char* column_name);
-    char* columnName;
-    bool ifExists;
-
-    ~DropColumnAction() override;
-  };
-
-  // Represents SQL Alter Table statements.
-  // Example "ALTER TABLE students DROP COLUMN name;"
-  struct AlterStatement : SQLStatement {
-
-    AlterStatement(char* name, AlterAction* action);
-    ~AlterStatement() override;
-
-    char* schema;
-    bool ifTableExists;
-    char* name;
-    AlterAction* action;
-  };
-} // namespace hsql
+enum ActionType {
+  DropColumn,
+};
+
+struct AlterAction {
+  AlterAction(ActionType type);
+  ActionType type;
+  virtual ~AlterAction();
+};
+
+struct DropColumnAction : AlterAction {
+  DropColumnAction(char* column_name);
+  char* columnName;
+  bool ifExists;
+
+  ~DropColumnAction() override;
+};
+
+// Represents SQL Alter Table statements.
+// Example "ALTER TABLE students DROP COLUMN name;"
+struct AlterStatement : SQLStatement {
+  AlterStatement(char* name, AlterAction* action);
+  ~AlterStatement() override;
+
+  char* schema;
+  bool ifTableExists;
+  char* name;
+  AlterAction* action;
+};
+}  // namespace hsql
 
 #endif

+ 34 - 42
src/libs/hsql/include/sql/ColumnType.h

@@ -4,47 +4,39 @@
 #include <ostream>
 
 namespace hsql {
-  enum class DataType {
-    UNKNOWN,
-    INT,
-    LONG,
-    FLOAT,
-    DOUBLE,
-    DECIMAL,
-    REAL,
-    CHAR,
-    VARCHAR,
-    TEXT,
-    DATETIME,
-    DATE,
-    TIME,
-    SMALLINT,
-  };
-
-  struct ColumnSpecification {
-    ColumnSpecification() = default;
-    ColumnSpecification(int64_t precision, int64_t scale);
-    ColumnSpecification(int64_t precision);
-    int64_t precision;
-    int64_t scale;
-  };
-
-
-
-  // Represents the type of a column, e.g., FLOAT or VARCHAR(10)
-  struct ColumnType {
-    ColumnType() = default;
-    ColumnType(DataType data_type, int64_t length = 0,
-               ColumnSpecification column_specification = ColumnSpecification{});
-    DataType data_type;
-    int64_t length;  // Used for, e.g., VARCHAR(10)
-    ColumnSpecification columnSpecification; // used for, e.g. DECIMAL (6, 4) or TIME (5)
-  };
-
-  bool operator==(const ColumnType& lhs, const ColumnType& rhs);
-  bool operator!=(const ColumnType& lhs, const ColumnType& rhs);
-  std::ostream& operator<<(std::ostream&, const ColumnType&);
-
-} // namespace hsql
+enum class DataType {
+  UNKNOWN,
+  BIGINT,
+  BOOLEAN,
+  CHAR,
+  DATE,
+  DATETIME,
+  DECIMAL,
+  DOUBLE,
+  FLOAT,
+  INT,
+  LONG,
+  REAL,
+  SMALLINT,
+  TEXT,
+  TIME,
+  VARCHAR,
+};
+
+// Represents the type of a column, e.g., FLOAT or VARCHAR(10)
+struct ColumnType {
+  ColumnType() = default;
+  ColumnType(DataType data_type, int64_t length = 0, int64_t precision = 0, int64_t scale = 0);
+  DataType data_type;
+  int64_t length;     // Used for, e.g., VARCHAR(10)
+  int64_t precision;  // Used for, e.g., DECIMAL (6, 4) or TIME (5)
+  int64_t scale;      // Used for DECIMAL (6, 4)
+};
+
+bool operator==(const ColumnType& lhs, const ColumnType& rhs);
+bool operator!=(const ColumnType& lhs, const ColumnType& rhs);
+std::ostream& operator<<(std::ostream&, const ColumnType&);
+
+}  // namespace hsql
 
 #endif

+ 64 - 80
src/libs/hsql/include/sql/CreateStatement.h

@@ -1,102 +1,86 @@
 #ifndef SQLPARSER_CREATE_STATEMENT_H
 #define SQLPARSER_CREATE_STATEMENT_H
 
-#include "SQLStatement.h"
 #include "ColumnType.h"
+#include "SQLStatement.h"
 
 #include <ostream>
+#include <set>
 
 // Note: Implementations of constructors and destructors can be found in statements.cpp.
 namespace hsql {
-  struct SelectStatement;
-
-  enum struct ConstraintType {
-    None,
-    NotNull,
-    Null,
-    PrimaryKey,
-    Unique
-  };
-
-  // Superclass for both TableConstraint and Column Definition
-  struct TableElement {
-    virtual ~TableElement(){}
-  };
+struct SelectStatement;
 
-  // Represents definition of a table constraint
-  struct TableConstraint : TableElement {
-    TableConstraint(ConstraintType keyType, std::vector<char*>* columnNames);
+enum struct ConstraintType { None, NotNull, Null, PrimaryKey, Unique };
 
-    ~TableConstraint() override;
+// Superclass for both TableConstraint and Column Definition
+struct TableElement {
+  virtual ~TableElement() {}
+};
 
-    ConstraintType type;
-    std::vector<char*>* columnNames;
-  };
+// Represents definition of a table constraint
+struct TableConstraint : TableElement {
+  TableConstraint(ConstraintType keyType, std::vector<char*>* columnNames);
 
-  // Represents definition of a table column
-  struct ColumnDefinition: TableElement {
-    ColumnDefinition(char* name, ColumnType type, std::vector<ConstraintType>* column_constraints);
+  ~TableConstraint() override;
 
-    ~ColumnDefinition() override;
+  ConstraintType type;
+  std::vector<char*>* columnNames;
+};
 
-    void setNullableExplicit() {
-      nullable = false;
+// Represents definition of a table column
+struct ColumnDefinition : TableElement {
+  ColumnDefinition(char* name, ColumnType type, std::set<ConstraintType>* column_constraints);
 
-      for(unsigned long constraint_index = 0; constraint_index < column_constraints->size(); constraint_index++) {
-        if(column_constraints->at(constraint_index) == ConstraintType::Null) {
-          nullable = true;
-          column_constraints->erase(column_constraints->cbegin() + constraint_index);
-        } else if(column_constraints->at(constraint_index) == ConstraintType::NotNull) {
-          column_constraints->erase(column_constraints->cbegin() + constraint_index);
-        }
-      }
-    }
+  ~ColumnDefinition() override;
 
-    std::vector<ConstraintType>* column_constraints;
-    char* name;
-    ColumnType type;
-    bool nullable;
-  };
-
-  enum CreateType {
-    kCreateTable,
-    kCreateTableFromTbl, // Hyrise file format
-    kCreateView,
-    kCreateIndex
-  };
-
-  // Represents SQL Create statements.
-  // Example: "CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE)"
-  struct CreateStatement : SQLStatement {
-    CreateStatement(CreateType type);
-    ~CreateStatement() override;
-
-    void setColumnDefsAndConstraints(std::vector<TableElement*>* tableElements) {
-      columns = new std::vector<ColumnDefinition*>();
-      tableConstraints = new std::vector<TableConstraint*>();
-
-      for(auto tableElem: *tableElements) {
-        if(auto *colDef = dynamic_cast<ColumnDefinition*>(tableElem)) {
-          columns->emplace_back(colDef);
-        } else if(auto *tableConstraint = dynamic_cast<TableConstraint*>(tableElem)) {
-          tableConstraints->emplace_back(tableConstraint);
-        }
+  // By default, columns are nullable. However, we track if a column is explicitly requested to be nullable to
+  // notice conflicts with PRIMARY KEY table constraints.
+  bool trySetNullableExplicit() {
+    if (column_constraints->count(ConstraintType::NotNull) || column_constraints->count(ConstraintType::PrimaryKey)) {
+      if (column_constraints->count(ConstraintType::Null)) {
+        return false;
       }
+      nullable = false;
     }
 
-    CreateType type;
-    bool ifNotExists; // default: false
-    char* filePath;   // default: nullptr
-    char* schema;     // default: nullptr
-    char* tableName;  // default: nullptr
-    char* indexName;  // default: nullptr
-    std::vector<char*>* indexColumns; // default: nullptr
-    std::vector<ColumnDefinition*>* columns; // default: nullptr
-    std::vector<TableConstraint*>* tableConstraints; // default: nullptr
-    std::vector<char*>* viewColumns;
-    SelectStatement* select;
-  };
-
-} // namespace hsql
+    return true;
+  }
+
+  std::set<ConstraintType>* column_constraints;
+  char* name;
+  ColumnType type;
+  bool nullable;
+};
+
+enum CreateType {
+  kCreateTable,
+  kCreateTableFromTbl,  // Hyrise file format
+  kCreateView,
+  kCreateIndex
+};
+
+// Represents SQL Create statements.
+// Example: "CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE)"
+struct CreateStatement : SQLStatement {
+  CreateStatement(CreateType type);
+  ~CreateStatement() override;
+
+  void setColumnDefsAndConstraints(std::vector<TableElement*>* tableElements);
+
+  CreateType type;
+  bool ifNotExists;                                 // default: false
+  char* filePath;                                   // default: nullptr
+  char* schema;                                     // default: nullptr
+  char* tableName;                                  // default: nullptr
+  char* indexName;                                  // default: nullptr
+  std::vector<char*>* indexColumns;                 // default: nullptr
+  std::vector<ColumnDefinition*>* columns;          // default: nullptr
+  std::vector<TableConstraint*>* tableConstraints;  // default: nullptr
+  std::vector<char*>* viewColumns;
+  SelectStatement* select;
+};
+
+}  // namespace hsql
 
 #endif

+ 11 - 11
src/libs/hsql/include/sql/DeleteStatement.h

@@ -6,18 +6,18 @@
 // Note: Implementations of constructors and destructors can be found in statements.cpp.
 namespace hsql {
 
-  // Represents SQL Delete statements.
-  // Example: "DELETE FROM students WHERE grade > 3.0"
-  // Note: if (expr == nullptr) => delete all rows (truncate)
-  struct DeleteStatement : SQLStatement {
-    DeleteStatement();
-    ~DeleteStatement() override;
+// Represents SQL Delete statements.
+// Example: "DELETE FROM students WHERE grade > 3.0"
+// Note: if (expr == nullptr) => delete all rows (truncate)
+struct DeleteStatement : SQLStatement {
+  DeleteStatement();
+  ~DeleteStatement() override;
 
-    char* schema;
-    char* tableName;
-    Expr* expr;
-  };
+  char* schema;
+  char* tableName;
+  Expr* expr;
+};
 
-} // namespace hsql
+}  // namespace hsql
 
 #endif

+ 13 - 20
src/libs/hsql/include/sql/DropStatement.h

@@ -6,27 +6,20 @@
 // Note: Implementations of constructors and destructors can be found in statements.cpp.
 namespace hsql {
 
-  enum DropType {
-    kDropTable,
-    kDropSchema,
-    kDropIndex,
-    kDropView,
-    kDropPreparedStatement
-  };
+enum DropType { kDropTable, kDropSchema, kDropIndex, kDropView, kDropPreparedStatement };
 
-  // Represents SQL Delete statements.
-  // Example "DROP TABLE students;"
-  struct DropStatement : SQLStatement {
+// Represents SQL Delete statements.
+// Example "DROP TABLE students;"
+struct DropStatement : SQLStatement {
+  DropStatement(DropType type);
+  ~DropStatement() override;
 
-    DropStatement(DropType type);
-    ~DropStatement() override;
+  DropType type;
+  bool ifExists;
+  char* schema;
+  char* name;
+  char* indexName;
+};
 
-    DropType type;
-    bool ifExists;
-    char* schema;
-    char* name;
-    char* indexName;
-  };
-
-} // namespace hsql
+}  // namespace hsql
 #endif

+ 9 - 9
src/libs/hsql/include/sql/ExecuteStatement.h

@@ -5,16 +5,16 @@
 
 namespace hsql {
 
-  // Represents SQL Execute statements.
-  // Example: "EXECUTE ins_prep(100, "test", 2.3);"
-  struct ExecuteStatement : SQLStatement {
-    ExecuteStatement();
-    ~ExecuteStatement() override;
+// Represents SQL Execute statements.
+// Example: "EXECUTE ins_prep(100, "test", 2.3);"
+struct ExecuteStatement : SQLStatement {
+  ExecuteStatement();
+  ~ExecuteStatement() override;
 
-    char* name;
-    std::vector<Expr*>* parameters;
-  };
+  char* name;
+  std::vector<Expr*>* parameters;
+};
 
-} // namsepace hsql
+}  // namespace hsql
 
 #endif

+ 11 - 11
src/libs/hsql/include/sql/ExportStatement.h

@@ -5,18 +5,18 @@
 #include "SQLStatement.h"
 
 namespace hsql {
-  // Represents SQL Export statements.
-  struct ExportStatement : SQLStatement {
-    ExportStatement(ImportType type);
-    ~ExportStatement() override;
+// Represents SQL Export statements.
+struct ExportStatement : SQLStatement {
+  ExportStatement(ImportType type);
+  ~ExportStatement() override;
 
-    // ImportType is used for compatibility reasons
-    ImportType type;
-    char* filePath;
-    char* schema;
-    char* tableName;
-  };
+  // ImportType is used for compatibility reasons
+  ImportType type;
+  char* filePath;
+  char* schema;
+  char* tableName;
+};
 
-} // namespace hsql
+}  // namespace hsql
 
 #endif

+ 122 - 123
src/libs/hsql/include/sql/Expr.h

@@ -14,73 +14,73 @@ struct SelectStatement;
 char* substr(const char* source, int from, int to);
 
 enum ExprType {
-    kExprLiteralFloat,
-    kExprLiteralString,
-    kExprLiteralInt,
-    kExprLiteralNull,
-    kExprLiteralDate,
-    kExprLiteralInterval,
-    kExprStar,
-    kExprParameter,
-    kExprColumnRef,
-    kExprFunctionRef,
-    kExprOperator,
-    kExprSelect,
-    kExprHint,
-    kExprArray,
-    kExprArrayIndex,
-    kExprExtract,
-    kExprCast
+  kExprLiteralFloat,
+  kExprLiteralString,
+  kExprLiteralInt,
+  kExprLiteralNull,
+  kExprLiteralDate,
+  kExprLiteralInterval,
+  kExprStar,
+  kExprParameter,
+  kExprColumnRef,
+  kExprFunctionRef,
+  kExprOperator,
+  kExprSelect,
+  kExprHint,
+  kExprArray,
+  kExprArrayIndex,
+  kExprExtract,
+  kExprCast
 };
 
 // Operator types. These are important for expressions of type kExprOperator.
 enum OperatorType {
-    kOpNone,
-
-    // Ternary operator
-    kOpBetween,
-
-    // n-nary special case
-    kOpCase,
-    kOpCaseListElement,  // `WHEN expr THEN expr`
-
-    // Binary operators.
-    kOpPlus,
-    kOpMinus,
-    kOpAsterisk,
-    kOpSlash,
-    kOpPercentage,
-    kOpCaret,
-
-    kOpEquals,
-    kOpNotEquals,
-    kOpLess,
-    kOpLessEq,
-    kOpGreater,
-    kOpGreaterEq,
-    kOpLike,
-    kOpNotLike,
-    kOpILike,
-    kOpAnd,
-    kOpOr,
-    kOpIn,
-    kOpConcat,
-
-    // Unary operators.
-    kOpNot,
-    kOpUnaryMinus,
-    kOpIsNull,
-    kOpExists
+  kOpNone,
+
+  // Ternary operator
+  kOpBetween,
+
+  // n-nary special case
+  kOpCase,
+  kOpCaseListElement,  // `WHEN expr THEN expr`
+
+  // Binary operators.
+  kOpPlus,
+  kOpMinus,
+  kOpAsterisk,
+  kOpSlash,
+  kOpPercentage,
+  kOpCaret,
+
+  kOpEquals,
+  kOpNotEquals,
+  kOpLess,
+  kOpLessEq,
+  kOpGreater,
+  kOpGreaterEq,
+  kOpLike,
+  kOpNotLike,
+  kOpILike,
+  kOpAnd,
+  kOpOr,
+  kOpIn,
+  kOpConcat,
+
+  // Unary operators.
+  kOpNot,
+  kOpUnaryMinus,
+  kOpIsNull,
+  kOpExists
 };
 
 enum DatetimeField {
-    kDatetimeNone,
-    kDatetimeSecond,
-    kDatetimeMinute,
-    kDatetimeHour,
-    kDatetimeDay,
-    kDatetimeMonth,
-    kDatetimeYear,
+  kDatetimeNone,
+  kDatetimeSecond,
+  kDatetimeMinute,
+  kDatetimeHour,
+  kDatetimeDay,
+  kDatetimeMonth,
+  kDatetimeYear,
 };
 
 typedef struct Expr Expr;
@@ -89,114 +89,113 @@ typedef struct Expr Expr;
 // TODO: When destructing a placeholder expression, we might need to alter the
 // placeholder_list.
 struct Expr {
-    Expr(ExprType type);
-    virtual ~Expr();
+  Expr(ExprType type);
+  virtual ~Expr();
 
-    ExprType type;
+  ExprType type;
 
-    // TODO: Replace expressions by list.
-    Expr* expr;
-    Expr* expr2;
-    std::vector<Expr*>* exprList;
-    SelectStatement* select;
-    char* name;
-    char* table;
-    char* alias;
-    double fval;
-    int64_t ival;
-    int64_t ival2;
-    DatetimeField datetimeField;
-    ColumnType columnType;
-    bool isBoolLiteral;
+  // TODO: Replace expressions by list.
+  Expr* expr;
+  Expr* expr2;
+  std::vector<Expr*>* exprList;
+  SelectStatement* select;
+  char* name;
+  char* table;
+  char* alias;
+  double fval;
+  int64_t ival;
+  int64_t ival2;
+  DatetimeField datetimeField;
+  ColumnType columnType;
+  bool isBoolLiteral;
 
-    OperatorType opType;
-    bool distinct;
+  OperatorType opType;
+  bool distinct;
 
-    // Convenience accessor methods.
+  // Convenience accessor methods.
 
-    bool isType(ExprType exprType) const;
+  bool isType(ExprType exprType) const;
 
-    bool isLiteral() const;
+  bool isLiteral() const;
 
-    bool hasAlias() const;
+  bool hasAlias() const;
 
-    bool hasTable() const;
+  bool hasTable() const;
 
-    const char* getName() const;
+  const char* getName() const;
 
-    // Static constructors.
+  // Static constructors.
 
-    static Expr* make(ExprType type);
+  static Expr* make(ExprType type);
 
-    static Expr* makeOpUnary(OperatorType op, Expr* expr);
+  static Expr* makeOpUnary(OperatorType op, Expr* expr);
 
-    static Expr* makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2);
+  static Expr* makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2);
 
-    static Expr* makeBetween(Expr* expr, Expr* left, Expr* right);
+  static Expr* makeBetween(Expr* expr, Expr* left, Expr* right);
 
-    static Expr* makeCaseList(Expr* caseListElement);
+  static Expr* makeCaseList(Expr* caseListElement);
 
-    static Expr* makeCaseListElement(Expr* when, Expr* then);
+  static Expr* makeCaseListElement(Expr* when, Expr* then);
 
-    static Expr* caseListAppend(Expr* caseList, Expr* caseListElement);
+  static Expr* caseListAppend(Expr* caseList, Expr* caseListElement);
 
-    static Expr* makeCase(Expr* expr, Expr* when, Expr* elseExpr);
+  static Expr* makeCase(Expr* expr, Expr* when, Expr* elseExpr);
 
-    static Expr* makeLiteral(int64_t val);
+  static Expr* makeLiteral(int64_t val);
 
-    static Expr* makeLiteral(double val);
+  static Expr* makeLiteral(double val);
 
-    static Expr* makeLiteral(char* val);
+  static Expr* makeLiteral(char* val);
 
-    static Expr* makeLiteral(bool val);
+  static Expr* makeLiteral(bool val);
 
-    static Expr* makeNullLiteral();
+  static Expr* makeNullLiteral();
 
-    static Expr* makeDateLiteral(char* val);
+  static Expr* makeDateLiteral(char* val);
 
-    static Expr* makeIntervalLiteral(int64_t duration, DatetimeField unit);
+  static Expr* makeIntervalLiteral(int64_t duration, DatetimeField unit);
 
-    static Expr* makeColumnRef(char* name);
+  static Expr* makeColumnRef(char* name);
 
-    static Expr* makeColumnRef(char* table, char* name);
+  static Expr* makeColumnRef(char* table, char* name);
 
-    static Expr* makeStar(void);
+  static Expr* makeStar(void);
 
-    static Expr* makeStar(char* table);
+  static Expr* makeStar(char* table);
 
-    static Expr* makeFunctionRef(char* func_name, std::vector<Expr*>* exprList,
-                                 bool distinct);
+  static Expr* makeFunctionRef(char* func_name, std::vector<Expr*>* exprList, bool distinct);
 
-    static Expr* makeArray(std::vector<Expr*>* exprList);
+  static Expr* makeArray(std::vector<Expr*>* exprList);
 
-    static Expr* makeArrayIndex(Expr* expr, int64_t index);
+  static Expr* makeArrayIndex(Expr* expr, int64_t index);
 
-    static Expr* makeParameter(int id);
+  static Expr* makeParameter(int id);
 
-    static Expr* makeSelect(SelectStatement* select);
+  static Expr* makeSelect(SelectStatement* select);
 
-    static Expr* makeExists(SelectStatement* select);
+  static Expr* makeExists(SelectStatement* select);
 
-    static Expr* makeInOperator(Expr* expr, std::vector<Expr*>* exprList);
+  static Expr* makeInOperator(Expr* expr, std::vector<Expr*>* exprList);
 
-    static Expr* makeInOperator(Expr* expr, SelectStatement* select);
+  static Expr* makeInOperator(Expr* expr, SelectStatement* select);
 
-    static Expr* makeExtract(DatetimeField datetimeField1, Expr* expr);
+  static Expr* makeExtract(DatetimeField datetimeField1, Expr* expr);
 
-    static Expr* makeCast(Expr* expr, ColumnType columnType);
+  static Expr* makeCast(Expr* expr, ColumnType columnType);
 };
 
 // Zero initializes an Expr object and assigns it to a space in the heap
 // For Hyrise we still had to put in the explicit NULL constructor
 // http://www.ex-parrot.com/~chris/random/initialise.html
 // Unused
-#define ALLOC_EXPR(var, type)             \
-    Expr* var;                            \
-    do {                                  \
-        Expr zero = {type};               \
-        var = (Expr*)malloc(sizeof *var); \
-        *var = zero;                      \
-    } while (0);
+#define ALLOC_EXPR(var, type)         \
+  Expr* var;                          \
+  do {                                \
+    Expr zero = {type};               \
+    var = (Expr*)malloc(sizeof *var); \
+    *var = zero;                      \
+  } while (0);
 #undef ALLOC_EXPR
 
 }  // namespace hsql

+ 16 - 16
src/libs/hsql/include/sql/ImportStatement.h

@@ -4,24 +4,24 @@
 #include "SQLStatement.h"
 
 namespace hsql {
-  enum ImportType {
-    kImportCSV,
-    kImportTbl, // Hyrise file format
-    kImportBinary,
-    kImportAuto
-  };
+enum ImportType {
+  kImportCSV,
+  kImportTbl,  // Hyrise file format
+  kImportBinary,
+  kImportAuto
+};
 
-  // Represents SQL Import statements.
-  struct ImportStatement : SQLStatement {
-    ImportStatement(ImportType type);
-    ~ImportStatement() override;
+// Represents SQL Import statements.
+struct ImportStatement : SQLStatement {
+  ImportStatement(ImportType type);
+  ~ImportStatement() override;
 
-    ImportType type;
-    char* filePath;
-    char* schema;
-    char* tableName;
-  };
+  ImportType type;
+  char* filePath;
+  char* schema;
+  char* tableName;
+};
 
-} // namespace hsql
+}  // namespace hsql
 
 #endif

+ 14 - 17
src/libs/hsql/include/sql/InsertStatement.h

@@ -5,25 +5,22 @@
 #include "SelectStatement.h"
 
 namespace hsql {
-  enum InsertType {
-    kInsertValues,
-    kInsertSelect
-  };
+enum InsertType { kInsertValues, kInsertSelect };
 
-  // Represents SQL Insert statements.
-  // Example: "INSERT INTO students VALUES ('Max', 1112233, 'Musterhausen', 2.3)"
-  struct InsertStatement : SQLStatement {
-    InsertStatement(InsertType type);
-    ~InsertStatement() override;
+// Represents SQL Insert statements.
+// Example: "INSERT INTO students VALUES ('Max', 1112233, 'Musterhausen', 2.3)"
+struct InsertStatement : SQLStatement {
+  InsertStatement(InsertType type);
+  ~InsertStatement() override;
 
-    InsertType type;
-    char* schema;
-    char* tableName;
-    std::vector<char*>* columns;
-    std::vector<Expr*>* values;
-    SelectStatement* select;
-  };
+  InsertType type;
+  char* schema;
+  char* tableName;
+  std::vector<char*>* columns;
+  std::vector<Expr*>* values;
+  SelectStatement* select;
+};
 
-} // namsepace hsql
+}  // namespace hsql
 
 #endif

+ 10 - 10
src/libs/hsql/include/sql/PrepareStatement.h

@@ -5,18 +5,18 @@
 
 namespace hsql {
 
-  // Represents SQL Prepare statements.
-  // Example: PREPARE test FROM 'SELECT * FROM test WHERE a = ?;'
-  struct PrepareStatement : SQLStatement {
-    PrepareStatement();
-    ~PrepareStatement() override;
+// Represents SQL Prepare statements.
+// Example: PREPARE test FROM 'SELECT * FROM test WHERE a = ?;'
+struct PrepareStatement : SQLStatement {
+  PrepareStatement();
+  ~PrepareStatement() override;
 
-    char* name;
+  char* name;
 
-    // The query that is supposed to be prepared.
-    char* query;
-  };
+  // The query that is supposed to be prepared.
+  char* query;
+};
 
-} // namsepace hsql
+}  // namespace hsql
 
 #endif

+ 33 - 35
src/libs/hsql/include/sql/SQLStatement.h

@@ -6,48 +6,46 @@
 #include "Expr.h"
 
 namespace hsql {
-  enum StatementType {
-    kStmtError, // unused
-    kStmtSelect,
-    kStmtImport,
-    kStmtInsert,
-    kStmtUpdate,
-    kStmtDelete,
-    kStmtCreate,
-    kStmtDrop,
-    kStmtPrepare,
-    kStmtExecute,
-    kStmtExport,
-    kStmtRename,
-    kStmtAlter,
-    kStmtShow,
-    kStmtTransaction
-  };
+enum StatementType {
+  kStmtError,  // unused
+  kStmtSelect,
+  kStmtImport,
+  kStmtInsert,
+  kStmtUpdate,
+  kStmtDelete,
+  kStmtCreate,
+  kStmtDrop,
+  kStmtPrepare,
+  kStmtExecute,
+  kStmtExport,
+  kStmtRename,
+  kStmtAlter,
+  kStmtShow,
+  kStmtTransaction
+};
 
-  // Base struct for every SQL statement
-  struct SQLStatement {
+// Base struct for every SQL statement
+struct SQLStatement {
+  SQLStatement(StatementType type);
 
-    SQLStatement(StatementType type);
+  virtual ~SQLStatement();
 
-    virtual ~SQLStatement();
+  StatementType type() const;
 
-    StatementType type() const;
+  bool isType(StatementType type) const;
 
-    bool isType(StatementType type) const;
+  // Shorthand for isType(type).
+  bool is(StatementType type) const;
 
-    // Shorthand for isType(type).
-    bool is(StatementType type) const;
+  // Length of the string in the SQL query string
+  size_t stringLength;
 
-    // Length of the string in the SQL query string
-    size_t stringLength;
+  std::vector<Expr*>* hints;
 
-    std::vector<Expr*>* hints;
+ private:
+  StatementType type_;
+};
 
-   private:
-    StatementType type_;
+}  // namespace hsql
 
-  };
-
-} // namespace hsql
-
-#endif // SQLPARSER_SQLSTATEMENT_H
+#endif  // SQLPARSER_SQLSTATEMENT_H

+ 107 - 103
src/libs/hsql/include/sql/SelectStatement.h

@@ -1,112 +1,116 @@
 #ifndef SQLPARSER_SELECT_STATEMENT_H
 #define SQLPARSER_SELECT_STATEMENT_H
 
-#include "SQLStatement.h"
 #include "Expr.h"
+#include "SQLStatement.h"
 #include "Table.h"
 
 namespace hsql {
-  enum OrderType {
-    kOrderAsc,
-    kOrderDesc
-  };
-
-  enum SetType {
-    kSetUnion,
-    kSetIntersect,
-    kSetExcept
-  };
-
-  // Description of the order by clause within a select statement.
-  struct OrderDescription {
-    OrderDescription(OrderType type, Expr* expr);
-    virtual ~OrderDescription();
-
-    OrderType type;
-    Expr* expr;
-  };
-
-  // Description of the limit clause within a select statement.
-  struct LimitDescription {
-    LimitDescription(Expr* limit, Expr* offset);
-    virtual ~LimitDescription();
-
-    Expr* limit;
-    Expr* offset;
-  };
-
-  // Description of the group-by clause within a select statement.
-  struct GroupByDescription {
-    GroupByDescription();
-    virtual ~GroupByDescription();
-
-    std::vector<Expr*>* columns;
-    Expr* having;
-  };
-
-  struct WithDescription {
-      ~WithDescription();
-
-      char* alias;
-      SelectStatement* select;
-  };
-
-  struct SetOperation {
-    SetOperation();
-    virtual ~SetOperation();
-
-    SetType setType;
-    bool isAll;
-
-    SelectStatement* nestedSelectStatement;
-    std::vector<OrderDescription*>* resultOrder;
-    LimitDescription* resultLimit;
-
-  };
-
-  // Representation of a full SQL select statement.
-  struct SelectStatement : SQLStatement {
-    SelectStatement();
-    ~SelectStatement() override;
-
-    TableRef* fromTable;
-    bool selectDistinct;
-    std::vector<Expr*>* selectList;
-    Expr* whereClause;
-    GroupByDescription* groupBy;
-
-    // Note that a SetOperation is always connected to a
-    // different SelectStatement. This statement can itself
-    // have SetOperation connections to other SelectStatements.
-    // To evaluate the operations in the correct order:
-    //    Iterate over the setOperations vector: 
-    //      1. Fully evaluate the nestedSelectStatement within the SetOperation
-    //      2. Connect the original statement with the 
-    //         evaluated nestedSelectStatement
-    //      3. Apply the resultOrder and the resultLimit
-    //      4. The result now functions as the the original statement
-    //         for the next iteration
-    //    
-    // Example:
-    //
-    //   (SELECT * FROM students INTERSECT SELECT * FROM students_2) UNION SELECT * FROM students_3 ORDER BY grade ASC;
-    //
-    //   1. We evaluate `Select * FROM students`
-    //   2. Then we iterate over the setOperations vector
-    //   3. We evalute the nestedSelectStatement of the first entry, which is: `SELECT * FROM students_2`
-    //   4. We connect the result of 1. with the results of 3. using the setType, which is INTERSECT
-    //   5. We continue the iteration of the setOperations vector
-    //   6. We evaluate the new nestedSelectStatement which is: `SELECT * FROM students_3`
-    //   7. We apply a Union-Operation to connect the results of 4. and 6.
-    //   8. Finally, we apply the resultOrder of the last SetOperation (ORDER BY grade ASC)
-    std::vector<SetOperation*>* setOperations;
-
-    std::vector<OrderDescription*>* order;
-    std::vector<WithDescription*>* withDescriptions;
-    LimitDescription* limit;
-  };
-
-
-} // namespace hsql
+enum OrderType { kOrderAsc, kOrderDesc };
+
+enum SetType { kSetUnion, kSetIntersect, kSetExcept };
+
+enum RowLockMode { ForUpdate, ForNoKeyUpdate, ForShare, ForKeyShare };
+enum RowLockWaitPolicy { NoWait, SkipLocked, None };
+
+enum SelectObjectType { kDataBase,kFiled };
+
+// Description of the order by clause within a select statement.
+struct OrderDescription {
+  OrderDescription(OrderType type, Expr* expr);
+  virtual ~OrderDescription();
+
+  OrderType type;
+  Expr* expr;
+};
+
+// Description of the limit clause within a select statement.
+struct LimitDescription {
+  LimitDescription(Expr* limit, Expr* offset);
+  virtual ~LimitDescription();
+
+  Expr* limit;
+  Expr* offset;
+};
+
+// Description of the group-by clause within a select statement.
+struct GroupByDescription {
+  GroupByDescription();
+  virtual ~GroupByDescription();
+
+  std::vector<Expr*>* columns;
+  Expr* having;
+};
+
+struct WithDescription {
+  ~WithDescription();
+
+  char* alias;
+  SelectStatement* select;
+};
+
+struct SetOperation {
+  SetOperation();
+  virtual ~SetOperation();
+
+  SetType setType;
+  bool isAll;
+
+  SelectStatement* nestedSelectStatement;
+  std::vector<OrderDescription*>* resultOrder;
+  LimitDescription* resultLimit;
+};
+
+struct LockingClause {
+  RowLockMode rowLockMode;
+  RowLockWaitPolicy rowLockWaitPolicy;
+  std::vector<char*>* tables;
+};
+
+// Representation of a full SQL select statement.
+struct SelectStatement : SQLStatement {
+  SelectStatement();
+  ~SelectStatement() override;
+
+  TableRef* fromTable;
+  bool selectDistinct;
+  std::vector<Expr*>* selectList;
+  Expr* whereClause;
+  GroupByDescription* groupBy;
+
+  // Note that a SetOperation is always connected to a
+  // different SelectStatement. This statement can itself
+  // have SetOperation connections to other SelectStatements.
+  // To evaluate the operations in the correct order:
+  //    Iterate over the setOperations vector:
+  //      1. Fully evaluate the nestedSelectStatement within the SetOperation
+  //      2. Connect the original statement with the
+  //         evaluated nestedSelectStatement
+  //      3. Apply the resultOrder and the resultLimit
+  //      4. The result now functions as the the original statement
+  //         for the next iteration
+  //
+  // Example:
+  //
+  //   (SELECT * FROM students INTERSECT SELECT * FROM students_2) UNION SELECT * FROM students_3 ORDER BY grade ASC;
+  //
+  //   1. We evaluate `Select * FROM students`
+  //   2. Then we iterate over the setOperations vector
+  //   3. We evalute the nestedSelectStatement of the first entry, which is: `SELECT * FROM students_2`
+  //   4. We connect the result of 1. with the results of 3. using the setType, which is INTERSECT
+  //   5. We continue the iteration of the setOperations vector
+  //   6. We evaluate the new nestedSelectStatement which is: `SELECT * FROM students_3`
+  //   7. We apply a Union-Operation to connect the results of 4. and 6.
+  //   8. Finally, we apply the resultOrder of the last SetOperation (ORDER BY grade ASC)
+  std::vector<SetOperation*>* setOperations;
+
+  std::vector<OrderDescription*>* order;
+  std::vector<WithDescription*>* withDescriptions;
+  LimitDescription* limit;
+  std::vector<LockingClause*>* lockings;
+  hsql::SelectObjectType select_object_type;
+};
+
+}  // namespace hsql
 
 #endif

+ 11 - 15
src/libs/hsql/include/sql/ShowStatement.h

@@ -6,22 +6,18 @@
 // Note: Implementations of constructors and destructors can be found in statements.cpp.
 namespace hsql {
 
-  enum ShowType {
-    kShowColumns,
-    kShowTables
-  };
+enum ShowType { kShowColumns, kShowTables, kShowDatabases ,kShowCreateTables};
 
-  // Represents SQL SHOW statements.
-  // Example "SHOW TABLES;"
-  struct ShowStatement : SQLStatement {
+// Represents SQL SHOW statements.
+// Example "SHOW TABLES;"
+struct ShowStatement : SQLStatement {
+  ShowStatement(ShowType type);
+  ~ShowStatement() override;
 
-    ShowStatement(ShowType type);
-    ~ShowStatement() override;
+  ShowType type;
+  char* schema;
+  char* name;
+};
 
-    ShowType type;
-    char* schema;
-    char* name;
-  };
-
-} // namespace hsql
+}  // namespace hsql
 #endif

+ 59 - 71
src/libs/hsql/include/sql/Table.h

@@ -1,80 +1,68 @@
 #ifndef SQLPARSER_TABLEREF_H
 #define SQLPARSER_TABLEREF_H
 
-#include "Expr.h"
 #include <stdio.h>
 #include <vector>
+#include "Expr.h"
 
 namespace hsql {
 
-  struct SelectStatement;
-  struct JoinDefinition;
-  struct TableRef;
-
-  // Possible table reference types.
-  enum TableRefType {
-    kTableName,
-    kTableSelect,
-    kTableJoin,
-    kTableCrossProduct
-  };
-
-  struct TableName {
-    char* schema;
-    char* name;
-  };
-
-  struct Alias {
-    Alias(char* name, std::vector<char*>* columns = nullptr);
-    ~Alias();
-
-    char* name;
-    std::vector<char*>* columns;
-  };
-
-  // Holds reference to tables. Can be either table names or a select statement.
-  struct TableRef {
-    TableRef(TableRefType type);
-    virtual ~TableRef();
-
-    TableRefType type;
-
-    char* schema;
-    char* name;
-    Alias* alias;
-
-    SelectStatement* select;
-    std::vector<TableRef*>* list;
-    JoinDefinition* join;
-
-    // Returns true if a schema is set.
-    bool hasSchema() const;
-
-    // Returns the alias, if it is set. Otherwise the name.
-    const char* getName() const;
-  };
-
-  // Possible types of joins.
-  enum JoinType {
-    kJoinInner,
-    kJoinFull,
-    kJoinLeft,
-    kJoinRight,
-    kJoinCross,
-    kJoinNatural
-  };
-
-  // Definition of a join construct.
-  struct JoinDefinition {
-    JoinDefinition();
-    virtual ~JoinDefinition();
-
-    TableRef* left;
-    TableRef* right;
-    Expr* condition;
-
-    JoinType type;
-  };
-
-} // namespace hsql
+struct SelectStatement;
+struct JoinDefinition;
+struct TableRef;
+
+// Possible table reference types.
+enum TableRefType { kTableName, kTableSelect, kTableJoin, kTableCrossProduct };
+
+struct TableName {
+  char* schema;
+  char* name;
+};
+
+struct Alias {
+  Alias(char* name, std::vector<char*>* columns = nullptr);
+  ~Alias();
+
+  char* name;
+  std::vector<char*>* columns;
+};
+
+// Holds reference to tables. Can be either table names or a select statement.
+struct TableRef {
+  TableRef(TableRefType type);
+  virtual ~TableRef();
+
+  TableRefType type;
+
+  char* schema;
+  char* name;
+  Alias* alias;
+
+  SelectStatement* select;
+  std::vector<TableRef*>* list;
+  JoinDefinition* join;
+
+  // Returns true if a schema is set.
+  bool hasSchema() const;
+
+  // Returns the alias, if it is set. Otherwise the name.
+  const char* getName() const;
+};
+
+// Possible types of joins.
+enum JoinType { kJoinInner, kJoinFull, kJoinLeft, kJoinRight, kJoinCross, kJoinNatural };
+
+// Definition of a join construct.
+struct JoinDefinition {
+  JoinDefinition();
+  virtual ~JoinDefinition();
+
+  TableRef* left;
+  TableRef* right;
+  Expr* condition;
+
+  JoinType type;
+};
+
+}  // namespace hsql
 #endif

+ 10 - 14
src/libs/hsql/include/sql/TransactionStatement.h

@@ -5,21 +5,17 @@
 
 namespace hsql {
 
-  // Represents SQL Transaction statements.
-  // Example: BEGIN TRANSACTION;
-  enum TransactionCommand {
-    kBeginTransaction,
-    kCommitTransaction,
-    kRollbackTransaction
-  };
+// Represents SQL Transaction statements.
+// Example: BEGIN TRANSACTION;
+enum TransactionCommand { kBeginTransaction, kCommitTransaction, kRollbackTransaction };
 
-  struct TransactionStatement : SQLStatement {
-    TransactionStatement(TransactionCommand command);
-    ~TransactionStatement() override;
+struct TransactionStatement : SQLStatement {
+  TransactionStatement(TransactionCommand command);
+  ~TransactionStatement() override;
 
-    TransactionCommand command;
-  };
-  
-} // namsepace hsql
+  TransactionCommand command;
+};
+
+}  // namespace hsql
 
 #endif

+ 15 - 15
src/libs/hsql/include/sql/UpdateStatement.h

@@ -5,23 +5,23 @@
 
 namespace hsql {
 
-  // Represents "column = value" expressions.
-  struct UpdateClause {
-    char* column;
-    Expr* value;
-  };
+// Represents "column = value" expressions.
+struct UpdateClause {
+  char* column;
+  Expr* value;
+};
 
-  // Represents SQL Update statements.
-  struct UpdateStatement : SQLStatement {
-    UpdateStatement();
-    ~UpdateStatement() override;
+// Represents SQL Update statements.
+struct UpdateStatement : SQLStatement {
+  UpdateStatement();
+  ~UpdateStatement() override;
 
-    // TODO: switch to char* instead of TableRef
-    TableRef* table;
-    std::vector<UpdateClause*>* updates;
-    Expr* where;
-  };
+  // TODO: switch to char* instead of TableRef
+  TableRef* table;
+  std::vector<UpdateClause*>* updates;
+  Expr* where;
+};
 
-} // namsepace hsql
+}  // namespace hsql
 
 #endif

+ 8 - 8
src/libs/hsql/include/sql/statements.h

@@ -1,18 +1,18 @@
 #ifndef SQLPARSER_STATEMENTS_H
 #define SQLPARSER_STATEMENTS_H
 
-#include "SelectStatement.h"
-#include "ImportStatement.h"
+#include "AlterStatement.h"
 #include "CreateStatement.h"
-#include "InsertStatement.h"
-#include "UpdateStatement.h"
 #include "DeleteStatement.h"
 #include "DropStatement.h"
-#include "PrepareStatement.h"
 #include "ExecuteStatement.h"
-#include "ShowStatement.h"
 #include "ExportStatement.h"
+#include "ImportStatement.h"
+#include "InsertStatement.h"
+#include "PrepareStatement.h"
+#include "SelectStatement.h"
+#include "ShowStatement.h"
 #include "TransactionStatement.h"
-#include "AlterStatement.h"
+#include "UpdateStatement.h"
 
-#endif // SQLPARSER_STATEMENTS_H
+#endif  // SQLPARSER_STATEMENTS_H

+ 19 - 19
src/libs/hsql/include/util/sqlhelper.h

@@ -5,33 +5,33 @@
 
 namespace hsql {
 
-  // Prints a summary of the given SQLStatement.
-  void printStatementInfo(const SQLStatement* stmt);
+// Prints a summary of the given SQLStatement.
+void printStatementInfo(const SQLStatement* stmt);
 
-  // Prints a summary of the given SelectStatement with the given indentation.
-  void printSelectStatementInfo(const SelectStatement* stmt, uintmax_t num_indent);
+// Prints a summary of the given SelectStatement with the given indentation.
+void printSelectStatementInfo(const SelectStatement* stmt, uintmax_t num_indent);
 
-  // Prints a summary of the given ImportStatement with the given indentation.
-  void printImportStatementInfo(const ImportStatement* stmt, uintmax_t num_indent);
+// Prints a summary of the given ImportStatement with the given indentation.
+void printImportStatementInfo(const ImportStatement* stmt, uintmax_t num_indent);
 
-    // Prints a summary of the given CopyStatement with the given indentation.
-  void printExportStatementInfo(const ExportStatement* stmt, uintmax_t num_indent);
+// Prints a summary of the given CopyStatement with the given indentation.
+void printExportStatementInfo(const ExportStatement* stmt, uintmax_t num_indent);
 
-  // Prints a summary of the given InsertStatement with the given indentation.
-  void printInsertStatementInfo(const InsertStatement* stmt, uintmax_t num_indent);
+// Prints a summary of the given InsertStatement with the given indentation.
+void printInsertStatementInfo(const InsertStatement* stmt, uintmax_t num_indent);
 
-  // Prints a summary of the given CreateStatement with the given indentation.
-  void printCreateStatementInfo(const CreateStatement* stmt, uintmax_t num_indent);
+// Prints a summary of the given CreateStatement with the given indentation.
+void printCreateStatementInfo(const CreateStatement* stmt, uintmax_t num_indent);
 
-  // Prints a summary of the given TransactionStatement with the given indentation.
-  void printTransactionStatementInfo(const TransactionStatement* stmt, uintmax_t num_indent);
+// Prints a summary of the given TransactionStatement with the given indentation.
+void printTransactionStatementInfo(const TransactionStatement* stmt, uintmax_t num_indent);
 
-  // Prints a summary of the given Expression with the given indentation.
-  void printExpression(Expr* expr, uintmax_t num_indent);
+// Prints a summary of the given Expression with the given indentation.
+void printExpression(Expr* expr, uintmax_t num_indent);
 
-  // Prints an ORDER BY clause
-  void printOrderBy(const std::vector<OrderDescription*>* expr, uintmax_t num_indent);
+// Prints an ORDER BY clause
+void printOrderBy(const std::vector<OrderDescription*>* expr, uintmax_t num_indent);
 
-} // namespace hsql
+}  // namespace hsql
 
 #endif

二進制
src/libs/hsql/libs/libsqlparser.a


二進制
src/libs/hsql/libs/libsqlparser.so


+ 2 - 2
src/rule/rule.cc

@@ -297,7 +297,7 @@ extern "C" bool is_show_db(const char* szsql)
     return false;
 }
 
-extern "C" int rule_sql_match(const char* szsql, const char* dbname, const char* conf)
+extern "C" int rule_sql_match(const char* szsql, const char* osql, const char* dbname, const char* conf)
 {
     if(!szsql)
         return -1;
@@ -318,7 +318,7 @@ extern "C" int rule_sql_match(const char* szsql, const char* dbname, const char*
             return -1;
     }
 
-    log4cplus_debug("key len: %d, key: %s, sql len: %d, sql: %s, dbname len: %d, dbname: %s", key.length(), key.c_str(), sql.length(), sql.c_str(), strlen(dbname), std::string(dbname).c_str());
+    log4cplus_debug("key len: %d, key: %s, sql len: %d, sql: %s, dbname len: %d, dbname: %s", key.length(), key.c_str(), key.length(), osql, strlen(dbname), std::string(dbname).c_str());
 
     if(is_show_db(szsql))
     {

+ 1 - 1
src/rule/rule.h

@@ -3,7 +3,7 @@
 extern "C"{
 #endif
 
-    int rule_sql_match(const char* szsql, const char* dbname, const char* conf);
+    int rule_sql_match(const char* szsql, const char* osql, const char* dbname, const char* conf);
     int re_load_table_key(char* key);
     int sql_parse_table(const char* szsql, char* out);
     int rule_get_key_type(const char* conf);

+ 53 - 22
tests/test_agent_cache_only.py

@@ -24,28 +24,6 @@ def test_insert_with_double_quotes():
     db.close()
 '''    
 
-'''
-def test_insert_remove_where_cluster():
-    db = pymysql.connect(host='127.0.0.1', port=12001, user='test', password='test', database='test')
-    cursor = db.cursor()
-    sql = "insert into opensource(uid, name) values(1, \"hello\")"
-    cursor.execute(sql)
-    db.commit()
-    cursor.close()
-    db.close()
-'''
-
-'''
-def test_insert_remove_where_cluster_without_specify_key():
-    db = pymysql.connect(host='127.0.0.1', port=12001, user='test', password='test', database='test')
-    cursor = db.cursor()
-    sql = "insert into opensource values(1, \"Jack\", \"Shanghai\", 1, 18)"
-    cursor.execute(sql)
-    db.commit()
-    cursor.close()
-    db.close()
-'''
-
 def test_select():
     db = pymysql.connect(host='127.0.0.1', port=12001, user='test', password='test', database='test')
     cursor = db.cursor()
@@ -148,3 +126,56 @@ def test_delete():
 '''
 def test_check_tablename():
 '''    
+
+def test_insert_remove_where_cluster():
+    db = pymysql.connect(host='127.0.0.1', port=12001, user='test', password='test', database='test')
+    cursor = db.cursor()
+    sql = "insert into opensource(uid, name) values(1, \"hello\")"
+    cursor.execute(sql)
+    db.commit()
+    rowsaffected = cursor.rowcount
+    print("affected rows: %s" % (rowsaffected))
+    cursor.close()
+    db.close()
+    assert rowsaffected == 1
+
+def test_insert_remove_where_cluster_without_specify_key():
+    db = pymysql.connect(host='127.0.0.1', port=12001, user='test', password='test', database='test')
+    cursor = db.cursor()
+    sql = "insert into opensource values(1, \"Jack\", \"Shanghai\", 1, 18)"
+    cursor.execute(sql)
+    db.commit()
+    rowsaffected = cursor.rowcount
+    print("affected rows: %s" % (rowsaffected))    
+    cursor.close()
+    db.close()
+    assert rowsaffected == 1
+
+def test_select_limit():
+    db = pymysql.connect(host='127.0.0.1', port=12001, user='test', password='test', database='test')
+    cursor = db.cursor()
+    sql = "select uid, name from opensource where uid = 1 limit 2"
+    cursor.execute(sql)
+    results = cursor.fetchall()
+    assert len(results) == 2
+   
+    cursor = db.cursor()
+    sql = "select uid, name from opensource where uid = 1 limit 1"
+    cursor.execute(sql)
+    results = cursor.fetchall()
+    assert len(results) == 1
+
+    cursor = db.cursor()
+    sql = "insert into opensource values(1, \"Jack\", \"Shanghai\", 1, 19)"
+    cursor.execute(sql)
+    db.commit()
+
+    cursor = db.cursor()
+    sql = "select uid, name from opensource where uid = 1 limit 1,3"
+    cursor.execute(sql)
+    results = cursor.fetchall()
+    assert len(results) == 2
+    assert results[0][4] == 18
+    assert results[1][4] == 19
+
+    db.close()

+ 60 - 22
tests/test_dtcd_cache_only.py

@@ -24,28 +24,6 @@ def test_insert_with_double_quotes():
     db.close()
 '''    
 
-'''
-def test_insert_remove_where_cluster():
-    db = pymysql.connect(host='127.0.0.1', port=20015, user='test', password='test', database='test')
-    cursor = db.cursor()
-    sql = "insert into opensource(uid, name) values(1, \"hello\")"
-    cursor.execute(sql)
-    db.commit()
-    cursor.close()
-    db.close()
-'''
-
-'''
-def test_insert_remove_where_cluster_without_specify_key():
-    db = pymysql.connect(host='127.0.0.1', port=20015, user='test', password='test', database='test')
-    cursor = db.cursor()
-    sql = "insert into opensource values(1, \"Jack\", \"Shanghai\", 1, 18)"
-    cursor.execute(sql)
-    db.commit()
-    cursor.close()
-    db.close()
-'''
-
 def test_select():
     db = pymysql.connect(host='127.0.0.1', port=20015, user='test', password='test', database='test')
     cursor = db.cursor()
@@ -131,3 +109,63 @@ def test_delete():
 '''
 def test_check_tablename():
 '''    
+
+def test_insert_remove_where_cluster():
+    db = pymysql.connect(host='127.0.0.1', port=20015, user='test', password='test', database='test')
+    cursor = db.cursor()
+    sql = "insert into opensource(uid, name) values(1, 'hello')"
+    cursor.execute(sql)
+    db.commit()
+    rowsaffected = cursor.rowcount
+    print("affected rows: %s" % (rowsaffected))
+    cursor.close()
+    db.close()
+    assert rowsaffected == 1
+
+'''
+def test_insert_remove_where_cluster_without_specify_key():
+    db = pymysql.connect(host='127.0.0.1', port=20015, user='test', password='test', database='test')
+    cursor = db.cursor()
+    sql = "insert into opensource values(1, 'Jack', 'Shanghai', 1, 18)"
+    cursor.execute(sql)
+    db.commit()
+    rowsaffected = cursor.rowcount
+    print("affected rows: %s" % (rowsaffected))    
+    cursor.close()
+    db.close()
+    assert rowsaffected == 1
+'''
+
+def test_select_limit():
+    db = pymysql.connect(host='127.0.0.1', port=20015, user='test', password='test', database='test')
+    cursor = db.cursor()
+
+    sql = "insert into opensource(uid,name,city,sex,age) values(1, 'Jack', 'Shanghai', 1, 18)"
+    cursor.execute(sql)
+    db.commit()
+
+    sql = "select uid, name from opensource where uid = 1 limit 2"
+    cursor.execute(sql)
+    results = cursor.fetchall()
+    assert len(results) == 2
+   
+    cursor = db.cursor()
+    sql = "select uid, name from opensource where uid = 1 limit 1"
+    cursor.execute(sql)
+    results = cursor.fetchall()
+    assert len(results) == 1
+
+    cursor = db.cursor()
+    sql = "insert into opensource(uid,name,city,sex,age) values(1, 'Jack', 'Shanghai', 1, 19)"
+    cursor.execute(sql)
+    db.commit()
+
+    cursor = db.cursor()
+    sql = "select uid, name,city,sex,age from opensource where uid = 1 limit 1,3"
+    cursor.execute(sql)
+    results = cursor.fetchall()
+    assert len(results) == 2
+    assert results[0][4] == 18
+    assert results[1][4] == 19
+
+    db.close()