From e84bea23c26011f3487870bc8a652173b476de19 Mon Sep 17 00:00:00 2001 From: Walter Weinmann Date: Thu, 11 Apr 2019 16:33:41 +0200 Subject: [PATCH] Version 4.6.1. (#170) Former-commit-id: 900dff239e2fe452a26fd3ff7e1607581982e324 --- README.md | 2 +- .../ParSqlparse.info.REMOVED.git-id | 2 +- priv/bnf_converter/sqlparse.cf | 34 +++++----- priv/railroad_diagram_generator/sqlparse.ebnf | 3 +- src/sqlparse.app.src | 66 +++++++++---------- src/sqlparse.yrl | 1 + test/eunit.create.tst | 1 + test/src/sqlparse_generator.erl | 17 +++-- 8 files changed, 69 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 8fc2713..0e2626b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ![GitHub](https://img.shields.io/github/license/K2InformaticsGmbH/sqlparse.svg) ![GitHub release](https://img.shields.io/github/release/K2InformaticsGmbH/sqlparse.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/K2InformaticsGmbH/sqlparse.svg) -![GitHub commits since latest release](https://img.shields.io/github/commits-since/K2InformaticsGmbH/sqlparse/4.6.0.svg) +![GitHub commits since latest release](https://img.shields.io/github/commits-since/K2InformaticsGmbH/sqlparse/4.6.1.svg) **sqlparse** is a production-ready SQL parser written in pure Erlang. **sqlparse** is aligned to the Oracle SQL language and enriched with [imem](https://github.com/K2InformaticsGmbH/imem) and [JSONPath](https://github.com/K2InformaticsGmbH/jpparse) specific features. diff --git a/priv/bnf_converter/ParSqlparse.info.REMOVED.git-id b/priv/bnf_converter/ParSqlparse.info.REMOVED.git-id index d738a8d..aa32168 100644 --- a/priv/bnf_converter/ParSqlparse.info.REMOVED.git-id +++ b/priv/bnf_converter/ParSqlparse.info.REMOVED.git-id @@ -1 +1 @@ -471644b0110f1d68fb0a60fff44588d03901c6db \ No newline at end of file +f1c099d07630eba772d9b7d8dc4d2de19299a51d \ No newline at end of file diff --git a/priv/bnf_converter/sqlparse.cf b/priv/bnf_converter/sqlparse.cf index 0031c87..d95eb0f 100644 --- a/priv/bnf_converter/sqlparse.cf +++ b/priv/bnf_converter/sqlparse.cf @@ -1947,6 +1947,7 @@ ColumnRef11. ColumnRef ::= Identifier "." Identifier "." "* -- data_type -> NUMBER : unwrap_bin('$1'). -- data_type -> RAW : unwrap_bin('$1'). -- data_type -> ROWID : unwrap_bin('$1'). +-- data_type -> STRING : unwrap_bin('$1'). -- data_type -> TIMESTAMP : unwrap_bin('$1'). -- data_type -> UROWID : unwrap_bin('$1'). -- data_type -> VARCHAR2 : unwrap_bin('$1'). @@ -1980,22 +1981,23 @@ DataType13. DataType ::= "NCLOB" DataType14. DataType ::= "NUMBER" ; DataType15. DataType ::= "RAW" ; DataType16. DataType ::= "ROWID" ; -DataType17. DataType ::= "TIMESTAMP" ; -DataType18. DataType ::= "UROWID" ; -DataType19. DataType ::= "VARCHAR2" ; -DataType20. DataType ::= "XMLTYPE" ; -DataType21. DataType ::= "CHAR" "(" SgnNum ")" ; -DataType22. DataType ::= "FLOAT" "(" SgnNum ")" ; -DataType23. DataType ::= "NAME" "(" SgnNum ")" ; -DataType24. DataType ::= "NCHAR" "(" SgnNum ")" ; -DataType25. DataType ::= "NUMBER" "(" SgnNum ")" ; -DataType26. DataType ::= "NVARCHAR2" "(" SgnNum ")" ; -DataType27. DataType ::= "RAW" "(" SgnNum ")" ; -DataType28. DataType ::= "TIMESTAMP" "(" SgnNum ")" ; -DataType29. DataType ::= "UROWID" "(" SgnNum ")" ; -DataType30. DataType ::= "VARCHAR2" "(" SgnNum ")" ; -DataType31. DataType ::= "NAME" "(" SgnNum "," SgnNum ")" ; -DataType32. DataType ::= "NUMBER" "(" SgnNum "," SgnNum ")" ; +DataType17. DataType ::= "STRING" ; +DataType18. DataType ::= "TIMESTAMP" ; +DataType19. DataType ::= "UROWID" ; +DataType20. DataType ::= "VARCHAR2" ; +DataType21. DataType ::= "XMLTYPE" ; +DataType22. DataType ::= "CHAR" "(" SgnNum ")" ; +DataType23. DataType ::= "FLOAT" "(" SgnNum ")" ; +DataType24. DataType ::= "NAME" "(" SgnNum ")" ; +DataType25. DataType ::= "NCHAR" "(" SgnNum ")" ; +DataType26. DataType ::= "NUMBER" "(" SgnNum ")" ; +DataType27. DataType ::= "NVARCHAR2" "(" SgnNum ")" ; +DataType28. DataType ::= "RAW" "(" SgnNum ")" ; +DataType29. DataType ::= "TIMESTAMP" "(" SgnNum ")" ; +DataType30. DataType ::= "UROWID" "(" SgnNum ")" ; +DataType31. DataType ::= "VARCHAR2" "(" SgnNum ")" ; +DataType32. DataType ::= "NAME" "(" SgnNum "," SgnNum ")" ; +DataType33. DataType ::= "NUMBER" "(" SgnNum "," SgnNum ")" ; -- sgn_num -> INTNUM : unwrap_bin('$1'). -- sgn_num -> '-' INTNUM : list_to_binary(["-",unwrap_bin('$2')]). diff --git a/priv/railroad_diagram_generator/sqlparse.ebnf b/priv/railroad_diagram_generator/sqlparse.ebnf index a92a3a7..ce85531 100644 --- a/priv/railroad_diagram_generator/sqlparse.ebnf +++ b/priv/railroad_diagram_generator/sqlparse.ebnf @@ -1996,6 +1996,7 @@ data_type -> NCLOB : unwrap_bin('$1'). data_type -> NUMBER : unwrap_bin('$1'). data_type -> RAW : unwrap_bin('$1'). data_type -> ROWID : unwrap_bin('$1'). +data_type -> STRING : unwrap_bin('$1'). data_type -> TIMESTAMP : unwrap_bin('$1'). data_type -> UROWID : unwrap_bin('$1'). data_type -> VARCHAR2 : unwrap_bin('$1'). @@ -2014,7 +2015,7 @@ data_type -> NAME '(' sgn_num ',' sgn_num ')' : {unwrap_bin('$1'), '$3', '$ data_type -> NUMBER '(' sgn_num ',' sgn_num ')' : {unwrap_bin('$1'), '$3', '$5'}. ============================================================================= */ -data_type ::= ( BFILE | BINARY_DOUBLE | BINARY_FLOAT | BLOB | CHAR | CLOB | DATE | FLOAT | LONG | ( LONG RAW ) | ( identifier '.' )? NAME | NCLOB | NUMBER | RAW | ROWID | TIMESTAMP | UROWID | VARCHAR2 | XMLTYPE ) +data_type ::= ( BFILE | BINARY_DOUBLE | BINARY_FLOAT | BLOB | CHAR | CLOB | DATE | FLOAT | LONG | ( LONG RAW ) | ( identifier '.' )? NAME | NCLOB | NUMBER | RAW | ROWID | STRING | TIMESTAMP | UROWID | VARCHAR2 | XMLTYPE ) | ( ( CHAR | FLOAT | NAME | NCHAR | NUMBER | NVARCHAR2 c| RAW | TIMESTAMP | UROWID | VARCHAR2 ) '(' sgn_num ')' ) | ( ( NAME | NUMBER ) '(' sgn_num ',' sgn_num ')' ) diff --git a/src/sqlparse.app.src b/src/sqlparse.app.src index 7618d79..2d72646 100644 --- a/src/sqlparse.app.src +++ b/src/sqlparse.app.src @@ -1,33 +1,33 @@ -%% ----------------------------------------------------------------------------- -%% -%% sqlparse.app.src: SQL - tool configuration. -%% -%% Copyright (c) 2012-18 K2 Informatics GmbH. All Rights Reserved. -%% -%% This file is provided to you under the Apache License, -%% Version 2.0 (the "License"); you may not use this file -%% except in compliance with the License. You may obtain -%% a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, -%% software distributed under the License is distributed on an -%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -%% KIND, either express or implied. See the License for the -%% specific language governing permissions and limitations -%% under the License. -%% -%% ----------------------------------------------------------------------------- - -{application, sqlparse, - [ - {description, "A LALR SQL parser and compiler"}, - {vsn, "4.6.0"}, - {applications, [ - kernel, - stdlib, - jpparse - ]}, - {modules, [sqlparse]} - ]}. +%% ----------------------------------------------------------------------------- +%% +%% sqlparse.app.src: SQL - tool configuration. +%% +%% Copyright (c) 2012-18 K2 Informatics GmbH. All Rights Reserved. +%% +%% This file is provided to you under the Apache License, +%% Version 2.0 (the "License"); you may not use this file +%% except in compliance with the License. You may obtain +%% a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, +%% software distributed under the License is distributed on an +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +%% KIND, either express or implied. See the License for the +%% specific language governing permissions and limitations +%% under the License. +%% +%% ----------------------------------------------------------------------------- + +{application, sqlparse, + [ + {description, "A LALR SQL parser and compiler"}, + {vsn, "4.6.1"}, + {applications, [ + kernel, + stdlib, + jpparse + ]}, + {modules, [sqlparse]} + ]}. diff --git a/src/sqlparse.yrl b/src/sqlparse.yrl index 4bef7fc..20da0d0 100644 --- a/src/sqlparse.yrl +++ b/src/sqlparse.yrl @@ -1484,6 +1484,7 @@ data_type -> NCLOB : unwrap_bin('$1'). data_type -> NUMBER : unwrap_bin('$1'). data_type -> RAW : unwrap_bin('$1'). data_type -> ROWID : unwrap_bin('$1'). +data_type -> STRING : unwrap_bin('$1'). data_type -> TIMESTAMP : unwrap_bin('$1'). data_type -> UROWID : unwrap_bin('$1'). data_type -> VARCHAR2 : unwrap_bin('$1'). diff --git a/test/eunit.create.tst b/test/eunit.create.tst index ca33bde..5c9ca7a 100644 --- a/test/eunit.create.tst +++ b/test/eunit.create.tst @@ -683,6 +683,7 @@ create table table_1 ( ) ". "CREATE TABLE test(fld CHAR)". +"create table key_test (col1 '{atom,integer}', col2 '{string,binstr}');". % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % create_user_def diff --git a/test/src/sqlparse_generator.erl b/test/src/sqlparse_generator.erl index 38f7764..ec491b5 100644 --- a/test/src/sqlparse_generator.erl +++ b/test/src/sqlparse_generator.erl @@ -1495,8 +1495,12 @@ create_code(cursor_def = Rule) -> ?CREATE_CODE_END; %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% data_type ::= ( BFILE | BINARY_DOUBLE | BINARY_FLOAT | BLOB | CHAR | CLOB | DATE | FLOAT | LONG | ( LONG RAW ) | ( identifier '.' )? NAME | NCLOB | NUMBER | RAW | ROWID | TIMESTAMP | UROWID | VARCHAR2 | XMLTYPE ) -%% | ( ( CHAR | FLOAT | NAME | NCHAR | NUMBER | NVARCHAR2 c| RAW | TIMESTAMP | UROWID | VARCHAR2 ) '(' sgn_num ')' ) +%% data_type ::= ( BFILE | BINARY_DOUBLE | BINARY_FLOAT | BLOB | CHAR | CLOB +%% | DATE | FLOAT | LONG | ( LONG RAW ) | ( identifier '.' )? NAME +%% | NCLOB | NUMBER | RAW | ROWID | STRING | TIMESTAMP | UROWID +%% | VARCHAR2 | XMLTYPE ) +%% | ( ( CHAR | FLOAT | NAME | NCHAR | NUMBER | NVARCHAR2 c| RAW +%% | TIMESTAMP | UROWID | VARCHAR2 ) '(' sgn_num ')' ) %% | ( ( NAME | NUMBER ) '(' sgn_num ',' sgn_num ')' ) %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1508,6 +1512,8 @@ create_code(data_type = Rule) -> Name_Length = length(Name), [{sgn_num, Sgn_Num}] = ets:lookup(?CODE_TEMPLATES, sgn_num), Sgn_Num_Length = length(Sgn_Num), + [{string, String}] = ets:lookup(?CODE_TEMPLATES, string), + String_Length = length(String), Code = [ @@ -1530,15 +1536,16 @@ create_code(data_type = Rule) -> "Varchar2 ", "Xmltype " ] ++ [ - case rand:uniform(4) rem 4 of + case rand:uniform(5) rem 5 of 1 -> lists:nth(rand:uniform(Name_Length), Name) ++ " "; - 2 -> lists:append([ + 2 -> lists:nth(rand:uniform(String_Length), String) ++ " "; + 3 -> lists:append([ lists:nth(rand:uniform(Identifier_Length), Identifier), ".", lists:nth(rand:uniform(Name_Length), Name), " " ]); - 3 -> lists:append([ + 4 -> lists:append([ case rand:uniform(10) rem 10 of 1 -> "Char"; 2 -> "Float";