diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..5926aa29 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: https://paypal.me/wumpz diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..52464bf3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,25 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Example SQL +2. Parsing this SQL using JSqlParser with this statements +3. Exception + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**System** + - Database you are using +- Java Version +- JSqlParser version diff --git a/.travis.yml b/.travis.yml index b0b3db6c..5652c04c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: java jdk: - - openjdk7 - - oraclejdk7 - - oraclejdk8 + - openjdk8 + - openjdk11 after_success: - mvn clean cobertura:cobertura coveralls:report \ No newline at end of file diff --git a/LICENSE_APACHEV2 b/LICENSE_APACHEV2 new file mode 100644 index 00000000..8dada3ed --- /dev/null +++ b/LICENSE_APACHEV2 @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed 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. diff --git a/LICENSE_LGPLV21 b/LICENSE_LGPLV21 new file mode 100644 index 00000000..19e30718 --- /dev/null +++ b/LICENSE_LGPLV21 @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +(This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.) + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + {signature of Ty Coon}, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/README.md b/README.md index de642c9a..1c3907e2 100644 --- a/README.md +++ b/README.md @@ -2,32 +2,49 @@ [![Build Status](https://travis-ci.org/JSQLParser/JSqlParser.svg?branch=master)](https://travis-ci.org/JSQLParser/JSqlParser) [![Coverage Status](https://coveralls.io/repos/JSQLParser/JSqlParser/badge.svg?branch=master)](https://coveralls.io/r/JSQLParser/JSqlParser?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/00b2d91995764ae4805b55627aca8d39)](https://www.codacy.com/app/wumpz/JSqlParser?utm_source=github.com&utm_medium=referral&utm_content=JSQLParser/JSqlParser&utm_campaign=Badge_Grade) - -[![PayPal donate button](http://img.shields.io/paypal/donate.png?color=blue)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=64CCN9JJANZXA "Help this JSqlParser version using Paypal") +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.jsqlparser/jsqlparser/badge.svg)](http://maven-badges.herokuapp.com/maven-central/com.github.jsqlparser/jsqlparser) +[![Javadocs](https://www.javadoc.io/badge/com.github.jsqlparser/jsqlparser.svg)](https://www.javadoc.io/doc/com.github.jsqlparser/jsqlparser) [![Gitter](https://badges.gitter.im/JSQLParser/JSqlParser.svg)](https://gitter.im/JSQLParser/JSqlParser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +[![Code Quality: Java](https://img.shields.io/lgtm/grade/java/g/JSQLParser/JSqlParser.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/JSQLParser/JSqlParser/context:java) +[![Total Alerts](https://img.shields.io/lgtm/alerts/g/JSQLParser/JSqlParser.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/JSQLParser/JSqlParser/alerts) Look here for more information and examples: https://github.com/JSQLParser/JSqlParser/wiki. ## License -JSqlParser is dual licensed under **LGPL V2.1** and **Apache Software License, Version 2.0**. +JSqlParser is dual licensed under **LGPL V2.1** or **Apache Software License, Version 2.0**. + +## Discussion +Please provide feedback on: + +* API changes: extend visitor with return values (https://github.com/JSQLParser/JSqlParser/issues/901) ## News +* Released version **3.1** of JSqlParser +* Released version **3.0** of JSqlParser +* The array parsing is the default behaviour. Square bracket quotation has to be enabled using + a parser flag (**CCJSqlParser.withSquareBracketQuotation**). +* due to an API change the version will be 3.0 +* JSqlParser uses now Java 8 at the minimum +* Released version **2.1** of JSqlParser +* Released version **2.0** of JSqlParser +* breaking **API** change: to support chained functions attribute type was changed to **Expression** +* Released version **1.4** of JSqlParser +* Released version **1.3** of JSqlParser +* Changed behaviour of dotted multipart names for user variables, tables and columns to accept e.g. ORM class names. To achieve this some behaviour of name parsing had to be changed. Before this the parser would fail missing databasenames for SqlServer queries (server..schema.table). But this is allowed for the schema (server.database..table). Now the parser accepts missing inner names per se to avoid some very complicated parsing rules. +* Released version **1.2** of JSqlParser +* breaking **API** change: merge of *within group* and *over* (window expressions) +* Released version **1.1** of JSqlParser. * JSqlParser has now a build in checkstyle configuration to introduce source code conventions. * Released first major version **1.0** of JSqlParser. -* Please test the actual **0.9.8-SNAPSHOT**. It includes includes grammar refactorings or changes which eventually results in parse tree changes. -* Version **0.9.7** released. -* Version **0.9.6** released. -* Version **0.9.5** released. -* Please test the actual **0.9.5-SNAPSHOT**. It includes some grammar refactorings which eventually results in parse tree changes. -* Version **0.9.4** released. -* Please test the actual SNAPSHOT, if there are problems using the extended identifier token. -* Version **0.9.3** released. More news can be found here: https://github.com/JSQLParser/JSqlParser/wiki/News. +## Alternatives to JSqlParser? +[**General SQL Parser**](http://www.sqlparser.com/features/introduce.php?utm_source=github-jsqlparser&utm_medium=text-general) looks pretty good, with extended SQL syntax (like PL/SQL and T-SQL) and java + .NET APIs. The tool is commercial (license available online), with a free download option. + ## JSqlParser JSqlParser is a SQL statement parser. It translates SQLs in a traversable hierarchy of Java classes. JSqlParser is not limited to one database but provides support for a lot of specials of Oracle, SqlServer, MySQL, PostgreSQL ... To name some, it has support for Oracles join syntax using (+), PostgreSQLs cast syntax using ::, relational operators like != and so on. @@ -36,28 +53,24 @@ JSqlParser is a SQL statement parser. It translates SQLs in a traversable hierar If you need help using JSqlParser feel free to file an issue or contact me. ## Contributions -To help JSqlParsers development you are encouraged to provide +To help JSqlParser's development you are encouraged to provide * feedback * bugreports * pull requests for new features * improvement requests -* fund new features +* fund new features or sponsor JSqlParser ([**Sponsor**](https://www.paypal.me/wumpz)) + +**Please write in English, since it's the language most of the dev team knows.** Also I would like to know about needed examples or documentation stuff. -## Extensions in the latest SNAPSHOT version 1.1 +## Extensions in the latest SNAPSHOT version 3.2 -* support for **UPSERT** syntax -* absolute token positions in addition to column/line -* common normal form transformer for expressions (https://en.wikipedia.org/wiki/Conjunctive_normal_form) -* checkstyle integration to force first souce code conventions - * checkstyle is activated by default, it can be deactivated by an environment property **skipCheckSources** - * pull requests should follow this style settings ## Extensions of JSqlParser releases * [Release Notes](https://github.com/JSQLParser/JSqlParser/releases) -* Modifications before GitHubs release tagging are listed in the [Older Releases](https://github.com/JSQLParser/JSqlParser/wiki/Older-Releases) page. +* Modifications before GitHub's release tagging are listed in the [Older Releases](https://github.com/JSQLParser/JSqlParser/wiki/Older-Releases) page. ## Building from the sources @@ -68,11 +81,15 @@ As the project is a Maven project, building is rather simple by running: The project requires the following to build: - Maven -- JDK 1.7 or later. The jar will target JDK 1.6, but the version of the maven-compiler-plugin that JsqlParser uses requires JDK 1.7+ +- JDK 8 or later. The jar will target JDK 8, but the version of the maven-compiler-plugin that JsqlParser uses requires JDK 8+ This will produce the jsqlparser-VERSION.jar file in the target/ directory. -**To build this project without using Maven, one has to build the parser by JavaCC using the CLI options it provids.** +**To build this project without using Maven, one has to build the parser by JavaCC using the CLI options it provides.** + +## Debugging through problems + +Refer to the [Visualize Parsing](https://github.com/JSQLParser/JSqlParser/wiki/Examples-of-SQL-parsing#visualize-parsing) section to learn how to run the parser in debug mode. ## Source Code conventions @@ -116,7 +133,7 @@ And this is the dependency declaration in your pom: com.github.jsqlparser jsqlparser - 1.0 + 3.1 ``` diff --git a/nb-configuration.xml b/nb-configuration.xml index 641fed0a..0e29529e 100644 --- a/nb-configuration.xml +++ b/nb-configuration.xml @@ -14,9 +14,11 @@ Any value defined here will override the pom.xml file value but is only applicable to the current project. --> none - true + false true LF false + true + JDK_1.8 diff --git a/pom.xml b/pom.xml index 8964479d..16fc59ba 100644 --- a/pom.xml +++ b/pom.xml @@ -2,8 +2,8 @@ 4.0.0 com.github.jsqlparser jsqlparser - 1.1 - JSQLParser library + 3.2-SNAPSHOT + JSQLParser library 2004 JSQLParser @@ -28,7 +28,7 @@ commons-io commons-io - 2.4 + 2.6 test @@ -38,15 +38,15 @@ test - org.hamcrest - hamcrest-library - 1.3 + org.mockito + mockito-core + 2.28.2 test - org.mockito - mockito-core - 2.7.22 + org.assertj + assertj-core + 3.11.1 test @@ -73,7 +73,7 @@ scm:git:https://github.com/JSQLParser/JSqlParser.git scm:git:ssh://git@github.com:JSQLParser/JSqlParser.git https://github.com/JSQLParser/JSqlParser.git - jsqlparser-1.1 + HEAD @@ -85,10 +85,10 @@ maven-compiler-plugin - 3.3 + 3.7.0 - 1.6 - 1.6 + 1.8 + 1.8 true ${project.build.sourceEncoding} @@ -106,16 +106,11 @@ - - true - true - true - net.java.dev.javacc javacc - 7.0.2 + 7.0.4 @@ -140,11 +135,13 @@ org.codehaus.mojo license-maven-plugin - 1.6 + 1.17 false false false + dual_lgpl_ap2 + ${project.baseUri}/src/license @@ -153,12 +150,6 @@ update-file-header process-sources - - lgpl_v2_1 - - src/main/java - - @@ -182,7 +173,7 @@ org.apache.maven.plugins maven-source-plugin - 2.4 + 3.0.1 attach-sources @@ -210,7 +201,7 @@ maven-site-plugin - 3.3 + 3.7.1 attach-descriptor @@ -262,44 +253,35 @@ org.apache.maven.plugins maven-surefire-report-plugin - 2.16 + 2.22.2 ${project.reporting.outputDirectory}/testresults - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - true - - - - html - - javadoc - - - - + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.0 + + true + 800m + none + + org.apache.maven.plugins maven-project-info-reports-plugin - 2.7 + 3.0.0 org.apache.maven.plugins maven-jxr-plugin - 2.3 - - true - + 3.0.0 org.codehaus.mojo cobertura-maven-plugin - 2.6 + 2.7 true %{project.reporting.outputDirectory}/cobertura @@ -308,7 +290,7 @@ org.codehaus.mojo findbugs-maven-plugin - 2.5.3 + 3.0.5 org.codehaus.mojo @@ -332,7 +314,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.4 + 1.6 sign-artifacts @@ -364,13 +346,14 @@ !skipCheckSources + [1.8,) org.apache.maven.plugins maven-checkstyle-plugin - 2.17 + 3.1.0 verify-style @@ -383,7 +366,7 @@ true true - ${project.build.sourceDirectory} + ${project.build.sourceDirectory} @@ -406,7 +389,7 @@ - + @@ -422,7 +405,7 @@ com.puppycrawl.tools checkstyle - 6.19 + 8.22 diff --git a/src/license/dual_lgpl_ap2/header.txt b/src/license/dual_lgpl_ap2/header.txt new file mode 100644 index 00000000..0dab2592 --- /dev/null +++ b/src/license/dual_lgpl_ap2/header.txt @@ -0,0 +1 @@ +Dual licensed under GNU LGPL 2.1 or Apache License 2.0 \ No newline at end of file diff --git a/src/license/dual_lgpl_ap2/license.txt b/src/license/dual_lgpl_ap2/license.txt new file mode 100644 index 00000000..8a2d35be --- /dev/null +++ b/src/license/dual_lgpl_ap2/license.txt @@ -0,0 +1,710 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +(This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.) + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + {signature of Ty Coon}, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + +********************************************************************************************* + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed 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. diff --git a/src/license/licenses.properties b/src/license/licenses.properties new file mode 100644 index 00000000..dfdce951 --- /dev/null +++ b/src/license/licenses.properties @@ -0,0 +1,10 @@ +### +# #%L +# JSQLParser library +# %% +# Copyright (C) 2004 - 2019 JSQLParser +# %% +# Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +# #L% +### +dual_lgpl_ap2=Dual License GNU LGPL 2.1 or Apache License 2.0 diff --git a/src/main/java/net/sf/jsqlparser/JSQLParserException.java b/src/main/java/net/sf/jsqlparser/JSQLParserException.java index 23494355..8ec0a3be 100644 --- a/src/main/java/net/sf/jsqlparser/JSQLParserException.java +++ b/src/main/java/net/sf/jsqlparser/JSQLParserException.java @@ -1,32 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser; -/** - * An exception class with stack trace informations - */ public class JSQLParserException extends Exception { - /* The serial class version */ private static final long serialVersionUID = -1099039459759769980L; private Throwable cause = null; @@ -48,7 +32,7 @@ public JSQLParserException(String arg0, Throwable arg1) { } @Override - public Throwable getCause() { + public synchronized Throwable getCause() { return cause; } diff --git a/src/main/java/net/sf/jsqlparser/expression/Alias.java b/src/main/java/net/sf/jsqlparser/expression/Alias.java index 6de50134..939f7136 100644 --- a/src/main/java/net/sf/jsqlparser/expression/Alias.java +++ b/src/main/java/net/sf/jsqlparser/expression/Alias.java @@ -1,34 +1,23 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -/** - * - * @author toben - */ +import java.util.List; +import java.util.Objects; +import net.sf.jsqlparser.statement.create.table.ColDataType; + public class Alias { private String name; private boolean useAs = true; + private List aliasColumns; public Alias(String name) { this.name = name; @@ -55,8 +44,48 @@ public void setUseAs(boolean useAs) { this.useAs = useAs; } + public List getAliasColumns() { + return aliasColumns; + } + + public void setAliasColumns(List aliasColumns) { + this.aliasColumns = aliasColumns; + } + @Override public String toString() { - return (useAs ? " AS " : " ") + name; + String alias = (useAs ? " AS " : " ") + name; + + if (aliasColumns != null && !aliasColumns.isEmpty()) { + String ac = ""; + for (AliasColumn col : aliasColumns) { + if (ac.length() > 0) { + ac += ", "; + } + ac += col.name; + if (col.colDataType != null) { + ac += " " + col.colDataType.toString(); + } + } + alias += "(" + ac + ")"; + } + + return alias; + } + + public static class AliasColumn { + + public final String name; + public final ColDataType colDataType; + + public AliasColumn(String name, ColDataType colDataType) { + Objects.requireNonNull(name); + this.name = name; + this.colDataType = colDataType; + } + + public AliasColumn(String name) { + this(name, null); + } } } diff --git a/src/main/java/net/sf/jsqlparser/expression/AllComparisonExpression.java b/src/main/java/net/sf/jsqlparser/expression/AllComparisonExpression.java index cfa10043..85fb4268 100644 --- a/src/main/java/net/sf/jsqlparser/expression/AllComparisonExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/AllComparisonExpression.java @@ -1,29 +1,18 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.statement.select.SubSelect; -public class AllComparisonExpression implements Expression { +public class AllComparisonExpression extends ASTNodeAccessImpl implements Expression { private final SubSelect subSelect; diff --git a/src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java b/src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java index 9be0d32b..af566ee2 100644 --- a/src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java @@ -1,31 +1,18 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -import net.sf.jsqlparser.statement.select.OrderByElement; - import java.util.List; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; -import net.sf.jsqlparser.statement.select.PlainSelect; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; +import net.sf.jsqlparser.statement.select.OrderByElement; /** * Analytic function. The name of the function is variable but the parameters following the special @@ -35,17 +22,47 @@ * * @author tw */ -public class AnalyticExpression implements Expression { +public class AnalyticExpression extends ASTNodeAccessImpl implements Expression { - private ExpressionList partitionExpressionList; - private List orderByElements; + private final OrderByClause orderBy = new OrderByClause(); + private final PartitionByClause partitionBy = new PartitionByClause(); private String name; private Expression expression; private Expression offset; private Expression defaultValue; private boolean allColumns = false; - private WindowElement windowElement; private KeepExpression keep = null; + private AnalyticType type = AnalyticType.OVER; + private boolean distinct = false; + private boolean ignoreNulls = false; + private Expression filterExpression = null; + private WindowElement windowElement = null; + + public AnalyticExpression() { + } + + public AnalyticExpression(Function function) { + name = function.getName(); + allColumns = function.isAllColumns(); + distinct = function.isDistinct(); + + ExpressionList list = function.getParameters(); + if (list != null) { + if (list.getExpressions().size() > 3) { + throw new IllegalArgumentException("function object not valid to initialize analytic expression"); + } + + expression = list.getExpressions().get(0); + if (list.getExpressions().size() > 1) { + offset = list.getExpressions().get(1); + } + if (list.getExpressions().size() > 2) { + defaultValue = list.getExpressions().get(2); + } + } + ignoreNulls = function.isIgnoreNulls(); + keep = function.getKeep(); + } @Override public void accept(ExpressionVisitor expressionVisitor) { @@ -53,11 +70,11 @@ public void accept(ExpressionVisitor expressionVisitor) { } public List getOrderByElements() { - return orderByElements; + return orderBy.getOrderByElements(); } public void setOrderByElements(List orderByElements) { - this.orderByElements = orderByElements; + orderBy.setOrderByElements(orderByElements); } public KeepExpression getKeep() { @@ -69,11 +86,19 @@ public void setKeep(KeepExpression keep) { } public ExpressionList getPartitionExpressionList() { - return partitionExpressionList; + return partitionBy.getPartitionExpressionList(); } public void setPartitionExpressionList(ExpressionList partitionExpressionList) { - this.partitionExpressionList = partitionExpressionList; + setPartitionExpressionList(partitionExpressionList, false); + } + + public void setPartitionExpressionList(ExpressionList partitionExpressionList, boolean brackets) { + partitionBy.setPartitionExpressionList(partitionExpressionList, brackets); + } + + public boolean isPartitionByBrackets() { + return partitionBy.isBrackets(); } public String getName() { @@ -116,11 +141,38 @@ public void setWindowElement(WindowElement windowElement) { this.windowElement = windowElement; } + public AnalyticType getType() { + return type; + } + + public void setType(AnalyticType type) { + this.type = type; + } + + public boolean isDistinct() { + return distinct; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isIgnoreNulls() { + return ignoreNulls; + } + + public void setIgnoreNulls(boolean ignoreNulls) { + this.ignoreNulls = ignoreNulls; + } + @Override public String toString() { StringBuilder b = new StringBuilder(); b.append(name).append("("); + if (isDistinct()) { + b.append("DISTINCT "); + } if (expression != null) { b.append(expression.toString()); if (offset != null) { @@ -132,14 +184,38 @@ public String toString() { } else if (isAllColumns()) { b.append("*"); } + if (isIgnoreNulls()) { + b.append(" IGNORE NULLS"); + } b.append(") "); if (keep != null) { b.append(keep.toString()).append(" "); } - b.append("OVER ("); - toStringPartitionBy(b); - toStringOrderByElements(b); + if (filterExpression != null) { + b.append("FILTER (WHERE "); + b.append(filterExpression.toString()); + b.append(") "); + } + + switch (type) { + case WITHIN_GROUP: + b.append("WITHIN GROUP"); + break; + default: + b.append("OVER"); + } + b.append(" ("); + + partitionBy.toStringPartitionBy(b); + orderBy.toStringOrderByElements(b); + + if (windowElement != null) { + if (orderBy.getOrderByElements()!=null) { + b.append(' '); + } + b.append(windowElement); + } b.append(")"); @@ -154,29 +230,11 @@ public void setAllColumns(boolean allColumns) { this.allColumns = allColumns; } - private void toStringPartitionBy(StringBuilder b) { - if (partitionExpressionList != null && !partitionExpressionList.getExpressions().isEmpty()) { - b.append("PARTITION BY "); - b.append(PlainSelect. - getStringList(partitionExpressionList.getExpressions(), true, false)); - b.append(" "); - } + public Expression getFilterExpression() { + return filterExpression; } - private void toStringOrderByElements(StringBuilder b) { - if (orderByElements != null && !orderByElements.isEmpty()) { - b.append("ORDER BY "); - for (int i = 0; i < orderByElements.size(); i++) { - if (i > 0) { - b.append(", "); - } - b.append(orderByElements.get(i).toString()); - } - - if (windowElement != null) { - b.append(' '); - b.append(windowElement); - } - } + public void setFilterExpression(Expression filterExpression) { + this.filterExpression = filterExpression; } } diff --git a/src/main/java/net/sf/jsqlparser/expression/AnalyticType.java b/src/main/java/net/sf/jsqlparser/expression/AnalyticType.java new file mode 100644 index 00000000..d4c8ad0c --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/AnalyticType.java @@ -0,0 +1,15 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +public enum AnalyticType { + OVER, + WITHIN_GROUP +} diff --git a/src/main/java/net/sf/jsqlparser/expression/AnyComparisonExpression.java b/src/main/java/net/sf/jsqlparser/expression/AnyComparisonExpression.java index 48b656ec..05d598b2 100644 --- a/src/main/java/net/sf/jsqlparser/expression/AnyComparisonExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/AnyComparisonExpression.java @@ -1,26 +1,15 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.statement.select.SubSelect; /** @@ -28,7 +17,7 @@ * * @author toben */ -public class AnyComparisonExpression implements Expression { +public class AnyComparisonExpression extends ASTNodeAccessImpl implements Expression { private final SubSelect subSelect; private final AnyType anyType; diff --git a/src/main/java/net/sf/jsqlparser/expression/AnyType.java b/src/main/java/net/sf/jsqlparser/expression/AnyType.java index 1e5c2451..d279b53d 100644 --- a/src/main/java/net/sf/jsqlparser/expression/AnyType.java +++ b/src/main/java/net/sf/jsqlparser/expression/AnyType.java @@ -1,48 +1,14 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ - /* - * Copyright (C) 2015 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ package net.sf.jsqlparser.expression; -/** - * - * @author toben - */ public enum AnyType { ANY, diff --git a/src/main/java/net/sf/jsqlparser/expression/ArrayExpression.java b/src/main/java/net/sf/jsqlparser/expression/ArrayExpression.java new file mode 100644 index 00000000..05ebfa95 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/ArrayExpression.java @@ -0,0 +1,49 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class ArrayExpression extends ASTNodeAccessImpl implements Expression { + + private Expression objExpression; + private Expression indexExpression; + + public ArrayExpression(Expression objExpression, Expression indexExpression) { + this.objExpression = objExpression; + this.indexExpression = indexExpression; + } + + public Expression getObjExpression() { + return objExpression; + } + + public void setObjExpression(Expression objExpression) { + this.objExpression = objExpression; + } + + public Expression getIndexExpression() { + return indexExpression; + } + + public void setIndexExpression(Expression indexExpression) { + this.indexExpression = indexExpression; + } + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } + + @Override + public String toString() { + return objExpression.toString() + "[" + indexExpression.toString() + "]"; + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/BinaryExpression.java b/src/main/java/net/sf/jsqlparser/expression/BinaryExpression.java index 90dbf7a8..1a7b932e 100644 --- a/src/main/java/net/sf/jsqlparser/expression/BinaryExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/BinaryExpression.java @@ -1,38 +1,26 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** * A basic class for binary expressions, that is expressions having a left member and a right member * which are in turn expressions. */ -public abstract class BinaryExpression implements Expression { +public abstract class BinaryExpression extends ASTNodeAccessImpl implements Expression { private Expression leftExpression; private Expression rightExpression; - private boolean not = false; - - - +// private boolean not = false; + public BinaryExpression() { } @@ -52,23 +40,23 @@ public void setRightExpression(Expression expression) { rightExpression = expression; } - public void setNot() { - not = true; - } - - public void removeNot() { - not = false; - } - - public boolean isNot() { - return not; - } - +// public void setNot() { +// not = true; +// } +// +// public void removeNot() { +// not = false; +// } +// +// public boolean isNot() { +// return not; +// } @Override public String toString() { - return (not ? "NOT " : "") + getLeftExpression() + " " + getStringExpression() + " " + getRightExpression(); + return //(not ? "NOT " : "") + + getLeftExpression() + " " + getStringExpression() + " " + getRightExpression(); } public abstract String getStringExpression(); - + } diff --git a/src/main/java/net/sf/jsqlparser/expression/CaseExpression.java b/src/main/java/net/sf/jsqlparser/expression/CaseExpression.java index a43f4e20..63c1faaa 100644 --- a/src/main/java/net/sf/jsqlparser/expression/CaseExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/CaseExpression.java @@ -1,28 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; import java.util.List; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.statement.select.PlainSelect; /** @@ -48,18 +37,11 @@ * END * * - * See also: https://aurora.vcu.edu/db2help/db2s0/frame3.htm#casexp - * http://sybooks.sybase.com/onlinebooks/group-as/asg1251e /commands/ - * - * @ebt-link;pt=5954?target=%25N%15_52628_START_RESTART_N%25 - * - * - * @author Havard Rast Blok */ -public class CaseExpression implements Expression { +public class CaseExpression extends ASTNodeAccessImpl implements Expression { private Expression switchExpression; - private List whenClauses; + private List whenClauses; private Expression elseExpression; @Override @@ -67,16 +49,10 @@ public void accept(ExpressionVisitor expressionVisitor) { expressionVisitor.visit(this); } - /** - * @return Returns the switchExpression. - */ public Expression getSwitchExpression() { return switchExpression; } - /** - * @param switchExpression The switchExpression to set. - */ public void setSwitchExpression(Expression switchExpression) { this.switchExpression = switchExpression; } @@ -98,14 +74,14 @@ public void setElseExpression(Expression elseExpression) { /** * @return Returns the whenClauses. */ - public List getWhenClauses() { + public List getWhenClauses() { return whenClauses; } /** * @param whenClauses The whenClauses to set. */ - public void setWhenClauses(List whenClauses) { + public void setWhenClauses(List whenClauses) { this.whenClauses = whenClauses; } diff --git a/src/main/java/net/sf/jsqlparser/expression/CastExpression.java b/src/main/java/net/sf/jsqlparser/expression/CastExpression.java index 0e757629..3031a20b 100644 --- a/src/main/java/net/sf/jsqlparser/expression/CastExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/CastExpression.java @@ -1,33 +1,18 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.statement.create.table.ColDataType; -/** - * - * @author tw - */ -public class CastExpression implements Expression { +public class CastExpression extends ASTNodeAccessImpl implements Expression { private Expression leftExpression; private ColDataType type; diff --git a/src/main/java/net/sf/jsqlparser/expression/CollateExpression.java b/src/main/java/net/sf/jsqlparser/expression/CollateExpression.java new file mode 100644 index 00000000..5638bcf7 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/CollateExpression.java @@ -0,0 +1,49 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class CollateExpression extends ASTNodeAccessImpl implements Expression { + + private Expression leftExpression; + private String collate; + + public CollateExpression(Expression leftExpression, String collate) { + this.leftExpression = leftExpression; + this.collate = collate; + } + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } + + public Expression getLeftExpression() { + return leftExpression; + } + + public void setLeftExpression(Expression leftExpression) { + this.leftExpression = leftExpression; + } + + public String getCollate() { + return collate; + } + + public void setCollate(String collate) { + this.collate = collate; + } + + @Override + public String toString() { + return leftExpression.toString() + " COLLATE " + collate; + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/DateTimeLiteralExpression.java b/src/main/java/net/sf/jsqlparser/expression/DateTimeLiteralExpression.java index e71617ea..8af8b1c1 100644 --- a/src/main/java/net/sf/jsqlparser/expression/DateTimeLiteralExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/DateTimeLiteralExpression.java @@ -1,49 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2016 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ - /* - * Copyright (C) 2016 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ package net.sf.jsqlparser.expression; -/** - * - * @author toben - */ -public class DateTimeLiteralExpression implements Expression { +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class DateTimeLiteralExpression extends ASTNodeAccessImpl implements Expression { private String value; private DateTime type; diff --git a/src/main/java/net/sf/jsqlparser/expression/DateValue.java b/src/main/java/net/sf/jsqlparser/expression/DateValue.java index f785bae8..c83e39e8 100644 --- a/src/main/java/net/sf/jsqlparser/expression/DateValue.java +++ b/src/main/java/net/sf/jsqlparser/expression/DateValue.java @@ -1,32 +1,22 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + import java.sql.Date; /** * A Date in the form {d 'yyyy-mm-dd'} */ -public class DateValue implements Expression { +public class DateValue extends ASTNodeAccessImpl implements Expression { private Date value; diff --git a/src/main/java/net/sf/jsqlparser/expression/DoubleValue.java b/src/main/java/net/sf/jsqlparser/expression/DoubleValue.java index aaa98e77..e882b1a7 100644 --- a/src/main/java/net/sf/jsqlparser/expression/DoubleValue.java +++ b/src/main/java/net/sf/jsqlparser/expression/DoubleValue.java @@ -1,30 +1,20 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** * Every number with a point or a exponential format is a DoubleValue */ -public class DoubleValue implements Expression { +public class DoubleValue extends ASTNodeAccessImpl implements Expression { private double value; private String stringValue; diff --git a/src/main/java/net/sf/jsqlparser/expression/Expression.java b/src/main/java/net/sf/jsqlparser/expression/Expression.java index 7c2c4181..dec9bbf4 100644 --- a/src/main/java/net/sf/jsqlparser/expression/Expression.java +++ b/src/main/java/net/sf/jsqlparser/expression/Expression.java @@ -1,27 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -public interface Expression { +import net.sf.jsqlparser.parser.ASTNodeAccess; + +public interface Expression extends ASTNodeAccess { void accept(ExpressionVisitor expressionVisitor); } diff --git a/src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java b/src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java index e9b9b5a6..e2dde0a3 100644 --- a/src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java +++ b/src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java @@ -1,57 +1,27 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -import net.sf.jsqlparser.expression.operators.arithmetic.Addition; -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd; -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr; -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor; -import net.sf.jsqlparser.expression.operators.arithmetic.Concat; -import net.sf.jsqlparser.expression.operators.arithmetic.Division; -import net.sf.jsqlparser.expression.operators.arithmetic.Modulo; -import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication; -import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction; +import net.sf.jsqlparser.expression.operators.arithmetic.*; import net.sf.jsqlparser.expression.operators.conditional.AndExpression; import net.sf.jsqlparser.expression.operators.conditional.OrExpression; -import net.sf.jsqlparser.expression.operators.relational.Between; -import net.sf.jsqlparser.expression.operators.relational.EqualsTo; -import net.sf.jsqlparser.expression.operators.relational.ExistsExpression; -import net.sf.jsqlparser.expression.operators.relational.GreaterThan; -import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals; -import net.sf.jsqlparser.expression.operators.relational.InExpression; -import net.sf.jsqlparser.expression.operators.relational.IsNullExpression; -import net.sf.jsqlparser.expression.operators.relational.LikeExpression; -import net.sf.jsqlparser.expression.operators.relational.Matches; -import net.sf.jsqlparser.expression.operators.relational.MinorThan; -import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals; -import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo; -import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator; -import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator; -import net.sf.jsqlparser.expression.operators.relational.JsonOperator; +import net.sf.jsqlparser.expression.operators.relational.*; import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.statement.select.SubSelect; public interface ExpressionVisitor { + public void visit(BitwiseRightShift aThis); + + public void visit(BitwiseLeftShift aThis); + void visit(NullValue nullValue); void visit(Function function); @@ -82,6 +52,8 @@ public interface ExpressionVisitor { void visit(Division division); + void visit(IntegerDivision division); + void visit(Multiplication multiplication); void visit(Subtraction subtraction); @@ -100,8 +72,12 @@ public interface ExpressionVisitor { void visit(InExpression inExpression); + void visit(FullTextSearch fullTextSearch); + void visit(IsNullExpression isNullExpression); + void visit(IsBooleanExpression isBooleanExpression); + void visit(LikeExpression likeExpression); void visit(MinorThan minorThan); @@ -140,8 +116,6 @@ public interface ExpressionVisitor { void visit(AnalyticExpression aexpr); - void visit(WithinGroupExpression wgexpr); - void visit(ExtractExpression eexpr); void visit(IntervalExpression iexpr); @@ -164,6 +138,8 @@ public interface ExpressionVisitor { void visit(MySQLGroupConcat groupConcat); + void visit(ValueListExpression valueList); + void visit(RowConstructor rowConstructor); void visit(OracleHint hint); @@ -174,4 +150,12 @@ public interface ExpressionVisitor { public void visit(NotExpression aThis); + public void visit(NextValExpression aThis); + + public void visit(CollateExpression aThis); + + public void visit(SimilarToExpression aThis); + + public void visit(ArrayExpression aThis); + } diff --git a/src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java b/src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java index 61a2e6b1..ea316804 100644 --- a/src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java +++ b/src/main/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapter.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; @@ -24,7 +12,6 @@ import net.sf.jsqlparser.expression.operators.arithmetic.*; import net.sf.jsqlparser.expression.operators.conditional.AndExpression; import net.sf.jsqlparser.expression.operators.conditional.OrExpression; -import net.sf.jsqlparser.expression.operators.relational.JsonOperator; import net.sf.jsqlparser.expression.operators.relational.*; import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.statement.select.AllColumns; @@ -39,6 +26,7 @@ import net.sf.jsqlparser.statement.select.SelectItemVisitor; import net.sf.jsqlparser.statement.select.SelectVisitor; import net.sf.jsqlparser.statement.select.SubSelect; +import net.sf.jsqlparser.statement.select.UnPivot; import net.sf.jsqlparser.statement.select.WithItem; public class ExpressionVisitorAdapter implements ExpressionVisitor, ItemsListVisitor, PivotVisitor, SelectItemVisitor { @@ -128,6 +116,11 @@ public void visit(Division expr) { visitBinaryExpression(expr); } + @Override + public void visit(IntegerDivision expr) { + visitBinaryExpression(expr); + } + @Override public void visit(Multiplication expr) { visitBinaryExpression(expr); @@ -185,6 +178,18 @@ public void visit(IsNullExpression expr) { expr.getLeftExpression().accept(this); } + @Override + public void visit(FullTextSearch expr) { + for (Column col : expr.getMatchColumns()) { + col.accept(this); + } + } + + @Override + public void visit(IsBooleanExpression expr) { + expr.getLeftExpression().accept(this); + } + @Override public void visit(LikeExpression expr) { visitBinaryExpression(expr); @@ -227,7 +232,7 @@ public void visit(SubSelect subSelect) { @Override public void visit(CaseExpression expr) { - if (expr.getSwitchExpression()!=null) { + if (expr.getSwitchExpression() != null) { expr.getSwitchExpression().accept(this); } for (Expression x : expr.getWhenClauses()) { @@ -296,9 +301,15 @@ public void visit(Modulo expr) { @Override public void visit(AnalyticExpression expr) { - expr.getExpression().accept(this); - expr.getDefaultValue().accept(this); - expr.getOffset().accept(this); + if (expr.getExpression() != null) { + expr.getExpression().accept(this); + } + if (expr.getDefaultValue() != null) { + expr.getDefaultValue().accept(this); + } + if (expr.getOffset() != null) { + expr.getOffset().accept(this); + } if (expr.getKeep() != null) { expr.getKeep().accept(this); } @@ -306,9 +317,11 @@ public void visit(AnalyticExpression expr) { element.getExpression().accept(this); } - expr.getWindowElement().getRange().getStart().getExpression().accept(this); - expr.getWindowElement().getRange().getEnd().getExpression().accept(this); - expr.getWindowElement().getOffset().getExpression().accept(this); + if (expr.getWindowElement() != null) { + expr.getWindowElement().getRange().getStart().getExpression().accept(this); + expr.getWindowElement().getRange().getEnd().getExpression().accept(this); + expr.getWindowElement().getOffset().getExpression().accept(this); + } } @Override @@ -338,6 +351,13 @@ public void visit(ExpressionList expressionList) { } } + @Override + public void visit(NamedExpressionList namedExpressionList) { + for (Expression expr : namedExpressionList.getExpressions()) { + expr.accept(this); + } + } + @Override public void visit(MultiExpressionList multiExprList) { for (ExpressionList list : multiExprList.getExprList()) { @@ -350,6 +370,16 @@ public void visit(NotExpression notExpr) { notExpr.getExpression().accept(this); } + @Override + public void visit(BitwiseRightShift expr) { + visitBinaryExpression(expr); + } + + @Override + public void visit(BitwiseLeftShift expr) { + visitBinaryExpression(expr); + } + protected void visitBinaryExpression(BinaryExpression expr) { expr.getLeftExpression().accept(this); expr.getRightExpression().accept(this); @@ -370,14 +400,6 @@ public void visit(RegExpMySQLOperator expr) { visitBinaryExpression(expr); } - @Override - public void visit(WithinGroupExpression wgexpr) { - wgexpr.getExprList().accept(this); - for (OrderByElement element : wgexpr.getOrderByElements()) { - element.getExpression().accept(this); - } - } - @Override public void visit(UserVariable var) { @@ -407,6 +429,13 @@ public void visit(MySQLGroupConcat groupConcat) { } } + @Override + public void visit(ValueListExpression valueListExpression) { + for (Expression expr : valueListExpression.getExpressionList().getExpressions()) { + expr.accept(this); + } + } + @Override public void visit(Pivot pivot) { for (FunctionItem item : pivot.getFunctionItems()) { @@ -441,6 +470,11 @@ public void visit(PivotXml pivot) { } } + @Override + public void visit(UnPivot unpivot) { + unpivot.accept(this); + } + @Override public void visit(AllColumns allColumns) { @@ -480,7 +514,25 @@ public void visit(TimeKeyExpression timeKeyExpression) { @Override public void visit(DateTimeLiteralExpression literal) { + } + @Override + public void visit(NextValExpression nextVal) { + } + + @Override + public void visit(CollateExpression col) { + col.getLeftExpression().accept(this); } + @Override + public void visit(SimilarToExpression expr) { + visitBinaryExpression(expr); + } + + @Override + public void visit(ArrayExpression array) { + array.getObjExpression().accept(this); + array.getIndexExpression().accept(this); + } } diff --git a/src/main/java/net/sf/jsqlparser/expression/ExtractExpression.java b/src/main/java/net/sf/jsqlparser/expression/ExtractExpression.java index e082266e..b3c07a0e 100644 --- a/src/main/java/net/sf/jsqlparser/expression/ExtractExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/ExtractExpression.java @@ -1,33 +1,23 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** * Extract value from date/time expression. The name stores the part - name to get from the * following date/time expression. * * @author tw */ -public class ExtractExpression implements Expression { +public class ExtractExpression extends ASTNodeAccessImpl implements Expression { private String name; private Expression expression; diff --git a/src/main/java/net/sf/jsqlparser/expression/Function.java b/src/main/java/net/sf/jsqlparser/expression/Function.java index 53c1ca3d..5658c29c 100644 --- a/src/main/java/net/sf/jsqlparser/expression/Function.java +++ b/src/main/java/net/sf/jsqlparser/expression/Function.java @@ -1,27 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.expression.operators.relational.NamedExpressionList; import net.sf.jsqlparser.parser.ASTNodeAccessImpl; /** @@ -31,22 +20,20 @@ public class Function extends ASTNodeAccessImpl implements Expression { private String name; private ExpressionList parameters; + private NamedExpressionList namedParameters; private boolean allColumns = false; private boolean distinct = false; private boolean isEscaped = false; - private String attribute; + private Expression attribute; + private String attributeName; private KeepExpression keep = null; + private boolean ignoreNulls = false; @Override public void accept(ExpressionVisitor expressionVisitor) { expressionVisitor.visit(this); } - /** - * The name of he function, i.e. "MAX" - * - * @return the name of he function - */ public String getName() { return name; } @@ -55,11 +42,6 @@ public void setName(String string) { name = string; } - /** - * true if the parameter to the function is "*" - * - * @return true if the parameter to the function is "*" - */ public boolean isAllColumns() { return allColumns; } @@ -68,6 +50,20 @@ public void setAllColumns(boolean b) { allColumns = b; } + public boolean isIgnoreNulls() { + return ignoreNulls; + } + + /** + * This is at the moment only necessary for AnalyticExpression initialization and not for normal + * functions. Therefore there is no deparsing for it for normal functions. + * + * @param ignoreNulls + */ + public void setIgnoreNulls(boolean ignoreNulls) { + this.ignoreNulls = ignoreNulls; + } + /** * true if the function is "distinct" * @@ -95,6 +91,19 @@ public void setParameters(ExpressionList list) { parameters = list; } + /** + * the parameters might be named parameters, e.g. substring('foobar' from 2 for 3) + * + * @return the list of named parameters of the function (if any, else null) + */ + public NamedExpressionList getNamedParameters() { + return namedParameters; + } + + public void setNamedParameters(NamedExpressionList list) { + namedParameters = list; + } + /** * Return true if it's in the form "{fn function_body() }" * @@ -108,14 +117,22 @@ public void setEscaped(boolean isEscaped) { this.isEscaped = isEscaped; } - public String getAttribute() { + public Expression getAttribute() { return attribute; } - public void setAttribute(String attribute) { + public void setAttribute(Expression attribute) { this.attribute = attribute; } + public String getAttributeName() { + return attributeName; + } + + public void setAttributeName(String attributeName) { + this.attributeName = attributeName; + } + public KeepExpression getKeep() { return keep; } @@ -128,12 +145,16 @@ public void setKeep(KeepExpression keep) { public String toString() { String params; - if (parameters != null) { - params = parameters.toString(); - if (isDistinct()) { - params = params.replaceFirst("\\(", "(DISTINCT "); - } else if (isAllColumns()) { - params = params.replaceFirst("\\(", "(ALL "); + if (parameters != null || namedParameters != null) { + if (parameters != null) { + params = parameters.toString(); + if (isDistinct()) { + params = params.replaceFirst("\\(", "(DISTINCT "); + } else if (isAllColumns()) { + params = params.replaceFirst("\\(", "(ALL "); + } + } else { + params = namedParameters.toString(); } } else if (isAllColumns()) { params = "(*)"; @@ -144,7 +165,9 @@ public String toString() { String ans = name + "" + params + ""; if (attribute != null) { - ans += "." + attribute; + ans += "." + attribute.toString(); + } else if (attributeName != null) { + ans += "." + attributeName; } if (keep != null) { diff --git a/src/main/java/net/sf/jsqlparser/expression/HexValue.java b/src/main/java/net/sf/jsqlparser/expression/HexValue.java index ba6ea49f..2bc3b421 100644 --- a/src/main/java/net/sf/jsqlparser/expression/HexValue.java +++ b/src/main/java/net/sf/jsqlparser/expression/HexValue.java @@ -1,30 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -/** - * Every number with a point or a exponential format is a DoubleValue - */ -public class HexValue implements Expression { +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class HexValue extends ASTNodeAccessImpl implements Expression { private String stringValue; diff --git a/src/main/java/net/sf/jsqlparser/expression/IntervalExpression.java b/src/main/java/net/sf/jsqlparser/expression/IntervalExpression.java index 4d62bf5d..3f82409a 100644 --- a/src/main/java/net/sf/jsqlparser/expression/IntervalExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/IntervalExpression.java @@ -1,34 +1,31 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -/** - * - * @author wumpz - */ -public class IntervalExpression implements Expression { +import java.util.Objects; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class IntervalExpression extends ASTNodeAccessImpl implements Expression { private String parameter = null; private String intervalType = null; + private final boolean intervalKeyword; + private Expression expression = null; + + public IntervalExpression() { + this(true); + } + + public IntervalExpression(boolean intervalKeyword) { + this.intervalKeyword = intervalKeyword; + } public String getParameter() { return parameter; @@ -46,9 +43,19 @@ public void setIntervalType(String intervalType) { this.intervalType = intervalType; } + public Expression getExpression() { + return expression; + } + + public void setExpression(Expression expression) { + this.expression = expression; + } + @Override public String toString() { - return "INTERVAL " + parameter + (intervalType != null ? " " + intervalType : ""); + return (intervalKeyword ? "INTERVAL " : "") + + Objects.toString(expression, parameter) + + (intervalType != null ? " " + intervalType : ""); } @Override diff --git a/src/main/java/net/sf/jsqlparser/expression/JdbcNamedParameter.java b/src/main/java/net/sf/jsqlparser/expression/JdbcNamedParameter.java index 8b5a3268..0c66dd46 100644 --- a/src/main/java/net/sf/jsqlparser/expression/JdbcNamedParameter.java +++ b/src/main/java/net/sf/jsqlparser/expression/JdbcNamedParameter.java @@ -1,39 +1,27 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -/** - * - * @author aud - */ -public class JdbcNamedParameter implements Expression { +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class JdbcNamedParameter extends ASTNodeAccessImpl implements Expression { private String name; - /** - * The name of the parameter - * - * @return the name of the parameter - */ + public JdbcNamedParameter() { + } + + public JdbcNamedParameter(String name) { + this.name = name; + } + public String getName() { return name; } diff --git a/src/main/java/net/sf/jsqlparser/expression/JdbcParameter.java b/src/main/java/net/sf/jsqlparser/expression/JdbcParameter.java index 37c06b11..d2dc0be5 100644 --- a/src/main/java/net/sf/jsqlparser/expression/JdbcParameter.java +++ b/src/main/java/net/sf/jsqlparser/expression/JdbcParameter.java @@ -1,30 +1,20 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** * A '?' in a statement or a ? e.g. ?4 */ -public class JdbcParameter implements Expression { +public class JdbcParameter extends ASTNodeAccessImpl implements Expression { private Integer index; private boolean useFixedIndex = false; diff --git a/src/main/java/net/sf/jsqlparser/expression/JsonExpression.java b/src/main/java/net/sf/jsqlparser/expression/JsonExpression.java index c8821741..7eed1cf1 100644 --- a/src/main/java/net/sf/jsqlparser/expression/JsonExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/JsonExpression.java @@ -1,35 +1,21 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; import java.util.ArrayList; import java.util.List; + +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.schema.Column; -/** - * - * @author toben - */ -public class JsonExpression implements Expression { +public class JsonExpression extends ASTNodeAccessImpl implements Expression { private Column column; diff --git a/src/main/java/net/sf/jsqlparser/expression/KeepExpression.java b/src/main/java/net/sf/jsqlparser/expression/KeepExpression.java index b0dfe82e..51fb5b8b 100644 --- a/src/main/java/net/sf/jsqlparser/expression/KeepExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/KeepExpression.java @@ -1,39 +1,20 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.statement.select.OrderByElement; import java.util.List; -/** - * Analytic function. The name of the function is variable but the parameters following the special - * analytic function path. e.g. row_number() over (order by test). Additional there can be an - * expression for an analytical aggregate like sum(col) or the "all collumns" wildcard like - * count(*). - * - * @author tw - */ -public class KeepExpression implements Expression { +public class KeepExpression extends ASTNodeAccessImpl implements Expression { private String name; private List orderByElements; diff --git a/src/main/java/net/sf/jsqlparser/expression/LongValue.java b/src/main/java/net/sf/jsqlparser/expression/LongValue.java index 23fd12ef..253c73a0 100644 --- a/src/main/java/net/sf/jsqlparser/expression/LongValue.java +++ b/src/main/java/net/sf/jsqlparser/expression/LongValue.java @@ -1,32 +1,22 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + import java.math.BigInteger; /** * Every number without a point or an exponential format is a LongValue. */ -public class LongValue implements Expression { +public class LongValue extends ASTNodeAccessImpl implements Expression { private String stringValue; diff --git a/src/main/java/net/sf/jsqlparser/expression/MySQLGroupConcat.java b/src/main/java/net/sf/jsqlparser/expression/MySQLGroupConcat.java index 291a2104..68f11071 100644 --- a/src/main/java/net/sf/jsqlparser/expression/MySQLGroupConcat.java +++ b/src/main/java/net/sf/jsqlparser/expression/MySQLGroupConcat.java @@ -1,54 +1,21 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ - /* - * Copyright (C) 2015 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ package net.sf.jsqlparser.expression; import java.util.List; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.statement.select.OrderByElement; import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * - * @author toben - */ -public class MySQLGroupConcat implements Expression { +public class MySQLGroupConcat extends ASTNodeAccessImpl implements Expression { private ExpressionList expressionList; private boolean distinct = false; diff --git a/src/main/java/net/sf/jsqlparser/expression/MySQLIndexHint.java b/src/main/java/net/sf/jsqlparser/expression/MySQLIndexHint.java index ca3bb758..cef60c50 100644 --- a/src/main/java/net/sf/jsqlparser/expression/MySQLIndexHint.java +++ b/src/main/java/net/sf/jsqlparser/expression/MySQLIndexHint.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; diff --git a/src/main/java/net/sf/jsqlparser/expression/NextValExpression.java b/src/main/java/net/sf/jsqlparser/expression/NextValExpression.java new file mode 100644 index 00000000..50e30553 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/NextValExpression.java @@ -0,0 +1,43 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +import java.util.List; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class NextValExpression extends ASTNodeAccessImpl implements Expression { + + private List nameList; + + public NextValExpression(List nameList) { + this.nameList = nameList; + } + + public String getName() { + StringBuilder b = new StringBuilder(); + for (String name : nameList) { + if (b.length() > 0) { + b.append("."); + } + b.append(name); + } + return b.toString(); + } + + @Override + public String toString() { + return "NEXTVAL FOR " + getName(); + } + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/NotExpression.java b/src/main/java/net/sf/jsqlparser/expression/NotExpression.java index e94d05fe..62d8846d 100644 --- a/src/main/java/net/sf/jsqlparser/expression/NotExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/NotExpression.java @@ -1,35 +1,32 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** - * It represents a "-" or "+" before an expression + * It represents a "not " or "!" before an expression. */ -public class NotExpression implements Expression { +public class NotExpression extends ASTNodeAccessImpl implements Expression { private Expression expression; + private boolean exclamationMark = false; + public NotExpression(Expression expression) { + this(expression, false); + } + + public NotExpression(Expression expression, boolean useExclamationMark) { setExpression(expression); + this.exclamationMark = useExclamationMark; } public Expression getExpression() { @@ -47,6 +44,14 @@ public void accept(ExpressionVisitor expressionVisitor) { @Override public String toString() { - return "NOT " + expression.toString(); + return (exclamationMark ? "! " : "NOT ") + expression.toString(); + } + + public boolean isExclamationMark() { + return exclamationMark; + } + + public void setExclamationMark(boolean exclamationMark) { + this.exclamationMark = exclamationMark; } } diff --git a/src/main/java/net/sf/jsqlparser/expression/NullValue.java b/src/main/java/net/sf/jsqlparser/expression/NullValue.java index d1fd4557..b6397030 100644 --- a/src/main/java/net/sf/jsqlparser/expression/NullValue.java +++ b/src/main/java/net/sf/jsqlparser/expression/NullValue.java @@ -1,30 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -/** - * A "NULL" in a sql statement - */ -public class NullValue implements Expression { +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class NullValue extends ASTNodeAccessImpl implements Expression { @Override public void accept(ExpressionVisitor expressionVisitor) { diff --git a/src/main/java/net/sf/jsqlparser/expression/NumericBind.java b/src/main/java/net/sf/jsqlparser/expression/NumericBind.java index e4c29d5d..106b2214 100644 --- a/src/main/java/net/sf/jsqlparser/expression/NumericBind.java +++ b/src/main/java/net/sf/jsqlparser/expression/NumericBind.java @@ -1,31 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -/** - * - * @author aud - */ -public class NumericBind implements Expression { +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class NumericBind extends ASTNodeAccessImpl implements Expression { private int bindId; diff --git a/src/main/java/net/sf/jsqlparser/expression/OracleHierarchicalExpression.java b/src/main/java/net/sf/jsqlparser/expression/OracleHierarchicalExpression.java index 9e8a9488..9c3b715c 100644 --- a/src/main/java/net/sf/jsqlparser/expression/OracleHierarchicalExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/OracleHierarchicalExpression.java @@ -1,31 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -/** - * - * @author toben - */ -public class OracleHierarchicalExpression implements Expression { +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class OracleHierarchicalExpression extends ASTNodeAccessImpl implements Expression { private Expression startExpression; private Expression connectExpression; diff --git a/src/main/java/net/sf/jsqlparser/expression/OracleHint.java b/src/main/java/net/sf/jsqlparser/expression/OracleHint.java index e0b82170..54ef90e4 100644 --- a/src/main/java/net/sf/jsqlparser/expression/OracleHint.java +++ b/src/main/java/net/sf/jsqlparser/expression/OracleHint.java @@ -1,35 +1,22 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; /** * Oracle Hint Expression - * - * @author valdo */ -public class OracleHint implements Expression { +public class OracleHint extends ASTNodeAccessImpl implements Expression { private static final Pattern SINGLE_LINE = Pattern.compile("--\\+ *([^ ].*[^ ])"); private static final Pattern MULTI_LINE = Pattern. diff --git a/src/main/java/net/sf/jsqlparser/expression/OrderByClause.java b/src/main/java/net/sf/jsqlparser/expression/OrderByClause.java new file mode 100644 index 00000000..c76a9c60 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/OrderByClause.java @@ -0,0 +1,38 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +import net.sf.jsqlparser.statement.select.OrderByElement; + +import java.util.List; + +public class OrderByClause { + private List orderByElements; + + public List getOrderByElements() { + return orderByElements; + } + + public void setOrderByElements(List orderByElements) { + this.orderByElements = orderByElements; + } + + void toStringOrderByElements(StringBuilder b) { + if (orderByElements != null && !orderByElements.isEmpty()) { + b.append("ORDER BY "); + for (int i = 0; i < orderByElements.size(); i++) { + if (i > 0) { + b.append(", "); + } + b.append(orderByElements.get(i).toString()); + } + } + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/Parenthesis.java b/src/main/java/net/sf/jsqlparser/expression/Parenthesis.java index 29217749..12bd6f3f 100644 --- a/src/main/java/net/sf/jsqlparser/expression/Parenthesis.java +++ b/src/main/java/net/sf/jsqlparser/expression/Parenthesis.java @@ -1,33 +1,22 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** * It represents an expression like "(" expression ")" */ -public class Parenthesis implements Expression { +public class Parenthesis extends ASTNodeAccessImpl implements Expression { private Expression expression; - private boolean not = false; public Parenthesis() { } @@ -49,16 +38,8 @@ public void accept(ExpressionVisitor expressionVisitor) { expressionVisitor.visit(this); } - public void setNot() { - not = true; - } - - public boolean isNot() { - return not; - } - @Override public String toString() { - return (not ? "NOT " : "") + "(" + expression + ")"; + return "(" + expression + ")"; } } diff --git a/src/main/java/net/sf/jsqlparser/expression/PartitionByClause.java b/src/main/java/net/sf/jsqlparser/expression/PartitionByClause.java new file mode 100644 index 00000000..57844ed6 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/PartitionByClause.java @@ -0,0 +1,44 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +import net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.statement.select.PlainSelect; + +public class PartitionByClause { + ExpressionList partitionExpressionList; + boolean brackets = false; + + public ExpressionList getPartitionExpressionList() { + return partitionExpressionList; + } + + public void setPartitionExpressionList(ExpressionList partitionExpressionList) { + setPartitionExpressionList(partitionExpressionList, false); + } + + public void setPartitionExpressionList(ExpressionList partitionExpressionList, boolean brackets) { + this.partitionExpressionList = partitionExpressionList; + this.brackets = brackets; + } + + void toStringPartitionBy(StringBuilder b) { + if (partitionExpressionList != null && !partitionExpressionList.getExpressions().isEmpty()) { + b.append("PARTITION BY "); + b.append(PlainSelect. + getStringList(partitionExpressionList.getExpressions(), true, brackets)); + b.append(" "); + } + } + + public boolean isBrackets() { + return brackets; + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/RowConstructor.java b/src/main/java/net/sf/jsqlparser/expression/RowConstructor.java index 575f4d4b..16144f24 100644 --- a/src/main/java/net/sf/jsqlparser/expression/RowConstructor.java +++ b/src/main/java/net/sf/jsqlparser/expression/RowConstructor.java @@ -1,34 +1,18 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; -/** - * Rowconstructor. - * - * @author tw - */ -public class RowConstructor implements Expression { +public class RowConstructor extends ASTNodeAccessImpl implements Expression { private ExpressionList exprList; private String name = null; diff --git a/src/main/java/net/sf/jsqlparser/expression/SignedExpression.java b/src/main/java/net/sf/jsqlparser/expression/SignedExpression.java index 2d766d24..ad8d3e1b 100644 --- a/src/main/java/net/sf/jsqlparser/expression/SignedExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/SignedExpression.java @@ -1,30 +1,20 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** - * It represents a "-" or "+" before an expression + * It represents a "-" or "+" or "~" before an expression */ -public class SignedExpression implements Expression { +public class SignedExpression extends ASTNodeAccessImpl implements Expression { private char sign; private Expression expression; @@ -40,8 +30,8 @@ public char getSign() { public final void setSign(char sign) { this.sign = sign; - if (sign != '+' && sign != '-') { - throw new IllegalArgumentException("illegal sign character, only + - allowed"); + if (sign != '+' && sign != '-' && sign != '~') { + throw new IllegalArgumentException("illegal sign character, only + - ~ allowed"); } } diff --git a/src/main/java/net/sf/jsqlparser/expression/StringValue.java b/src/main/java/net/sf/jsqlparser/expression/StringValue.java index d0a4d71f..25deae03 100644 --- a/src/main/java/net/sf/jsqlparser/expression/StringValue.java +++ b/src/main/java/net/sf/jsqlparser/expression/StringValue.java @@ -1,46 +1,56 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import java.util.Arrays; +import java.util.List; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** * A string as in 'example_string' */ -public class StringValue implements Expression { +public final class StringValue extends ASTNodeAccessImpl implements Expression { private String value = ""; + private String prefix = null; + + public static final List ALLOWED_PREFIXES = Arrays.asList("N", "U", "E", "R", "B", "RB", "_utf8"); public StringValue(String escapedValue) { - // romoving "'" at the start and at the end + // removing "'" at the start and at the end if (escapedValue.startsWith("'") && escapedValue.endsWith("'")) { value = escapedValue.substring(1, escapedValue.length() - 1); - } else { - value = escapedValue; + return; } + + if (escapedValue.length() > 2) { + for (String p : ALLOWED_PREFIXES) { + if (escapedValue.length() > p.length() && escapedValue.substring(0, p.length()).equalsIgnoreCase(p) && escapedValue.charAt(p.length()) == '\'') { + this.prefix = p; + value = escapedValue.substring(p.length() + 1, escapedValue.length() - 1); + return; + } + } + } + + value = escapedValue; } public String getValue() { return value; } + public String getPrefix() { + return prefix; + } + public String getNotExcapedValue() { StringBuilder buffer = new StringBuilder(value); int index = 0; @@ -57,6 +67,10 @@ public void setValue(String string) { value = string; } + public void setPrefix(String prefix) { + this.prefix = prefix; + } + @Override public void accept(ExpressionVisitor expressionVisitor) { expressionVisitor.visit(this); @@ -64,6 +78,6 @@ public void accept(ExpressionVisitor expressionVisitor) { @Override public String toString() { - return "'" + value + "'"; + return (prefix != null ? prefix : "") + "'" + value + "'"; } } diff --git a/src/main/java/net/sf/jsqlparser/expression/TimeKeyExpression.java b/src/main/java/net/sf/jsqlparser/expression/TimeKeyExpression.java index 4d22ef9d..b82b8856 100644 --- a/src/main/java/net/sf/jsqlparser/expression/TimeKeyExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/TimeKeyExpression.java @@ -1,27 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2016 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; -public class TimeKeyExpression implements Expression { +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class TimeKeyExpression extends ASTNodeAccessImpl implements Expression { private String stringValue; diff --git a/src/main/java/net/sf/jsqlparser/expression/TimeValue.java b/src/main/java/net/sf/jsqlparser/expression/TimeValue.java index b100a3f5..cadd9539 100644 --- a/src/main/java/net/sf/jsqlparser/expression/TimeValue.java +++ b/src/main/java/net/sf/jsqlparser/expression/TimeValue.java @@ -1,32 +1,22 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + import java.sql.Time; /** * A Time in the form {t 'hh:mm:ss'} */ -public class TimeValue implements Expression { +public class TimeValue extends ASTNodeAccessImpl implements Expression { private Time value; diff --git a/src/main/java/net/sf/jsqlparser/expression/TimestampValue.java b/src/main/java/net/sf/jsqlparser/expression/TimestampValue.java index 5c5a2c17..b37c19a2 100644 --- a/src/main/java/net/sf/jsqlparser/expression/TimestampValue.java +++ b/src/main/java/net/sf/jsqlparser/expression/TimestampValue.java @@ -1,37 +1,35 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + import java.sql.Timestamp; /** * A Timestamp in the form {ts 'yyyy-mm-dd hh:mm:ss.f . . .'} */ -public class TimestampValue implements Expression { +public class TimestampValue extends ASTNodeAccessImpl implements Expression { private Timestamp value; - + private char quotation = '\''; public TimestampValue(String value) { - this.value = Timestamp.valueOf(value.substring(1, value.length() - 1)); + if (value == null) { + throw new java.lang.IllegalArgumentException("null string"); + } else { + if (value.charAt(0) == quotation) { + this.value = Timestamp.valueOf(value.substring(1, value.length() - 1)); + } else { + this.value = Timestamp.valueOf(value.substring(0, value.length())); + } + } } @Override diff --git a/src/main/java/net/sf/jsqlparser/expression/UserVariable.java b/src/main/java/net/sf/jsqlparser/expression/UserVariable.java index 1b843cd6..92098813 100644 --- a/src/main/java/net/sf/jsqlparser/expression/UserVariable.java +++ b/src/main/java/net/sf/jsqlparser/expression/UserVariable.java @@ -1,41 +1,24 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** * Simple uservariables like @test. - * - * @author aud */ -public class UserVariable implements Expression { +public class UserVariable extends ASTNodeAccessImpl implements Expression { private String name; private boolean doubleAdd = false; - /** - * The name of the parameter - * - * @return the name of the parameter - */ public String getName() { return name; } diff --git a/src/main/java/net/sf/jsqlparser/expression/ValueListExpression.java b/src/main/java/net/sf/jsqlparser/expression/ValueListExpression.java new file mode 100644 index 00000000..1886eeb9 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/ValueListExpression.java @@ -0,0 +1,43 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +import net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +/** + * Models a list of expressions usable as condition.
+ * This allows for instance the following expression : + * "[WHERE] (a, b) [OPERATOR] (c, d)" + * where "(a, b)" and "(c, d)" are instances of this class. + */ +public class ValueListExpression extends ASTNodeAccessImpl implements Expression { + + private ExpressionList expressionList; + + public ExpressionList getExpressionList() { + return expressionList; + } + + public void setExpressionList(ExpressionList expressionList) { + this.expressionList = expressionList; + } + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } + + @Override + public String toString() { + return expressionList.toString(); + } + +} diff --git a/src/main/java/net/sf/jsqlparser/expression/WhenClause.java b/src/main/java/net/sf/jsqlparser/expression/WhenClause.java index 1700c14f..ed591537 100644 --- a/src/main/java/net/sf/jsqlparser/expression/WhenClause.java +++ b/src/main/java/net/sf/jsqlparser/expression/WhenClause.java @@ -1,32 +1,20 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + /** * A clause of following syntax: WHEN condition THEN expression. Which is part of a CaseExpression. - * - * @author Havard Rast Blok */ -public class WhenClause implements Expression { +public class WhenClause extends ASTNodeAccessImpl implements Expression { private Expression whenExpression; private Expression thenExpression; @@ -36,16 +24,10 @@ public void accept(ExpressionVisitor expressionVisitor) { expressionVisitor.visit(this); } - /** - * @return Returns the thenExpression. - */ public Expression getThenExpression() { return thenExpression; } - /** - * @param thenExpression The thenExpression to set. - */ public void setThenExpression(Expression thenExpression) { this.thenExpression = thenExpression; } diff --git a/src/main/java/net/sf/jsqlparser/expression/WindowElement.java b/src/main/java/net/sf/jsqlparser/expression/WindowElement.java index 7ad4f7a0..0d493039 100644 --- a/src/main/java/net/sf/jsqlparser/expression/WindowElement.java +++ b/src/main/java/net/sf/jsqlparser/expression/WindowElement.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; diff --git a/src/main/java/net/sf/jsqlparser/expression/WindowOffset.java b/src/main/java/net/sf/jsqlparser/expression/WindowOffset.java index e899becc..b7c7efb9 100644 --- a/src/main/java/net/sf/jsqlparser/expression/WindowOffset.java +++ b/src/main/java/net/sf/jsqlparser/expression/WindowOffset.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; @@ -60,18 +48,20 @@ public String toString() { buffer.append(type); } } else { - switch (type) { - case PRECEDING: - buffer.append(" UNBOUNDED PRECEDING"); - break; - case FOLLOWING: - buffer.append(" UNBOUNDED FOLLOWING"); - break; - case CURRENT: - buffer.append(" CURRENT ROW"); - break; - default: - break; + if (type != null) { + switch (type) { + case PRECEDING: + buffer.append(" UNBOUNDED PRECEDING"); + break; + case FOLLOWING: + buffer.append(" UNBOUNDED FOLLOWING"); + break; + case CURRENT: + buffer.append(" CURRENT ROW"); + break; + default: + break; + } } } return buffer.toString(); diff --git a/src/main/java/net/sf/jsqlparser/expression/WindowRange.java b/src/main/java/net/sf/jsqlparser/expression/WindowRange.java index d90ace12..3698f82f 100644 --- a/src/main/java/net/sf/jsqlparser/expression/WindowRange.java +++ b/src/main/java/net/sf/jsqlparser/expression/WindowRange.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression; diff --git a/src/main/java/net/sf/jsqlparser/expression/WithinGroupExpression.java b/src/main/java/net/sf/jsqlparser/expression/WithinGroupExpression.java deleted file mode 100644 index 89669431..00000000 --- a/src/main/java/net/sf/jsqlparser/expression/WithinGroupExpression.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * #%L - * JSQLParser library - * %% - * Copyright (C) 2004 - 2015 JSQLParser - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * #L% - */ -package net.sf.jsqlparser.expression; - -import java.util.List; -import net.sf.jsqlparser.expression.operators.relational.ExpressionList; -import net.sf.jsqlparser.statement.select.OrderByElement; - -/** - * - * @author toben - */ -public class WithinGroupExpression implements Expression { - - private String name; - - private List orderByElements; - - private ExpressionList exprList; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getOrderByElements() { - return orderByElements; - } - - public void setOrderByElements(List orderByElements) { - this.orderByElements = orderByElements; - } - - public ExpressionList getExprList() { - return exprList; - } - - public void setExprList(ExpressionList exprList) { - this.exprList = exprList; - } - - @Override - public void accept(ExpressionVisitor visitor) { - visitor.visit(this); - } - - @Override - public String toString() { - StringBuilder b = new StringBuilder(); - - b.append(name); - b.append(exprList.toString()); - b.append(" WITHIN GROUP ("); - - b.append("ORDER BY "); - for (int i = 0; i < orderByElements.size(); i++) { - if (i > 0) { - b.append(", "); - } - b.append(orderByElements.get(i).toString()); - } - - b.append(")"); - - return b.toString(); - } - -} diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Addition.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Addition.java index e3c6af3d..eae793e5 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Addition.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Addition.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.arithmetic; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseAnd.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseAnd.java index fe998947..d09a639a 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseAnd.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseAnd.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.arithmetic; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseLeftShift.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseLeftShift.java new file mode 100644 index 00000000..9e370b8c --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseLeftShift.java @@ -0,0 +1,26 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression.operators.arithmetic; + +import net.sf.jsqlparser.expression.BinaryExpression; +import net.sf.jsqlparser.expression.ExpressionVisitor; + +public class BitwiseLeftShift extends BinaryExpression { + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } + + @Override + public String getStringExpression() { + return "<<"; + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseOr.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseOr.java index 1365e1a9..71018b32 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseOr.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseOr.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.arithmetic; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseRightShift.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseRightShift.java new file mode 100644 index 00000000..5166d5c7 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseRightShift.java @@ -0,0 +1,26 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression.operators.arithmetic; + +import net.sf.jsqlparser.expression.BinaryExpression; +import net.sf.jsqlparser.expression.ExpressionVisitor; + +public class BitwiseRightShift extends BinaryExpression { + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } + + @Override + public String getStringExpression() { + return ">>"; + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseXor.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseXor.java index bcc49f15..8fed7afd 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseXor.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/BitwiseXor.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.arithmetic; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Concat.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Concat.java index b9981d4e..b2ede365 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Concat.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Concat.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.arithmetic; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Division.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Division.java index 201d78ed..d6097216 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Division.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Division.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.arithmetic; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/IntegerDivision.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/IntegerDivision.java new file mode 100644 index 00000000..c2fa939f --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/IntegerDivision.java @@ -0,0 +1,26 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression.operators.arithmetic; + +import net.sf.jsqlparser.expression.BinaryExpression; +import net.sf.jsqlparser.expression.ExpressionVisitor; + +public class IntegerDivision extends BinaryExpression { + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } + + @Override + public String getStringExpression() { + return "DIV"; + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Modulo.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Modulo.java index 9b88105a..f6fb98ba 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Modulo.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Modulo.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.arithmetic; @@ -26,8 +14,6 @@ /** * Modulo expression (a % b). - * - * @author toben */ public class Modulo extends BinaryExpression { diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Multiplication.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Multiplication.java index 64d5fb55..dcc193c5 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Multiplication.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Multiplication.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.arithmetic; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Subtraction.java b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Subtraction.java index 630cf590..2ebc55bf 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Subtraction.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/Subtraction.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.arithmetic; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/arithmetic.uod b/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/arithmetic.uod deleted file mode 100644 index 9ad39aea..00000000 --- a/src/main/java/net/sf/jsqlparser/expression/operators/arithmetic/arithmetic.uod +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/conditional/AndExpression.java b/src/main/java/net/sf/jsqlparser/expression/operators/conditional/AndExpression.java index 4dc1367d..aab07f29 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/conditional/AndExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/conditional/AndExpression.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.conditional; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/conditional/OrExpression.java b/src/main/java/net/sf/jsqlparser/expression/operators/conditional/OrExpression.java index 7a1fc5dd..35bd21f3 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/conditional/OrExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/conditional/OrExpression.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.conditional; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/Between.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/Between.java index 5e046920..58d88516 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/Between.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/Between.java @@ -1,33 +1,22 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitor; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; /** * A "BETWEEN" expr1 expr2 statement */ -public class Between implements Expression { +public class Between extends ASTNodeAccessImpl implements Expression { private Expression leftExpression; private boolean not = false; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ComparisonOperator.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ComparisonOperator.java index 1f0b6f35..dba54396 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ComparisonOperator.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ComparisonOperator.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/EqualsTo.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/EqualsTo.java index c23fbd57..b890860d 100755 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/EqualsTo.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/EqualsTo.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ExistsExpression.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ExistsExpression.java index 0660874e..e0b30214 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ExistsExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ExistsExpression.java @@ -1,30 +1,19 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitor; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; -public class ExistsExpression implements Expression { +public class ExistsExpression extends ASTNodeAccessImpl implements Expression { private Expression rightExpression; private boolean not = false; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ExpressionList.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ExpressionList.java index 39247ea9..d1144cbd 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ExpressionList.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ExpressionList.java @@ -1,26 +1,15 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; +import java.util.Arrays; import java.util.List; import net.sf.jsqlparser.expression.Expression; @@ -39,6 +28,10 @@ public ExpressionList() { public ExpressionList(List expressions) { this.expressions = expressions; } + + public ExpressionList(Expression ... expressions) { + this.expressions = Arrays.asList(expressions); + } public List getExpressions() { return expressions; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/FullTextSearch.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/FullTextSearch.java new file mode 100644 index 00000000..d011d48f --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/FullTextSearch.java @@ -0,0 +1,76 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression.operators.relational; + +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.ExpressionVisitor; +import net.sf.jsqlparser.expression.StringValue; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; +import net.sf.jsqlparser.schema.Column; + +import java.util.Iterator; +import java.util.List; + +public class FullTextSearch extends ASTNodeAccessImpl implements Expression { + + private List _matchColumns; + private StringValue _againstValue; + private String _searchModifier; + + public FullTextSearch() { + + } + + public void setMatchColumns(List columns) { + this._matchColumns = columns; + } + + public List getMatchColumns() { + return this._matchColumns; + } + + public void setAgainstValue(StringValue val) { + this._againstValue = val; + } + + public StringValue getAgainstValue() { + return this._againstValue; + } + + public void setSearchModifier(String val) { + this._searchModifier = val; + } + + public String getSearchModifier() { + return this._searchModifier; + } + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } + + @Override + public String toString() { + // Build a list of matched columns + String columnsListCommaSeperated = ""; + Iterator iterator = this._matchColumns.iterator(); + while (iterator.hasNext()) { + Column col = iterator.next(); + columnsListCommaSeperated += col.getFullyQualifiedName(); + if (iterator.hasNext()) { + columnsListCommaSeperated += ","; + } + } + + return "MATCH (" + columnsListCommaSeperated + ") AGAINST (" + this._againstValue + + (this._searchModifier != null ? " " + this._searchModifier : "") + ")"; + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/GreaterThan.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/GreaterThan.java index bb0e4457..f8e4a9d6 100755 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/GreaterThan.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/GreaterThan.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/GreaterThanEquals.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/GreaterThanEquals.java index ad30668b..0a232663 100755 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/GreaterThanEquals.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/GreaterThanEquals.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/InExpression.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/InExpression.java index 8fe568fd..b5709201 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/InExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/InExpression.java @@ -1,30 +1,19 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitor; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; -public class InExpression implements Expression, SupportsOldOracleJoinSyntax { +public class InExpression extends ASTNodeAccessImpl implements Expression, SupportsOldOracleJoinSyntax { private Expression leftExpression; private ItemsList leftItemsList; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/IsBooleanExpression.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/IsBooleanExpression.java new file mode 100644 index 00000000..96e10e91 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/IsBooleanExpression.java @@ -0,0 +1,59 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression.operators.relational; + +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.ExpressionVisitor; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class IsBooleanExpression extends ASTNodeAccessImpl implements Expression { + + private Expression leftExpression; + private boolean not = false; + private boolean isTrue = false; + + public Expression getLeftExpression() { + return leftExpression; + } + + public boolean isNot() { + return not; + } + + public void setLeftExpression(Expression expression) { + leftExpression = expression; + } + + public void setNot(boolean b) { + not = b; + } + + public boolean isTrue() { + return isTrue; + } + + public void setIsTrue(boolean isTrue) { + this.isTrue = isTrue; + } + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } + + @Override + public String toString() { + if (isTrue()) { + return leftExpression + " IS" + (not ? " NOT" : "") + " TRUE"; + } else { + return leftExpression + " IS" + (not ? " NOT" : "") + " FALSE"; + } + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/IsNullExpression.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/IsNullExpression.java index a12dd869..9a511171 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/IsNullExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/IsNullExpression.java @@ -1,33 +1,23 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitor; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; -public class IsNullExpression implements Expression { +public class IsNullExpression extends ASTNodeAccessImpl implements Expression { private Expression leftExpression; private boolean not = false; + private boolean useIsNull = false; public Expression getLeftExpression() { return leftExpression; @@ -45,6 +35,14 @@ public void setNot(boolean b) { not = b; } + public boolean isUseIsNull() { + return useIsNull; + } + + public void setUseIsNull(boolean useIsNull) { + this.useIsNull = useIsNull; + } + @Override public void accept(ExpressionVisitor expressionVisitor) { expressionVisitor.visit(this); @@ -52,6 +50,10 @@ public void accept(ExpressionVisitor expressionVisitor) { @Override public String toString() { - return leftExpression + " IS " + (not ? "NOT " : "") + "NULL"; + if (isUseIsNull()) { + return leftExpression + (not ? " NOT" : "") + " ISNULL"; + } else { + return leftExpression + " IS " + (not ? "NOT " : "") + "NULL"; + } } } diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsList.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsList.java index 655d5f90..caffa1fe 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsList.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsList.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitor.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitor.java index 3c630c21..ced59be3 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitor.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitor.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; @@ -29,5 +17,7 @@ public interface ItemsListVisitor { void visit(ExpressionList expressionList); + void visit(NamedExpressionList namedExpressionList); + void visit(MultiExpressionList multiExprList); } diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitorAdapter.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitorAdapter.java index ff2cf1cc..49deff77 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitorAdapter.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/ItemsListVisitorAdapter.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; @@ -30,6 +18,11 @@ public void visit(SubSelect subSelect) { } + @Override + public void visit(NamedExpressionList namedExpressionList) { + + } + @Override public void visit(ExpressionList expressionList) { diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/JsonOperator.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/JsonOperator.java index 99796125..e10c71ea 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/JsonOperator.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/JsonOperator.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/LikeExpression.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/LikeExpression.java index 23f70196..95513513 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/LikeExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/LikeExpression.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; @@ -30,7 +18,6 @@ public class LikeExpression extends BinaryExpression { private String escape = null; private boolean caseInsensitive = false; - @Override public boolean isNot() { return not; } @@ -46,12 +33,12 @@ public void accept(ExpressionVisitor expressionVisitor) { @Override public String getStringExpression() { - return (not ? "NOT " : "") + (caseInsensitive ? "ILIKE" : "LIKE"); + return caseInsensitive ? "ILIKE" : "LIKE"; } @Override public String toString() { - String retval = super.toString(); + String retval = getLeftExpression() + " " + (not ? "NOT " : "") + getStringExpression() + " " + getRightExpression(); if (escape != null) { retval += " ESCAPE " + "'" + escape + "'"; } diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/Matches.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/Matches.java index 2da8a0fd..4b3d305a 100755 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/Matches.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/Matches.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/MinorThan.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/MinorThan.java index 950733ad..182170f1 100755 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/MinorThan.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/MinorThan.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/MinorThanEquals.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/MinorThanEquals.java index 39dd6476..641fe238 100755 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/MinorThanEquals.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/MinorThanEquals.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/MultiExpressionList.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/MultiExpressionList.java index 0ff7f477..782fb343 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/MultiExpressionList.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/MultiExpressionList.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; @@ -30,8 +18,6 @@ /** * A list of ExpressionList items. e.g. multi values of insert statements. This one allows only * equally sized ExpressionList. - * - * @author toben */ public class MultiExpressionList implements ItemsList { diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/NamedExpressionList.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/NamedExpressionList.java new file mode 100644 index 00000000..3de97cc2 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/NamedExpressionList.java @@ -0,0 +1,76 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression.operators.relational; + +import java.util.Arrays; +import java.util.List; +import net.sf.jsqlparser.expression.Expression; + +/** + * A list of named expressions, as in + * as in select substr('xyzzy' from 2 for 3) + */ +public class NamedExpressionList implements ItemsList { + + private List expressions; + private List names; + + public NamedExpressionList() { + } + + public NamedExpressionList(List expressions) { + this.expressions = expressions; + } + + public NamedExpressionList(Expression... expressions) { + this.expressions = Arrays.asList(expressions); + } + + public List getExpressions() { + return expressions; + } + + public List getNames() { + return names; + } + + public void setExpressions(List list) { + expressions = list; + } + + public void setNames(List list) { + names = list; + } + + @Override + public void accept(ItemsListVisitor itemsListVisitor) { + itemsListVisitor.visit(this); + } + + @Override + public String toString() { + + StringBuilder ret = new StringBuilder(); + ret.append("("); + for (int i = 0; i < expressions.size(); i++) { + if (i > 0) { + ret.append(" "); + } + if (!names.get(i).equals("")) { + ret.append(names.get(i)).append(" ").append(expressions.get(i)); + } else { + ret.append(expressions.get(i)); + } + } + ret.append(")"); + + return ret.toString(); + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/NotEqualsTo.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/NotEqualsTo.java index 3ff92d3f..14749fd8 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/NotEqualsTo.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/NotEqualsTo.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/OldOracleJoinBinaryExpression.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/OldOracleJoinBinaryExpression.java index c620a62e..114673d1 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/OldOracleJoinBinaryExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/OldOracleJoinBinaryExpression.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; @@ -40,8 +28,8 @@ public void setOldOracleJoinSyntax(int oldOracleJoinSyntax) { @Override public String toString() { - return (isNot() ? "NOT " : "") - + (oraclePriorPosition == ORACLE_PRIOR_START ? "PRIOR " : "") + return //(isNot() ? "NOT " : "") + (oraclePriorPosition == ORACLE_PRIOR_START ? "PRIOR " : "") + getLeftExpression() + (oldOracleJoinSyntax == ORACLE_JOIN_RIGHT ? "(+)" : "") + " " + getStringExpression() + " " diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMatchOperator.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMatchOperator.java index 27f0fff3..ce1b4295 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMatchOperator.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMatchOperator.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMatchOperatorType.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMatchOperatorType.java index 764ce845..8d324a4a 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMatchOperatorType.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMatchOperatorType.java @@ -1,30 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; /** * PostgresSQL match operators. - * - * @author toben */ public enum RegExpMatchOperatorType { MATCH_CASESENSITIVE, diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMySQLOperator.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMySQLOperator.java index 2fd7a39a..6f4761ef 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMySQLOperator.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/RegExpMySQLOperator.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; @@ -27,6 +15,7 @@ public class RegExpMySQLOperator extends BinaryExpression { private RegExpMatchOperatorType operatorType; + private boolean useRLike = false; public RegExpMySQLOperator(RegExpMatchOperatorType operatorType) { if (operatorType == null) { @@ -39,6 +28,15 @@ public RegExpMatchOperatorType getOperatorType() { return operatorType; } + public boolean isUseRLike() { + return useRLike; + } + + public RegExpMySQLOperator useRLike() { + useRLike = true; + return this; + } + @Override public void accept(ExpressionVisitor expressionVisitor) { expressionVisitor.visit(this); @@ -46,13 +44,7 @@ public void accept(ExpressionVisitor expressionVisitor) { @Override public String getStringExpression() { - switch (operatorType) { - case MATCH_CASESENSITIVE: - return "REGEXP BINARY"; - case MATCH_CASEINSENSITIVE: - return "REGEXP"; - default: - } - return null; + return (useRLike ? "RLIKE" : "REGEXP") + + (operatorType == RegExpMatchOperatorType.MATCH_CASESENSITIVE ? " BINARY" : ""); } } diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/SimilarToExpression.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/SimilarToExpression.java new file mode 100644 index 00000000..234d0011 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/SimilarToExpression.java @@ -0,0 +1,55 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression.operators.relational; + +import net.sf.jsqlparser.expression.BinaryExpression; +import net.sf.jsqlparser.expression.ExpressionVisitor; + +public class SimilarToExpression extends BinaryExpression { + + private boolean not = false; + private String escape = null; + + public boolean isNot() { + return not; + } + + public void setNot(boolean b) { + not = b; + } + + @Override + public void accept(ExpressionVisitor expressionVisitor) { + expressionVisitor.visit(this); + } + + @Override + public String getStringExpression() { + return "SIMILAR TO"; + } + + @Override + public String toString() { + String retval = getLeftExpression() + " " + (not ? "NOT " : "") + getStringExpression() + " " + getRightExpression(); + if (escape != null) { + retval += " ESCAPE " + "'" + escape + "'"; + } + + return retval; + } + + public String getEscape() { + return escape; + } + + public void setEscape(String escape) { + this.escape = escape; + } +} diff --git a/src/main/java/net/sf/jsqlparser/expression/operators/relational/SupportsOldOracleJoinSyntax.java b/src/main/java/net/sf/jsqlparser/expression/operators/relational/SupportsOldOracleJoinSyntax.java index 970bb2ef..05e9839c 100644 --- a/src/main/java/net/sf/jsqlparser/expression/operators/relational/SupportsOldOracleJoinSyntax.java +++ b/src/main/java/net/sf/jsqlparser/expression/operators/relational/SupportsOldOracleJoinSyntax.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.expression.operators.relational; diff --git a/src/main/java/net/sf/jsqlparser/parser/ASTNodeAccess.java b/src/main/java/net/sf/jsqlparser/parser/ASTNodeAccess.java index 2d540d39..46914102 100644 --- a/src/main/java/net/sf/jsqlparser/parser/ASTNodeAccess.java +++ b/src/main/java/net/sf/jsqlparser/parser/ASTNodeAccess.java @@ -1,48 +1,14 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ - /* - * Copyright (C) 2015 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ package net.sf.jsqlparser.parser; -/** - * - * @author toben - */ public interface ASTNodeAccess { SimpleNode getASTNode(); diff --git a/src/main/java/net/sf/jsqlparser/parser/ASTNodeAccessImpl.java b/src/main/java/net/sf/jsqlparser/parser/ASTNodeAccessImpl.java index 2ade908e..2bf503ac 100644 --- a/src/main/java/net/sf/jsqlparser/parser/ASTNodeAccessImpl.java +++ b/src/main/java/net/sf/jsqlparser/parser/ASTNodeAccessImpl.java @@ -1,30 +1,14 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.parser; -/** - * - * @author toben - */ public class ASTNodeAccessImpl implements ASTNodeAccess { private SimpleNode node; diff --git a/src/main/java/net/sf/jsqlparser/parser/BaseToken.java b/src/main/java/net/sf/jsqlparser/parser/BaseToken.java index 68b9c63c..6972f0a5 100644 --- a/src/main/java/net/sf/jsqlparser/parser/BaseToken.java +++ b/src/main/java/net/sf/jsqlparser/parser/BaseToken.java @@ -1,49 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ - /* - * Copyright (C) 2017 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ package net.sf.jsqlparser.parser; -/** - * - * @author toben - */ public class BaseToken { + public int absoluteBegin = 0; public int absoluteEnd = 0; } diff --git a/src/main/java/net/sf/jsqlparser/parser/CCJSqlParserManager.java b/src/main/java/net/sf/jsqlparser/parser/CCJSqlParserManager.java index 88f53869..fb0bf211 100644 --- a/src/main/java/net/sf/jsqlparser/parser/CCJSqlParserManager.java +++ b/src/main/java/net/sf/jsqlparser/parser/CCJSqlParserManager.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.parser; @@ -26,14 +14,11 @@ import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.statement.Statement; -/** - * A JSqlParser implementation that uses a parser generated by JavaCC - */ public class CCJSqlParserManager implements JSqlParser { @Override public Statement parse(Reader statementReader) throws JSQLParserException { - CCJSqlParser parser = new CCJSqlParser(statementReader); + CCJSqlParser parser = new CCJSqlParser(new StreamProvider(statementReader)); try { return parser.Statement(); } catch (Exception ex) { diff --git a/src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java b/src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java index fe2bcf51..99533df3 100644 --- a/src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java +++ b/src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java @@ -1,29 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.parser; import java.io.InputStream; import java.io.Reader; -import java.io.StringReader; +import java.util.function.Consumer; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.statement.Statement; @@ -40,7 +28,7 @@ private CCJSqlParserUtil() { } public static Statement parse(Reader statementReader) throws JSQLParserException { - CCJSqlParser parser = new CCJSqlParser(statementReader); + CCJSqlParser parser = new CCJSqlParser(new StreamProvider(statementReader)); try { return parser.Statement(); } catch (Exception ex) { @@ -49,7 +37,28 @@ public static Statement parse(Reader statementReader) throws JSQLParserException } public static Statement parse(String sql) throws JSQLParserException { - CCJSqlParser parser = new CCJSqlParser(new StringReader(sql)); + return parse(sql, null); + } + + /** + * Parses an sql statement while allowing via consumer to configure the used parser before. + * + * For instance to activate SQLServer bracket quotation on could use: + * + * {@code + * CCJSqlParserUtil.parse("select * from [mytable]", parser -> parser.withSquareBracketQuotation(true)); + * } + * + * @param sql + * @param consumer + * @return + * @throws JSQLParserException + */ + public static Statement parse(String sql, Consumer consumer) throws JSQLParserException { + CCJSqlParser parser = new CCJSqlParser(new StringProvider(sql)); + if (consumer != null) { + consumer.accept(parser); + } try { return parser.Statement(); } catch (Exception ex) { @@ -58,7 +67,7 @@ public static Statement parse(String sql) throws JSQLParserException { } public static Node parseAST(String sql) throws JSQLParserException { - CCJSqlParser parser = new CCJSqlParser(new StringReader(sql)); + CCJSqlParser parser = new CCJSqlParser(new StringProvider(sql)); try { parser.Statement(); return parser.jjtree.rootNode(); @@ -68,8 +77,8 @@ public static Node parseAST(String sql) throws JSQLParserException { } public static Statement parse(InputStream is) throws JSQLParserException { - CCJSqlParser parser = new CCJSqlParser(is); try { + CCJSqlParser parser = new CCJSqlParser(new StreamProvider(is)); return parser.Statement(); } catch (Exception ex) { throw new JSQLParserException(ex); @@ -77,42 +86,56 @@ public static Statement parse(InputStream is) throws JSQLParserException { } public static Statement parse(InputStream is, String encoding) throws JSQLParserException { - CCJSqlParser parser = new CCJSqlParser(is, encoding); try { + CCJSqlParser parser = new CCJSqlParser(new StreamProvider(is, encoding)); return parser.Statement(); } catch (Exception ex) { throw new JSQLParserException(ex); } } - /** - * Parse an expression. - * - * @param expression - * @return - * @throws JSQLParserException - */ public static Expression parseExpression(String expression) throws JSQLParserException { - CCJSqlParser parser = new CCJSqlParser(new StringReader(expression)); + return parseExpression(expression, true); + } + + public static Expression parseExpression(String expression, boolean allowPartialParse) throws JSQLParserException { + CCJSqlParser parser = new CCJSqlParser(new StringProvider(expression)); try { - return parser.SimpleExpression(); - } catch (Exception ex) { + Expression expr = parser.SimpleExpression(); + if (!allowPartialParse && parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) { + throw new JSQLParserException("could only parse partial expression " + expr.toString()); + } + return expr; + } catch (JSQLParserException ex) { + throw ex; + } catch (ParseException ex) { throw new JSQLParserException(ex); } } + public static Expression parseCondExpression(String condExpr) throws JSQLParserException { + return parseCondExpression(condExpr, true); + } + /** - * Parse an conditional expression. This is the expression after a where clause. + * Parse an conditional expression. This is the expression after a where + * clause. * * @param condExpr + * @param allowPartialParse false: needs the whole string to be processed. * @return - * @throws JSQLParserException */ - public static Expression parseCondExpression(String condExpr) throws JSQLParserException { - CCJSqlParser parser = new CCJSqlParser(new StringReader(condExpr)); + public static Expression parseCondExpression(String condExpr, boolean allowPartialParse) throws JSQLParserException { + CCJSqlParser parser = new CCJSqlParser(new StringProvider(condExpr)); try { - return parser.Expression(); - } catch (Exception ex) { + Expression expr = parser.Expression(); + if (!allowPartialParse && parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) { + throw new JSQLParserException("could only parse partial expression " + expr.toString()); + } + return expr; + } catch (JSQLParserException ex) { + throw ex; + } catch (ParseException ex) { throw new JSQLParserException(ex); } } @@ -121,7 +144,7 @@ public static Expression parseCondExpression(String condExpr) throws JSQLParserE * Parse a statement list. */ public static Statements parseStatements(String sqls) throws JSQLParserException { - CCJSqlParser parser = new CCJSqlParser(new StringReader(sqls)); + CCJSqlParser parser = new CCJSqlParser(new StringProvider(sqls)); try { return parser.Statements(); } catch (Exception ex) { @@ -129,4 +152,23 @@ public static Statements parseStatements(String sqls) throws JSQLParserException } } + public static void streamStatements(StatementListener listener, InputStream is, String encoding) throws JSQLParserException { + try { + CCJSqlParser parser = new CCJSqlParser(new StreamProvider(is, encoding)); + while (true) { + Statement stmt = parser.SingleStatement(); + listener.accept(stmt); + if (parser.getToken(1).kind == CCJSqlParserTokenManager.ST_SEMICOLON) { + parser.getNextToken(); + } + + if (parser.getToken(1).kind == CCJSqlParserTokenManager.EOF) { + break; + } + } + } catch (Exception ex) { + throw new JSQLParserException(ex); + } + } + } diff --git a/src/main/java/net/sf/jsqlparser/parser/JSqlParser.java b/src/main/java/net/sf/jsqlparser/parser/JSqlParser.java index b7e4e25d..8a2aa953 100644 --- a/src/main/java/net/sf/jsqlparser/parser/JSqlParser.java +++ b/src/main/java/net/sf/jsqlparser/parser/JSqlParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.parser; @@ -26,9 +14,6 @@ import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.statement.Statement; -/** - * Every parser must implements this interface - */ public interface JSqlParser { Statement parse(Reader statementReader) throws JSQLParserException; diff --git a/src/main/java/net/sf/jsqlparser/parser/SimpleCharStream.java b/src/main/java/net/sf/jsqlparser/parser/SimpleCharStream.java index faf672c7..4026730e 100644 --- a/src/main/java/net/sf/jsqlparser/parser/SimpleCharStream.java +++ b/src/main/java/net/sf/jsqlparser/parser/SimpleCharStream.java @@ -1,32 +1,14 @@ -/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 7.0 */ - /* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ - /* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.parser; -/** - * An implementation of interface CharStream, where the stream is assumed to - * contain only ASCII characters (without unicode processing). - */ public class SimpleCharStream { /** @@ -50,7 +32,8 @@ public class SimpleCharStream { protected boolean prevCharIsCR = false; protected boolean prevCharIsLF = false; - protected java.io.Reader inputStream; + protected Provider inputStream; + private boolean isStringProvider; protected char[] buffer; protected int maxNextCharInd = 0; @@ -106,7 +89,7 @@ protected void ExpandBuff(boolean wrapAround) { maxNextCharInd = bufpos -= tokenBegin; } } catch (Throwable t) { - throw new Error(t.getMessage()); + throw new RuntimeException(t.getMessage()); } bufsize += 2048; @@ -115,7 +98,7 @@ protected void ExpandBuff(boolean wrapAround) { } protected void FillBuff() throws java.io.IOException { - if (maxNextCharInd == available) { + if (!isStringProvider && maxNextCharInd == available) { if (available == bufsize) { if (tokenBegin > 2048) { bufpos = maxNextCharInd = 0; @@ -136,11 +119,19 @@ protected void FillBuff() throws java.io.IOException { int i; try { - if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) { - inputStream.close(); - throw new java.io.IOException(); + if (inputStream instanceof StringProvider) { + i = ((StringProvider) inputStream)._string.length(); + if (maxNextCharInd == i) { + throw new java.io.IOException(); + } + maxNextCharInd = i; } else { - maxNextCharInd += i; + if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) { + inputStream.close(); + throw new java.io.IOException(); + } else { + maxNextCharInd += i; + } } return; } catch (java.io.IOException e) { @@ -198,6 +189,14 @@ protected void UpdateLineColumn(char c) { bufcolumn[bufpos] = column; } + private char readChar(int pos) { + if (this.inputStream instanceof StringProvider) { + return ((StringProvider) inputStream)._string.charAt(pos); + } else { + return buffer[pos]; + } + } + /** * Read a character. */ @@ -210,7 +209,7 @@ public char readChar() throws java.io.IOException { } totalCharsRead++; - return buffer[bufpos]; + return readChar(bufpos); } if (++bufpos >= maxNextCharInd) { @@ -219,7 +218,7 @@ public char readChar() throws java.io.IOException { totalCharsRead++; - char c = buffer[bufpos]; + char c = readChar(bufpos); UpdateLineColumn(c); return c; @@ -286,22 +285,30 @@ public void backup(int amount) { /** * Constructor. */ - public SimpleCharStream(java.io.Reader dstream, int startline, + public SimpleCharStream(Provider dstream, int startline, int startcolumn, int buffersize) { inputStream = dstream; + isStringProvider = dstream instanceof StringProvider; line = startline; column = startcolumn - 1; - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; + if (isStringProvider) { + int bs = ((StringProvider) inputStream)._string.length(); + available = bufsize = bs; + bufline = new int[bs]; + bufcolumn = new int[bs]; + } else { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } } /** * Constructor. */ - public SimpleCharStream(java.io.Reader dstream, int startline, + public SimpleCharStream(Provider dstream, int startline, int startcolumn) { this(dstream, startline, startcolumn, 4096); } @@ -309,24 +316,31 @@ public SimpleCharStream(java.io.Reader dstream, int startline, /** * Constructor. */ - public SimpleCharStream(java.io.Reader dstream) { + public SimpleCharStream(Provider dstream) { this(dstream, 1, 1, 4096); } /** * Reinitialise. */ - public void ReInit(java.io.Reader dstream, int startline, + public void ReInit(Provider dstream, int startline, int startcolumn, int buffersize) { inputStream = dstream; + isStringProvider = dstream instanceof StringProvider; line = startline; column = startcolumn - 1; - - if (buffer == null || buffersize != buffer.length) { - available = bufsize = buffersize; - buffer = new char[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; + if (isStringProvider) { + int bs = ((StringProvider) inputStream)._string.length(); + available = bufsize = bs; + bufline = new int[bs]; + bufcolumn = new int[bs]; + } else { + if (buffer == null || buffersize != buffer.length) { + available = bufsize = buffersize; + buffer = new char[buffersize]; + bufline = new int[buffersize]; + bufcolumn = new int[buffersize]; + } } prevCharIsLF = prevCharIsCR = false; tokenBegin = inBuf = maxNextCharInd = 0; @@ -336,7 +350,7 @@ public void ReInit(java.io.Reader dstream, int startline, /** * Reinitialise. */ - public void ReInit(java.io.Reader dstream, int startline, + public void ReInit(Provider dstream, int startline, int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } @@ -344,111 +358,29 @@ public void ReInit(java.io.Reader dstream, int startline, /** * Reinitialise. */ - public void ReInit(java.io.Reader dstream) { + public void ReInit(Provider dstream) { ReInit(dstream, 1, 1, 4096); } - /** - * Constructor. - */ - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { - this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); - } - - /** - * Constructor. - */ - public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) { - this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); - } - - /** - * Constructor. - */ - public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException { - this(dstream, encoding, startline, startcolumn, 4096); - } - - /** - * Constructor. - */ - public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn) { - this(dstream, startline, startcolumn, 4096); - } - - /** - * Constructor. - */ - public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { - this(dstream, encoding, 1, 1, 4096); - } - - /** - * Constructor. - */ - public SimpleCharStream(java.io.InputStream dstream) { - this(dstream, 1, 1, 4096); - } - - /** - * Reinitialise. - */ - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { - ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); - } - - /** - * Reinitialise. - */ - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) { - ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); - } - - /** - * Reinitialise. - */ - public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { - ReInit(dstream, encoding, 1, 1, 4096); - } - - /** - * Reinitialise. - */ - public void ReInit(java.io.InputStream dstream) { - ReInit(dstream, 1, 1, 4096); - } - - /** - * Reinitialise. - */ - public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException { - ReInit(dstream, encoding, startline, startcolumn, 4096); - } - - /** - * Reinitialise. - */ - public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn) { - ReInit(dstream, startline, startcolumn, 4096); - } - /** * Get token literal value. */ public String GetImage() { - if (bufpos >= tokenBegin) { - return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + if (isStringProvider) { + String data = ((StringProvider) inputStream)._string; + if (bufpos >= tokenBegin) { + return data.substring(tokenBegin, bufpos + 1); + } else { + return data.substring(tokenBegin, bufsize) + + data.substring(0, bufpos + 1); + } } else { - return new String(buffer, tokenBegin, bufsize - tokenBegin) - + new String(buffer, 0, bufpos + 1); + if (bufpos >= tokenBegin) { + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + } else { + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); + } } } @@ -456,14 +388,25 @@ public String GetImage() { * Get the suffix. */ public char[] GetSuffix(int len) { + char[] ret = new char[len]; - if ((bufpos + 1) >= len) { - System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + if (isStringProvider) { + String str = ((StringProvider) inputStream)._string; + if ((bufpos + 1) >= len) { + str.getChars(bufpos - len + 1, bufpos - len + 1 + len, ret, 0); + } else { + str.getChars(bufsize - (len - bufpos - 1), bufsize - (len - bufpos - 1) + len - bufpos - 1, ret, 0); + str.getChars(0, bufpos + 1, ret, len - bufpos - 1); + } } else { - System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, - len - bufpos - 1); - System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + if ((bufpos + 1) >= len) { + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } else { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } } return ret; @@ -495,7 +438,7 @@ public void adjustBeginLineColumn(int newLine, int newCol) { int i = 0; int j = 0; int k = 0; - int nextColDiff = 0; + int nextColDiff = 0; int columnDiff = 0; while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) { diff --git a/src/main/java/net/sf/jsqlparser/parser/StatementListener.java b/src/main/java/net/sf/jsqlparser/parser/StatementListener.java new file mode 100644 index 00000000..d48901f3 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/parser/StatementListener.java @@ -0,0 +1,21 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.parser; + +import net.sf.jsqlparser.statement.Statement; + +/** + * + * @author Tobias Warneke (t.warneke@gmx.net) + */ +public interface StatementListener { + + void accept(Statement statement); +} diff --git a/src/main/java/net/sf/jsqlparser/schema/Column.java b/src/main/java/net/sf/jsqlparser/schema/Column.java index 4b343c30..3c2cec0b 100644 --- a/src/main/java/net/sf/jsqlparser/schema/Column.java +++ b/src/main/java/net/sf/jsqlparser/schema/Column.java @@ -1,33 +1,22 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.schema; +import java.util.List; import net.sf.jsqlparser.expression.*; import net.sf.jsqlparser.parser.ASTNodeAccessImpl; /** * A column. It can have the table name it belongs to. */ -public final class Column extends ASTNodeAccessImpl implements Expression, MultiPartName { +public class Column extends ASTNodeAccessImpl implements Expression, MultiPartName { private Table table; private String columnName; @@ -40,10 +29,38 @@ public Column(Table table, String columnName) { setColumnName(columnName); } + public Column(List nameParts) { + this(nameParts.size() > 1 + ? new Table(nameParts.subList(0, nameParts.size() - 1)) : null, + nameParts.get(nameParts.size() - 1)); + } + public Column(String columnName) { this(null, columnName); } + /** + * Retrieve the information regarding the {@code Table} this {@code Column} does + * belong to, if any can be inferred. + *

+ * The inference is based only on local information, and not on the whole SQL command. + * For example, consider the following query: + *

+     *  SELECT x FROM Foo
+     * 
+ * Given the {@code Column} called {@code x}, this method would return {@code null}, + * and not the info about the table {@code Foo}. + * On the other hand, consider: + *
+     *  SELECT t.x FROM Foo t
+     * 
+ * Here, we will get a {@code Table} object for a table called {@code t}. + * But because the inference is local, such object will not know that {@code t} is + * just an alias for {@code Foo}. + * + * @return an instance of {@link net.sf.jsqlparser.schema.Table} representing the + * table this column does belong to, if it can be inferred. Can be {@code null}. + */ public Table getTable() { return table; } @@ -65,12 +82,6 @@ public String getFullyQualifiedName() { return getName(false); } - /** - * Get name with out without using aliases. - * - * @param aliases - * @return - */ public String getName(boolean aliases) { StringBuilder fqn = new StringBuilder(); diff --git a/src/main/java/net/sf/jsqlparser/schema/Database.java b/src/main/java/net/sf/jsqlparser/schema/Database.java index 5035b4fd..9ec4b539 100644 --- a/src/main/java/net/sf/jsqlparser/schema/Database.java +++ b/src/main/java/net/sf/jsqlparser/schema/Database.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.schema; diff --git a/src/main/java/net/sf/jsqlparser/schema/MultiPartName.java b/src/main/java/net/sf/jsqlparser/schema/MultiPartName.java index b238c755..57960855 100644 --- a/src/main/java/net/sf/jsqlparser/schema/MultiPartName.java +++ b/src/main/java/net/sf/jsqlparser/schema/MultiPartName.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.schema; diff --git a/src/main/java/net/sf/jsqlparser/schema/Server.java b/src/main/java/net/sf/jsqlparser/schema/Server.java index 7b83ab67..ea983b60 100644 --- a/src/main/java/net/sf/jsqlparser/schema/Server.java +++ b/src/main/java/net/sf/jsqlparser/schema/Server.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.schema; diff --git a/src/main/java/net/sf/jsqlparser/schema/Table.java b/src/main/java/net/sf/jsqlparser/schema/Table.java index 97b82098..93c30f5e 100644 --- a/src/main/java/net/sf/jsqlparser/schema/Table.java +++ b/src/main/java/net/sf/jsqlparser/schema/Table.java @@ -1,26 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.schema; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import net.sf.jsqlparser.expression.*; import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.statement.select.*; @@ -30,54 +21,69 @@ */ public class Table extends ASTNodeAccessImpl implements FromItem, MultiPartName { - private Database database; - private String schemaName; - private String name; +// private Database database; +// private String schemaName; +// private String name; + private static final int NAME_IDX = 0; + private static final int SCHEMA_IDX = 1; + private static final int DATABASE_IDX = 2; + private static final int SERVER_IDX = 3; + + private List partItems = new ArrayList<>(); private Alias alias; private Pivot pivot; + private UnPivot unpivot; private MySQLIndexHint hint; public Table() { } public Table(String name) { - this.name = name; + setName(name); } public Table(String schemaName, String name) { - this.schemaName = schemaName; - this.name = name; + setName(name); + setSchemaName(schemaName); } public Table(Database database, String schemaName, String name) { - this.database = database; - this.schemaName = schemaName; - this.name = name; + setName(name); + setSchemaName(schemaName); + setDatabase(database); + } + + public Table(List partItems) { + this.partItems = new ArrayList<>(partItems); + Collections.reverse(this.partItems); } public Database getDatabase() { - return database; + return new Database(getIndex(DATABASE_IDX)); } public void setDatabase(Database database) { - this.database = database; + setIndex(DATABASE_IDX, database.getDatabaseName()); + if (database.getServer() != null) { + setIndex(SERVER_IDX, database.getServer().getFullyQualifiedName()); + } } public String getSchemaName() { - return schemaName; + return getIndex(SCHEMA_IDX); } public void setSchemaName(String string) { - schemaName = string; + setIndex(SCHEMA_IDX, string); } public String getName() { - return name; + return getIndex(NAME_IDX); } public void setName(String string) { - name = string; + setIndex(NAME_IDX, string); } @Override @@ -90,29 +96,38 @@ public void setAlias(Alias alias) { this.alias = alias; } - @Override - public String getFullyQualifiedName() { - String fqn = ""; - - if (database != null) { - fqn += database.getFullyQualifiedName(); - } - if (!fqn.isEmpty()) { - fqn += "."; + private void setIndex(int idx, String value) { + int size = partItems.size(); + for (int i = 0; i < idx - size + 1; i++) { + partItems.add(null); } + partItems.set(idx, value); + } - if (schemaName != null) { - fqn += schemaName; - } - if (!fqn.isEmpty()) { - fqn += "."; + private String getIndex(int idx) { + if (idx < partItems.size()) { + return partItems.get(idx); + } else { + return null; } + } - if (name != null) { - fqn += name; + @Override + public String getFullyQualifiedName() { + StringBuilder fqn = new StringBuilder(); + + for (int i = partItems.size() - 1; i >= 0; i--) { + String part = partItems.get(i); + if (part == null) { + part = ""; + } + fqn.append(part); + if (i != 0) { + fqn.append("."); + } } - return fqn; + return fqn.toString(); } @Override @@ -134,6 +149,16 @@ public void setPivot(Pivot pivot) { this.pivot = pivot; } + @Override + public UnPivot getUnPivot() { + return this.unpivot; + } + + @Override + public void setUnPivot(UnPivot unpivot) { + this.unpivot = unpivot; + } + public MySQLIndexHint getIndexHint() { return hint; } @@ -145,8 +170,9 @@ public void setHint(MySQLIndexHint hint) { @Override public String toString() { return getFullyQualifiedName() - + ((pivot != null) ? " " + pivot : "") + ((alias != null) ? alias.toString() : "") + + ((pivot != null) ? " " + pivot : "") + + ((unpivot != null) ? " " + unpivot : "") + ((hint != null) ? hint.toString() : ""); } } diff --git a/src/main/java/net/sf/jsqlparser/statement/Block.java b/src/main/java/net/sf/jsqlparser/statement/Block.java new file mode 100644 index 00000000..8d41cc74 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/Block.java @@ -0,0 +1,33 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +public class Block implements Statement { + + private Statements statements; + + public Statements getStatements() { + return statements; + } + + public void setStatements(Statements statements) { + this.statements = statements; + } + + @Override + public void accept(StatementVisitor statementVisitor) { + statementVisitor.visit(this); + } + + @Override + public String toString() { + return "BEGIN\n" + (statements != null ? statements.toString() : "") + "END"; + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/Commit.java b/src/main/java/net/sf/jsqlparser/statement/Commit.java index 66116a4b..f33a36ae 100644 --- a/src/main/java/net/sf/jsqlparser/statement/Commit.java +++ b/src/main/java/net/sf/jsqlparser/statement/Commit.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement; diff --git a/src/main/java/net/sf/jsqlparser/statement/DeclareStatement.java b/src/main/java/net/sf/jsqlparser/statement/DeclareStatement.java new file mode 100644 index 00000000..da84c419 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/DeclareStatement.java @@ -0,0 +1,132 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import java.util.ArrayList; +import java.util.List; +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.UserVariable; +import net.sf.jsqlparser.statement.create.table.ColDataType; +import net.sf.jsqlparser.statement.create.table.ColumnDefinition; + +public final class DeclareStatement implements Statement { + + private UserVariable userVariable = null; + private DeclareType type = DeclareType.TYPE; + private String typeName; + private List typeDefExprList = new ArrayList<>(); + private List colDefs = new ArrayList<>(); + + public DeclareStatement() { + } + + public void setUserVariable(UserVariable userVariable) { + this.userVariable = userVariable; + } + + public UserVariable getUserVariable() { + return userVariable; + } + + public DeclareType getType() { + return type; + } + + public String getTypeName() { + return typeName; + } + + public void setDeclareType(DeclareType type) { + this.type = type; + } + + public void addType(ColDataType colDataType, Expression defaultExpr) { + typeDefExprList.add(new TypeDefExpr(colDataType, defaultExpr)); + } + + public void addType(UserVariable userVariable, ColDataType colDataType, Expression defaultExpr) { + typeDefExprList.add(new TypeDefExpr(userVariable, colDataType, defaultExpr)); + } + + public void addColumnDefinition(ColumnDefinition colDef) { + colDefs.add(colDef); + } + + public List getColumnDefinitions() { + return colDefs; + } + + public List getTypeDefinitions() { + return typeDefExprList; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder("DECLARE "); + if (type == DeclareType.AS) { + b.append(userVariable.toString()); + b.append(" AS ").append(typeName); + } else { + if (type == DeclareType.TABLE) { + b.append(userVariable.toString()); + b.append(" TABLE ("); + for (int i = 0; i < colDefs.size(); i++) { + if (i > 0) { + b.append(", "); + } + b.append(colDefs.get(i).toString()); + } + b.append(")"); + } else { + for (int i = 0; i < typeDefExprList.size(); i++) { + if (i > 0) { + b.append(", "); + } + final TypeDefExpr type = typeDefExprList.get(i); + if (type.userVariable != null) { + b.append(type.userVariable.toString()).append(" "); + } + b.append(type.colDataType.toString()); + if (type.defaultExpr != null) { + b.append(" = ").append(type.defaultExpr.toString()); + } + } + } + } + return b.toString(); + } + + @Override + public void accept(StatementVisitor statementVisitor + ) { + statementVisitor.visit(this); + } + + public static class TypeDefExpr { + + public final UserVariable userVariable; + public final ColDataType colDataType; + public final Expression defaultExpr; + + public TypeDefExpr(ColDataType colDataType, Expression defaultExpr) { + this(null, colDataType, defaultExpr); + } + + public TypeDefExpr(UserVariable userVariable, ColDataType colDataType, Expression defaultExpr) { + this.userVariable = userVariable; + this.colDataType = colDataType; + this.defaultExpr = defaultExpr; + } + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/DeclareType.java b/src/main/java/net/sf/jsqlparser/statement/DeclareType.java new file mode 100644 index 00000000..8e0d7119 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/DeclareType.java @@ -0,0 +1,18 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +/** + * + * @author tobens + */ +public enum DeclareType { + TABLE, AS, TYPE +} diff --git a/src/main/java/net/sf/jsqlparser/statement/DescribeStatement.java b/src/main/java/net/sf/jsqlparser/statement/DescribeStatement.java new file mode 100644 index 00000000..26bf26dc --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/DescribeStatement.java @@ -0,0 +1,39 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import net.sf.jsqlparser.schema.Table; + +public class DescribeStatement implements Statement { + + private Table table; + + public DescribeStatement(Table table) { + this.table = table; + } + + public Table getTable() { + return table; + } + + public void setTable(Table table) { + this.table = table; + } + + @Override + public String toString() { + return "DESCRIBE " + table.getFullyQualifiedName(); + } + + @Override + public void accept(StatementVisitor statementVisitor) { + statementVisitor.visit(this); + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/ExplainStatement.java b/src/main/java/net/sf/jsqlparser/statement/ExplainStatement.java new file mode 100644 index 00000000..35c8c377 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/ExplainStatement.java @@ -0,0 +1,39 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import net.sf.jsqlparser.statement.select.Select; + +public class ExplainStatement implements Statement { + + private Select select; + + public ExplainStatement(Select select) { + this.select = select; + } + + public Select getStatement() { + return select; + } + + public void setStatement(Select select) { + this.select = select; + } + + @Override + public String toString() { + return "EXPLAIN " + select.toString(); + } + + @Override + public void accept(StatementVisitor statementVisitor) { + statementVisitor.visit(this); + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/SetStatement.java b/src/main/java/net/sf/jsqlparser/statement/SetStatement.java index 8794bd1b..8350f007 100644 --- a/src/main/java/net/sf/jsqlparser/statement/SetStatement.java +++ b/src/main/java/net/sf/jsqlparser/statement/SetStatement.java @@ -1,93 +1,120 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ - /* - * Copyright (C) 2015 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ package net.sf.jsqlparser.statement; +import java.util.ArrayList; +import java.util.List; import net.sf.jsqlparser.expression.Expression; -/** - * - * @author toben - */ -public class SetStatement implements Statement { +public final class SetStatement implements Statement { - private String name; - private Expression expression; - private boolean useEqual; + private final List values = new ArrayList<>(); public SetStatement(String name, Expression expression) { - this.name = name; - this.expression = expression; + add(name, expression, true); + } + + public void add(String name, Expression expression, boolean useEqual) { + values.add(new NameExpr(name, expression, useEqual)); + } + + public void remove(int idx) { + values.remove(idx); + } + + public int getCount() { + return values.size(); + } + + public boolean isUseEqual(int idx) { + return values.get(idx).useEqual; } public boolean isUseEqual() { - return useEqual; + return isUseEqual(0); } - public SetStatement setUseEqual(boolean useEqual) { - this.useEqual = useEqual; + public SetStatement setUseEqual(int idx, boolean useEqual) { + values.get(idx).useEqual = useEqual; return this; } + public SetStatement setUseEqual(boolean useEqual) { + return setUseEqual(0, useEqual); + } + public String getName() { - return name; + return getName(0); + } + + public String getName(int idx) { + return values.get(idx).name; } public void setName(String name) { - this.name = name; + setName(0, name); + } + + public void setName(int idx, String name) { + values.get(idx).name = name; + } + + public Expression getExpression(int idx) { + return values.get(idx).expression; } public Expression getExpression() { - return expression; + return getExpression(0); + } + + public void setExpression(int idx, Expression expression) { + values.get(idx).expression = expression; } public void setExpression(Expression expression) { - this.expression = expression; + setExpression(0, expression); + } + + private String toString(NameExpr ne) { + return ne.name + (ne.useEqual ? " = " : " ") + ne.expression.toString(); } @Override public String toString() { - return "SET " + name + (useEqual ? " = " : " ") + expression.toString(); + StringBuilder b = new StringBuilder("SET "); + + for (NameExpr ne : values) { + if (b.length() != 4) { + b.append(", "); + } + b.append(toString(ne)); + } + + return b.toString(); } @Override public void accept(StatementVisitor statementVisitor) { statementVisitor.visit(this); } + + static class NameExpr { + + private String name; + private Expression expression; + private boolean useEqual; + + public NameExpr(String name, Expression expr, boolean useEqual) { + this.name = name; + this.expression = expr; + this.useEqual = useEqual; + } + } } diff --git a/src/main/java/net/sf/jsqlparser/statement/ShowColumnsStatement.java b/src/main/java/net/sf/jsqlparser/statement/ShowColumnsStatement.java new file mode 100644 index 00000000..71f9822e --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/ShowColumnsStatement.java @@ -0,0 +1,37 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +public class ShowColumnsStatement implements Statement { + + private String tableName; + + public ShowColumnsStatement(String tableName) { + this.tableName = tableName; + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + @Override + public String toString() { + return "SHOW COLUMNS FROM " + tableName; + } + + @Override + public void accept(StatementVisitor statementVisitor) { + statementVisitor.visit(this); + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/ShowStatement.java b/src/main/java/net/sf/jsqlparser/statement/ShowStatement.java new file mode 100644 index 00000000..9e3bd62a --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/ShowStatement.java @@ -0,0 +1,37 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +public class ShowStatement implements Statement { + + private String name; + + public ShowStatement(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "SHOW " + name; + } + + @Override + public void accept(StatementVisitor statementVisitor) { + statementVisitor.visit(this); + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/Statement.java b/src/main/java/net/sf/jsqlparser/statement/Statement.java index bf45b83c..e90f8746 100644 --- a/src/main/java/net/sf/jsqlparser/statement/Statement.java +++ b/src/main/java/net/sf/jsqlparser/statement/Statement.java @@ -1,29 +1,14 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement; -/** - * An operation on the db (SELECT, UPDATE ecc.) - */ public interface Statement { void accept(StatementVisitor statementVisitor); diff --git a/src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java b/src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java index 9a9a05ee..531921ba 100644 --- a/src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java +++ b/src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java @@ -1,27 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement; import net.sf.jsqlparser.statement.alter.Alter; +import net.sf.jsqlparser.statement.comment.Comment; import net.sf.jsqlparser.statement.create.index.CreateIndex; import net.sf.jsqlparser.statement.create.table.CreateTable; import net.sf.jsqlparser.statement.create.view.AlterView; @@ -36,9 +25,12 @@ import net.sf.jsqlparser.statement.truncate.Truncate; import net.sf.jsqlparser.statement.update.Update; import net.sf.jsqlparser.statement.upsert.Upsert; +import net.sf.jsqlparser.statement.values.ValuesStatement; public interface StatementVisitor { + void visit(Comment comment); + void visit(Commit commit); void visit(Delete delete); @@ -69,10 +61,25 @@ public interface StatementVisitor { void visit(SetStatement set); + void visit(ShowColumnsStatement set); + void visit(Merge merge); void visit(Select select); void visit(Upsert upsert); + void visit(UseStatement use); + + void visit(Block block); + + void visit(ValuesStatement values); + + void visit(DescribeStatement describe); + + public void visit(ExplainStatement aThis); + + public void visit(ShowStatement aThis); + + public void visit(DeclareStatement aThis); } diff --git a/src/main/java/net/sf/jsqlparser/statement/StatementVisitorAdapter.java b/src/main/java/net/sf/jsqlparser/statement/StatementVisitorAdapter.java index b2a364c8..df46cc2f 100644 --- a/src/main/java/net/sf/jsqlparser/statement/StatementVisitorAdapter.java +++ b/src/main/java/net/sf/jsqlparser/statement/StatementVisitorAdapter.java @@ -1,27 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement; import net.sf.jsqlparser.statement.alter.Alter; +import net.sf.jsqlparser.statement.comment.Comment; import net.sf.jsqlparser.statement.create.index.CreateIndex; import net.sf.jsqlparser.statement.create.table.CreateTable; import net.sf.jsqlparser.statement.create.view.AlterView; @@ -36,11 +25,18 @@ import net.sf.jsqlparser.statement.truncate.Truncate; import net.sf.jsqlparser.statement.update.Update; import net.sf.jsqlparser.statement.upsert.Upsert; +import net.sf.jsqlparser.statement.values.ValuesStatement; public class StatementVisitorAdapter implements StatementVisitor { + + @Override + public void visit(Comment comment) { + + } + @Override public void visit(Commit commit) { - + } @Override @@ -115,6 +111,10 @@ public void visit(SetStatement set) { } + @Override + public void visit(ShowColumnsStatement set) { + } + @Override public void visit(Merge merge) { @@ -126,6 +126,33 @@ public void visit(AlterView alterView) { @Override public void visit(Upsert upsert) { - + } + + @Override + public void visit(UseStatement use) { + } + + @Override + public void visit(Block block) { + } + + @Override + public void visit(ValuesStatement values) { + } + + @Override + public void visit(DescribeStatement describe) { + } + + @Override + public void visit(ExplainStatement aThis) { + } + + @Override + public void visit(ShowStatement aThis) { + } + + @Override + public void visit(DeclareStatement aThis) { } } diff --git a/src/main/java/net/sf/jsqlparser/statement/Statements.java b/src/main/java/net/sf/jsqlparser/statement/Statements.java index 1d9f38eb..a0f7989c 100644 --- a/src/main/java/net/sf/jsqlparser/statement/Statements.java +++ b/src/main/java/net/sf/jsqlparser/statement/Statements.java @@ -1,32 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement; import java.util.List; -/** - * - * @author toben - */ public class Statements { private List statements; diff --git a/src/main/java/net/sf/jsqlparser/statement/UseStatement.java b/src/main/java/net/sf/jsqlparser/statement/UseStatement.java new file mode 100644 index 00000000..37d5e150 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/UseStatement.java @@ -0,0 +1,37 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +public class UseStatement implements Statement { + + private String name; + + public UseStatement(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return "USE " + name; + } + + @Override + public void accept(StatementVisitor statementVisitor) { + statementVisitor.visit(this); + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/alter/Alter.java b/src/main/java/net/sf/jsqlparser/statement/alter/Alter.java index b0ea9342..944284f6 100644 --- a/src/main/java/net/sf/jsqlparser/statement/alter/Alter.java +++ b/src/main/java/net/sf/jsqlparser/statement/alter/Alter.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.alter; @@ -29,10 +17,6 @@ import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.StatementVisitor; -/** - * - * @author toben & wrobstory - */ public class Alter implements Statement { private Table table; diff --git a/src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java b/src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java index 62b31b66..fb1ee97d 100644 --- a/src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java +++ b/src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java @@ -1,42 +1,28 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2016 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.alter; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; - import net.sf.jsqlparser.statement.create.table.ColDataType; import net.sf.jsqlparser.statement.create.table.Index; import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * - * @author toben & wrobstory - */ public class AlterExpression { private AlterOperation operation; + private String optionalSpecifier; private String columnName; + private String columnOldName; //private ColDataType dataType; private List colDataTypeList; @@ -46,14 +32,18 @@ public class AlterExpression { private String ukName; private Index index = null; private String constraintName; + private boolean constraintIfExists; private boolean onDeleteRestrict; private boolean onDeleteSetNull; private boolean onDeleteCascade; private List fkColumns; private String fkSourceTable; private List fkSourceColumns; + private boolean uk; + private boolean useEqual; private List constraints; + private List parameters; public AlterOperation getOperation() { return operation; @@ -63,6 +53,14 @@ public void setOperation(AlterOperation operation) { this.operation = operation; } + public String getOptionalSpecifier() { + return optionalSpecifier; + } + + public void setOptionalSpecifier(String optionalSpecifier) { + this.optionalSpecifier = optionalSpecifier; + } + public boolean isOnDeleteCascade() { return onDeleteCascade; } @@ -108,7 +106,7 @@ public List getColDataTypeList() { } public void addColDataType(String columnName, ColDataType colDataType) { - addColDataType(new ColumnDataType(columnName, colDataType, null)); + addColDataType(new ColumnDataType(columnName, false, colDataType, null)); } public void addColDataType(ColumnDataType columnDataType) { @@ -134,6 +132,14 @@ public void setColumnName(String columnName) { this.columnName = columnName; } + public String getColOldName() { + return columnOldName; + } + + public void setColOldName(String columnOldName) { + this.columnOldName = columnOldName; + } + public String getConstraintName() { return this.constraintName; } @@ -142,6 +148,14 @@ public void setConstraintName(final String constraintName) { this.constraintName = constraintName; } + public boolean isConstraintIfExists() { + return constraintIfExists; + } + + public void setConstraintIfExists(boolean constraintIfExists) { + this.constraintIfExists = constraintIfExists; + } + public List getPkColumns() { return pkColumns; } @@ -182,6 +196,33 @@ public void setConstraints(List constraints) { this.constraints = constraints; } + public void addParameters(String... params) { + if (parameters == null) { + parameters = new ArrayList(); + } + parameters.addAll(Arrays.asList(params)); + } + + public List getParameters() { + return parameters; + } + + public boolean getUseEqual() { + return useEqual; + } + + public void setUseEqual(boolean useEqual) { + this.useEqual = useEqual; + } + + public boolean getUk() { + return uk; + } + + public void setUk(boolean uk) { + this.uk = uk; + } + @Override public String toString() { @@ -192,7 +233,12 @@ public String toString() { if (columnName != null) { b.append("COLUMN ").append(columnName); } else if (getColDataTypeList() != null) { - if (colDataTypeList.size() > 1) { + if (operation == AlterOperation.CHANGE) { + if (optionalSpecifier != null) { + b.append(optionalSpecifier).append(" "); + } + b.append(columnOldName).append(" "); + } else if (colDataTypeList.size() > 1) { b.append("("); } else { b.append("COLUMN "); @@ -202,12 +248,24 @@ public String toString() { b.append(")"); } } else if (constraintName != null) { - b.append("CONSTRAINT ").append(constraintName); + b.append("CONSTRAINT "); + if (constraintIfExists) { + b.append("IF EXISTS "); + } + b.append(constraintName); } else if (pkColumns != null) { b.append("PRIMARY KEY (").append(PlainSelect.getStringList(pkColumns)).append(')'); } else if (ukColumns != null) { - b.append("UNIQUE KEY ").append(ukName).append(" (").append(PlainSelect. - getStringList(ukColumns)).append(")"); + b.append("UNIQUE"); + if (ukName != null) { + if (getUk()) { + b.append(" KEY "); + } else { + b.append(" INDEX "); + } + b.append(ukName); + } + b.append(" (").append(PlainSelect.getStringList(ukColumns)).append(")"); } else if (fkColumns != null) { b.append("FOREIGN KEY (").append(PlainSelect.getStringList(fkColumns)). append(") REFERENCES ").append(fkSourceTable).append(" (").append( @@ -225,6 +283,12 @@ public String toString() { if (getConstraints() != null && !getConstraints().isEmpty()) { b.append(' ').append(PlainSelect.getStringList(constraints, false, false)); } + if (getUseEqual()) { + b.append('='); + } + if (parameters != null && !parameters.isEmpty()) { + b.append(' ').append(PlainSelect.getStringList(parameters, false, false)); + } return b.toString(); } @@ -232,11 +296,13 @@ public String toString() { public static class ColumnDataType { private final String columnName; + private final boolean withType; private final ColDataType colDataType; private final List columnSpecs; - public ColumnDataType(String columnName, ColDataType colDataType, List columnSpecs) { + public ColumnDataType(String columnName, boolean withType, ColDataType colDataType, List columnSpecs) { this.columnName = columnName; + this.withType = withType; this.colDataType = colDataType; this.columnSpecs = columnSpecs; } @@ -258,7 +324,7 @@ public List getColumnSpecs() { @Override public String toString() { - return columnName + " " + colDataType + parametersToString(); + return columnName + (withType ? " TYPE " : " ") + colDataType + parametersToString(); } private String parametersToString() { diff --git a/src/main/java/net/sf/jsqlparser/statement/alter/AlterOperation.java b/src/main/java/net/sf/jsqlparser/statement/alter/AlterOperation.java index ea37d08c..53b27893 100644 --- a/src/main/java/net/sf/jsqlparser/statement/alter/AlterOperation.java +++ b/src/main/java/net/sf/jsqlparser/statement/alter/AlterOperation.java @@ -1,30 +1,14 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2016 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.alter; -/** - * - * @author toben - */ public enum AlterOperation { - ADD, DROP, MODIFY, CHANGE; + ADD, ALTER, DROP, MODIFY, CHANGE, ALGORITHM; } diff --git a/src/main/java/net/sf/jsqlparser/statement/alter/ConstraintState.java b/src/main/java/net/sf/jsqlparser/statement/alter/ConstraintState.java index 878566b1..432173a8 100644 --- a/src/main/java/net/sf/jsqlparser/statement/alter/ConstraintState.java +++ b/src/main/java/net/sf/jsqlparser/statement/alter/ConstraintState.java @@ -1,30 +1,13 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.alter; -/** - * Based on https://docs.oracle.com/cd/B28359_01/server.111/b28286/clauses002.htm#i1002273 - * - * @author Christophe Moine - */ public interface ConstraintState { } diff --git a/src/main/java/net/sf/jsqlparser/statement/alter/DeferrableConstraint.java b/src/main/java/net/sf/jsqlparser/statement/alter/DeferrableConstraint.java index c249b7d8..15bba4a1 100644 --- a/src/main/java/net/sf/jsqlparser/statement/alter/DeferrableConstraint.java +++ b/src/main/java/net/sf/jsqlparser/statement/alter/DeferrableConstraint.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.alter; diff --git a/src/main/java/net/sf/jsqlparser/statement/alter/EnableConstraint.java b/src/main/java/net/sf/jsqlparser/statement/alter/EnableConstraint.java index 1bdcd7ec..9573a1b6 100644 --- a/src/main/java/net/sf/jsqlparser/statement/alter/EnableConstraint.java +++ b/src/main/java/net/sf/jsqlparser/statement/alter/EnableConstraint.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.alter; diff --git a/src/main/java/net/sf/jsqlparser/statement/alter/ValidateConstraint.java b/src/main/java/net/sf/jsqlparser/statement/alter/ValidateConstraint.java index c4241fa4..36d000a9 100644 --- a/src/main/java/net/sf/jsqlparser/statement/alter/ValidateConstraint.java +++ b/src/main/java/net/sf/jsqlparser/statement/alter/ValidateConstraint.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.alter; diff --git a/src/main/java/net/sf/jsqlparser/statement/comment/Comment.java b/src/main/java/net/sf/jsqlparser/statement/comment/Comment.java new file mode 100755 index 00000000..b44fbf12 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/comment/Comment.java @@ -0,0 +1,64 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.comment; + +import net.sf.jsqlparser.expression.StringValue; +import net.sf.jsqlparser.schema.Column; +import net.sf.jsqlparser.schema.Table; +import net.sf.jsqlparser.statement.Statement; +import net.sf.jsqlparser.statement.StatementVisitor; + +public class Comment implements Statement { + + private Table table; + private Column column; + private StringValue comment; + + @Override + public void accept(StatementVisitor statementVisitor) { + statementVisitor.visit(this); + } + + public Table getTable() { + return table; + } + + public void setTable(Table table) { + this.table = table; + } + + public Column getColumn() { + return column; + } + + public void setColumn(Column column) { + this.column = column; + } + + public StringValue getComment() { + return comment; + } + + public void setComment(StringValue comment) { + this.comment = comment; + } + + @Override + public String toString() { + String sql = "COMMENT ON "; + if (table != null) { + sql += "TABLE " + table + " "; + } else if (column != null) { + sql += "COLUMN " + column + " "; + } + sql += "IS " + comment; + return sql; + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/create/index/CreateIndex.java b/src/main/java/net/sf/jsqlparser/statement/create/index/CreateIndex.java index 5b590ea4..92c602d5 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/index/CreateIndex.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/index/CreateIndex.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.index; @@ -27,11 +15,6 @@ import java.util.*; -/** - * A "CREATE INDEX" statement - * - * @author Raymond Augé - */ public class CreateIndex implements Statement { private Table table; @@ -42,9 +25,6 @@ public void accept(StatementVisitor statementVisitor) { statementVisitor.visit(this); } - /** - * The index to be created - */ public Index getIndex() { return index; } @@ -53,9 +33,6 @@ public void setIndex(Index index) { this.index = index; } - /** - * The table on which the index is to be created - */ public Table getTable() { return table; } @@ -80,6 +57,11 @@ public String toString() { buffer.append(" ON "); buffer.append(table.getFullyQualifiedName()); + if (index.getUsing() != null){ + buffer.append(" USING "); + buffer.append(index.getUsing()); + } + if (index.getColumnsNames() != null) { buffer.append(" ("); diff --git a/src/main/java/net/sf/jsqlparser/statement/create/table/CheckConstraint.java b/src/main/java/net/sf/jsqlparser/statement/create/table/CheckConstraint.java index 8d2c14cf..30dfbc42 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/table/CheckConstraint.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/table/CheckConstraint.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.table; @@ -24,12 +12,6 @@ import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.schema.Table; -/** - * Table Check Constraint Eg. ' CONSTRAINT less_than_ten CHECK (count < 10) ' @au - * - * - * thor mw - */ public class CheckConstraint extends NamedConstraint { private Table table; diff --git a/src/main/java/net/sf/jsqlparser/statement/create/table/ColDataType.java b/src/main/java/net/sf/jsqlparser/statement/create/table/ColDataType.java index fafb4f06..de414896 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/table/ColDataType.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/table/ColDataType.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.table; diff --git a/src/main/java/net/sf/jsqlparser/statement/create/table/ColumnDefinition.java b/src/main/java/net/sf/jsqlparser/statement/create/table/ColumnDefinition.java index c43adcbf..91e6640b 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/table/ColumnDefinition.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/table/ColumnDefinition.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.table; @@ -25,20 +13,12 @@ import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * A column definition in a CREATE TABLE statement.
- * Example: mycol VARCHAR(30) NOT NULL - */ public class ColumnDefinition { private String columnName; private ColDataType colDataType; private List columnSpecStrings; - /** - * A list of strings of every word after the datatype of the column.
- * Example ("NOT", "NULL") - */ public List getColumnSpecStrings() { return columnSpecStrings; } @@ -47,9 +27,6 @@ public void setColumnSpecStrings(List list) { columnSpecStrings = list; } - /** - * The {@link ColDataType} of this column definition - */ public ColDataType getColDataType() { return colDataType; } diff --git a/src/main/java/net/sf/jsqlparser/statement/create/table/CreateTable.java b/src/main/java/net/sf/jsqlparser/statement/create/table/CreateTable.java index 0cc64f61..3f7e58ee 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/table/CreateTable.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/table/CreateTable.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.table; @@ -29,9 +17,6 @@ import net.sf.jsqlparser.statement.select.PlainSelect; import net.sf.jsqlparser.statement.select.Select; -/** - * A "CREATE TABLE" statement - */ public class CreateTable implements Statement { private Table table; @@ -49,9 +34,6 @@ public void accept(StatementVisitor statementVisitor) { statementVisitor.visit(this); } - /** - * The name of the table to be created - */ public Table getTable() { return table; } @@ -60,11 +42,6 @@ public void setTable(Table table) { this.table = table; } - /** - * Whether the table is unlogged or not (PostgreSQL 9.1+ feature) - * - * @return - */ public boolean isUnlogged() { return unlogged; } diff --git a/src/main/java/net/sf/jsqlparser/statement/create/table/ExcludeConstraint.java b/src/main/java/net/sf/jsqlparser/statement/create/table/ExcludeConstraint.java index 63fee20f..0cc4c9d7 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/table/ExcludeConstraint.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/table/ExcludeConstraint.java @@ -1,33 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2016 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.table; import net.sf.jsqlparser.expression.Expression; -/** - * Table Exclusion Constraint Eg. 'EXCLUDE WHERE (col1 > 100)' - * - * @author wrobstory - */ public class ExcludeConstraint extends Index { private Expression expression; diff --git a/src/main/java/net/sf/jsqlparser/statement/create/table/ForeignKeyIndex.java b/src/main/java/net/sf/jsqlparser/statement/create/table/ForeignKeyIndex.java index 0c371751..3d8a23b6 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/table/ForeignKeyIndex.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/table/ForeignKeyIndex.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.table; @@ -25,11 +13,6 @@ import net.sf.jsqlparser.schema.Table; import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * Foreign Key Index - * - * @author toben - */ public class ForeignKeyIndex extends NamedConstraint { private Table table; diff --git a/src/main/java/net/sf/jsqlparser/statement/create/table/Index.java b/src/main/java/net/sf/jsqlparser/statement/create/table/Index.java index 30beff48..4136d563 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/table/Index.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/table/Index.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.table; @@ -25,19 +13,14 @@ import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * An index (unique, primary etc.) in a CREATE TABLE statement - */ public class Index { private String type; + private String using; private List columnsNames; private String name; private List idxSpec; - /** - * A list of strings of all the columns regarding this index - */ public List getColumnsNames() { return columnsNames; } @@ -46,13 +29,21 @@ public String getName() { return name; } - /** - * The type of this index: "PRIMARY KEY", "UNIQUE", "INDEX" - */ public String getType() { return type; } + /** + * In postgresql, the index type (Btree, GIST, etc.) is indicated + * with a USING clause. + * Please note that: + * Oracle - the type might be BITMAP, indicating a bitmap kind of index + * MySQL - the type might be FULLTEXT or SPATIAL + */ + public void setUsing(String string) { + using = string; + } + public void setColumnsNames(List list) { columnsNames = list; } @@ -65,6 +56,10 @@ public void setType(String string) { type = string; } + public String getUsing() { + return using; + } + public List getIndexSpec() { return idxSpec; } diff --git a/src/main/java/net/sf/jsqlparser/statement/create/table/NamedConstraint.java b/src/main/java/net/sf/jsqlparser/statement/create/table/NamedConstraint.java index 454c8b03..55cb4a21 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/table/NamedConstraint.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/table/NamedConstraint.java @@ -1,50 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ - /* - * Copyright (C) 2014 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ package net.sf.jsqlparser.statement.create.table; import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * - * @author toben - */ public class NamedConstraint extends Index { @Override diff --git a/src/main/java/net/sf/jsqlparser/statement/create/view/AlterView.java b/src/main/java/net/sf/jsqlparser/statement/create/view/AlterView.java index fb87502a..2e9af610 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/view/AlterView.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/view/AlterView.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.view; @@ -28,13 +16,11 @@ import net.sf.jsqlparser.statement.select.PlainSelect; import net.sf.jsqlparser.statement.select.SelectBody; -/** - * A "CREATE VIEW" statement - */ public class AlterView implements Statement { private Table view; private SelectBody selectBody; + private boolean useReplace = false; private List columnNames = null; @Override @@ -42,11 +28,6 @@ public void accept(StatementVisitor statementVisitor) { statementVisitor.visit(this); } - /** - * In the syntax tree, a view looks and acts just like a Table. - * - * @return The name of the view to be created. - */ public Table getView() { return view; } @@ -55,9 +36,6 @@ public void setView(Table view) { this.view = view; } - /** - * @return the SelectBody - */ public SelectBody getSelectBody() { return selectBody; } @@ -74,9 +52,22 @@ public void setColumnNames(List columnNames) { this.columnNames = columnNames; } + public boolean isUseReplace() { + return useReplace; + } + + public void setUseReplace(boolean useReplace) { + this.useReplace = useReplace; + } + @Override public String toString() { - StringBuilder sql = new StringBuilder("ALTER "); + StringBuilder sql; + if (useReplace) { + sql = new StringBuilder("REPLACE "); + } else { + sql = new StringBuilder("ALTER "); + } sql.append("VIEW "); sql.append(view); if (columnNames != null) { diff --git a/src/main/java/net/sf/jsqlparser/statement/create/view/CreateView.java b/src/main/java/net/sf/jsqlparser/statement/create/view/CreateView.java index e3d51451..f4143fff 100644 --- a/src/main/java/net/sf/jsqlparser/statement/create/view/CreateView.java +++ b/src/main/java/net/sf/jsqlparser/statement/create/view/CreateView.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.create.view; @@ -26,29 +14,24 @@ import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.StatementVisitor; import net.sf.jsqlparser.statement.select.PlainSelect; -import net.sf.jsqlparser.statement.select.SelectBody; +import net.sf.jsqlparser.statement.select.Select; -/** - * A "CREATE VIEW" statement - */ public class CreateView implements Statement { private Table view; - private SelectBody selectBody; + private Select select; private boolean orReplace = false; private List columnNames = null; private boolean materialized = false; + private ForceOption force = ForceOption.NONE; + private TemporaryOption temp = TemporaryOption.NONE; + private boolean withReadOnly = false; @Override public void accept(StatementVisitor statementVisitor) { statementVisitor.visit(this); } - /** - * In the syntax tree, a view looks and acts just like a Table. - * - * @return The name of the view to be created. - */ public Table getView() { return view; } @@ -57,9 +40,6 @@ public void setView(Table view) { this.view = view; } - /** - * @return was "OR REPLACE" specified? - */ public boolean isOrReplace() { return orReplace; } @@ -71,15 +51,12 @@ public void setOrReplace(boolean orReplace) { this.orReplace = orReplace; } - /** - * @return the SelectBody - */ - public SelectBody getSelectBody() { - return selectBody; + public Select getSelect() { + return select; } - public void setSelectBody(SelectBody selectBody) { - this.selectBody = selectBody; + public void setSelect(Select select) { + this.select = select; } public List getColumnNames() { @@ -98,12 +75,49 @@ public void setMaterialized(boolean materialized) { this.materialized = materialized; } + public ForceOption getForce() { + return force; + } + + public void setForce(ForceOption force) { + this.force = force; + } + + public TemporaryOption getTemporary() { + return temp; + } + + public void setTemporary(TemporaryOption temp) { + this.temp = temp; + } + + public boolean isWithReadOnly() { + return withReadOnly; + } + + public void setWithReadOnly(boolean withReadOnly) { + this.withReadOnly = withReadOnly; + } + @Override public String toString() { StringBuilder sql = new StringBuilder("CREATE "); if (isOrReplace()) { sql.append("OR REPLACE "); } + switch (force) { + case FORCE: + sql.append("FORCE "); + break; + case NO_FORCE: + sql.append("NO FORCE "); + break; + } + + if (temp != TemporaryOption.NONE) { + sql.append(temp.name()).append(" "); + } + if (isMaterialized()) { sql.append("MATERIALIZED "); } @@ -112,7 +126,10 @@ public String toString() { if (columnNames != null) { sql.append(PlainSelect.getStringList(columnNames, true, true)); } - sql.append(" AS ").append(selectBody); + sql.append(" AS ").append(select); + if (isWithReadOnly()) { + sql.append(" WITH READ ONLY"); + } return sql.toString(); } } diff --git a/src/main/java/net/sf/jsqlparser/statement/create/view/ForceOption.java b/src/main/java/net/sf/jsqlparser/statement/create/view/ForceOption.java new file mode 100644 index 00000000..66d3a962 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/create/view/ForceOption.java @@ -0,0 +1,18 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.create.view; + +public enum ForceOption { + NONE, + + FORCE, + + NO_FORCE +} diff --git a/src/main/java/net/sf/jsqlparser/statement/create/view/TemporaryOption.java b/src/main/java/net/sf/jsqlparser/statement/create/view/TemporaryOption.java new file mode 100644 index 00000000..31b1721f --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/create/view/TemporaryOption.java @@ -0,0 +1,18 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.create.view; + +public enum TemporaryOption { + NONE, + + TEMP, + + TEMPORARY +} diff --git a/src/main/java/net/sf/jsqlparser/statement/delete/Delete.java b/src/main/java/net/sf/jsqlparser/statement/delete/Delete.java index 75e6e06c..3e59b2e7 100644 --- a/src/main/java/net/sf/jsqlparser/statement/delete/Delete.java +++ b/src/main/java/net/sf/jsqlparser/statement/delete/Delete.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.delete; @@ -31,6 +19,7 @@ import net.sf.jsqlparser.statement.select.PlainSelect; import java.util.List; +import static java.util.stream.Collectors.joining; public class Delete implements Statement { @@ -100,9 +89,9 @@ public String toString() { if (tables != null && tables.size() > 0) { b.append(" "); - for (Table t : tables) { - b.append(t.toString()); - } + b.append(tables.stream() + .map(t -> t.toString()) + .collect(joining(", "))); } b.append(" FROM "); diff --git a/src/main/java/net/sf/jsqlparser/statement/drop/Drop.java b/src/main/java/net/sf/jsqlparser/statement/drop/Drop.java index 69dceb18..177f6398 100644 --- a/src/main/java/net/sf/jsqlparser/statement/drop/Drop.java +++ b/src/main/java/net/sf/jsqlparser/statement/drop/Drop.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.drop; diff --git a/src/main/java/net/sf/jsqlparser/statement/execute/Execute.java b/src/main/java/net/sf/jsqlparser/statement/execute/Execute.java index 4a26bd61..75422b0c 100644 --- a/src/main/java/net/sf/jsqlparser/statement/execute/Execute.java +++ b/src/main/java/net/sf/jsqlparser/statement/execute/Execute.java @@ -1,39 +1,26 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.execute; +import java.util.List; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.StatementVisitor; import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * - * @author toben - */ public class Execute implements Statement { + private EXEC_TYPE execType = EXEC_TYPE.EXECUTE; private String name; private ExpressionList exprList; + private boolean parenthesis = false; public String getName() { return name; @@ -43,6 +30,16 @@ public void setName(String name) { this.name = name; } + public void setName(List names) { + for (String item : names) { + if (this.name != null) { + this.name = this.name + "." + item; + } else { + this.name = item; + } + } + } + public ExpressionList getExprList() { return exprList; } @@ -51,6 +48,22 @@ public void setExprList(ExpressionList exprList) { this.exprList = exprList; } + public EXEC_TYPE getExecType() { + return execType; + } + + public void setExecType(EXEC_TYPE execType) { + this.execType = execType; + } + + public boolean isParenthesis() { + return parenthesis; + } + + public void setParenthesis(boolean parenthesis) { + this.parenthesis = parenthesis; + } + @Override public void accept(StatementVisitor statementVisitor) { statementVisitor.visit(this); @@ -58,8 +71,15 @@ public void accept(StatementVisitor statementVisitor) { @Override public String toString() { - return "EXECUTE " + name + " " + PlainSelect. - getStringList(exprList.getExpressions(), true, false); + return execType.name() + " " + name + + (exprList != null && exprList.getExpressions() != null ? " " + + PlainSelect.getStringList(exprList.getExpressions(), true, parenthesis) : ""); + } + + public static enum EXEC_TYPE { + EXECUTE, + EXEC, + CALL } } diff --git a/src/main/java/net/sf/jsqlparser/statement/insert/Insert.java b/src/main/java/net/sf/jsqlparser/statement/insert/Insert.java index 31541aaa..14db1219 100644 --- a/src/main/java/net/sf/jsqlparser/statement/insert/Insert.java +++ b/src/main/java/net/sf/jsqlparser/statement/insert/Insert.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.insert; @@ -33,10 +21,6 @@ import net.sf.jsqlparser.statement.select.Select; import net.sf.jsqlparser.statement.select.SelectExpressionItem; -/** - * The insert statement. Every column name in columnNames matches an item in - * itemsList - */ public class Insert implements Statement { private Table table; @@ -54,6 +38,10 @@ public class Insert implements Statement { private boolean returningAllColumns = false; private List returningExpressionList = null; + + private boolean useSet = false; + private List setColumns; + private List setExpressionList; @Override public void accept(StatementVisitor statementVisitor) { @@ -68,11 +56,6 @@ public void setTable(Table name) { table = name; } - /** - * Get the columns (found in "INSERT INTO (col1,col2..) [...]" ) - * - * @return a list of {@link net.sf.jsqlparser.schema.Column} - */ public List getColumns() { return columns; } @@ -173,6 +156,30 @@ public boolean isModifierIgnore() { public void setModifierIgnore(boolean modifierIgnore) { this.modifierIgnore = modifierIgnore; } + + public void setUseSet(boolean useSet) { + this.useSet = useSet; + } + + public boolean isUseSet() { + return useSet; + } + + public void setSetColumns(List setColumns) { + this.setColumns = setColumns; + } + + public List getSetColumns() { + return setColumns; + } + + public void setSetExpressionList(List setExpressionList) { + this.setExpressionList = setExpressionList; + } + + public List getSetExpressionList() { + return setExpressionList; + } @Override public String toString() { @@ -208,6 +215,17 @@ public String toString() { sql.append(")"); } } + + if (useSet) { + sql.append("SET "); + for (int i = 0; i < getSetColumns().size(); i++) { + if (i != 0) { + sql.append(", "); + } + sql.append(setColumns.get(i)).append(" = "); + sql.append(setExpressionList.get(i)); + } + } if (useDuplicate) { sql.append(" ON DUPLICATE KEY UPDATE "); @@ -229,4 +247,5 @@ public String toString() { return sql.toString(); } + } diff --git a/src/main/java/net/sf/jsqlparser/statement/insert/InsertModifierPriority.java b/src/main/java/net/sf/jsqlparser/statement/insert/InsertModifierPriority.java index c5296a99..534281e8 100644 --- a/src/main/java/net/sf/jsqlparser/statement/insert/InsertModifierPriority.java +++ b/src/main/java/net/sf/jsqlparser/statement/insert/InsertModifierPriority.java @@ -1,30 +1,14 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.insert; -/** - * - * @author tw - */ public enum InsertModifierPriority { LOW_PRIORITY, DELAYED, HIGH_PRIORITY, IGNORE } diff --git a/src/main/java/net/sf/jsqlparser/statement/merge/Merge.java b/src/main/java/net/sf/jsqlparser/statement/merge/Merge.java index 5bb95e1d..f9c7bced 100644 --- a/src/main/java/net/sf/jsqlparser/statement/merge/Merge.java +++ b/src/main/java/net/sf/jsqlparser/statement/merge/Merge.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.merge; @@ -28,11 +16,6 @@ import net.sf.jsqlparser.statement.StatementVisitor; import net.sf.jsqlparser.statement.select.SubSelect; -/** - * Merge - statement - * - * @author tw - */ public class Merge implements Statement { private Table table; diff --git a/src/main/java/net/sf/jsqlparser/statement/merge/MergeInsert.java b/src/main/java/net/sf/jsqlparser/statement/merge/MergeInsert.java index cfc679c1..6f46a357 100644 --- a/src/main/java/net/sf/jsqlparser/statement/merge/MergeInsert.java +++ b/src/main/java/net/sf/jsqlparser/statement/merge/MergeInsert.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.merge; @@ -26,10 +14,6 @@ import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * - * @author toben - */ public class MergeInsert { private List columns = null; @@ -53,7 +37,8 @@ public void setValues(List values) { @Override public String toString() { - return " WHEN NOT MATCHED THEN INSERT " + PlainSelect.getStringList(columns, true, true) + return " WHEN NOT MATCHED THEN INSERT " + + (columns.isEmpty() ? "" : PlainSelect.getStringList(columns, true, true)) + " VALUES " + PlainSelect.getStringList(values, true, true); } } diff --git a/src/main/java/net/sf/jsqlparser/statement/merge/MergeUpdate.java b/src/main/java/net/sf/jsqlparser/statement/merge/MergeUpdate.java index bdd1a404..b81b446d 100644 --- a/src/main/java/net/sf/jsqlparser/statement/merge/MergeUpdate.java +++ b/src/main/java/net/sf/jsqlparser/statement/merge/MergeUpdate.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.merge; @@ -25,10 +13,6 @@ import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.schema.Column; -/** - * - * @author toben - */ public class MergeUpdate { private List columns = null; diff --git a/src/main/java/net/sf/jsqlparser/statement/replace/Replace.java b/src/main/java/net/sf/jsqlparser/statement/replace/Replace.java index 936d1665..51252d3e 100644 --- a/src/main/java/net/sf/jsqlparser/statement/replace/Replace.java +++ b/src/main/java/net/sf/jsqlparser/statement/replace/Replace.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.replace; @@ -31,9 +19,6 @@ import net.sf.jsqlparser.statement.StatementVisitor; import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * The replace statement. - */ public class Replace implements Statement { private Table table; @@ -64,20 +49,10 @@ public void setUseIntoTables(boolean useIntoTables) { this.useIntoTables = useIntoTables; } - /** - * A list of {@link net.sf.jsqlparser.schema.Column}s either from a "REPLACE mytab (col1, col2) - * [...]" or a "REPLACE mytab SET col1=exp1, col2=exp2". - * - * @return a list of {@link net.sf.jsqlparser.schema.Column}s - */ public List getColumns() { return columns; } - /** - * An {@link ItemsList} (either from a "REPLACE mytab VALUES (exp1,exp2)" or a "REPLACE mytab - * SELECT * FROM mytab2") it is null in case of a "REPLACE mytab SET col1=exp1, col2=exp2" - */ public ItemsList getItemsList() { return itemsList; } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/AllColumns.java b/src/main/java/net/sf/jsqlparser/statement/select/AllColumns.java index 36949093..b01828b3 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/AllColumns.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/AllColumns.java @@ -1,30 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; -/** - * All the columns (as in "SELECT * FROM ...") - */ -public class AllColumns implements SelectItem { +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class AllColumns extends ASTNodeAccessImpl implements SelectItem { public AllColumns() { } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/AllTableColumns.java b/src/main/java/net/sf/jsqlparser/statement/select/AllTableColumns.java index 35c8acb5..e1b7d3d5 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/AllTableColumns.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/AllTableColumns.java @@ -1,32 +1,18 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; -/** - * All the columns of a table (as in "SELECT TableName.* FROM ...") - */ +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.schema.*; -public class AllTableColumns implements SelectItem { +public class AllTableColumns extends ASTNodeAccessImpl implements SelectItem { private Table table; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Distinct.java b/src/main/java/net/sf/jsqlparser/statement/select/Distinct.java index e9d62ab0..9b2f6c83 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/Distinct.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Distinct.java @@ -1,31 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import java.util.List; -/** - * A DISTINCT [ON (expression, ...)] clause - */ public class Distinct { private List onSelectItems; @@ -38,11 +23,6 @@ public Distinct(boolean useUnique) { this.useUnique = useUnique; } - /** - * A list of {@link SelectItem}s expressions, as in "select DISTINCT ON (a,b,c) a,b FROM..." - * - * @return a list of {@link SelectItem}s expressions - */ public List getOnSelectItems() { return onSelectItems; } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/ExceptOp.java b/src/main/java/net/sf/jsqlparser/statement/select/ExceptOp.java index d0db50bb..f6b11a70 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/ExceptOp.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/ExceptOp.java @@ -1,32 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.statement.select.SetOperationList.SetOperationType; -/** - * - * @author tw - */ public class ExceptOp extends SetOperation { public ExceptOp() { diff --git a/src/main/java/net/sf/jsqlparser/statement/select/ExpressionListItem.java b/src/main/java/net/sf/jsqlparser/statement/select/ExpressionListItem.java index 35e026a9..7ae1d1a9 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/ExpressionListItem.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/ExpressionListItem.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Fetch.java b/src/main/java/net/sf/jsqlparser/statement/select/Fetch.java index 4918ce75..3a7f34a5 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/Fetch.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Fetch.java @@ -1,33 +1,20 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; -/** - * A fetch clause in the form FETCH (FIRST | NEXT) row_count (ROW | ROWS) ONLY - */ +import net.sf.jsqlparser.expression.JdbcParameter; + public class Fetch { private long rowCount; - private boolean fetchJdbcParameter = false; + private JdbcParameter fetchJdbcParameter = null; private boolean isFetchParamFirst = false; private String fetchParam = "ROW"; @@ -39,7 +26,7 @@ public void setRowCount(long l) { rowCount = l; } - public boolean isFetchJdbcParameter() { + public JdbcParameter getFetchJdbcParameter() { return fetchJdbcParameter; } @@ -51,8 +38,8 @@ public boolean isFetchParamFirst() { return isFetchParamFirst; } - public void setFetchJdbcParameter(boolean b) { - fetchJdbcParameter = b; + public void setFetchJdbcParameter(JdbcParameter jdbc) { + fetchJdbcParameter = jdbc; } public void setFetchParam(String s) { @@ -65,7 +52,8 @@ public void setFetchParamFirst(boolean b) { @Override public String toString() { - return " FETCH " + (isFetchParamFirst ? "FIRST" : "NEXT") + " " + (fetchJdbcParameter ? "?" : Long. - toString(rowCount)) + " " + fetchParam + " ONLY"; + return " FETCH " + (isFetchParamFirst ? "FIRST" : "NEXT") + " " + + (fetchJdbcParameter!=null ? fetchJdbcParameter.toString() : + Long.toString(rowCount)) + " " + fetchParam + " ONLY"; } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/First.java b/src/main/java/net/sf/jsqlparser/statement/select/First.java index a476f025..dfac655b 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/First.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/First.java @@ -1,35 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.expression.JdbcParameter; -/** - * A FIRST clause in the form [FIRST row_count] the alternative form [LIMIT row_count] is also - * supported. - * - * Initial implementation was done for informix special syntax: - * http://www-01.ibm.com/support/knowledgecenter/SSGU8G_12.1.0/com.ibm.sqls.doc/ids_sqs_0156.htm - */ public class First { public enum Keyword { diff --git a/src/main/java/net/sf/jsqlparser/statement/select/FromItem.java b/src/main/java/net/sf/jsqlparser/statement/select/FromItem.java index f3781e28..b191750b 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/FromItem.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/FromItem.java @@ -1,31 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.expression.Alias; -/** - * An item in a "SELECT [...] FROM item1" statement. (for example a table or a sub-select) - */ public interface FromItem { void accept(FromItemVisitor fromItemVisitor); @@ -38,4 +23,8 @@ public interface FromItem { void setPivot(Pivot pivot); + UnPivot getUnPivot(); + + void setUnPivot(UnPivot unpivot); + } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitor.java b/src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitor.java index 8ec50c1b..c1c1d077 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitor.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitor.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; @@ -36,4 +24,6 @@ public interface FromItemVisitor { void visit(ValuesList valuesList); void visit(TableFunction tableFunction); + + public void visit(ParenthesisFromItem aThis); } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitorAdapter.java b/src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitorAdapter.java index c2af2a11..3cdcb9c5 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitorAdapter.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/FromItemVisitorAdapter.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; @@ -54,4 +42,9 @@ public void visit(ValuesList valuesList) { public void visit(TableFunction valuesList) { } + + @Override + public void visit(ParenthesisFromItem aThis) { + + } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/FunctionItem.java b/src/main/java/net/sf/jsqlparser/statement/select/FunctionItem.java index 292cb6d8..50c920f7 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/FunctionItem.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/FunctionItem.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/GroupByElement.java b/src/main/java/net/sf/jsqlparser/statement/select/GroupByElement.java new file mode 100644 index 00000000..f57a06ed --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/select/GroupByElement.java @@ -0,0 +1,82 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import java.util.ArrayList; +import java.util.List; +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.operators.relational.ExpressionList; + +public class GroupByElement { + + private List groupByExpressions = new ArrayList<>(); + private List groupingSets = new ArrayList(); + + public void accept(GroupByVisitor groupByVisitor) { + groupByVisitor.visit(this); + } + + public List getGroupByExpressions() { + return groupByExpressions; + } + + public void setGroupByExpressions(List groupByExpressions) { + this.groupByExpressions = groupByExpressions; + } + + public void addGroupByExpression(Expression groupByExpression) { + groupByExpressions.add(groupByExpression); + } + + public List getGroupingSets() { + return groupingSets; + } + + public void setGroupingSets(List groupingSets) { + this.groupingSets = groupingSets; + } + + public void addGroupingSet(Expression expr) { + this.groupingSets.add(expr); + } + + public void addGroupingSet(ExpressionList list) { + this.groupingSets.add(list); + } + + @Override + public String toString() { + StringBuilder b = new StringBuilder(); + b.append("GROUP BY "); + + if (groupByExpressions.size() > 0) { + b.append(PlainSelect.getStringList(groupByExpressions)); + } else if (groupingSets.size() > 0) { + b.append("GROUPING SETS ("); + boolean first = true; + for (Object o : groupingSets) { + if (first) { + first = false; + } else { + b.append(", "); + } + if (o instanceof Expression) { + b.append(o.toString()); + } else if (o instanceof ExpressionList) { + ExpressionList list = (ExpressionList) o; + b.append(list.getExpressions() == null ? "()" : list.toString()); + } + } + b.append(")"); + } + + return b.toString(); + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/select/GroupByVisitor.java b/src/main/java/net/sf/jsqlparser/statement/select/GroupByVisitor.java new file mode 100644 index 00000000..21bfc578 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/select/GroupByVisitor.java @@ -0,0 +1,15 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +public interface GroupByVisitor { + + void visit(GroupByElement groupBy); +} diff --git a/src/main/java/net/sf/jsqlparser/statement/select/IntersectOp.java b/src/main/java/net/sf/jsqlparser/statement/select/IntersectOp.java index e6976134..f2248ca1 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/IntersectOp.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/IntersectOp.java @@ -1,32 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.statement.select.SetOperationList.SetOperationType; -/** - * - * @author tw - */ public class IntersectOp extends SetOperation { public IntersectOp() { diff --git a/src/main/java/net/sf/jsqlparser/statement/select/IntoTableVisitor.java b/src/main/java/net/sf/jsqlparser/statement/select/IntoTableVisitor.java index 9b0746d4..64a85ca9 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/IntoTableVisitor.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/IntoTableVisitor.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/IntoTableVisitorAdapter.java b/src/main/java/net/sf/jsqlparser/statement/select/IntoTableVisitorAdapter.java index 32f960e7..5875cc6f 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/IntoTableVisitorAdapter.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/IntoTableVisitorAdapter.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Join.java b/src/main/java/net/sf/jsqlparser/statement/select/Join.java index a2c87fb4..98e4a89b 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/Join.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Join.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; @@ -24,12 +12,10 @@ import java.util.List; import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.schema.Column; -/** - * A join clause - */ -public class Join { +public class Join extends ASTNodeAccessImpl { private boolean outer = false; private boolean right = false; @@ -40,15 +26,13 @@ public class Join { private boolean simple = false; private boolean cross = false; private boolean semi = false; + private boolean straight = false; + private boolean apply = false; private FromItem rightItem; private Expression onExpression; private List usingColumns; + private KSQLJoinWindow joinWindow; - /** - * Whether is a tab1,tab2 join - * - * @return true if is a "tab1,tab2" join - */ public boolean isSimple() { return simple; } @@ -57,11 +41,6 @@ public void setSimple(boolean b) { simple = b; } - /** - * Whether is a "INNER" join - * - * @return true if is a "INNER" join - */ public boolean isInner() { return inner; } @@ -70,6 +49,14 @@ public void setInner(boolean b) { inner = b; } + public boolean isStraight() { + return straight; + } + + public void setStraight(boolean b) { + straight = b; + } + /** * Whether is a "OUTER" join * @@ -83,6 +70,14 @@ public void setOuter(boolean b) { outer = b; } + public boolean isApply() { + return apply; + } + + public void setApply(boolean apply) { + this.apply = apply; + } + /** * Whether is a "SEMI" join * @@ -189,9 +184,26 @@ public void setUsingColumns(List list) { usingColumns = list; } + public boolean isWindowJoin() { + return joinWindow != null; + } + + /** + * Return the "WITHIN" join window (if any) + */ + public KSQLJoinWindow getJoinWindow() { + return joinWindow; + } + + public void setJoinWindow(KSQLJoinWindow joinWindow) { + this.joinWindow = joinWindow; + } + @Override public String toString() { - if (isSimple()) { + if (isSimple() && isOuter()) { + return "OUTER " + rightItem; + } else if (isSimple()) { return "" + rightItem; } else { String type = ""; @@ -216,7 +228,16 @@ public String toString() { type += "SEMI "; } - return type + "JOIN " + rightItem + ((onExpression != null) ? " ON " + onExpression + "" : "") + if (isStraight()) { + type = "STRAIGHT_JOIN "; + } else if (isApply()) { + type += "APPLY "; + } else { + type += "JOIN "; + } + + return type + rightItem + ((joinWindow != null) ? " WITHIN " + joinWindow : "") + + ((onExpression != null) ? " ON " + onExpression + "" : "") + PlainSelect.getFormatedList(usingColumns, "USING", true, true); } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/KSQLJoinWindow.java b/src/main/java/net/sf/jsqlparser/statement/select/KSQLJoinWindow.java new file mode 100644 index 00000000..871dc028 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/select/KSQLJoinWindow.java @@ -0,0 +1,113 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class KSQLJoinWindow extends ASTNodeAccessImpl { + + public enum TimeUnit { + DAY ("DAY"), + HOUR ("HOUR"), + MINUTE ("MINUTE"), + SECOND ("SECOND"), + MILLISECOND ("MILLISECOND"), + DAYS ("DAYS"), + HOURS ("HOURS"), + MINUTES ("MINUTES"), + SECONDS ("SECONDS"), + MILLISECONDS ("MILLISECONDS"); + + private String timeUnit; + + TimeUnit(String timeUnit) { + this.timeUnit = timeUnit; + } + + public String getTimeUnit() { + return timeUnit; + } + } + + private boolean beforeAfter; + private long duration; + private TimeUnit timeUnit; + private long beforeDuration; + private TimeUnit beforeTimeUnit; + private long afterDuration; + private TimeUnit afterTimeUnit; + + public KSQLJoinWindow() { + } + + public boolean isBeforeAfterWindow() { + return beforeAfter; + } + + public void setBeforeAfterWindow(boolean beforeAfter) { + this.beforeAfter = beforeAfter; + } + + public long getDuration() { + return duration; + } + + public void setDuration(long duration) { + this.duration = duration; + } + + public TimeUnit getTimeUnit() { + return timeUnit; + } + + public void setTimeUnit(TimeUnit timeUnit) { + this.timeUnit = timeUnit; + } + + public long getBeforeDuration() { + return beforeDuration; + } + + public void setBeforeDuration(long beforeDuration) { + this.beforeDuration = beforeDuration; + } + + public TimeUnit getBeforeTimeUnit() { + return beforeTimeUnit; + } + + public void setBeforeTimeUnit(TimeUnit beforeTimeUnit) { + this.beforeTimeUnit = beforeTimeUnit; + } + + public long getAfterDuration() { + return afterDuration; + } + + public void setAfterDuration(long afterDuration) { + this.afterDuration = afterDuration; + } + + public TimeUnit getAfterTimeUnit() { + return afterTimeUnit; + } + + public void setAfterTimeUnit(TimeUnit afterTimeUnit) { + this.afterTimeUnit = afterTimeUnit; + } + + @Override + public String toString() { + if (isBeforeAfterWindow()) { + return "(" + beforeDuration + " " + beforeTimeUnit + ", " + afterDuration + " " + afterTimeUnit + ")"; + } + return "(" + duration + " " + timeUnit + ")"; + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/select/KSQLWindow.java b/src/main/java/net/sf/jsqlparser/statement/select/KSQLWindow.java new file mode 100644 index 00000000..620cb142 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/select/KSQLWindow.java @@ -0,0 +1,133 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; + +public class KSQLWindow extends ASTNodeAccessImpl { + + public enum TimeUnit { + DAY ("DAY"), + HOUR ("HOUR"), + MINUTE ("MINUTE"), + SECOND ("SECOND"), + MILLISECOND ("MILLISECOND"), + DAYS ("DAYS"), + HOURS ("HOURS"), + MINUTES ("MINUTES"), + SECONDS ("SECONDS"), + MILLISECONDS ("MILLISECONDS"); + + private String timeUnit; + + TimeUnit(String timeUnit) { + this.timeUnit = timeUnit; + } + + public String getTimeUnit() { + return timeUnit; + } + } + + public enum WindowType { + HOPPING ("HOPPING"), + SESSION ("SESSION"), + TUMBLING ("TUMBLING"); + + private String windowType; + + WindowType(String windowType) { + this.windowType = windowType; + } + + public String getWindowType() { + return windowType; + } + } + + private boolean hopping; + private boolean tumbling; + private boolean session; + private long sizeDuration; + private TimeUnit sizeTimeUnit; + private long advanceDuration; + private TimeUnit advanceTimeUnit; + + public boolean isHoppingWindow() { + return hopping; + } + + public void setHoppingWindow(boolean hopping) { + this.hopping = hopping; + } + + public boolean isTumblingWindow() { + return tumbling; + } + + public void setTumblingWindow(boolean tumbling) { + this.tumbling = tumbling; + } + + public boolean isSessionWindow() { + return session; + } + + public void setSessionWindow(boolean session) { + this.session = session; + } + + public long getSizeDuration() { + return sizeDuration; + } + + public void setSizeDuration(long sizeDuration) { + this.sizeDuration = sizeDuration; + } + + public TimeUnit getSizeTimeUnit() { + return sizeTimeUnit; + } + + public void setSizeTimeUnit(TimeUnit sizeTimeUnit) { + this.sizeTimeUnit = sizeTimeUnit; + } + + public long getAdvanceDuration() { + return advanceDuration; + } + + public void setAdvanceDuration(long advanceDuration) { + this.advanceDuration = advanceDuration; + } + + public TimeUnit getAdvanceTimeUnit() { + return advanceTimeUnit; + } + + public void setAdvanceTimeUnit(TimeUnit advanceTimeUnit) { + this.advanceTimeUnit = advanceTimeUnit; + } + + public KSQLWindow() { + } + + @Override + public String toString() { + if (isHoppingWindow()) { + return "HOPPING (" + "SIZE " + sizeDuration + " " + sizeTimeUnit + ", " + + "ADVANCE BY " + advanceDuration + " " + advanceTimeUnit + ")"; + } else if (isSessionWindow()) { + return "SESSION (" + sizeDuration + " " + sizeTimeUnit + ")"; + } else { + return "TUMBLING (" + "SIZE " + sizeDuration + " " + sizeTimeUnit + ")"; + } + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/select/LateralSubSelect.java b/src/main/java/net/sf/jsqlparser/statement/select/LateralSubSelect.java index 52b094f7..fb9bde26 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/LateralSubSelect.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/LateralSubSelect.java @@ -1,76 +1,26 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; -import net.sf.jsqlparser.expression.Alias; - /** - * A lateral subselect followed by an alias. - * - * @author Tobias Warneke + * lateral sub select + * @author tobens */ -public class LateralSubSelect implements FromItem { - - private SubSelect subSelect; - private Alias alias; - private Pivot pivot; - - public void setSubSelect(SubSelect subSelect) { - this.subSelect = subSelect; +public class LateralSubSelect extends SpecialSubSelect { + + public LateralSubSelect() { + super("LATERAL"); } - - public SubSelect getSubSelect() { - return subSelect; - } - + @Override public void accept(FromItemVisitor fromItemVisitor) { fromItemVisitor.visit(this); } - - @Override - public Alias getAlias() { - return alias; - } - - @Override - public void setAlias(Alias alias) { - this.alias = alias; - } - - @Override - public Pivot getPivot() { - return pivot; - } - - @Override - public void setPivot(Pivot pivot) { - this.pivot = pivot; - } - - @Override - public String toString() { - return "LATERAL" + subSelect.toString() - + ((pivot != null) ? " " + pivot : "") - + ((alias != null) ? alias.toString() : ""); - } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Limit.java b/src/main/java/net/sf/jsqlparser/statement/select/Limit.java index 981ba5d5..3ddd975b 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/Limit.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Limit.java @@ -1,32 +1,18 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; -/** - * A limit clause in the form [LIMIT {[offset,] row_count) | (row_count | ALL) OFFSET offset}] - */ -public class Limit { +public class Limit extends ASTNodeAccessImpl { private Expression rowCount; private Expression offset; @@ -49,9 +35,6 @@ public void setRowCount(Expression l) { rowCount = l; } - /** - * @return true if the limit is "LIMIT ALL [OFFSET ...]) - */ public boolean isLimitAll() { return limitAll; } @@ -60,9 +43,6 @@ public void setLimitAll(boolean b) { limitAll = b; } - /** - * @return true if the limit is "LIMIT NULL [OFFSET ...]) - */ public boolean isLimitNull() { return limitNull; } @@ -77,11 +57,15 @@ public String toString() { if (limitNull) { retVal += "NULL"; } else { - if (null != offset) { - retVal += offset + ", "; - } - if (null != rowCount) { - retVal += rowCount; + if (limitAll) { + retVal += "ALL"; + } else { + if (null != offset) { + retVal += offset + ", "; + } + if (null != rowCount) { + retVal += rowCount; + } } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/MinusOp.java b/src/main/java/net/sf/jsqlparser/statement/select/MinusOp.java index d63a04bc..ab779978 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/MinusOp.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/MinusOp.java @@ -1,32 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.statement.select.SetOperationList.SetOperationType; -/** - * - * @author tw - */ public class MinusOp extends SetOperation { public MinusOp() { diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Offset.java b/src/main/java/net/sf/jsqlparser/statement/select/Offset.java index a8bb81fa..310226c0 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/Offset.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Offset.java @@ -1,33 +1,22 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; -/** - * An offset clause in the form OFFSET offset or in the form OFFSET offset (ROW | ROWS) - */ +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.JdbcNamedParameter; +import net.sf.jsqlparser.expression.JdbcParameter; + public class Offset { private long offset; - private boolean offsetJdbcParameter = false; + private Expression offsetJdbcParameter = null; private String offsetParam = null; public long getOffset() { @@ -46,16 +35,20 @@ public void setOffsetParam(String s) { offsetParam = s; } - public boolean isOffsetJdbcParameter() { + public Expression getOffsetJdbcParameter() { return offsetJdbcParameter; } - public void setOffsetJdbcParameter(boolean b) { - offsetJdbcParameter = b; + public void setOffsetJdbcParameter(JdbcParameter jdbc) { + offsetJdbcParameter = jdbc; + } + + public void setOffsetJdbcParameter(JdbcNamedParameter jdbc) { + offsetJdbcParameter = jdbc; } @Override public String toString() { - return " OFFSET " + (offsetJdbcParameter ? "?" : offset) + (offsetParam != null ? " " + offsetParam : ""); + return " OFFSET " + (offsetJdbcParameter!=null ? offsetJdbcParameter.toString() : offset) + (offsetParam != null ? " " + offsetParam : ""); } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/OptimizeFor.java b/src/main/java/net/sf/jsqlparser/statement/select/OptimizeFor.java new file mode 100644 index 00000000..d10d1161 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/select/OptimizeFor.java @@ -0,0 +1,35 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +/** + * A optimize for clause. + */ +public class OptimizeFor { + + private long rowCount; + + public OptimizeFor(long rowCount) { + this.rowCount = rowCount; + } + + public long getRowCount() { + return rowCount; + } + + public void setRowCount(long l) { + rowCount = l; + } + + @Override + public String toString() { + return " OPTIMIZE FOR " + rowCount + " ROWS"; + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/select/OrderByElement.java b/src/main/java/net/sf/jsqlparser/statement/select/OrderByElement.java index 1a1a3fe6..60a953a8 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/OrderByElement.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/OrderByElement.java @@ -1,31 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.expression.Expression; -/** - * An element (column reference) in an "ORDER BY" clause. - */ public class OrderByElement { public enum NullOrdering { diff --git a/src/main/java/net/sf/jsqlparser/statement/select/OrderByVisitor.java b/src/main/java/net/sf/jsqlparser/statement/select/OrderByVisitor.java index cd82b688..e54b8fc0 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/OrderByVisitor.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/OrderByVisitor.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/OrderByVisitorAdapter.java b/src/main/java/net/sf/jsqlparser/statement/select/OrderByVisitorAdapter.java index ba5bee90..95d9f189 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/OrderByVisitorAdapter.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/OrderByVisitorAdapter.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/ParenthesisFromItem.java b/src/main/java/net/sf/jsqlparser/statement/select/ParenthesisFromItem.java new file mode 100644 index 00000000..8ed4eeab --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/select/ParenthesisFromItem.java @@ -0,0 +1,74 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import net.sf.jsqlparser.expression.*; + +public class ParenthesisFromItem implements FromItem { + + private FromItem fromItem; + + private Alias alias; + + public ParenthesisFromItem() { + } + + public ParenthesisFromItem(FromItem fromItem) { + setFromItem(fromItem); + } + + public FromItem getFromItem() { + return fromItem; + } + + public final void setFromItem(FromItem fromItem) { + this.fromItem = fromItem; + } + + @Override + public void accept(FromItemVisitor fromItemVisitor) { + fromItemVisitor.visit(this); + } + + @Override + public String toString() { + return "(" + fromItem + ")" + (alias!=null?alias.toString():""); + } + + @Override + public Alias getAlias() { + return alias; + } + + @Override + public void setAlias(Alias alias) { + this.alias = alias; + } + + @Override + public Pivot getPivot() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setPivot(Pivot pivot) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public UnPivot getUnPivot() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setUnPivot(UnPivot unpivot) { + throw new UnsupportedOperationException("Not supported yet."); + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Pivot.java b/src/main/java/net/sf/jsqlparser/statement/select/Pivot.java index 0c472971..191ca0b1 100755 --- a/src/main/java/net/sf/jsqlparser/statement/select/Pivot.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Pivot.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; @@ -24,16 +12,15 @@ import net.sf.jsqlparser.schema.Column; import java.util.List; +import net.sf.jsqlparser.expression.Alias; public class Pivot { private List functionItems; - private List forColumns; - private List singleInItems; - private List multiInItems; + private Alias alias; public void accept(PivotVisitor pivotVisitor) { pivotVisitor.visit(this); @@ -75,12 +62,21 @@ public List getInItems() { return singleInItems == null ? multiInItems : singleInItems; } + public Alias getAlias() { + return alias; + } + + public void setAlias(Alias alias) { + this.alias = alias; + } + @Override public String toString() { return "PIVOT (" + PlainSelect.getStringList(functionItems) + " FOR " + PlainSelect. getStringList(forColumns, true, forColumns != null && forColumns.size() > 1) - + " IN " + PlainSelect.getStringList(getInItems(), true, true) + ")"; + + " IN " + PlainSelect.getStringList(getInItems(), true, true) + ")" + + (alias!=null?alias.toString():""); } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/PivotVisitor.java b/src/main/java/net/sf/jsqlparser/statement/select/PivotVisitor.java index 656a50e3..e348aa9d 100755 --- a/src/main/java/net/sf/jsqlparser/statement/select/PivotVisitor.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/PivotVisitor.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; @@ -27,4 +15,6 @@ public interface PivotVisitor { void visit(PivotXml pivot); + void visit(UnPivot unpivot); + } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/PivotVisitorAdapter.java b/src/main/java/net/sf/jsqlparser/statement/select/PivotVisitorAdapter.java index 95ceaba6..31f6d2e0 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/PivotVisitorAdapter.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/PivotVisitorAdapter.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; @@ -32,4 +20,9 @@ public void visit(Pivot pivot) { public void visit(PivotXml pivot) { } + + @Override + public void visit(UnPivot unpivot) { + + } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/PivotXml.java b/src/main/java/net/sf/jsqlparser/statement/select/PivotXml.java index 43f76c12..51c1bde9 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/PivotXml.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/PivotXml.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java b/src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java index 4380288a..bc86874e 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/PlainSelect.java @@ -1,40 +1,25 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import java.util.ArrayList; import java.util.Collections; -import net.sf.jsqlparser.expression.Expression; -import net.sf.jsqlparser.schema.Table; - import java.util.Iterator; import java.util.List; +import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.OracleHierarchicalExpression; import net.sf.jsqlparser.expression.OracleHint; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; +import net.sf.jsqlparser.schema.Table; -/** - * The core of a "SELECT" statement (no UNION, no ORDER BY) - */ -public class PlainSelect implements SelectBody { +public class PlainSelect extends ASTNodeAccessImpl implements SelectBody { private Distinct distinct = null; private List selectItems; @@ -42,13 +27,15 @@ public class PlainSelect implements SelectBody { private FromItem fromItem; private List joins; private Expression where; - private List groupByColumnReferences; + private GroupByElement groupBy; private List orderByElements; private Expression having; private Limit limit; private Offset offset; private Fetch fetch; + private OptimizeFor optimizeFor; private Skip skip; + private boolean mySqlHintStraightJoin; private First first; private Top top; private OracleHierarchicalExpression oracleHierarchical = null; @@ -58,6 +45,11 @@ public class PlainSelect implements SelectBody { private Table forUpdateTable = null; private boolean useBrackets = false; private Wait wait; + private boolean mySqlSqlCalcFoundRows = false; + private boolean sqlNoCacheFlag = false; + private String forXmlPath; + private KSQLWindow ksqlWindow = null; + private boolean noWait = false; public boolean isUseBrackets() { return useBrackets; @@ -67,11 +59,6 @@ public void setUseBrackets(boolean useBrackets) { this.useBrackets = useBrackets; } - /** - * The {@link FromItem} in this query - * - * @return the {@link FromItem} - */ public FromItem getFromItem() { return fromItem; } @@ -80,11 +67,6 @@ public List getIntoTables() { return intoTables; } - /** - * The {@link SelectItem}s in this query (for example the A,B,C in "SELECT A,B,C") - * - * @return a list of {@link SelectItem}s - */ public List getSelectItems() { return selectItems; } @@ -166,6 +148,14 @@ public void setFetch(Fetch fetch) { this.fetch = fetch; } + public OptimizeFor getOptimizeFor() { + return optimizeFor; + } + + public void setOptimizeFor(OptimizeFor optimizeFor) { + this.optimizeFor = optimizeFor; + } + public Top getTop() { return top; } @@ -182,6 +172,14 @@ public void setSkip(Skip skip) { this.skip = skip; } + public boolean getMySqlHintStraightJoin() { + return this.mySqlHintStraightJoin; + } + + public void setMySqlHintStraightJoin(boolean mySqlHintStraightJoin) { + this.mySqlHintStraightJoin = mySqlHintStraightJoin; + } + public First getFirst() { return first; } @@ -212,19 +210,19 @@ public void setHaving(Expression expression) { * * @return a list of {@link Expression}s */ - public List getGroupByColumnReferences() { - return groupByColumnReferences; + public GroupByElement getGroupBy() { + return this.groupBy; } - public void setGroupByColumnReferences(List list) { - groupByColumnReferences = list; + public void setGroupByElement(GroupByElement groupBy) { + this.groupBy = groupBy; } public void addGroupByColumnReference(Expression expr) { - if (groupByColumnReferences == null) { - groupByColumnReferences = new ArrayList(); + if (groupBy == null) { + groupBy = new GroupByElement(); } - groupByColumnReferences.add(expr); + groupBy.addGroupByExpression(expr); } public OracleHierarchicalExpression getOracleHierarchical() { @@ -285,6 +283,22 @@ public Wait getWait() { return wait; } + public String getForXmlPath() { + return forXmlPath; + } + + public void setForXmlPath(String forXmlPath) { + this.forXmlPath = forXmlPath; + } + + public KSQLWindow getKsqlWindow() { + return ksqlWindow; + } + + public void setKsqlWindow(KSQLWindow ksqlWindow) { + this.ksqlWindow = ksqlWindow; + } + @Override public String toString() { StringBuilder sql = new StringBuilder(); @@ -293,6 +307,10 @@ public String toString() { } sql.append("SELECT "); + if (this.mySqlHintStraightJoin) { + sql.append("STRAIGHT_JOIN "); + } + if (oracleHint != null) { sql.append(oracleHint).append(" "); } @@ -311,6 +329,12 @@ public String toString() { if (top != null) { sql.append(top).append(" "); } + if (sqlNoCacheFlag) { + sql.append("SQL_NO_CACHE").append(" "); + } + if (mySqlSqlCalcFoundRows) { + sql.append("SQL_CALC_FOUND_ROWS").append(" "); + } sql.append(getStringList(selectItems)); if (intoTables != null) { @@ -336,13 +360,19 @@ public String toString() { } } } + + if (ksqlWindow != null) { + sql.append(" WINDOW ").append(ksqlWindow.toString()); + } if (where != null) { sql.append(" WHERE ").append(where); } if (oracleHierarchical != null) { sql.append(oracleHierarchical.toString()); } - sql.append(getFormatedList(groupByColumnReferences, "GROUP BY")); + if (groupBy != null) { + sql.append(" ").append(groupBy.toString()); + } if (having != null) { sql.append(" HAVING ").append(having); } @@ -367,6 +397,13 @@ public String toString() { // Wait's toString will do the formatting for us sql.append(wait); } + + if (isNoWait()) { + sql.append(" NOWAIT"); + } + } + if (optimizeFor != null) { + sql.append(optimizeFor); } } else { //without from @@ -374,6 +411,9 @@ public String toString() { sql.append(" WHERE ").append(where); } } + if (forXmlPath != null) { + sql.append(" FOR XML PATH(").append(forXmlPath).append(")"); + } if (useBrackets) { sql.append(")"); } @@ -455,4 +495,28 @@ public static String getStringList(List list, boolean useComma, boolean useBr return ans.toString(); } + + public void setMySqlSqlCalcFoundRows(boolean mySqlCalcFoundRows) { + this.mySqlSqlCalcFoundRows = mySqlCalcFoundRows; + } + + public void setMySqlSqlNoCache(boolean sqlNoCacheFlagSet) { + this.sqlNoCacheFlag = sqlNoCacheFlagSet; + } + + public boolean getMySqlSqlCalcFoundRows() { + return this.mySqlSqlCalcFoundRows; + } + + public boolean getMySqlSqlNoCache() { + return this.sqlNoCacheFlag; + } + + public void setNoWait(boolean noWait) { + this.noWait = noWait; + } + + public boolean isNoWait() { + return this.noWait; + } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Select.java b/src/main/java/net/sf/jsqlparser/statement/select/Select.java index 2d6b385e..7a28e1cd 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/Select.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Select.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SelectBody.java b/src/main/java/net/sf/jsqlparser/statement/select/SelectBody.java index 40e320d5..bbe9c545 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SelectBody.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SelectBody.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SelectExpressionItem.java b/src/main/java/net/sf/jsqlparser/statement/select/SelectExpressionItem.java index 7250d197..d7be09c6 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SelectExpressionItem.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SelectExpressionItem.java @@ -1,33 +1,19 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.expression.Alias; import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; -/** - * An expression as in "SELECT expr1 AS EXPR" - */ -public class SelectExpressionItem implements SelectItem { +public class SelectExpressionItem extends ASTNodeAccessImpl implements SelectItem { private Expression expression; private Alias alias; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SelectItem.java b/src/main/java/net/sf/jsqlparser/statement/select/SelectItem.java index 8b186ed5..27b29097 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SelectItem.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SelectItem.java @@ -1,31 +1,17 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; -/** - * Anything between "SELECT" and "FROM"
- * (that is, any column or expression etc to be retrieved with the query) - */ -public interface SelectItem { +import net.sf.jsqlparser.parser.ASTNodeAccess; + +public interface SelectItem extends ASTNodeAccess { void accept(SelectItemVisitor selectItemVisitor); } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SelectItemVisitor.java b/src/main/java/net/sf/jsqlparser/statement/select/SelectItemVisitor.java index 955999ef..4ea463b3 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SelectItemVisitor.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SelectItemVisitor.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SelectItemVisitorAdapter.java b/src/main/java/net/sf/jsqlparser/statement/select/SelectItemVisitorAdapter.java index cb702aa8..443b00ca 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SelectItemVisitorAdapter.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SelectItemVisitorAdapter.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SelectVisitor.java b/src/main/java/net/sf/jsqlparser/statement/select/SelectVisitor.java index 2aff5e38..0fff1527 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SelectVisitor.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SelectVisitor.java @@ -1,26 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; +import net.sf.jsqlparser.statement.values.ValuesStatement; + public interface SelectVisitor { void visit(PlainSelect plainSelect); @@ -28,4 +18,6 @@ public interface SelectVisitor { void visit(SetOperationList setOpList); void visit(WithItem withItem); + + void visit(ValuesStatement aThis); } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SelectVisitorAdapter.java b/src/main/java/net/sf/jsqlparser/statement/select/SelectVisitorAdapter.java index 0d60728e..4ceef851 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SelectVisitorAdapter.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SelectVisitorAdapter.java @@ -1,26 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; +import net.sf.jsqlparser.statement.values.ValuesStatement; + public class SelectVisitorAdapter implements SelectVisitor { @Override @@ -37,4 +27,9 @@ public void visit(SetOperationList setOpList) { public void visit(WithItem withItem) { } + + @Override + public void visit(ValuesStatement aThis) { + + } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SetOperation.java b/src/main/java/net/sf/jsqlparser/statement/select/SetOperation.java index 918eb435..0600e595 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SetOperation.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SetOperation.java @@ -1,34 +1,18 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; import net.sf.jsqlparser.statement.select.SetOperationList.SetOperationType; -/** - * Single Set-Operation (name). Placeholder for one specific set operation, e.g. union, intersect. - * - * @author tw - */ -public abstract class SetOperation { +public abstract class SetOperation extends ASTNodeAccessImpl { private SetOperationType type; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SetOperationList.java b/src/main/java/net/sf/jsqlparser/statement/select/SetOperationList.java index 7bde7cd8..7a96b227 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SetOperationList.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SetOperationList.java @@ -1,34 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import java.util.List; -/** - * A database set operation. This operation consists of a list of plainSelects connected by set - * operations (UNION,INTERSECT,MINUS,EXCEPT). All these operations have the same priority. - * - * @author tw - */ public class SetOperationList implements SelectBody { private List selects; @@ -132,9 +114,6 @@ public String toString() { return buffer.toString(); } - /** - * list of set operations. - */ public enum SetOperationType { INTERSECT, diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Skip.java b/src/main/java/net/sf/jsqlparser/statement/select/Skip.java index d9237ee6..13a6b838 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/Skip.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Skip.java @@ -1,34 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.expression.JdbcParameter; -/** - * A skip clause in the form [SKIP row_count] - * - * Initial implementation was done for informix special syntax: - * http://www-01.ibm.com/support/knowledgecenter/SSGU8G_12.1.0/com.ibm.sqls.doc/ids_sqs_0156.htm - */ public class Skip { private Long rowCount; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SpecialSubSelect.java b/src/main/java/net/sf/jsqlparser/statement/select/SpecialSubSelect.java new file mode 100644 index 00000000..0d67959d --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/select/SpecialSubSelect.java @@ -0,0 +1,79 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import net.sf.jsqlparser.expression.Alias; + +/** + * Special sub selects of the form prefix ( subselect ) e.g. lateral ( select * from mytable ). + * @author tobens + */ +public abstract class SpecialSubSelect implements FromItem { + + private SubSelect subSelect; + private Alias alias; + private Pivot pivot; + private UnPivot unpivot; + private final String prefix; + + public SpecialSubSelect(String prefix) { + this.prefix = prefix; + } + + public String getPrefix() { + return prefix; + } + + public void setSubSelect(SubSelect subSelect) { + this.subSelect = subSelect; + } + + public SubSelect getSubSelect() { + return subSelect; + } + + @Override + public Alias getAlias() { + return alias; + } + + @Override + public void setAlias(Alias alias) { + this.alias = alias; + } + + @Override + public Pivot getPivot() { + return pivot; + } + + @Override + public void setPivot(Pivot pivot) { + this.pivot = pivot; + } + + @Override + public UnPivot getUnPivot() { + return this.unpivot; + } + + @Override + public void setUnPivot(UnPivot unpivot) { + this.unpivot = unpivot; + } + + @Override + public String toString() { + return prefix + subSelect.toString() + + ((alias != null) ? alias.toString() : "") + + ((pivot != null) ? " " + pivot : "") + + ((unpivot != null) ? " " + unpivot : ""); + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SubJoin.java b/src/main/java/net/sf/jsqlparser/statement/select/SubJoin.java index ee568f9d..24ceb2c1 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SubJoin.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SubJoin.java @@ -1,37 +1,24 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; +import java.util.List; import net.sf.jsqlparser.expression.Alias; -/** - * A table created by "(tab1 join tab2)". - */ public class SubJoin implements FromItem { private FromItem left; - private Join join; private Alias alias; private Pivot pivot; + private UnPivot unpivot; + private List joinList; @Override public void accept(FromItemVisitor fromItemVisitor) { @@ -46,12 +33,12 @@ public void setLeft(FromItem l) { left = l; } - public Join getJoin() { - return join; + public List getJoinList() { + return joinList; } - public void setJoin(Join j) { - join = j; + public void setJoinList(List joinList) { + this.joinList = joinList; } @Override @@ -64,6 +51,16 @@ public void setPivot(Pivot pivot) { this.pivot = pivot; } + @Override + public UnPivot getUnPivot() { + return this.unpivot; + } + + @Override + public void setUnPivot(UnPivot unpivot) { + this.unpivot = unpivot; + } + @Override public Alias getAlias() { return alias; @@ -76,8 +73,18 @@ public void setAlias(Alias alias) { @Override public String toString() { - return "(" + left + " " + join + ")" - + ((pivot != null) ? " " + pivot : "") - + ((alias != null) ? alias.toString() : ""); + StringBuilder sb = new StringBuilder(); + sb.append("(").append(left); + for (Join j : joinList) { + if (j.isSimple()) { + sb.append(", ").append(j); + } else { + sb.append(" ").append(j); + } + } + + sb.append(")").append((alias != null) ? (" " + alias.toString()) : "").append((pivot != null) ? " " + pivot : "") + .append((unpivot != null) ? " " + unpivot : ""); + return sb.toString(); } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/SubSelect.java b/src/main/java/net/sf/jsqlparser/statement/select/SubSelect.java index 741fc9d0..2078abfe 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/SubSelect.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/SubSelect.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; @@ -28,11 +16,9 @@ import net.sf.jsqlparser.expression.ExpressionVisitor; import net.sf.jsqlparser.expression.operators.relational.ItemsList; import net.sf.jsqlparser.expression.operators.relational.ItemsListVisitor; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; -/** - * A subselect followed by an optional alias. - */ -public class SubSelect implements FromItem, Expression, ItemsList { +public class SubSelect extends ASTNodeAccessImpl implements FromItem, Expression, ItemsList { private SelectBody selectBody; private Alias alias; @@ -40,6 +26,7 @@ public class SubSelect implements FromItem, Expression, ItemsList { private List withItemsList; private Pivot pivot; + private UnPivot unpivot; @Override public void accept(FromItemVisitor fromItemVisitor) { @@ -79,6 +66,16 @@ public void setPivot(Pivot pivot) { this.pivot = pivot; } + @Override + public UnPivot getUnPivot() { + return this.unpivot; + } + + @Override + public void setUnPivot(UnPivot unpivot) { + this.unpivot = unpivot; + } + public boolean isUseBrackets() { return useBrackets; } @@ -122,11 +119,14 @@ public String toString() { retval.append(")"); } + if (alias != null) { + retval.append(alias.toString()); + } if (pivot != null) { retval.append(" ").append(pivot); } - if (alias != null) { - retval.append(alias.toString()); + if (unpivot != null) { + retval.append(" ").append(unpivot); } return retval.toString(); diff --git a/src/main/java/net/sf/jsqlparser/statement/select/TableFunction.java b/src/main/java/net/sf/jsqlparser/statement/select/TableFunction.java index 3bb89b7e..2b4085c8 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/TableFunction.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/TableFunction.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; @@ -36,4 +24,13 @@ public Pivot getPivot() { @Override public void setPivot(Pivot pivot) { } + + @Override + public UnPivot getUnPivot() { + return null; + } + + @Override + public void setUnPivot(UnPivot unpivot) { + } } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Top.java b/src/main/java/net/sf/jsqlparser/statement/select/Top.java index bb283d57..f2f3ac52 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/Top.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Top.java @@ -1,31 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.expression.Expression; -/** - * A top clause in the form [TOP (row_count) or TOP row_count] - */ public class Top { private boolean hasParenthesis = false; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/UnPivot.java b/src/main/java/net/sf/jsqlparser/statement/select/UnPivot.java new file mode 100644 index 00000000..5af759d5 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/select/UnPivot.java @@ -0,0 +1,74 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import net.sf.jsqlparser.schema.Column; + +import java.util.List; + +public class UnPivot { + + private boolean includeNulls = false; + private boolean includeNullsSpecified = false; + private Column unpivotClause; + private List unpivotForClause; + private List unpivotInClause; + + public void accept(PivotVisitor pivotVisitor) { + pivotVisitor.visit(this); + } + + public boolean getIncludeNulls() { + return includeNulls; + } + + public void setIncludeNulls(boolean includeNulls) { + this.includeNullsSpecified = true; + this.includeNulls = includeNulls; + } + + public boolean getIncludeNullsSpecified() { + return includeNullsSpecified; + } + + public Column getUnPivotClause() { + return unpivotClause; + } + + public void setUnPivotClause(Column unpivotClause) { + this.unpivotClause = unpivotClause; + } + + public List getUnPivotForClause() { + return unpivotForClause; + } + + public void setUnPivotForClause(List forColumns) { + this.unpivotForClause = forColumns; + } + + public List getUnPivotInClause() { + return unpivotInClause; + } + + public void setUnPivotInClause(List unpivotInClause) { + this.unpivotInClause = unpivotInClause; + } + + @Override + public String toString() { + return "UNPIVOT" + + (includeNullsSpecified && includeNulls ? " INCLUDE NULLS" : "") + + (includeNullsSpecified && !includeNulls ? " EXCLUDE NULLS" : "") + + " (" + unpivotClause + + " FOR " + PlainSelect.getStringList(unpivotForClause, true, unpivotForClause != null && unpivotForClause.size() > 1) + + " IN " + PlainSelect.getStringList(unpivotInClause, true, true) + ")"; + } +} diff --git a/src/main/java/net/sf/jsqlparser/statement/select/UnionOp.java b/src/main/java/net/sf/jsqlparser/statement/select/UnionOp.java index 43eb4946..a9dd91e8 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/UnionOp.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/UnionOp.java @@ -1,32 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.statement.select.SetOperationList.SetOperationType; -/** - * - * @author tw - */ public class UnionOp extends SetOperation { private boolean distinct; diff --git a/src/main/java/net/sf/jsqlparser/statement/select/ValuesList.java b/src/main/java/net/sf/jsqlparser/statement/select/ValuesList.java index 26f9a919..c8b0a777 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/ValuesList.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/ValuesList.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; @@ -28,12 +16,6 @@ import java.util.List; import net.sf.jsqlparser.expression.Alias; -/** - * This is a container for a values item within a select statement. It holds some syntactical stuff - * that differs from values within an insert statement. - * - * @author toben - */ public class ValuesList implements FromItem { private Alias alias; @@ -72,6 +54,15 @@ public Pivot getPivot() { public void setPivot(Pivot pivot) { } + @Override + public UnPivot getUnPivot() { + return null; + } + + @Override + public void setUnPivot(UnPivot unpivot) { + } + public MultiExpressionList getMultiExpressionList() { return multiExpressionList; } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/Wait.java b/src/main/java/net/sf/jsqlparser/statement/select/Wait.java index 7de26ba2..984ee318 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/Wait.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/Wait.java @@ -1,38 +1,22 @@ -/* - * #%L JSQLParser library %% Copyright (C) 2004 - 2017 JSQLParser %% This program is free software: - * you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 2.1 of the License, or (at your - * option) any later version. This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Lesser Public License for more details. You should have - * received a copy of the GNU General Lesser Public License along with this program. If not, see - * . #L% +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.statement.select; -/** - * A timeout applied to SELECT to specify how long to wait for the row on the lock to be released. - * - * @author janmonterrubio - */ public class Wait { private long timeout; - /** - * Returns the number of seconds specified for the WAIT command - * - * @return the number of seconds specified for the WAIT command - */ public long getTimeout() { return timeout; } - /** - * Sets the number of seconds to WAIT for this {@link Wait} - * - * @param timeout the number of seconds to WAIT for this {@link Wait} - */ public void setTimeout(long timeout) { this.timeout = timeout; } diff --git a/src/main/java/net/sf/jsqlparser/statement/select/WithItem.java b/src/main/java/net/sf/jsqlparser/statement/select/WithItem.java index 6a8b16d3..6bba0498 100644 --- a/src/main/java/net/sf/jsqlparser/statement/select/WithItem.java +++ b/src/main/java/net/sf/jsqlparser/statement/select/WithItem.java @@ -1,31 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.select; import java.util.List; -/** - * One of the parts of a "WITH" clause of a "SELECT" statement - */ public class WithItem implements SelectBody { private String name; @@ -33,11 +18,6 @@ public class WithItem implements SelectBody { private SelectBody selectBody; private boolean recursive; - /** - * The name of this WITH item (for example, "myWITH" in "WITH myWITH AS (SELECT A,B,C))" - * - * @return the name of this WITH - */ public String getName() { return name; } @@ -54,11 +34,6 @@ public void setRecursive(boolean recursive) { this.recursive = recursive; } - /** - * The {@link SelectBody} of this WITH item is the part after the "AS" keyword - * - * @return {@link SelectBody} of this WITH item - */ public SelectBody getSelectBody() { return selectBody; } diff --git a/src/main/java/net/sf/jsqlparser/statement/truncate/Truncate.java b/src/main/java/net/sf/jsqlparser/statement/truncate/Truncate.java index d0729928..94a7c95a 100644 --- a/src/main/java/net/sf/jsqlparser/statement/truncate/Truncate.java +++ b/src/main/java/net/sf/jsqlparser/statement/truncate/Truncate.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.truncate; @@ -25,12 +13,10 @@ import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.StatementVisitor; -/** - * A TRUNCATE TABLE statement - */ public class Truncate implements Statement { private Table table; + boolean cascade; // to support TRUNCATE TABLE ... CASCADE @Override public void accept(StatementVisitor statementVisitor) { @@ -45,8 +31,19 @@ public void setTable(Table table) { this.table = table; } + public boolean getCascade() { + return cascade; + } + + public void setCascade(boolean c) { + cascade = c; + } + @Override public String toString() { + if (cascade) { + return "TRUNCATE TABLE " + table + " CASCADE"; + } return "TRUNCATE TABLE " + table; } } diff --git a/src/main/java/net/sf/jsqlparser/statement/update/Update.java b/src/main/java/net/sf/jsqlparser/statement/update/Update.java index ab9e22c1..592db5d1 100644 --- a/src/main/java/net/sf/jsqlparser/statement/update/Update.java +++ b/src/main/java/net/sf/jsqlparser/statement/update/Update.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.update; @@ -36,17 +24,15 @@ import net.sf.jsqlparser.statement.select.Limit; import net.sf.jsqlparser.statement.select.SelectExpressionItem; -/** - * The update statement. - */ public class Update implements Statement { - private List
tables; + private Table table; private Expression where; private List columns; private List expressions; private FromItem fromItem; private List joins; + private List startJoins; private Select select; private boolean useColumnsBrackets = true; private boolean useSelect = false; @@ -60,37 +46,26 @@ public void accept(StatementVisitor statementVisitor) { statementVisitor.visit(this); } - public List
getTables() { - return tables; + public Table getTable() { + return table; } public Expression getWhere() { return where; } - public void setTables(List
list) { - tables = list; + public void setTable(Table table) { + this.table = table; } public void setWhere(Expression expression) { where = expression; } - /** - * The {@link net.sf.jsqlparser.schema.Column}s in this update (as col1 and col2 in UPDATE - * col1='a', col2='b') - * - * @return a list of {@link net.sf.jsqlparser.schema.Column}s - */ public List getColumns() { return columns; } - /** - * The {@link Expression}s in this update (as 'a' and 'b' in UPDATE col1='a', col2='b') - * - * @return a list of {@link Expression}s - */ public List getExpressions() { return expressions; } @@ -119,6 +94,14 @@ public void setJoins(List joins) { this.joins = joins; } + public List getStartJoins() { + return startJoins; + } + + public void setStartJoins(List startJoins) { + this.startJoins = startJoins; + } + public Select getSelect() { return select; } @@ -178,7 +161,17 @@ public void setReturningExpressionList(List returningExpre @Override public String toString() { StringBuilder b = new StringBuilder("UPDATE "); - b.append(PlainSelect.getStringList(getTables(), true, false)).append(" SET "); + b.append(table); + if (startJoins != null) { + for (Join join : startJoins) { + if (join.isSimple()) { + b.append(", ").append(join); + } else { + b.append(" ").append(join); + } + } + } + b.append(" SET "); if (!useSelect) { for (int i = 0; i < getColumns().size(); i++) { diff --git a/src/main/java/net/sf/jsqlparser/statement/upsert/Upsert.java b/src/main/java/net/sf/jsqlparser/statement/upsert/Upsert.java index a5d9a86d..f8f7d2e0 100644 --- a/src/main/java/net/sf/jsqlparser/statement/upsert/Upsert.java +++ b/src/main/java/net/sf/jsqlparser/statement/upsert/Upsert.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.statement.upsert; @@ -32,20 +20,6 @@ import net.sf.jsqlparser.statement.select.PlainSelect; import net.sf.jsqlparser.statement.select.Select; -/** - * The UPSERT INTO statement. This statement is basically the combination of - * "insert" and "update". That means it will operate inserts if not present - * and updates otherwise the value in the table. Note the values modified - * will be either a list of values or a select statement. - * - * - * Here is the documentation of the grammar of this operation: - * http://phoenix.apache.org/language/#upsert_values - * http://phoenix.apache.org/language/#upsert_select - * - * @author messfish - * - */ public class Upsert implements Statement { private Table table; diff --git a/src/main/java/net/sf/jsqlparser/statement/values/ValuesStatement.java b/src/main/java/net/sf/jsqlparser/statement/values/ValuesStatement.java new file mode 100644 index 00000000..4d34792a --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/statement/values/ValuesStatement.java @@ -0,0 +1,53 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.values; + +import java.util.List; +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.statement.Statement; +import net.sf.jsqlparser.statement.StatementVisitor; +import net.sf.jsqlparser.statement.select.PlainSelect; +import net.sf.jsqlparser.statement.select.SelectBody; +import net.sf.jsqlparser.statement.select.SelectVisitor; + +public class ValuesStatement implements Statement, SelectBody { + + private List expressions; + + public ValuesStatement(List expressions) { + this.expressions = expressions; + } + + @Override + public void accept(StatementVisitor statementVisitor) { + statementVisitor.visit(this); + } + + public List getExpressions() { + return expressions; + } + + public void setExpressions(List list) { + expressions = list; + } + + @Override + public String toString() { + StringBuilder sql = new StringBuilder(); + sql.append("VALUES "); + sql.append(PlainSelect.getStringList(expressions, true, true)); + return sql.toString(); + } + + @Override + public void accept(SelectVisitor selectVisitor) { + selectVisitor.visit(this); + } +} diff --git a/src/main/java/net/sf/jsqlparser/util/AddAliasesVisitor.java b/src/main/java/net/sf/jsqlparser/util/AddAliasesVisitor.java index 370a363d..e5209445 100644 --- a/src/main/java/net/sf/jsqlparser/util/AddAliasesVisitor.java +++ b/src/main/java/net/sf/jsqlparser/util/AddAliasesVisitor.java @@ -1,30 +1,18 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util; +import java.util.*; import net.sf.jsqlparser.expression.*; import net.sf.jsqlparser.statement.select.*; - -import java.util.*; +import net.sf.jsqlparser.statement.values.ValuesStatement; /** * Add aliases to every column and expression selected by a select - statement. Existing aliases are @@ -88,21 +76,11 @@ public void visit(SelectExpressionItem selectExpressionItem) { } } - /** - * Calculate next alias name to use. - * - * @return - */ protected String getNextAlias() { counter++; return prefix + counter; } - /** - * Set alias prefix. - * - * @param prefix - */ public void setPrefix(String prefix) { this.prefix = prefix; } @@ -116,4 +94,9 @@ public void visit(WithItem withItem) { public void visit(AllColumns allColumns) { throw new UnsupportedOperationException(NOT_SUPPORTED_YET); //To change body of generated methods, choose Tools | Templates. } + + @Override + public void visit(ValuesStatement aThis) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } } diff --git a/src/main/java/net/sf/jsqlparser/util/ConnectExpressionsVisitor.java b/src/main/java/net/sf/jsqlparser/util/ConnectExpressionsVisitor.java index a581f239..1dbc9a23 100644 --- a/src/main/java/net/sf/jsqlparser/util/ConnectExpressionsVisitor.java +++ b/src/main/java/net/sf/jsqlparser/util/ConnectExpressionsVisitor.java @@ -1,30 +1,18 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util; +import java.util.*; import net.sf.jsqlparser.expression.*; import net.sf.jsqlparser.statement.select.*; - -import java.util.*; +import net.sf.jsqlparser.statement.values.ValuesStatement; /** * Connect all selected expressions with a binary expression. Out of select a,b from table one gets @@ -45,11 +33,6 @@ public ConnectExpressionsVisitor(String alias) { this.alias = alias; } - /** - * Create instances of this binary expression that connects all selected expressions. - * - * @return - */ protected abstract BinaryExpression createBinaryExpression(); @Override @@ -104,4 +87,10 @@ public void visit(AllColumns allColumns) { public void visit(SelectExpressionItem selectExpressionItem) { itemsExpr.add(selectExpressionItem); } + + @Override + public void visit(ValuesStatement aThis) { + throw new UnsupportedOperationException("Not supported yet."); + } + } diff --git a/src/main/java/net/sf/jsqlparser/util/SelectUtils.java b/src/main/java/net/sf/jsqlparser/util/SelectUtils.java index b617b298..744cd1b3 100644 --- a/src/main/java/net/sf/jsqlparser/util/SelectUtils.java +++ b/src/main/java/net/sf/jsqlparser/util/SelectUtils.java @@ -1,29 +1,16 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util; import java.util.ArrayList; import java.util.List; - import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.parser.CCJSqlParserUtil; @@ -37,12 +24,8 @@ import net.sf.jsqlparser.statement.select.SelectVisitor; import net.sf.jsqlparser.statement.select.SetOperationList; import net.sf.jsqlparser.statement.select.WithItem; +import net.sf.jsqlparser.statement.values.ValuesStatement; -/** - * Utility function for select statements. - * - * @author toben - */ public final class SelectUtils { private static final String NOT_SUPPORTED_YET = "Not supported yet."; @@ -50,13 +33,6 @@ public final class SelectUtils { private SelectUtils() { } - /** - * Builds select expr1, expr2 from table. - * - * @param table - * @param expr - * @return - */ public static Select buildSelectFromTableAndExpressions(Table table, Expression... expr) { SelectItem[] list = new SelectItem[expr.length]; for (int i = 0; i < expr.length; i++) { @@ -65,14 +41,6 @@ public static Select buildSelectFromTableAndExpressions(Table table, Expression. return buildSelectFromTableAndSelectItems(table, list); } - /** - * Builds select expr1, expr2 from table. - * - * @param table - * @param expr - * @return - * @throws net.sf.jsqlparser.JSQLParserException - */ public static Select buildSelectFromTableAndExpressions(Table table, String... expr) throws JSQLParserException { SelectItem[] list = new SelectItem[expr.length]; for (int i = 0; i < expr.length; i++) { @@ -123,6 +91,11 @@ public void visit(SetOperationList setOpList) { public void visit(WithItem withItem) { throw new UnsupportedOperationException(NOT_SUPPORTED_YET); } + + @Override + public void visit(ValuesStatement aThis) { + throw new UnsupportedOperationException(NOT_SUPPORTED_YET); + } }); } @@ -175,6 +148,11 @@ public void visit(SetOperationList setOpList) { public void visit(WithItem withItem) { throw new UnsupportedOperationException(NOT_SUPPORTED_YET); } + + @Override + public void visit(ValuesStatement aThis) { + throw new UnsupportedOperationException(NOT_SUPPORTED_YET); + } }); } } diff --git a/src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java b/src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java index a8b97247..05e79ab9 100644 --- a/src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java +++ b/src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java @@ -1,35 +1,24 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util; import java.util.ArrayList; import java.util.List; - import net.sf.jsqlparser.expression.AllComparisonExpression; import net.sf.jsqlparser.expression.AnalyticExpression; import net.sf.jsqlparser.expression.AnyComparisonExpression; +import net.sf.jsqlparser.expression.ArrayExpression; import net.sf.jsqlparser.expression.BinaryExpression; import net.sf.jsqlparser.expression.CaseExpression; import net.sf.jsqlparser.expression.CastExpression; +import net.sf.jsqlparser.expression.CollateExpression; import net.sf.jsqlparser.expression.DateTimeLiteralExpression; import net.sf.jsqlparser.expression.DateValue; import net.sf.jsqlparser.expression.DoubleValue; @@ -45,6 +34,7 @@ import net.sf.jsqlparser.expression.KeepExpression; import net.sf.jsqlparser.expression.LongValue; import net.sf.jsqlparser.expression.MySQLGroupConcat; +import net.sf.jsqlparser.expression.NextValExpression; import net.sf.jsqlparser.expression.NotExpression; import net.sf.jsqlparser.expression.NullValue; import net.sf.jsqlparser.expression.NumericBind; @@ -58,45 +48,28 @@ import net.sf.jsqlparser.expression.TimeValue; import net.sf.jsqlparser.expression.TimestampValue; import net.sf.jsqlparser.expression.UserVariable; +import net.sf.jsqlparser.expression.ValueListExpression; import net.sf.jsqlparser.expression.WhenClause; -import net.sf.jsqlparser.expression.WithinGroupExpression; -import net.sf.jsqlparser.expression.operators.arithmetic.Addition; -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd; -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr; -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor; -import net.sf.jsqlparser.expression.operators.arithmetic.Concat; -import net.sf.jsqlparser.expression.operators.arithmetic.Division; -import net.sf.jsqlparser.expression.operators.arithmetic.Modulo; -import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication; -import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction; +import net.sf.jsqlparser.expression.operators.arithmetic.*; import net.sf.jsqlparser.expression.operators.conditional.AndExpression; import net.sf.jsqlparser.expression.operators.conditional.OrExpression; -import net.sf.jsqlparser.expression.operators.relational.Between; -import net.sf.jsqlparser.expression.operators.relational.EqualsTo; -import net.sf.jsqlparser.expression.operators.relational.ExistsExpression; -import net.sf.jsqlparser.expression.operators.relational.ExpressionList; -import net.sf.jsqlparser.expression.operators.relational.GreaterThan; -import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals; -import net.sf.jsqlparser.expression.operators.relational.InExpression; -import net.sf.jsqlparser.expression.operators.relational.IsNullExpression; -import net.sf.jsqlparser.expression.operators.relational.ItemsListVisitor; -import net.sf.jsqlparser.expression.operators.relational.JsonOperator; -import net.sf.jsqlparser.expression.operators.relational.LikeExpression; -import net.sf.jsqlparser.expression.operators.relational.Matches; -import net.sf.jsqlparser.expression.operators.relational.MinorThan; -import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals; -import net.sf.jsqlparser.expression.operators.relational.MultiExpressionList; -import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo; -import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator; -import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator; +import net.sf.jsqlparser.expression.operators.relational.*; import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.schema.Table; +import net.sf.jsqlparser.statement.Block; import net.sf.jsqlparser.statement.Commit; +import net.sf.jsqlparser.statement.DeclareStatement; +import net.sf.jsqlparser.statement.DescribeStatement; +import net.sf.jsqlparser.statement.ExplainStatement; import net.sf.jsqlparser.statement.SetStatement; +import net.sf.jsqlparser.statement.ShowColumnsStatement; +import net.sf.jsqlparser.statement.ShowStatement; import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.StatementVisitor; import net.sf.jsqlparser.statement.Statements; +import net.sf.jsqlparser.statement.UseStatement; import net.sf.jsqlparser.statement.alter.Alter; +import net.sf.jsqlparser.statement.comment.Comment; import net.sf.jsqlparser.statement.create.index.CreateIndex; import net.sf.jsqlparser.statement.create.table.CreateTable; import net.sf.jsqlparser.statement.create.view.AlterView; @@ -112,6 +85,7 @@ import net.sf.jsqlparser.statement.select.FromItemVisitor; import net.sf.jsqlparser.statement.select.Join; import net.sf.jsqlparser.statement.select.LateralSubSelect; +import net.sf.jsqlparser.statement.select.ParenthesisFromItem; import net.sf.jsqlparser.statement.select.PlainSelect; import net.sf.jsqlparser.statement.select.Select; import net.sf.jsqlparser.statement.select.SelectBody; @@ -128,28 +102,23 @@ import net.sf.jsqlparser.statement.truncate.Truncate; import net.sf.jsqlparser.statement.update.Update; import net.sf.jsqlparser.statement.upsert.Upsert; +import net.sf.jsqlparser.statement.values.ValuesStatement; /** * Find all used tables within an select statement. + * + * Override extractTableName method to modify the extracted table names (e.g. without schema). */ public class TablesNamesFinder implements SelectVisitor, FromItemVisitor, ExpressionVisitor, ItemsListVisitor, SelectItemVisitor, StatementVisitor { private static final String NOT_SUPPORTED_YET = "Not supported yet."; private List tables; - /** - * There are special names, that are not table names but are parsed as tables. These names are - * collected here and are not included in the tables - names anymore. - */ + private boolean allowColumnProcessing = false; + private List otherItemNames; - /** - * Main entry for this Tool class. A list of found tables is returned. - * - * @param delete - * @return - */ public List getTableList(Statement statement) { - init(); + init(false); statement.accept(this); return tables; } @@ -166,12 +135,9 @@ public void visit(Select select) { /** * Main entry for this Tool class. A list of found tables is returned. - * - * @param update - * @return */ public List getTableList(Expression expr) { - init(); + init(true); expr.accept(this); return tables; } @@ -202,14 +168,29 @@ public void visit(PlainSelect plainSelect) { if (plainSelect.getWhere() != null) { plainSelect.getWhere().accept(this); } + + if (plainSelect.getHaving() != null) { + plainSelect.getHaving().accept(this); + } + if (plainSelect.getOracleHierarchical() != null) { plainSelect.getOracleHierarchical().accept(this); } } + /** + * Override to adapt the tableName generation (e.g. with / without schema). + * + * @param table + * @return + */ + protected String extractTableName(Table table) { + return table.getFullyQualifiedName(); + } + @Override public void visit(Table tableName) { - String tableWholeName = tableName.getFullyQualifiedName(); + String tableWholeName = extractTableName(tableName); if (!otherItemNames.contains(tableWholeName.toLowerCase()) && !tables.contains(tableWholeName)) { tables.add(tableWholeName); @@ -245,6 +226,9 @@ public void visit(Between between) { @Override public void visit(Column tableColumn) { + if (allowColumnProcessing && tableColumn.getTable() != null && tableColumn.getTable().getName() != null) { + visit(tableColumn.getTable()); + } } @Override @@ -252,6 +236,11 @@ public void visit(Division division) { visitBinaryExpression(division); } + @Override + public void visit(IntegerDivision division) { + visitBinaryExpression(division); + } + @Override public void visit(DoubleValue doubleValue) { } @@ -289,6 +278,10 @@ public void visit(InExpression inExpression) { inExpression.getRightItemsList().accept(this); } + @Override + public void visit(FullTextSearch fullTextSearch) { + } + @Override public void visit(SignedExpression signedExpression) { signedExpression.getExpression().accept(this); @@ -298,6 +291,10 @@ public void visit(SignedExpression signedExpression) { public void visit(IsNullExpression isNullExpression) { } + @Override + public void visit(IsBooleanExpression isBooleanExpression) { + } + @Override public void visit(JdbcParameter jdbcParameter) { } @@ -364,6 +361,16 @@ public void visit(NotExpression notExpr) { notExpr.getExpression().accept(this); } + @Override + public void visit(BitwiseRightShift expr) { + visitBinaryExpression(expr); + } + + @Override + public void visit(BitwiseLeftShift expr) { + visitBinaryExpression(expr); + } + public void visitBinaryExpression(BinaryExpression binaryExpression) { binaryExpression.getLeftExpression().accept(this); binaryExpression.getRightExpression().accept(this); @@ -376,6 +383,13 @@ public void visit(ExpressionList expressionList) { } } + @Override + public void visit(NamedExpressionList namedExpressionList) { + for (Expression expression : namedExpressionList.getExpressions()) { + expression.accept(this); + } + } + @Override public void visit(DateValue dateValue) { } @@ -395,6 +409,17 @@ public void visit(TimeValue timeValue) { */ @Override public void visit(CaseExpression caseExpression) { + if (caseExpression.getSwitchExpression() != null) { + caseExpression.getSwitchExpression().accept(this); + } + if (caseExpression.getWhenClauses() != null) { + for (WhenClause when : caseExpression.getWhenClauses()) { + when.accept(this); + } + } + if (caseExpression.getElseExpression() != null) { + caseExpression.getElseExpression().accept(this); + } } /* @@ -404,6 +429,12 @@ public void visit(CaseExpression caseExpression) { */ @Override public void visit(WhenClause whenClause) { + if (whenClause.getWhenExpression() != null) { + whenClause.getWhenExpression().accept(this); + } + if (whenClause.getThenExpression() != null) { + whenClause.getThenExpression().accept(this); + } } @Override @@ -419,7 +450,9 @@ public void visit(AnyComparisonExpression anyComparisonExpression) { @Override public void visit(SubJoin subjoin) { subjoin.getLeft().accept(this); - subjoin.getJoin().getRightItem().accept(this); + for (Join join : subjoin.getJoinList()) { + join.getRightItem().accept(this); + } } @Override @@ -476,7 +509,7 @@ public void visit(ExtractExpression eexpr) { public void visit(LateralSubSelect lateralSubSelect) { lateralSubSelect.getSubSelect().getSelectBody().accept(this); } - + @Override public void visit(MultiExpressionList multiExprList) { for (ExpressionList exprList : multiExprList.getExprList()) { @@ -489,11 +522,17 @@ public void visit(ValuesList valuesList) { } /** - * Initializes table names collector. + * Initializes table names collector. Important is the usage of Column instances to find table + * names. This is only allowed for expression parsing, where a better place for tablenames could + * not be there. For complete statements only from items are used to avoid some alias as + * tablenames. + * + * @param allowColumnProcessing */ - protected void init() { + protected void init(boolean allowColumnProcessing) { otherItemNames = new ArrayList(); tables = new ArrayList(); + this.allowColumnProcessing = allowColumnProcessing; } @Override @@ -546,10 +585,6 @@ public void visit(SelectExpressionItem item) { item.getExpression().accept(this); } - @Override - public void visit(WithinGroupExpression wgexpr) { - } - @Override public void visit(UserVariable var) { } @@ -567,9 +602,21 @@ public void visit(KeepExpression aexpr) { public void visit(MySQLGroupConcat groupConcat) { } + @Override + public void visit(ValueListExpression valueList) { + valueList.getExpressionList().accept(this); + } + @Override public void visit(Delete delete) { - tables.add(delete.getTable().getName()); + visit(delete.getTable()); + + if (delete.getJoins() != null) { + for (Join join : delete.getJoins()) { + join.getRightItem().accept(this); + } + } + if (delete.getWhere() != null) { delete.getWhere().accept(this); } @@ -577,8 +624,11 @@ public void visit(Delete delete) { @Override public void visit(Update update) { - for (Table table : update.getTables()) { - tables.add(table.getName()); + visit(update.getTable()); + if (update.getStartJoins() != null) { + for (Join join : update.getStartJoins()) { + join.getRightItem().accept(this); + } } if (update.getExpressions() != null) { for (Expression expression : update.getExpressions()) { @@ -603,7 +653,7 @@ public void visit(Update update) { @Override public void visit(Insert insert) { - tables.add(insert.getTable().getName()); + visit(insert.getTable()); if (insert.getItemsList() != null) { insert.getItemsList().accept(this); } @@ -614,7 +664,7 @@ public void visit(Insert insert) { @Override public void visit(Replace replace) { - tables.add(replace.getTable().getName()); + visit(replace.getTable()); if (replace.getExpressions() != null) { for (Expression expression : replace.getExpressions()) { expression.accept(this); @@ -632,7 +682,7 @@ public void visit(Drop drop) { @Override public void visit(Truncate truncate) { - throw new UnsupportedOperationException(NOT_SUPPORTED_YET); + visit(truncate.getTable()); } @Override @@ -642,7 +692,7 @@ public void visit(CreateIndex createIndex) { @Override public void visit(CreateTable create) { - tables.add(create.getTable().getFullyQualifiedName()); + visit(create.getTable()); if (create.getSelect() != null) { create.getSelect().accept(this); } @@ -673,6 +723,11 @@ public void visit(SetStatement set) { throw new UnsupportedOperationException(NOT_SUPPORTED_YET); } + @Override + public void visit(ShowColumnsStatement set) { + throw new UnsupportedOperationException(NOT_SUPPORTED_YET); + } + @Override public void visit(RowConstructor rowConstructor) { for (Expression expr : rowConstructor.getExprList().getExpressions()) { @@ -687,7 +742,7 @@ public void visit(HexValue hexValue) { @Override public void visit(Merge merge) { - tables.add(merge.getTable().getName()); + visit(merge.getTable()); if (merge.getUsingTable() != null) { merge.getUsingTable().accept(this); } else if (merge.getUsingSelect() != null) { @@ -716,15 +771,15 @@ public void visit(TimeKeyExpression timeKeyExpression) { public void visit(DateTimeLiteralExpression literal) { } - + @Override public void visit(Commit commit) { - + } @Override public void visit(Upsert upsert) { - tables.add(upsert.getTable().getName()); + visit(upsert.getTable()); if (upsert.getItemsList() != null) { upsert.getItemsList().accept(this); } @@ -732,4 +787,78 @@ public void visit(Upsert upsert) { visit(upsert.getSelect()); } } + + @Override + public void visit(UseStatement use) { + } + + @Override + public void visit(ParenthesisFromItem parenthesis) { + parenthesis.getFromItem().accept(this); + } + + @Override + public void visit(Block block) { + if (block.getStatements() != null) { + visit(block.getStatements()); + } + } + + @Override + public void visit(Comment comment) { + if (comment.getTable() != null) { + visit(comment.getTable()); + } + if (comment.getColumn() != null) { + Table table = comment.getColumn().getTable(); + if (table != null) { + visit(table); + } + } + } + + @Override + public void visit(ValuesStatement values) { + for (Expression expr : values.getExpressions()) { + expr.accept(this); + } + } + + @Override + public void visit(DescribeStatement describe) { + describe.getTable().accept(this); + } + + @Override + public void visit(ExplainStatement explain) { + explain.getStatement().accept(this); + } + + @Override + public void visit(NextValExpression nextVal) { + } + + @Override + public void visit(CollateExpression col) { + col.getLeftExpression().accept(this); + } + + @Override + public void visit(ShowStatement aThis) { + } + + @Override + public void visit(SimilarToExpression expr) { + visitBinaryExpression(expr); + } + + @Override + public void visit(DeclareStatement aThis) { + } + + @Override + public void visit(ArrayExpression array) { + array.getObjExpression().accept(this); + array.getIndexExpression().accept(this); + } } diff --git a/src/main/java/net/sf/jsqlparser/util/cnfexpression/CNFConverter.java b/src/main/java/net/sf/jsqlparser/util/cnfexpression/CNFConverter.java index c327aa5c..4411807a 100644 --- a/src/main/java/net/sf/jsqlparser/util/cnfexpression/CNFConverter.java +++ b/src/main/java/net/sf/jsqlparser/util/cnfexpression/CNFConverter.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.cnfexpression; @@ -26,196 +14,193 @@ import java.util.List; import java.util.Queue; import java.util.Stack; - import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.NotExpression; -import net.sf.jsqlparser.expression.operators.relational.LikeExpression; -import net.sf.jsqlparser.expression.BinaryExpression; /** * This class handles the conversion from a normal expression tree into - * the CNF form. - * - * Here is the definition of CNF form: + * the CNF form. + * + * Here is the definition of CNF form: * https://en.wikipedia.org/wiki/Conjunctive_normal_form - * + * * Basically it will follow these steps: - * + * * To help understanding, I will generate an example: * Here is the original tree: - * OR - * / \ - * OR NOT - * / \ | - * NOT H AND - * | / \ - * NOT G OR - * | / \ - * F H NOT - * | - * OR - * / \ - * AND L - * / \ - * ( ) ( ) - * | | - * J K - * - * 1. rebuild the tree by replacing the "and" and "or" operators - * (which are binary) into their counterparts node that could hold - * multiple elements. Also, leave out the parenthesis node between the + * OR + * / \ + * OR NOT + * / \ | + * NOT H AND + * | / \ + * NOT G OR + * | / \ + * F H NOT + * | + * OR + * / \ + * AND L + * / \ + * ( ) ( ) + * | | + * J K + * + * 1. rebuild the tree by replacing the "and" and "or" operators + * (which are binary) into their counterparts node that could hold + * multiple elements. Also, leave out the parenthesis node between the * conditional operators to make the tree uniform. - * + * * After the transform, the result should be like this: - * OR(M) - * / \ - * OR(M) NOT - * / \ | - * NOT H AND(M) - * | / \ - * NOT G OR(M) - * | / \ - * F H NOT - * | - * OR(M) - * / \ - * AND(M) L - * / \ - * J K - * + * OR(M) + * / \ + * OR(M) NOT + * / \ | + * NOT H AND(M) + * | / \ + * NOT G OR(M) + * | / \ + * F H NOT + * | + * OR(M) + * / \ + * AND(M) L + * / \ + * J K + * * 2. push the not operators into the bottom of the expression. That * means the not operator will be the root of the expression tree * where no "and" or "or" exists. Be sure use the De Morgan's law * and double not law. - * + * * How to use De Morgan law: * For example, here is the original expression tree: - * NOT - * | - * AND(M) - * / \ - * G H - * + * NOT + * | + * AND(M) + * / \ + * G H + * * After we use the De Morgan law, the result should be like this: - * OR(M) - * / \ - * NOT NOT - * | | - * G H - * + * OR(M) + * / \ + * NOT NOT + * | | + * G H + * * After the transform, the result should be like this: - * OR(M) - * / \ - * OR(M) OR(M) - * / \ / \ - * F H NOT AND(M) - * | / \ - * G NOT OR(M) - * | / \ - * H AND(M) L - * / \ - * J K - * + * OR(M) + * / \ + * OR(M) OR(M) + * / \ / \ + * F H NOT AND(M) + * | / \ + * G NOT OR(M) + * | / \ + * H AND(M) L + * / \ + * J K + * * 3. gather all the adjacent "and" or "or" operator together. * After doing that, the expression tree will be presented as: * all the and expression will be in either odd or even levels, * this will be the same for the or operator. - * + * * After the transform, the expression tree should be like this: - * OR(M) - * / / \ \ - * F H NOT AND(M) - * | / \ - * G NOT OR(M) - * | / \ - * H AND(M) L - * / \ - * J K - * - * 4. push the and operator upwards until the root is an and + * OR(M) + * / / \ \ + * F H NOT AND(M) + * | / \ + * G NOT OR(M) + * | / \ + * H AND(M) L + * / \ + * J K + * + * 4. push the and operator upwards until the root is an and * operator and all the children are or operators with multiple * components. At this time we get the result: an expression in CNF form. * How do we push and up? Use distribution law! - * + * * For example, here is the way to push the and up and merge them. - * OR - * / \ - * AND L - * / \ - * J K - * + * OR + * / \ + * AND L + * / \ + * J K + * * In the normal form, it could be: (J AND K) OR L. * If we apply the distribution law, we will get the result like this: * (J OR L) AND (K OR L), the tree form of this should be like: - * AND - * / \ - * OR OR - * / \ / \ - * J L K L - * - * So after we push the AND at the deepest level up and merge it with the + * AND + * / \ + * OR OR + * / \ / \ + * J L K L + * + * So after we push the AND at the deepest level up and merge it with the * existing add, we get this result. - * OR(M) - * / / \ \ - * F H NOT AND(M) - * | / | \ - * G NOT OR(M) OR(M) - * | / \ / \ - * H J L K L - * + * OR(M) + * / / \ \ + * F H NOT AND(M) + * | / | \ + * G NOT OR(M) OR(M) + * | / \ / \ + * H J L K L + * * Now let us push the and up and we will get the result like this: - * AND(M) - * / | \ - * OR(M) OR(M) OR(M) - * / / \ \ / / | \ \ / / | \ \ - * F H NOT NOT F H NOT J L F H NOT K L - * | | | | - * G H G G - * + * AND(M) + * / | \ + * OR(M) OR(M) OR(M) + * / / \ \ / / | \ \ / / | \ \ + * F H NOT NOT F H NOT J L F H NOT K L + * | | | | + * G H G G + * * 5. The last step, convert the Multiple Expression back to the binary - * form. Note the final tree shall be left-inclined. - * + * form. Note the final tree shall be left-inclined. + * * The final expression tree shall be like this: - * AND - * / \ - * AND ( ) - * / \ | - * ( ) ( ) part1 - * | | - * OR part2 - * / \ - * OR NOT - * / \ | - * OR NOT H - * / \ | - * F H G - * - * part1: OR - * / \ - * OR L - * / \ - * OR K - * / \ - * OR NOT - * / \ | - * F H G - * - * part2: OR - * / \ - * OR L - * / \ - * OR J - * / \ - * OR NOT - * / \ | - * F H G - * + * AND + * / \ + * AND ( ) + * / \ | + * ( ) ( ) part1 + * | | + * OR part2 + * / \ + * OR NOT + * / \ | + * OR NOT H + * / \ | + * F H G + * + * part1: OR + * / \ + * OR L + * / \ + * OR K + * / \ + * OR NOT + * / \ | + * F H G + * + * part2: OR + * / \ + * OR L + * / \ + * OR J + * / \ + * OR NOT + * / \ | + * F H G + * * @author messfish * */ public class CNFConverter { - private Expression root; + private Expression root; // the variable that stores the newly generated root. private Expression dummy; // this variable mainly serves as the dummy root of the true root. @@ -229,46 +214,35 @@ public class CNFConverter { // settled as the dummy root. private boolean isUsed = false; private CloneHelper clone = new CloneHelper(); - - /** - * this class is mainly used for gather the parent expression, - * children expression and the level of the children expression - * in the expression tree together. - * @author messfish - * - */ + private class Mule { + private Expression parent; private Expression child; private int level; + private Mule(Expression parent, Expression child, int level) { this.parent = parent; this.child = child; this.level = level; } } - - /** - * Since the class is only used once, I create this method to make the rest - * of the methods private. - * @param expr the expression that will be converted. - * @return the converted expression. - */ + public static Expression convertToCNF(Expression expr) { CNFConverter cnf = new CNFConverter(); return cnf.convert(expr); } - + /** - * this method takes an expression tree and converts that into - * a CNF form. Notice the 5 steps shown above will turn into - * 5 different methods. For the sake of testing, I set them public. + * this method takes an expression tree and converts that into a CNF form. Notice the 5 steps + * shown above will turn into 5 different methods. For the sake of testing, I set them public. * return the converted expression. + * * @param express the original expression tree. */ - private Expression convert(Expression express) + private Expression convert(Expression express) throws IllegalStateException { - if(isUsed) { + if (isUsed) { throw new IllegalStateException("The class could only be used once!"); } else { isUsed = true; @@ -284,11 +258,11 @@ private Expression convert(Expression express) changeBack(); return root; } - + /** - * this is the first step that rebuild the expression tree. - * Use the standard specified in the above class. Traverse the - * original tree recursively and rebuild the tree from that. + * this is the first step that rebuild the expression tree. Use the standard specified in the + * above class. Traverse the original tree recursively and rebuild the tree from that. + * * @param express the original expression tree. */ private void reorder(Expression express) { @@ -297,11 +271,10 @@ private void reorder(Expression express) { list.add(root); dummy = new MultiAndExpression(list); } - + /** - * This method is used to deal with pushing not operators down. - * Since it needs an extra parameter, I will create a new - * method to handle this. + * This method is used to deal with pushing not operators down. Since it needs an extra + * parameter, I will create a new method to handle this. */ private void pushNotDown() { /* set the two temp parameters to their staring point. */ @@ -315,81 +288,79 @@ private void pushNotDown() { temp1 = root; temp2 = dummy; } - + /** - * This method is the helper function to push not operators down. - * traverse the tree thoroughly, when we meet the not operator. - * We only need to consider these three operators: MultiAndOperator, - * MultiOrOperator, NotOperator. Handle them in a seperate way. - * when we finish the traverse, the expression tree will have - * all the not operators pushed as downwards as they could. - * In the method, I use two global variables: temp1 and temp2 - * to traverse the expression tree. Notice that temp2 will always - * be the parent of temp1. + * This method is the helper function to push not operators down. traverse the tree thoroughly, + * when we meet the not operator. We only need to consider these three operators: + * MultiAndOperator, MultiOrOperator, NotOperator. Handle them in a seperate way. when we finish + * the traverse, the expression tree will have all the not operators pushed as downwards as they + * could. In the method, I use two global variables: temp1 and temp2 to traverse the expression + * tree. Notice that temp2 will always be the parent of temp1. + * * @param index the index of the children appeared in parents array. */ private void pushNot(int index) { /* what really matters is the three logical operators: * and, or, not. so we only deal with these three operators. */ - if(temp1 instanceof MultiAndExpression) { + if (temp1 instanceof MultiAndExpression) { MultiAndExpression and = (MultiAndExpression) temp1; - for(int i=0; i< and.size(); i++) { + for (int i = 0; i < and.size(); i++) { temp2 = and; temp1 = and.getChild(i); pushNot(i); } - }else if(temp1 instanceof MultiOrExpression) { + } else if (temp1 instanceof MultiOrExpression) { MultiOrExpression or = (MultiOrExpression) temp1; - for(int i=0; i< or.size(); i++) { + for (int i = 0; i < or.size(); i++) { temp2 = or; temp1 = or.getChild(i); pushNot(i); } - }else if(temp1 instanceof NotExpression) { + } else if (temp1 instanceof NotExpression) { handleNot(index); } } - + /** - * This function mainly deals with pushing not operators down. - * check the child. If it is not a logic operator(and or or). - * stop at that point. Else use De Morgan law to push not downwards. + * This function mainly deals with pushing not operators down. check the child. If it is not a + * logic operator(and or or). stop at that point. Else use De Morgan law to push not downwards. + * * @param index the index of the children appeared in parents array. */ private void handleNot(int index) { child = ((NotExpression) temp1).getExpression(); int nums = 1; // takes down the number of not operators. - while(child instanceof NotExpression){ + while (child instanceof NotExpression) { child = ((NotExpression) child).getExpression(); nums++; } /* if the number of not operators are even. we could get * rid of all the not operators. set the child to the parent. */ - if(nums%2==0) { + if (nums % 2 == 0) { ((MultipleExpression) temp2).setChild(index, child); temp1 = child; pushNot(-1); - } else{ + } else { /* otherwise there will be one not left to push. * if the child is not these two types of operators. * that means we reach the leaves of the logical part. * set a new not operator whose child is the current one * and connect that operator with the parent and return. */ - if(!(child instanceof MultiAndExpression) && - !(child instanceof MultiOrExpression)){ - if (child instanceof LikeExpression) { - ((LikeExpression) child).setNot(true); - }else if(child instanceof BinaryExpression) { - ((BinaryExpression) child).setNot(); - }else { - child = new NotExpression(child); - } + if (!(child instanceof MultiAndExpression) + && !(child instanceof MultiOrExpression)) { +// if (child instanceof LikeExpression) { +// ((LikeExpression) child).setNot(); +// } else if (child instanceof BinaryExpression) { +// ((BinaryExpression) child).setNot(); +// } else { + child = new NotExpression(child); +// } ((MultipleExpression) temp2).setChild(index, child); - return; - }else if(child instanceof MultiAndExpression) { +// return; + } else if (child instanceof MultiAndExpression) { MultiAndExpression and = (MultiAndExpression) child; List list = new ArrayList(); - for(int i=0; i list = new ArrayList(); - for(int i=0; i queue = new LinkedList(); queue.offer(temp1); - while(!queue.isEmpty()) { + while (!queue.isEmpty()) { Expression express = queue.poll(); /* at this level, we only deal with "multi and" and "multi or" * operators, so we only consider these two operators. * that means we do nothing if the operator is not those two. */ - if(express instanceof MultiAndExpression) { + if (express instanceof MultiAndExpression) { MultiAndExpression and = (MultiAndExpression) express; - while(true) { + while (true) { int index = 0; Expression get = null; - for(; index queue = new LinkedList(); @@ -511,22 +480,22 @@ private void pushAndUp() { int level = 1; /* do the BFS and store valid mule into the stack. Notice the * first parameter is parent and the second parameter is children. */ - while(!queue.isEmpty()) { + while (!queue.isEmpty()) { int size = queue.size(); - for(int i=0; i stack) { int level = 0; - if(!stack.isEmpty()) { + if (!stack.isEmpty()) { level = stack.peek().level; } - while(!stack.isEmpty()) { + while (!stack.isEmpty()) { Mule mule = stack.pop(); /* we finish a level, uniform the tree by calling gather. */ - if(level!= mule.level) { + if (level != mule.level) { gather(); level = mule.level; } @@ -576,23 +543,23 @@ private void pushAnd(Stack stack) { * tree, so simply set a 0 to the last parameter. */ Mule combined = new Mule(mule.parent, mule.child, 0); queue.offer(combined); - while(!queue.isEmpty()) { + while (!queue.isEmpty()) { Mule get = queue.poll(); Expression parent = get.parent; Expression child = get.child; /* based on the code above, the stack only have the expression * which they are multi operators. so safely convert them. */ MultipleExpression children = (MultipleExpression) child; - int index = 0; + int index = 0; MultiAndExpression and = null; /* find the children that the child is an multi and operator. */ - for(; index stack) { List list = new ArrayList(); MultiAndExpression newand = new MultiAndExpression(list); parents.setChild(parents.getIndex(children), newand); - for(int i=0; i stack) { } } } - + /** - * This is the final step of the CNF conversion: now we have the - * Expression tree that has one multiple and expression with a list - * of multiple or expression as the child. So we need to convert the - * multiple expression back to the binary counterparts. Note the - * converted tree is left inclined. Also I attach a parenthesis node - * before the or expression that is attached to the and expression - * to make the generated result resembles the CNF form. + * This is the final step of the CNF conversion: now we have the Expression tree that has one + * multiple and expression with a list of multiple or expression as the child. So we need to + * convert the multiple expression back to the binary counterparts. Note the converted tree is + * left inclined. Also I attach a parenthesis node before the or expression that is attached to + * the and expression to make the generated result resembles the CNF form. */ private void changeBack() { - if(!(root instanceof MultiAndExpression)) { + if (!(root instanceof MultiAndExpression)) { return; } MultipleExpression temp = (MultipleExpression) root; - for(int i=0; i. + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.cnfexpression; import java.util.ArrayList; import java.util.List; - -import net.sf.jsqlparser.expression.BinaryExpression; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.NotExpression; import net.sf.jsqlparser.expression.Parenthesis; @@ -36,85 +22,69 @@ * Note this is the shallow copy of the tree. That means I do not modify * or copy the expression other than these expressions: * AND, OR, NOT, (), MULTI-AND, MULTI-OR. - * Since the CNF conversion only change the condition part of the tree. + * Since the CNF conversion only change the condition part of the tree. + * * @author messfish * */ class CloneHelper { - /** - * This method is used for changing the logical structure of the tree. - * The main method is to convert and operator and or operator to let - * them have multiple children (reflected in MultipleExpression.java - * from the conditional package). Note if the value from the conditional - * operator has a not attached to it we need to append an not operator - * ahead of it since the not operator needed to be pushed down during - * the second step. Also, I will leave out all the parenthesis expression - * which is connected to the conditional operator. - * @param express the expression that will be modified - * @return the modified expression. - * - */ public Expression modify(Expression express) { - if(express instanceof NotExpression) { + if (express instanceof NotExpression) { return new NotExpression(modify(((NotExpression) express).getExpression())); } - if(express instanceof Parenthesis) { + if (express instanceof Parenthesis) { Parenthesis parenthesis = (Parenthesis) express; Expression result = modify(parenthesis.getExpression()); - if(parenthesis.isNot()) { - return new NotExpression(result); - } return result; } - if(express instanceof AndExpression) { + if (express instanceof AndExpression) { AndExpression and = (AndExpression) express; List list = new ArrayList(); list.add(modify(and.getLeftExpression())); list.add(modify(and.getRightExpression())); MultiAndExpression result = new MultiAndExpression(list); - if(and.isNot()) { - return new NotExpression(result); - } +// if (and.isNot()) { +// return new NotExpression(result); +// } return result; } - if(express instanceof OrExpression) { + if (express instanceof OrExpression) { OrExpression or = (OrExpression) express; List list = new ArrayList(); list.add(modify(or.getLeftExpression())); list.add(modify(or.getRightExpression())); MultiOrExpression result = new MultiOrExpression(list); - if(or.isNot()) { - return new NotExpression(result); - } +// if (or.isNot()) { +// return new NotExpression(result); +// } return result; } - if(express instanceof BinaryExpression) { - BinaryExpression binary = (BinaryExpression) express; - if(binary.isNot()) { - binary.removeNot(); - return new NotExpression(modify(binary)); - } - } - /* at this stage, there is no need to modify, just simply return. */ +// if (express instanceof BinaryExpression) { +// BinaryExpression binary = (BinaryExpression) express; +// if (binary.isNot()) { +// binary.removeNot(); +// return new NotExpression(modify(binary)); +// } +// } return express; } - + /** - * This method is used to copy the expression which happens at - * step four. I only copy the conditional expressions since the - * CNF only changes the conditional part. + * This method is used to copy the expression which happens at step four. I only copy the + * conditional expressions since the CNF only changes the conditional part. + * * @param express the expression that will be copied. * @return the copied expression. */ public Expression shallowCopy(Expression express) { - if(express instanceof MultipleExpression) { + if (express instanceof MultipleExpression) { MultipleExpression multi = (MultipleExpression) express; List list = new ArrayList(); - for(int i=0; i. + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.cnfexpression; @@ -27,6 +15,7 @@ /** * This helper class is mainly used for handling the CNF conversion. + * * @author messfish * */ @@ -41,4 +30,4 @@ public String getStringExpression() { return "AND"; } -} \ No newline at end of file +} diff --git a/src/main/java/net/sf/jsqlparser/util/cnfexpression/MultiOrExpression.java b/src/main/java/net/sf/jsqlparser/util/cnfexpression/MultiOrExpression.java index 9b8bdcba..8cc6f56d 100644 --- a/src/main/java/net/sf/jsqlparser/util/cnfexpression/MultiOrExpression.java +++ b/src/main/java/net/sf/jsqlparser/util/cnfexpression/MultiOrExpression.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.cnfexpression; @@ -25,11 +13,6 @@ import net.sf.jsqlparser.expression.Expression; -/** - * This helper class is mainly used for handling the CNF conversion. - * @author messfish - * - */ public final class MultiOrExpression extends MultipleExpression { public MultiOrExpression(List childlist) { diff --git a/src/main/java/net/sf/jsqlparser/util/cnfexpression/MultipleExpression.java b/src/main/java/net/sf/jsqlparser/util/cnfexpression/MultipleExpression.java index 7bdef475..f37e823c 100644 --- a/src/main/java/net/sf/jsqlparser/util/cnfexpression/MultipleExpression.java +++ b/src/main/java/net/sf/jsqlparser/util/cnfexpression/MultipleExpression.java @@ -1,92 +1,81 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.cnfexpression; import java.util.List; - import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitor; import net.sf.jsqlparser.expression.NullValue; +import net.sf.jsqlparser.parser.ASTNodeAccessImpl; /** * This is a helper class that mainly used for handling the CNF conversion. + * * @author messfish * */ -public abstract class MultipleExpression implements Expression { +public abstract class MultipleExpression extends ASTNodeAccessImpl implements Expression { private final List childlist; - + public MultipleExpression(List childlist) { this.childlist = childlist; } - + public int size() { return childlist.size(); } - + @Override public void accept(ExpressionVisitor expressionVisitor) { expressionVisitor.visit(new NullValue()); } - + public List getList() { return childlist; } - + public Expression getChild(int index) { return childlist.get(index); } - + public Expression removeChild(int index) { return childlist.remove(index); } - + public void setChild(int index, Expression express) { childlist.set(index, express); } - + public int getIndex(Expression express) { return childlist.indexOf(express); } - + public void addChild(int index, Expression express) { childlist.add(index, express); } - + public abstract String getStringExpression(); - + @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("("); - for(int i=0; i. + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; import net.sf.jsqlparser.statement.alter.Alter; -/** - * very simple alter statement deparser - * - * @author toben - */ public class AlterDeParser { - private StringBuilder buffer; + protected StringBuilder buffer; public AlterDeParser(StringBuilder buffer) { this.buffer = buffer; diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/AlterViewDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/AlterViewDeParser.java index 9f4f72d9..867317c2 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/AlterViewDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/AlterViewDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -25,18 +13,11 @@ import net.sf.jsqlparser.statement.select.PlainSelect; import net.sf.jsqlparser.statement.select.SelectVisitor; -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) a - * {@link net.sf.jsqlparser.statement.create.view.AlterView} - */ public class AlterViewDeParser { - private StringBuilder buffer; + protected StringBuilder buffer; private SelectVisitor selectVisitor; - /** - * @param buffer the buffer that will be filled with the select - */ public AlterViewDeParser(StringBuilder buffer) { SelectDeParser selectDeParser = new SelectDeParser(); selectDeParser.setBuffer(buffer); @@ -52,7 +33,11 @@ public AlterViewDeParser(StringBuilder buffer, SelectVisitor selectVisitor) { } public void deParse(AlterView alterView) { - buffer.append("ALTER "); + if (alterView.isUseReplace()) { + buffer.append("REPLACE "); + } else { + buffer.append("ALTER "); + } buffer.append("VIEW ").append(alterView.getView().getFullyQualifiedName()); if (alterView.getColumnNames() != null) { buffer.append(PlainSelect.getStringList(alterView.getColumnNames(), true, true)); diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/CreateIndexDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/CreateIndexDeParser.java index 450d2ab3..0d446b6d 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/CreateIndexDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/CreateIndexDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -26,19 +14,10 @@ import net.sf.jsqlparser.statement.create.index.CreateIndex; import net.sf.jsqlparser.statement.create.table.Index; -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) a - * {@link net.sf.jsqlparser.statement.create.index.CreateIndex} - * - * @author Raymond Augé - */ public class CreateIndexDeParser { - private StringBuilder buffer; + protected StringBuilder buffer; - /** - * @param buffer the buffer that will be filled with the create - */ public CreateIndexDeParser(StringBuilder buffer) { this.buffer = buffer; } @@ -58,6 +37,12 @@ public void deParse(CreateIndex createIndex) { buffer.append(" ON "); buffer.append(createIndex.getTable().getFullyQualifiedName()); + String using = index.getUsing(); + if (using != null){ + buffer.append(" USING "); + buffer.append(using); + } + if (index.getColumnsNames() != null) { buffer.append(" ("); for (Iterator iter = index.getColumnsNames().iterator(); iter.hasNext();) { diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/CreateTableDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/CreateTableDeParser.java index 9226f366..98275aae 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/CreateTableDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/CreateTableDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -27,22 +15,24 @@ import net.sf.jsqlparser.statement.create.table.CreateTable; import net.sf.jsqlparser.statement.create.table.Index; import net.sf.jsqlparser.statement.select.PlainSelect; +import net.sf.jsqlparser.statement.select.Select; + -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) a - * {@link net.sf.jsqlparser.statement.create.table.CreateTable} - */ public class CreateTableDeParser { - private StringBuilder buffer; + protected StringBuilder buffer; + private StatementDeParser statementDeParser; - /** - * @param buffer the buffer that will be filled with the select - */ public CreateTableDeParser(StringBuilder buffer) { this.buffer = buffer; } + public CreateTableDeParser(StatementDeParser statementDeParser, StringBuilder buffer) { + this.buffer = buffer; + this.statementDeParser = statementDeParser; + } + + public void deParse(CreateTable createTable) { buffer.append("CREATE "); if (createTable.isUnlogged()) { @@ -64,7 +54,8 @@ public void deParse(CreateTable createTable) { if (createTable.isSelectParenthesis()) { buffer.append("("); } - buffer.append(createTable.getSelect().toString()); + Select sel = createTable.getSelect(); + sel.accept(this.statementDeParser); if (createTable.isSelectParenthesis()) { buffer.append(")"); } diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/CreateViewDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/CreateViewDeParser.java index 0a7fbe69..698608a7 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/CreateViewDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/CreateViewDeParser.java @@ -1,42 +1,26 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; import net.sf.jsqlparser.statement.create.view.CreateView; +import net.sf.jsqlparser.statement.create.view.TemporaryOption; import net.sf.jsqlparser.statement.select.PlainSelect; +import net.sf.jsqlparser.statement.select.Select; import net.sf.jsqlparser.statement.select.SelectVisitor; +import net.sf.jsqlparser.statement.select.WithItem; -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) a - * {@link net.sf.jsqlparser.statement.create.view.CreateView} - */ public class CreateViewDeParser { - private StringBuilder buffer; - private SelectVisitor selectVisitor; + protected StringBuilder buffer; + private final SelectVisitor selectVisitor; - /** - * @param buffer the buffer that will be filled with the select - */ public CreateViewDeParser(StringBuilder buffer) { SelectDeParser selectDeParser = new SelectDeParser(); selectDeParser.setBuffer(buffer); @@ -56,6 +40,17 @@ public void deParse(CreateView createView) { if (createView.isOrReplace()) { buffer.append("OR REPLACE "); } + switch (createView.getForce()) { + case FORCE: + buffer.append("FORCE "); + break; + case NO_FORCE: + buffer.append("NO FORCE "); + break; + } + if (createView.getTemporary() != TemporaryOption.NONE) { + buffer.append(createView.getTemporary().name()).append(" "); + } if (createView.isMaterialized()) { buffer.append("MATERIALIZED "); } @@ -65,7 +60,25 @@ public void deParse(CreateView createView) { } buffer.append(" AS "); - createView.getSelectBody().accept(selectVisitor); + Select select = createView.getSelect(); + if (select.getWithItemsList() != null) { + buffer.append("WITH "); + boolean first = true; + for (WithItem item : select.getWithItemsList()) { + if (!first) { + buffer.append(", "); + } else { + first = false; + } + + item.accept(selectVisitor); + } + buffer.append(" "); + } + createView.getSelect().getSelectBody().accept(selectVisitor); + if (createView.isWithReadOnly()) { + buffer.append(" WITH READ ONLY"); + } } public StringBuilder getBuffer() { diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/DeclareStatementDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/DeclareStatementDeParser.java new file mode 100644 index 00000000..6f712a0b --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/util/deparser/DeclareStatementDeParser.java @@ -0,0 +1,84 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.util.deparser; + +import net.sf.jsqlparser.expression.ExpressionVisitor; +import net.sf.jsqlparser.statement.DeclareStatement; +import net.sf.jsqlparser.statement.DeclareType; + +public class DeclareStatementDeParser { + + protected StringBuilder buffer; + private ExpressionVisitor expressionVisitor; + + public DeclareStatementDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) { + this.buffer = buffer; + this.expressionVisitor = expressionVisitor; + } + + public StringBuilder getBuffer() { + return buffer; + } + + public void setBuffer(StringBuilder buffer) { + this.buffer = buffer; + } + + public void deParse(DeclareStatement declare) { + buffer.append("DECLARE "); + + if (declare.getUserVariable() != null) { + declare.getUserVariable().accept(expressionVisitor); + } + + if (declare.getType() == DeclareType.AS) { + buffer.append(" AS "); + buffer.append(declare.getTypeName()); + return; + } + + if (declare.getType() == DeclareType.TABLE) { + buffer.append(" TABLE ("); + for (int i = 0; i < declare.getColumnDefinitions().size(); i++) { + if (i > 0) { + buffer.append(", "); + } + buffer.append(declare.getColumnDefinitions().get(i).toString()); + } + buffer.append(")"); + } else { + if (declare.getTypeDefinitions() != null) { + for (int i = 0; i < declare.getTypeDefinitions().size(); i++) { + if (i > 0) { + buffer.append(", "); + } + DeclareStatement.TypeDefExpr type = declare.getTypeDefinitions().get(i); + if (type.userVariable != null) { + type.userVariable.accept(expressionVisitor); + buffer.append(" "); + } + buffer.append(type.colDataType.toString()); + if (type.defaultExpr != null) { + buffer.append(" = "); + type.defaultExpr.accept(expressionVisitor); + } + } + } + } + } + + public ExpressionVisitor getExpressionVisitor() { + return expressionVisitor; + } + + public void setExpressionVisitor(ExpressionVisitor visitor) { + expressionVisitor = visitor; + } +} diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/DeleteDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/DeleteDeParser.java index 3f32de21..199481ff 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/DeleteDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/DeleteDeParser.java @@ -1,50 +1,28 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; +import static java.util.stream.Collectors.joining; import net.sf.jsqlparser.expression.ExpressionVisitor; import net.sf.jsqlparser.expression.ExpressionVisitorAdapter; -import net.sf.jsqlparser.schema.Table; import net.sf.jsqlparser.statement.delete.Delete; import net.sf.jsqlparser.statement.select.Join; -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) a - * {@link net.sf.jsqlparser.statement.delete.Delete} - */ public class DeleteDeParser { - private StringBuilder buffer = new StringBuilder(); + protected StringBuilder buffer = new StringBuilder(); private ExpressionVisitor expressionVisitor = new ExpressionVisitorAdapter(); public DeleteDeParser() { } - /** - * @param expressionVisitor a {@link ExpressionVisitor} to de-parse expressions. It has to share - * the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param buffer the buffer that will be filled with the select - */ public DeleteDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) { this.buffer = buffer; this.expressionVisitor = expressionVisitor; @@ -61,9 +39,9 @@ public void setBuffer(StringBuilder buffer) { public void deParse(Delete delete) { buffer.append("DELETE"); if (delete.getTables() != null && delete.getTables().size() > 0) { - for (Table table : delete.getTables()) { - buffer.append(" ").append(table.getFullyQualifiedName()); - } + buffer.append(delete.getTables().stream() + .map(t -> t.getFullyQualifiedName()) + .collect(joining(", ", " " , ""))); } buffer.append(" FROM ").append(delete.getTable().toString()); diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/DropDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/DropDeParser.java index 72dd1080..175a4bd9 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/DropDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/DropDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -24,12 +12,9 @@ import net.sf.jsqlparser.statement.drop.Drop; import net.sf.jsqlparser.statement.select.PlainSelect; -/** - * @author tw - */ public class DropDeParser { - private StringBuilder buffer; + protected StringBuilder buffer; public DropDeParser(StringBuilder buffer) { this.buffer = buffer; diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/ExecuteDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/ExecuteDeParser.java index d4a5ab6f..fd98dba8 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/ExecuteDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/ExecuteDeParser.java @@ -1,43 +1,24 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; import java.util.List; - import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitor; import net.sf.jsqlparser.statement.execute.Execute; public class ExecuteDeParser { - private StringBuilder buffer; + protected StringBuilder buffer; private ExpressionVisitor expressionVisitor; - /** - * @param expressionVisitor a {@link ExpressionVisitor} to de-parse expressions. It has to share - * the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param buffer the buffer that will be filled with the select - */ public ExecuteDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) { this.buffer = buffer; this.expressionVisitor = expressionVisitor; @@ -52,14 +33,23 @@ public void setBuffer(StringBuilder buffer) { } public void deParse(Execute execute) { - buffer.append("EXECUTE ").append(execute.getName()); - List expressions = execute.getExprList().getExpressions(); - for (int i = 0; i < expressions.size(); i++) { - if (i > 0) { - buffer.append(","); - } + buffer.append(execute.getExecType().name()).append(" ").append(execute.getName()); + if (execute.isParenthesis()) { + buffer.append(" ("); + } else if (execute.getExprList() != null) { buffer.append(" "); - expressions.get(i).accept(expressionVisitor); + } + if (execute.getExprList() != null) { + List expressions = execute.getExprList().getExpressions(); + for (int i = 0; i < expressions.size(); i++) { + if (i > 0) { + buffer.append(", "); + } + expressions.get(i).accept(expressionVisitor); + } + } + if (execute.isParenthesis()) { + buffer.append(")"); } } diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java index ac10939a..62869de3 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/ExpressionDeParser.java @@ -1,35 +1,24 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; import java.util.Iterator; import java.util.List; - import net.sf.jsqlparser.expression.AllComparisonExpression; import net.sf.jsqlparser.expression.AnalyticExpression; import net.sf.jsqlparser.expression.AnyComparisonExpression; +import net.sf.jsqlparser.expression.ArrayExpression; import net.sf.jsqlparser.expression.BinaryExpression; import net.sf.jsqlparser.expression.CaseExpression; import net.sf.jsqlparser.expression.CastExpression; +import net.sf.jsqlparser.expression.CollateExpression; import net.sf.jsqlparser.expression.DateTimeLiteralExpression; import net.sf.jsqlparser.expression.DateValue; import net.sf.jsqlparser.expression.DoubleValue; @@ -45,6 +34,7 @@ import net.sf.jsqlparser.expression.KeepExpression; import net.sf.jsqlparser.expression.LongValue; import net.sf.jsqlparser.expression.MySQLGroupConcat; +import net.sf.jsqlparser.expression.NextValExpression; import net.sf.jsqlparser.expression.NotExpression; import net.sf.jsqlparser.expression.NullValue; import net.sf.jsqlparser.expression.NumericBind; @@ -58,40 +48,13 @@ import net.sf.jsqlparser.expression.TimeValue; import net.sf.jsqlparser.expression.TimestampValue; import net.sf.jsqlparser.expression.UserVariable; +import net.sf.jsqlparser.expression.ValueListExpression; import net.sf.jsqlparser.expression.WhenClause; import net.sf.jsqlparser.expression.WindowElement; -import net.sf.jsqlparser.expression.WithinGroupExpression; -import net.sf.jsqlparser.expression.operators.arithmetic.Addition; -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd; -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr; -import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor; -import net.sf.jsqlparser.expression.operators.arithmetic.Concat; -import net.sf.jsqlparser.expression.operators.arithmetic.Division; -import net.sf.jsqlparser.expression.operators.arithmetic.Modulo; -import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication; -import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction; +import net.sf.jsqlparser.expression.operators.arithmetic.*; import net.sf.jsqlparser.expression.operators.conditional.AndExpression; import net.sf.jsqlparser.expression.operators.conditional.OrExpression; -import net.sf.jsqlparser.expression.operators.relational.Between; -import net.sf.jsqlparser.expression.operators.relational.EqualsTo; -import net.sf.jsqlparser.expression.operators.relational.ExistsExpression; -import net.sf.jsqlparser.expression.operators.relational.ExpressionList; -import net.sf.jsqlparser.expression.operators.relational.GreaterThan; -import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals; -import net.sf.jsqlparser.expression.operators.relational.InExpression; -import net.sf.jsqlparser.expression.operators.relational.IsNullExpression; -import net.sf.jsqlparser.expression.operators.relational.ItemsListVisitor; -import net.sf.jsqlparser.expression.operators.relational.JsonOperator; -import net.sf.jsqlparser.expression.operators.relational.LikeExpression; -import net.sf.jsqlparser.expression.operators.relational.Matches; -import net.sf.jsqlparser.expression.operators.relational.MinorThan; -import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals; -import net.sf.jsqlparser.expression.operators.relational.MultiExpressionList; -import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo; -import net.sf.jsqlparser.expression.operators.relational.OldOracleJoinBinaryExpression; -import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator; -import net.sf.jsqlparser.expression.operators.relational.RegExpMySQLOperator; -import net.sf.jsqlparser.expression.operators.relational.SupportsOldOracleJoinSyntax; +import net.sf.jsqlparser.expression.operators.relational.*; import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.schema.Table; import net.sf.jsqlparser.statement.select.OrderByElement; @@ -99,14 +62,10 @@ import net.sf.jsqlparser.statement.select.SubSelect; import net.sf.jsqlparser.statement.select.WithItem; -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) an - * {@link net.sf.jsqlparser.expression.Expression} - */ public class ExpressionDeParser implements ExpressionVisitor, ItemsListVisitor { private static final String NOT = "NOT "; - private StringBuilder buffer = new StringBuilder(); + protected StringBuilder buffer = new StringBuilder(); private SelectVisitor selectVisitor; private boolean useBracketsInExprList = true; private OrderByDeParser orderByDeParser = new OrderByDeParser(); @@ -114,21 +73,6 @@ public class ExpressionDeParser implements ExpressionVisitor, ItemsListVisitor { public ExpressionDeParser() { } - /** - * @param selectVisitor a SelectVisitor to de-parse SubSelects. It has to share the same
- * StringBuilder as this object in order to work, as: - * - *
-     * 
-     * StringBuilder myBuf = new StringBuilder();
-     * MySelectDeparser selectDeparser = new  MySelectDeparser();
-     * selectDeparser.setBuffer(myBuf);
-     * ExpressionDeParser expressionDeParser = new ExpressionDeParser(selectDeparser, myBuf);
-     * 
-     * 
- * - * @param buffer the buffer that will be filled with the expression - */ public ExpressionDeParser(SelectVisitor selectVisitor, StringBuilder buffer) { this(selectVisitor, buffer, new OrderByDeParser()); } @@ -181,6 +125,11 @@ public void visit(Division division) { visitBinaryExpression(division, " / "); } + @Override + public void visit(IntegerDivision division) { + visitBinaryExpression(division, " DIV "); + } + @Override public void visit(DoubleValue doubleValue) { buffer.append(doubleValue.toString()); @@ -193,14 +142,28 @@ public void visit(HexValue hexValue) { @Override public void visit(NotExpression notExpr) { - buffer.append(NOT); + if (notExpr.isExclamationMark()) { + buffer.append("! "); + } else { + buffer.append(NOT); + } notExpr.getExpression().accept(this); } + @Override + public void visit(BitwiseRightShift expr) { + visitBinaryExpression(expr, " >> "); + } + + @Override + public void visit(BitwiseLeftShift expr) { + visitBinaryExpression(expr, " << "); + } + public void visitOldOracleJoinBinaryExpression(OldOracleJoinBinaryExpression expression, String operator) { - if (expression.isNot()) { - buffer.append(NOT); - } +// if (expression.isNot()) { +// buffer.append(NOT); +// } expression.getLeftExpression().accept(this); if (expression.getOldOracleJoinSyntax() == EqualsTo.ORACLE_JOIN_RIGHT) { buffer.append("(+)"); @@ -241,6 +204,22 @@ public void visit(InExpression inExpression) { inExpression.getRightItemsList().accept(this); } + @Override + public void visit(FullTextSearch fullTextSearch) { + // Build a list of matched columns + String columnsListCommaSeperated = ""; + Iterator iterator = fullTextSearch.getMatchColumns().iterator(); + while (iterator.hasNext()) { + Column col = iterator.next(); + columnsListCommaSeperated += col.getFullyQualifiedName(); + if (iterator.hasNext()) { + columnsListCommaSeperated += ","; + } + } + buffer.append("MATCH (" + columnsListCommaSeperated + ") AGAINST (" + fullTextSearch.getAgainstValue() + + (fullTextSearch.getSearchModifier() != null ? " " + fullTextSearch.getSearchModifier() : "") + ")"); + } + @Override public void visit(SignedExpression signedExpression) { buffer.append(signedExpression.getSign()); @@ -250,10 +229,36 @@ public void visit(SignedExpression signedExpression) { @Override public void visit(IsNullExpression isNullExpression) { isNullExpression.getLeftExpression().accept(this); - if (isNullExpression.isNot()) { - buffer.append(" IS NOT NULL"); + if (isNullExpression.isUseIsNull()) { + if (isNullExpression.isNot()) { + buffer.append(" NOT ISNULL"); + } else { + buffer.append(" ISNULL"); + } } else { - buffer.append(" IS NULL"); + if (isNullExpression.isNot()) { + buffer.append(" IS NOT NULL"); + } else { + buffer.append(" IS NULL"); + } + } + } + + @Override + public void visit(IsBooleanExpression isBooleanExpression) { + isBooleanExpression.getLeftExpression().accept(this); + if (isBooleanExpression.isTrue()) { + if (isBooleanExpression.isNot()) { + buffer.append(" IS NOT TRUE"); + } else { + buffer.append(" IS TRUE"); + } + } else { + if (isBooleanExpression.isNot()) { + buffer.append(" IS NOT FALSE"); + } else { + buffer.append(" IS FALSE"); + } } } @@ -268,7 +273,9 @@ public void visit(JdbcParameter jdbcParameter) { @Override public void visit(LikeExpression likeExpression) { - visitBinaryExpression(likeExpression, likeExpression.isCaseInsensitive() ? " ILIKE " : " LIKE "); + visitBinaryExpression(likeExpression, + (likeExpression.isNot() ? " NOT" : "") + + (likeExpression.isCaseInsensitive() ? " ILIKE " : " LIKE ")); String escape = likeExpression.getEscape(); if (escape != null) { buffer.append(" ESCAPE '").append(escape).append('\''); @@ -329,18 +336,16 @@ public void visit(OrExpression orExpression) { @Override public void visit(Parenthesis parenthesis) { - if (parenthesis.isNot()) { - buffer.append(NOT); - } - buffer.append("("); parenthesis.getExpression().accept(this); buffer.append(")"); - } @Override public void visit(StringValue stringValue) { + if (stringValue.getPrefix() != null) { + buffer.append(stringValue.getPrefix()); + } buffer.append("'").append(stringValue.getValue()).append("'"); } @@ -348,13 +353,9 @@ public void visit(StringValue stringValue) { @Override public void visit(Subtraction subtraction) { visitBinaryExpression(subtraction, " - "); - } - private void visitBinaryExpression(BinaryExpression binaryExpression, String operator) { - if (binaryExpression.isNot()) { - buffer.append(NOT); - } + protected void visitBinaryExpression(BinaryExpression binaryExpression, String operator) { binaryExpression.getLeftExpression().accept(this); buffer.append(operator); binaryExpression.getRightExpression().accept(this); @@ -363,7 +364,9 @@ private void visitBinaryExpression(BinaryExpression binaryExpression, String ope @Override public void visit(SubSelect subSelect) { - buffer.append("("); + if (subSelect.isUseBrackets()) { + buffer.append("("); + } if (selectVisitor != null) { if (subSelect.getWithItemsList() != null) { buffer.append("WITH "); @@ -380,7 +383,9 @@ public void visit(SubSelect subSelect) { subSelect.getSelectBody().accept(selectVisitor); } - buffer.append(")"); + if (subSelect.isUseBrackets()) { + buffer.append(")"); + } } @Override @@ -410,10 +415,11 @@ public void visit(Function function) { buffer.append(function.getName()); if (function.isAllColumns() && function.getParameters() == null) { buffer.append("(*)"); - } else if (function.getParameters() == null) { + } else if (function.getParameters() == null && function.getNamedParameters() == null) { buffer.append("()"); } else { boolean oldUseBracketsInExprList = useBracketsInExprList; + useBracketsInExprList = true; if (function.isDistinct()) { useBracketsInExprList = false; buffer.append("(DISTINCT "); @@ -421,7 +427,12 @@ public void visit(Function function) { useBracketsInExprList = false; buffer.append("(ALL "); } - visit(function.getParameters()); + if (function.getNamedParameters() != null) { + visit(function.getNamedParameters()); + } + if (function.getParameters() != null) { + visit(function.getParameters()); + } useBracketsInExprList = oldUseBracketsInExprList; if (function.isDistinct() || function.isAllColumns()) { buffer.append(")"); @@ -430,6 +441,8 @@ public void visit(Function function) { if (function.getAttribute() != null) { buffer.append(".").append(function.getAttribute()); + } else if (function.getAttributeName() != null) { + buffer.append(".").append(function.getAttributeName()); } if (function.getKeep() != null) { buffer.append(" ").append(function.getKeep()); @@ -457,6 +470,29 @@ public void visit(ExpressionList expressionList) { } } + @Override + public void visit(NamedExpressionList namedExpressionList) { + if (useBracketsInExprList) { + buffer.append("("); + } + List names = namedExpressionList.getNames(); + List expressions = namedExpressionList.getExpressions(); + for (int i = 0; i < names.size(); i++) { + if (i > 0) { + buffer.append(" "); + } + String name = names.get(i); + if (!name.equals("")) { + buffer.append(name); + buffer.append(" "); + } + expressions.get(i).accept(this); + } + if (useBracketsInExprList) { + buffer.append(")"); + } + } + public SelectVisitor getSelectVisitor() { return selectVisitor; } @@ -553,12 +589,12 @@ public void visit(BitwiseXor bitwiseXor) { public void visit(CastExpression cast) { if (cast.isUseCastKeyword()) { buffer.append("CAST("); - buffer.append(cast.getLeftExpression()); + cast.getLeftExpression().accept(this); buffer.append(" AS "); buffer.append(cast.getType()); buffer.append(")"); } else { - buffer.append(cast.getLeftExpression()); + cast.getLeftExpression().accept(this); buffer.append("::"); buffer.append(cast.getType()); } @@ -582,6 +618,9 @@ public void visit(AnalyticExpression aexpr) { WindowElement windowElement = aexpr.getWindowElement(); buffer.append(name).append("("); + if (aexpr.isDistinct()) { + buffer.append("DISTINCT "); + } if (expression != null) { expression.accept(this); if (offset != null) { @@ -595,15 +634,35 @@ public void visit(AnalyticExpression aexpr) { } else if (isAllColumns) { buffer.append("*"); } + if (aexpr.isIgnoreNulls()) { + buffer.append(" IGNORE NULLS"); + } buffer.append(") "); if (keep != null) { keep.accept(this); buffer.append(" "); } - buffer.append("OVER ("); + + if (aexpr.getFilterExpression() != null) { + buffer.append("FILTER (WHERE "); + aexpr.getFilterExpression().accept(this); + buffer.append(") "); + } + + switch (aexpr.getType()) { + case WITHIN_GROUP: + buffer.append("WITHIN GROUP"); + break; + default: + buffer.append("OVER"); + } + buffer.append(" ("); if (partitionExpressionList != null && !partitionExpressionList.getExpressions().isEmpty()) { buffer.append("PARTITION BY "); + if (aexpr.isPartitionByBrackets()) { + buffer.append("("); + } List expressions = partitionExpressionList.getExpressions(); for (int i = 0; i < expressions.size(); i++) { if (i > 0) { @@ -611,6 +670,9 @@ public void visit(AnalyticExpression aexpr) { } expressions.get(i).accept(this); } + if (aexpr.isPartitionByBrackets()) { + buffer.append(")"); + } buffer.append(" "); } if (orderByElements != null && !orderByElements.isEmpty()) { @@ -623,11 +685,13 @@ public void visit(AnalyticExpression aexpr) { } orderByDeParser.deParseElement(orderByElements.get(i)); } + } - if (windowElement != null) { + if (windowElement != null) { + if (orderByElements != null && !orderByElements.isEmpty()) { buffer.append(' '); - buffer.append(windowElement); } + buffer.append(windowElement); } buffer.append(")"); @@ -686,11 +750,6 @@ public void visit(JsonOperator jsonExpr) { visitBinaryExpression(jsonExpr, " " + jsonExpr.getStringExpression() + " "); } - @Override - public void visit(WithinGroupExpression wgexpr) { - buffer.append(wgexpr.toString()); - } - @Override public void visit(UserVariable var) { buffer.append(var.toString()); @@ -711,6 +770,11 @@ public void visit(MySQLGroupConcat groupConcat) { buffer.append(groupConcat.toString()); } + @Override + public void visit(ValueListExpression valueList) { + buffer.append(valueList.toString()); + } + @Override public void visit(RowConstructor rowConstructor) { if (rowConstructor.getName() != null) { @@ -744,4 +808,26 @@ public void visit(DateTimeLiteralExpression literal) { buffer.append(literal.toString()); } + @Override + public void visit(NextValExpression nextVal) { + buffer.append("NEXTVAL FOR ").append(nextVal.getName()); + } + + @Override + public void visit(CollateExpression col) { + buffer.append(col.getLeftExpression().toString()).append(" COLLATE ").append(col.getCollate()); + } + + @Override + public void visit(SimilarToExpression expr) { + visitBinaryExpression(expr, (expr.isNot() ? " NOT" : "") + " SIMILAR TO "); + } + + @Override + public void visit(ArrayExpression array) { + array.getObjExpression().accept(this); + buffer.append("["); + array.getIndexExpression().accept(this); + buffer.append("]"); + } } diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/GroupByDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/GroupByDeParser.java new file mode 100644 index 00000000..aa5c4df9 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/util/deparser/GroupByDeParser.java @@ -0,0 +1,66 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.util.deparser; + +import java.util.Iterator; +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.ExpressionVisitor; +import net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.statement.select.GroupByElement; + +public class GroupByDeParser { + + protected StringBuilder buffer; + private ExpressionVisitor expressionVisitor; + + GroupByDeParser() { + } + + public GroupByDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) { + this.expressionVisitor = expressionVisitor; + this.buffer = buffer; + } + + public void deParse(GroupByElement groupBy) { + buffer.append("GROUP BY "); + for (Iterator iter = groupBy.getGroupByExpressions().iterator(); iter.hasNext();) { + iter.next().accept(expressionVisitor); + if (iter.hasNext()) { + buffer.append(", "); + } + } + if (groupBy.getGroupingSets().size() > 0) { + buffer.append("GROUPING SETS ("); + boolean first = true; + for (Object o : groupBy.getGroupingSets()) { + if (first) { + first = false; + } else { + buffer.append(", "); + } + if (o instanceof Expression) { + buffer.append(o.toString()); + } else if (o instanceof ExpressionList) { + ExpressionList list = (ExpressionList) o; + buffer.append(list.getExpressions() == null ? "()" : list.toString()); + } + } + buffer.append(")"); + } + } + + void setExpressionVisitor(ExpressionVisitor expressionVisitor) { + this.expressionVisitor = expressionVisitor; + } + + void setBuffer(StringBuilder buffer) { + this.buffer = buffer; + } +} diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/InsertDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/InsertDeParser.java index 15420915..672caea5 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/InsertDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/InsertDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -26,6 +14,7 @@ import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitor; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.expression.operators.relational.NamedExpressionList; import net.sf.jsqlparser.expression.operators.relational.ItemsListVisitor; import net.sf.jsqlparser.expression.operators.relational.MultiExpressionList; import net.sf.jsqlparser.schema.Column; @@ -35,28 +24,15 @@ import net.sf.jsqlparser.statement.select.SubSelect; import net.sf.jsqlparser.statement.select.WithItem; -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) an - * {@link net.sf.jsqlparser.statement.insert.Insert} - */ public class InsertDeParser implements ItemsListVisitor { - private StringBuilder buffer; + protected StringBuilder buffer; private ExpressionVisitor expressionVisitor; private SelectVisitor selectVisitor; public InsertDeParser() { } - /** - * @param expressionVisitor a {@link ExpressionVisitor} to de-parse - * {@link net.sf.jsqlparser.expression.Expression}s. It has to share the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param selectVisitor a {@link SelectVisitor} to de-parse - * {@link net.sf.jsqlparser.statement.select.Select}s. It has to share the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param buffer the buffer that will be filled with the insert - */ public InsertDeParser(ExpressionVisitor expressionVisitor, SelectVisitor selectVisitor, StringBuilder buffer) { this.buffer = buffer; this.expressionVisitor = expressionVisitor; @@ -81,7 +57,8 @@ public void deParse(Insert insert) { } buffer.append("INTO "); - buffer.append(insert.getTable().getFullyQualifiedName()); + buffer.append(insert.getTable().toString()); + if (insert.getColumns() != null) { buffer.append(" ("); for (Iterator iter = insert.getColumns().iterator(); iter.hasNext();) { @@ -116,6 +93,22 @@ public void deParse(Insert insert) { } } + if (insert.isUseSet()) { + buffer.append(" SET "); + for (int i = 0; i < insert.getSetColumns().size(); i++) { + Column column = insert.getSetColumns().get(i); + column.accept(expressionVisitor); + + buffer.append(" = "); + + Expression expression = insert.getSetExpressionList().get(i); + expression.accept(expressionVisitor); + if (i < insert.getSetColumns().size() - 1) { + buffer.append(", "); + } + } + } + if (insert.isUseDuplicate()) { buffer.append(" ON DUPLICATE KEY UPDATE "); for (int i = 0; i < insert.getDuplicateUpdateColumns().size(); i++) { @@ -157,6 +150,12 @@ public void visit(ExpressionList expressionList) { buffer.append(")"); } +// not used in a top-level insert statement + @Override + public void visit(NamedExpressionList NamedExpressionList) { + + } + @Override public void visit(MultiExpressionList multiExprList) { buffer.append(" VALUES "); diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/LimitDeparser.java b/src/main/java/net/sf/jsqlparser/util/deparser/LimitDeparser.java index 16320ca2..18cec1fe 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/LimitDeparser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/LimitDeparser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -25,7 +13,7 @@ public class LimitDeparser { - private final StringBuilder buffer; + protected final StringBuilder buffer; public LimitDeparser(StringBuilder buffer) { this.buffer = buffer; @@ -36,12 +24,16 @@ public void deParse(Limit limit) { if (limit.isLimitNull()) { buffer.append("NULL"); } else { - if (null != limit.getOffset()) { - buffer.append(limit.getOffset()).append(", "); - } + if (limit.isLimitAll()) { + buffer.append("ALL"); + } else { + if (null != limit.getOffset()) { + buffer.append(limit.getOffset()).append(", "); + } - if (null != limit.getRowCount()) { - buffer.append(limit.getRowCount()); + if (null != limit.getRowCount()) { + buffer.append(limit.getRowCount()); + } } } } diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/OrderByDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/OrderByDeParser.java index dca6fbc8..9bd4bc01 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/OrderByDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/OrderByDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -29,7 +17,7 @@ public class OrderByDeParser { - private StringBuilder buffer; + protected StringBuilder buffer; private ExpressionVisitor expressionVisitor; OrderByDeParser() { diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/ReplaceDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/ReplaceDeParser.java index 1ead53a1..c3929500 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/ReplaceDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/ReplaceDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -26,6 +14,7 @@ import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitor; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.expression.operators.relational.NamedExpressionList; import net.sf.jsqlparser.expression.operators.relational.ItemsListVisitor; import net.sf.jsqlparser.expression.operators.relational.MultiExpressionList; import net.sf.jsqlparser.schema.Column; @@ -33,28 +22,15 @@ import net.sf.jsqlparser.statement.select.SelectVisitor; import net.sf.jsqlparser.statement.select.SubSelect; -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) a - * {@link net.sf.jsqlparser.statement.replace.Replace} - */ public class ReplaceDeParser implements ItemsListVisitor { - private StringBuilder buffer; + protected StringBuilder buffer; private ExpressionVisitor expressionVisitor; private SelectVisitor selectVisitor; public ReplaceDeParser() { } - /** - * @param expressionVisitor a {@link ExpressionVisitor} to de-parse expressions. It has to share - * the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param selectVisitor a {@link SelectVisitor} to de-parse - * {@link net.sf.jsqlparser.statement.select.Select}s. It has to share the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param buffer the buffer that will be filled with the select - */ public ReplaceDeParser(ExpressionVisitor expressionVisitor, SelectVisitor selectVisitor, StringBuilder buffer) { this.buffer = buffer; this.expressionVisitor = expressionVisitor; @@ -125,6 +101,11 @@ public void visit(ExpressionList expressionList) { buffer.append(")"); } +// NamedExpressionList not use by top-level Replace + @Override + public void visit(NamedExpressionList namedExpressionList) { + } + @Override public void visit(SubSelect subSelect) { subSelect.getSelectBody().accept(selectVisitor); @@ -148,6 +129,20 @@ public void setSelectVisitor(SelectVisitor visitor) { @Override public void visit(MultiExpressionList multiExprList) { - throw new UnsupportedOperationException("Not supported yet."); + buffer.append("VALUES "); + for (Iterator it = multiExprList.getExprList().iterator(); it.hasNext();) { + buffer.append("("); + for (Iterator iter = it.next().getExpressions().iterator(); iter.hasNext();) { + Expression expression = iter.next(); + expression.accept(expressionVisitor); + if (iter.hasNext()) { + buffer.append(", "); + } + } + buffer.append(")"); + if (it.hasNext()) { + buffer.append(", "); + } + } } } diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java index 424b5d1e..829811ef 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java @@ -1,50 +1,29 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; +import java.util.Iterator; +import java.util.List; import net.sf.jsqlparser.expression.*; import net.sf.jsqlparser.schema.*; import net.sf.jsqlparser.statement.select.*; +import net.sf.jsqlparser.statement.values.ValuesStatement; -import java.util.*; - -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) a - * {@link net.sf.jsqlparser.statement.select.Select} - */ public class SelectDeParser implements SelectVisitor, SelectItemVisitor, FromItemVisitor, PivotVisitor { - private StringBuilder buffer = new StringBuilder(); + protected StringBuilder buffer = new StringBuilder(); private ExpressionVisitor expressionVisitor = new ExpressionVisitorAdapter(); public SelectDeParser() { } - /** - * @param expressionVisitor a {@link ExpressionVisitor} to de-parse expressions. It has to share - * the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param buffer the buffer that will be filled with the select - */ public SelectDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) { this.buffer = buffer; this.expressionVisitor = expressionVisitor; @@ -57,6 +36,10 @@ public void visit(PlainSelect plainSelect) { } buffer.append("SELECT "); + if (plainSelect.getMySqlHintStraightJoin()) { + buffer.append("STRAIGHT_JOIN "); + } + OracleHint hint = plainSelect.getOracleHint(); if (hint != null) { buffer.append(hint).append(" "); @@ -92,11 +75,20 @@ public void visit(PlainSelect plainSelect) { } } + Top top = plainSelect.getTop(); if (top != null) { buffer.append(top).append(" "); } + if (plainSelect.getMySqlSqlNoCache()) { + buffer.append("SQL_NO_CACHE").append(" "); + } + + if (plainSelect.getMySqlSqlCalcFoundRows()) { + buffer.append("SQL_CALC_FOUND_ROWS").append(" "); + } + for (Iterator iter = plainSelect.getSelectItems().iterator(); iter.hasNext();) { SelectItem selectItem = iter.next(); selectItem.accept(this); @@ -126,6 +118,11 @@ public void visit(PlainSelect plainSelect) { } } + if (plainSelect.getKsqlWindow() != null) { + buffer.append(" WINDOW "); + buffer.append(plainSelect.getKsqlWindow().toString()); + } + if (plainSelect.getWhere() != null) { buffer.append(" WHERE "); plainSelect.getWhere().accept(expressionVisitor); @@ -135,16 +132,9 @@ public void visit(PlainSelect plainSelect) { plainSelect.getOracleHierarchical().accept(expressionVisitor); } - if (plainSelect.getGroupByColumnReferences() != null) { - buffer.append(" GROUP BY "); - for (Iterator iter = plainSelect.getGroupByColumnReferences().iterator(); iter. - hasNext();) { - Expression columnReference = iter.next(); - columnReference.accept(expressionVisitor); - if (iter.hasNext()) { - buffer.append(", "); - } - } + if (plainSelect.getGroupBy() != null) { + buffer.append(" "); + new GroupByDeParser(expressionVisitor, buffer).deParse(plainSelect.getGroupBy()); } if (plainSelect.getHaving() != null) { @@ -175,6 +165,15 @@ public void visit(PlainSelect plainSelect) { // wait's toString will do the formatting for us buffer.append(plainSelect.getWait()); } + if (plainSelect.isNoWait()) { + buffer.append(" NOWAIT"); + } + } + if (plainSelect.getOptimizeFor() != null) { + deparseOptimizeFor(plainSelect.getOptimizeFor()); + } + if (plainSelect.getForXmlPath() != null) { + buffer.append(" FOR XML PATH(").append(plainSelect.getForXmlPath()).append(")"); } if (plainSelect.isUseBrackets()) { buffer.append(")"); @@ -192,7 +191,6 @@ public void visit(SelectExpressionItem selectExpressionItem) { if (selectExpressionItem.getAlias() != null) { buffer.append(selectExpressionItem.getAlias().toString()); } - } @Override @@ -211,26 +209,30 @@ public void visit(SubSelect subSelect) { } subSelect.getSelectBody().accept(this); buffer.append(")"); - Pivot pivot = subSelect.getPivot(); - if (pivot != null) { - pivot.accept(this); - } Alias alias = subSelect.getAlias(); if (alias != null) { buffer.append(alias.toString()); } + Pivot pivot = subSelect.getPivot(); + if (pivot != null) { + pivot.accept(this); + } } @Override public void visit(Table tableName) { buffer.append(tableName.getFullyQualifiedName()); + Alias alias = tableName.getAlias(); + if (alias != null) { + buffer.append(alias); + } Pivot pivot = tableName.getPivot(); if (pivot != null) { pivot.accept(this); } - Alias alias = tableName.getAlias(); - if (alias != null) { - buffer.append(alias); + UnPivot unpivot = tableName.getUnPivot(); + if (unpivot != null) { + unpivot.accept(this); } MySQLIndexHint indexHint = tableName.getIndexHint(); if (indexHint != null) { @@ -249,6 +251,24 @@ public void visit(Pivot pivot) { append(" IN ") .append(PlainSelect.getStringList(pivot.getInItems(), true, true)) .append(")"); + if (pivot.getAlias() != null) { + buffer.append(pivot.getAlias().toString()); + } + } + + @Override + public void visit(UnPivot unpivot) { + boolean showOptions = unpivot.getIncludeNullsSpecified(); + boolean includeNulls = unpivot.getIncludeNulls(); + List unpivotForClause = unpivot.getUnPivotForClause(); + buffer.append(" UNPIVOT") + .append(showOptions && includeNulls ? " INCLUDE NULLS" : "") + .append(showOptions && !includeNulls ? " EXCULDE NULLS" : "") + .append(" (") + .append(unpivot.getUnPivotClause()) + .append(" FOR ").append(PlainSelect.getStringList(unpivotForClause, true, unpivotForClause != null && unpivotForClause.size() > 1)) + .append(" IN ").append(PlainSelect.getStringList(unpivot.getUnPivotInClause(), true, true)) + .append(")"); } @Override @@ -273,9 +293,9 @@ public void visit(PivotXml pivot) { public void deparseOffset(Offset offset) { // OFFSET offset // or OFFSET offset (ROW | ROWS) - if (offset.isOffsetJdbcParameter()) { - buffer.append(" OFFSET ?"); - } else if (offset.getOffset() != 0) { + if (offset.getOffsetJdbcParameter() != null) { + buffer.append(" OFFSET ").append(offset.getOffsetJdbcParameter()); + } else { buffer.append(" OFFSET "); buffer.append(offset.getOffset()); } @@ -293,8 +313,8 @@ public void deparseFetch(Fetch fetch) { } else { buffer.append("NEXT "); } - if (fetch.isFetchJdbcParameter()) { - buffer.append("?"); + if (fetch.getFetchJdbcParameter() != null) { + buffer.append(fetch.getFetchJdbcParameter().toString()); } else { buffer.append(fetch.getRowCount()); } @@ -322,7 +342,9 @@ public void setExpressionVisitor(ExpressionVisitor visitor) { public void visit(SubJoin subjoin) { buffer.append("("); subjoin.getLeft().accept(this); - deparseJoin(subjoin.getJoin()); + for (Join join : subjoin.getJoinList()) { + deparseJoin(join); + } buffer.append(")"); if (subjoin.getPivot() != null) { @@ -331,7 +353,9 @@ public void visit(SubJoin subjoin) { } public void deparseJoin(Join join) { - if (join.isSimple()) { + if (join.isSimple() && join.isOuter()) { + buffer.append(", OUTER "); + } else if (join.isSimple()) { buffer.append(", "); } else { @@ -355,12 +379,22 @@ public void deparseJoin(Join join) { buffer.append(" SEMI"); } - buffer.append(" JOIN "); + if (join.isStraight()) { + buffer.append(" STRAIGHT_JOIN "); + } else if (join.isApply()) { + buffer.append(" APPLY "); + } else { + buffer.append(" JOIN "); + } } FromItem fromItem = join.getRightItem(); fromItem.accept(this); + if (join.isWindowJoin()) { + buffer.append(" WITHIN "); + buffer.append(join.getJoinWindow().toString()); + } if (join.getOnExpression() != null) { buffer.append(" ON "); join.getOnExpression().accept(expressionVisitor); @@ -443,4 +477,25 @@ public void visit(AllColumns allColumns) { public void visit(TableFunction tableFunction) { buffer.append(tableFunction.toString()); } + + @Override + public void visit(ParenthesisFromItem parenthesis) { + buffer.append("("); + parenthesis.getFromItem().accept(this); + buffer.append(")"); + if (parenthesis.getAlias() != null) { + buffer.append(parenthesis.getAlias().toString()); + } + } + + @Override + public void visit(ValuesStatement values) { + new ValuesStatementDeParser(expressionVisitor, buffer).deParse(values); + } + + private void deparseOptimizeFor(OptimizeFor optimizeFor) { + buffer.append(" OPTIMIZE FOR "); + buffer.append(optimizeFor.getRowCount()); + buffer.append(" ROWS"); + } } diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/SetStatementDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/SetStatementDeParser.java index 01578f97..01eb4cfb 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/SetStatementDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/SetStatementDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2015 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -26,15 +14,9 @@ public class SetStatementDeParser { - private StringBuilder buffer; + protected StringBuilder buffer; private ExpressionVisitor expressionVisitor; - /** - * @param expressionVisitor a {@link ExpressionVisitor} to de-parse expressions. It has to share - * the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param buffer the buffer that will be filled with the select - */ public SetStatementDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) { this.buffer = buffer; this.expressionVisitor = expressionVisitor; @@ -49,12 +31,20 @@ public void setBuffer(StringBuilder buffer) { } public void deParse(SetStatement set) { - buffer.append("SET ").append(set.getName()); - if (set.isUseEqual()) { - buffer.append(" ="); + buffer.append("SET "); + + for (int i = 0; i < set.getCount(); i++) { + if (i > 0) { + buffer.append(", "); + } + buffer.append(set.getName(i)); + if (set.isUseEqual(i)) { + buffer.append(" ="); + } + buffer.append(" "); + set.getExpression(i).accept(expressionVisitor); } - buffer.append(" "); - set.getExpression().accept(expressionVisitor); + } public ExpressionVisitor getExpressionVisitor() { diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/ShowColumnsStatementDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/ShowColumnsStatementDeParser.java new file mode 100644 index 00000000..d4ffc9ab --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/util/deparser/ShowColumnsStatementDeParser.java @@ -0,0 +1,33 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.util.deparser; + +import net.sf.jsqlparser.statement.ShowColumnsStatement; + +public class ShowColumnsStatementDeParser { + + protected StringBuilder buffer; + + public ShowColumnsStatementDeParser(StringBuilder buffer) { + this.buffer = buffer; + } + + public StringBuilder getBuffer() { + return buffer; + } + + public void setBuffer(StringBuilder buffer) { + this.buffer = buffer; + } + + public void deParse(ShowColumnsStatement show) { + buffer.append("SHOW COLUMNS FROM ").append(show.getTableName()); + } +} diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/ShowStatementDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/ShowStatementDeParser.java new file mode 100644 index 00000000..1b5653ee --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/util/deparser/ShowStatementDeParser.java @@ -0,0 +1,33 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.util.deparser; + +import net.sf.jsqlparser.statement.ShowStatement; + +public class ShowStatementDeParser { + + protected StringBuilder buffer; + + public ShowStatementDeParser(StringBuilder buffer) { + this.buffer = buffer; + } + + public StringBuilder getBuffer() { + return buffer; + } + + public void setBuffer(StringBuilder buffer) { + this.buffer = buffer; + } + + public void deParse(ShowStatement show) { + buffer.append("SHOW ").append(show.getName()); + } +} diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/StatementDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/StatementDeParser.java index 9b4379ef..2f879952 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/StatementDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/StatementDeParser.java @@ -1,33 +1,29 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; import java.util.Iterator; - +import net.sf.jsqlparser.statement.Block; import net.sf.jsqlparser.statement.Commit; +import net.sf.jsqlparser.statement.DeclareStatement; +import net.sf.jsqlparser.statement.DescribeStatement; +import net.sf.jsqlparser.statement.ExplainStatement; import net.sf.jsqlparser.statement.SetStatement; +import net.sf.jsqlparser.statement.ShowColumnsStatement; +import net.sf.jsqlparser.statement.ShowStatement; +import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.StatementVisitor; import net.sf.jsqlparser.statement.Statements; +import net.sf.jsqlparser.statement.UseStatement; import net.sf.jsqlparser.statement.alter.Alter; +import net.sf.jsqlparser.statement.comment.Comment; import net.sf.jsqlparser.statement.create.index.CreateIndex; import net.sf.jsqlparser.statement.create.table.CreateTable; import net.sf.jsqlparser.statement.create.view.AlterView; @@ -43,13 +39,15 @@ import net.sf.jsqlparser.statement.truncate.Truncate; import net.sf.jsqlparser.statement.update.Update; import net.sf.jsqlparser.statement.upsert.Upsert; +import net.sf.jsqlparser.statement.values.ValuesStatement; public class StatementDeParser implements StatementVisitor { + private ExpressionDeParser expressionDeParser; private SelectDeParser selectDeParser; - private StringBuilder buffer; + protected StringBuilder buffer; public StatementDeParser(StringBuilder buffer) { this(new ExpressionDeParser(), new SelectDeParser(), buffer); @@ -69,7 +67,7 @@ public void visit(CreateIndex createIndex) { @Override public void visit(CreateTable createTable) { - CreateTableDeParser createTableDeParser = new CreateTableDeParser(buffer); + CreateTableDeParser createTableDeParser = new CreateTableDeParser(this, buffer); createTableDeParser.deParse(createTable); } @@ -143,6 +141,11 @@ public void visit(Select select) { @Override public void visit(Truncate truncate) { + buffer.append("TRUNCATE TABLE "); + buffer.append(truncate.getTable()); + if (truncate.getCascade()) { + buffer.append(" CASCADE"); + } } @Override @@ -200,7 +203,7 @@ public void visit(Merge merge) { //TODO implementation of a deparser buffer.append(merge.toString()); } - + @Override public void visit(Commit commit) { buffer.append(commit.toString()); @@ -215,4 +218,60 @@ public void visit(Upsert upsert) { UpsertDeParser upsertDeParser = new UpsertDeParser(expressionDeParser, selectDeParser, buffer); upsertDeParser.deParse(upsert); } + + @Override + public void visit(UseStatement use) { + new UseStatementDeParser(buffer).deParse(use); + } + + @Override + public void visit(ShowColumnsStatement show) { + new ShowColumnsStatementDeParser(buffer).deParse(show); + } + + @Override + public void visit(Block block) { + buffer.append("BEGIN\n"); + if (block.getStatements() != null) { + for (Statement stmt : block.getStatements().getStatements()) { + stmt.accept(this); + buffer.append(";\n"); + } + } + buffer.append("END"); + } + + @Override + public void visit(Comment comment) { + buffer.append(comment.toString()); + } + + @Override + public void visit(ValuesStatement values) { + expressionDeParser.setBuffer(buffer); + new ValuesStatementDeParser(expressionDeParser, buffer).deParse(values); + } + + @Override + public void visit(DescribeStatement describe) { + buffer.append("DESCRIBE "); + buffer.append(describe.getTable()); + } + + @Override + public void visit(ExplainStatement explain) { + buffer.append("EXPLAIN "); + explain.getStatement().accept(this); + } + + @Override + public void visit(ShowStatement show) { + new ShowStatementDeParser(buffer).deParse(show); + } + + @Override + public void visit(DeclareStatement declare) { + expressionDeParser.setBuffer(buffer); + new DeclareStatementDeParser(expressionDeParser, buffer).deParse(declare); + } } diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/UpdateDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/UpdateDeParser.java index cbdd7dca..fb154103 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/UpdateDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/UpdateDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -28,7 +16,6 @@ import net.sf.jsqlparser.expression.ExpressionVisitorAdapter; import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.statement.select.Join; -import net.sf.jsqlparser.statement.select.PlainSelect; import net.sf.jsqlparser.statement.update.Update; import net.sf.jsqlparser.statement.select.Select; import net.sf.jsqlparser.statement.select.SelectVisitor; @@ -37,28 +24,15 @@ import net.sf.jsqlparser.statement.select.SelectExpressionItem; import net.sf.jsqlparser.statement.select.SelectVisitorAdapter; -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) an - * {@link net.sf.jsqlparser.statement.update.Update} - */ public class UpdateDeParser implements OrderByVisitor { - private StringBuilder buffer = new StringBuilder(); + protected StringBuilder buffer = new StringBuilder(); private ExpressionVisitor expressionVisitor = new ExpressionVisitorAdapter(); private SelectVisitor selectVisitor = new SelectVisitorAdapter(); public UpdateDeParser() { } - /** - * @param expressionVisitor a {@link ExpressionVisitor} to de-parse expressions. It has to share - * the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param selectVisitor a {@link SelectVisitor} to de-parse - * {@link net.sf.jsqlparser.statement.select.Select}s. It has to share the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param buffer the buffer that will be filled with the select - */ public UpdateDeParser(ExpressionVisitor expressionVisitor, SelectVisitor selectVisitor, StringBuilder buffer) { this.buffer = buffer; this.expressionVisitor = expressionVisitor; @@ -74,8 +48,17 @@ public void setBuffer(StringBuilder buffer) { } public void deParse(Update update) { - buffer.append("UPDATE ").append(PlainSelect.getStringList(update.getTables(), true, false)). - append(" SET "); + buffer.append("UPDATE ").append(update.getTable()); + if (update.getStartJoins() != null) { + for (Join join : update.getStartJoins()) { + if (join.isSimple()) { + buffer.append(", ").append(join); + } else { + buffer.append(" ").append(join); + } + } + } + buffer.append(" SET "); if (!update.isUseSelect()) { for (int i = 0; i < update.getColumns().size(); i++) { diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/UpsertDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/UpsertDeParser.java index 6d40d2d4..6c9b3ed3 100644 --- a/src/main/java/net/sf/jsqlparser/util/deparser/UpsertDeParser.java +++ b/src/main/java/net/sf/jsqlparser/util/deparser/UpsertDeParser.java @@ -1,22 +1,10 @@ -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2017 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ package net.sf.jsqlparser.util.deparser; @@ -26,6 +14,7 @@ import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.ExpressionVisitor; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.expression.operators.relational.NamedExpressionList; import net.sf.jsqlparser.expression.operators.relational.ItemsListVisitor; import net.sf.jsqlparser.expression.operators.relational.MultiExpressionList; import net.sf.jsqlparser.schema.Column; @@ -34,28 +23,12 @@ import net.sf.jsqlparser.statement.select.WithItem; import net.sf.jsqlparser.statement.upsert.Upsert; -/** - * A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) - * @author messfish - * - */ public class UpsertDeParser implements ItemsListVisitor { - private StringBuilder buffer; + protected StringBuilder buffer; private ExpressionVisitor expressionVisitor; private SelectVisitor selectVisitor; - /** - * Constructor: this constructor is used to assign the values coming from the - * arguments to their global values. - * @param expressionVisitor a {@link ExpressionVisitor} to de-parse - * {@link net.sf.jsqlparser.expression.Expression}s. It has to share the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param selectVisitor a {@link SelectVisitor} to de-parse - * {@link net.sf.jsqlparser.statement.select.Select}s. It has to share the same
- * StringBuilder (buffer parameter) as this object in order to work - * @param buffer the buffer that will be filled with the insert - */ public UpsertDeParser(ExpressionVisitor expressionVisitor, SelectVisitor selectVisitor, StringBuilder buffer) { this.buffer = buffer; this.expressionVisitor = expressionVisitor; @@ -149,6 +122,11 @@ public void visit(ExpressionList expressionList) { buffer.append(")"); } +// not used by top-level upsert + @Override + public void visit(NamedExpressionList namedExpressionList) { + } + @Override public void visit(MultiExpressionList multiExprList) { buffer.append(" VALUES "); diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/UseStatementDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/UseStatementDeParser.java new file mode 100644 index 00000000..e28bcae1 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/util/deparser/UseStatementDeParser.java @@ -0,0 +1,33 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.util.deparser; + +import net.sf.jsqlparser.statement.UseStatement; + +public class UseStatementDeParser { + + protected StringBuilder buffer; + + public UseStatementDeParser(StringBuilder buffer) { + this.buffer = buffer; + } + + public StringBuilder getBuffer() { + return buffer; + } + + public void setBuffer(StringBuilder buffer) { + this.buffer = buffer; + } + + public void deParse(UseStatement set) { + buffer.append("USE ").append(set.getName()); + } +} diff --git a/src/main/java/net/sf/jsqlparser/util/deparser/ValuesStatementDeParser.java b/src/main/java/net/sf/jsqlparser/util/deparser/ValuesStatementDeParser.java new file mode 100644 index 00000000..b589e821 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/util/deparser/ValuesStatementDeParser.java @@ -0,0 +1,47 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.util.deparser; + +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.ExpressionVisitor; +import net.sf.jsqlparser.statement.values.ValuesStatement; + +public class ValuesStatementDeParser { + + protected StringBuilder buffer; + private final ExpressionVisitor expressionVisitor; + + public ValuesStatementDeParser(ExpressionVisitor expressionVisitor, StringBuilder buffer) { + this.buffer = buffer; + this.expressionVisitor = expressionVisitor; + } + + public StringBuilder getBuffer() { + return buffer; + } + + public void setBuffer(StringBuilder buffer) { + this.buffer = buffer; + } + + public void deParse(ValuesStatement values) { + boolean first = true; + buffer.append("VALUES ("); + for (Expression expr : values.getExpressions()) { + if (first) { + first = false; + } else { + buffer.append(", "); + } + expr.accept(expressionVisitor); + } + buffer.append(")"); + } +} diff --git a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt index 5a60c39b..070356d7 100644 --- a/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt +++ b/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt @@ -2,61 +2,31 @@ * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2014 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ options{ - IGNORE_CASE=true ; - STATIC=false; - DEBUG_PARSER=false; - DEBUG_LOOKAHEAD=false; - DEBUG_TOKEN_MANAGER=false; - CACHE_TOKENS=false; -// FORCE_LA_CHECK=true; - UNICODE_INPUT=true; - JAVA_TEMPLATE_TYPE = "classic"; - JDK_VERSION = "1.6"; - TOKEN_EXTENDS ="BaseToken"; - COMMON_TOKEN_ACTION=true; + IGNORE_CASE = true ; + STATIC = false; + DEBUG_PARSER = false; + DEBUG_LOOKAHEAD = false; + DEBUG_TOKEN_MANAGER = false; + CACHE_TOKENS = false; +// FORCE_LA_CHECK = true; + UNICODE_INPUT = true; + JAVA_TEMPLATE_TYPE = "modern"; + JDK_VERSION = "1.7"; + TOKEN_EXTENDS = "BaseToken"; + COMMON_TOKEN_ACTION = true; + NODE_DEFAULT_VOID = true; + TRACK_TOKENS = true; + VISITOR = true; } PARSER_BEGIN(CCJSqlParser) -/* - * #%L - * JSQLParser library - * %% - * Copyright (C) 2004 - 2014 JSQLParser - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . - * #L% - */ package net.sf.jsqlparser.parser; @@ -67,6 +37,7 @@ import net.sf.jsqlparser.expression.operators.relational.*; import net.sf.jsqlparser.schema.*; import net.sf.jsqlparser.statement.*; import net.sf.jsqlparser.statement.alter.*; +import net.sf.jsqlparser.statement.comment.*; import net.sf.jsqlparser.statement.create.index.*; import net.sf.jsqlparser.statement.create.table.*; import net.sf.jsqlparser.statement.create.view.*; @@ -80,6 +51,7 @@ import net.sf.jsqlparser.statement.truncate.*; import net.sf.jsqlparser.statement.update.*; import net.sf.jsqlparser.statement.upsert.*; import net.sf.jsqlparser.statement.merge.*; +import net.sf.jsqlparser.statement.values.*; import java.util.*; /** @@ -90,6 +62,11 @@ public class CCJSqlParser { boolean errorRecovery = false; List parseErrors = new ArrayList(); + public CCJSqlParser withSquareBracketQuotation(boolean allowSquareBracketQuotation) { + token_source.allowSquareBracketQuotation = allowSquareBracketQuotation; + return this; + } + private void linkAST(ASTNodeAccess access, SimpleNode node) { access.setASTNode(node); node.jjtSetValue(access); @@ -111,6 +88,8 @@ public class CCJSqlParser { PARSER_END(CCJSqlParser) TOKEN_MGR_DECLS : { + public boolean allowSquareBracketQuotation = false; + public void CommonTokenAction(Token t) { t.absoluteBegin = getCurrentTokenAbsolutePosition(); @@ -132,159 +111,213 @@ SKIP: TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */ { - -| -| -| -| -| -| + +| +| +| +| | +| | +| | -| -| -| +| +| | -| -| -| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| | -| -| -| -| +| +| +| +| +| +| | -| -| -| -| -| -| -| -| +| | -| -| -| -| -| -| -| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| | -| -| -| -| +| +| +| +| +| | -| +| +| +| +| +| +| +| +| +| +| +| | | -| -| -| -| -| -| -| -| -| -| -| +| | -| -| -| -| -| -| -| -| -| -| -| | -| -| -| -| -| -| -| -| | -| -| -| -| -| -| -| -| -| -| -| -| -| -| -| -| -| -| +| +| +| +| +| +| +| | -| -| -| -| -| -| -| -| -| -| -| -| -| -| +| +| +| +| +| +| +| +| +| +| +| +| +| | +| +| +| +| +| +| +| +| +| +| +| | -| -| -| -| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| | -| -| -| -| -| -| -| -| +| +| +| +| | -| -| -| -| -| -| -| +| +| +| +| +| | -| -| -| -| -| +| +| +| +| +| +| +| +| +| +| +| +| | -| -| -| -| -| -| -| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| | -| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| +| } TOKEN : /* Stuff */ @@ -297,7 +330,8 @@ TOKEN : /* Operators */ " ()* "="> | )* "="> | )* ">"> -| )* "="> +| )* "|"> } TOKEN : /* Date/Time with time zones */ @@ -328,23 +362,30 @@ SPECIAL_TOKEN: TOKEN: { ()*> -| <#LETTER: ["$","A"-"Z","_","a"-"z","\u00a2"-"\u00a5","\u00aa","\u00b5","\u00ba","\u00c0"-"\u00d6","\u00d8"-"\u00f6","\u00f8"-"\u021f","\u0222"-"\u0233","\u0250"-"\u02ad","\u02b0"-"\u02b8","\u02bb"-"\u02c1","\u02d0"-"\u02d1","\u02e0"-"\u02e4","\u02ee","\u037a","\u0386","\u0388"-"\u038a","\u038c","\u038e"-"\u03a1","\u03a3"-"\u03ce","\u03d0"-"\u03d7","\u03da"-"\u03f3","\u0400"-"\u0481","\u048c"-"\u04c4","\u04c7"-"\u04c8","\u04cb"-"\u04cc","\u04d0"-"\u04f5","\u04f8"-"\u04f9","\u0531"-"\u0556","\u0559","\u0561"-"\u0587","\u05d0"-"\u05ea","\u05f0"-"\u05f2","\u0621"-"\u063a","\u0640"-"\u064a","\u0671"-"\u06d3","\u06d5","\u06e5"-"\u06e6","\u06fa"-"\u06fc","\u0710","\u0712"-"\u072c","\u0780"-"\u07a5","\u0905"-"\u0939","\u093d","\u0950","\u0958"-"\u0961","\u0985"-"\u098c","\u098f"-"\u0990","\u0993"-"\u09a8","\u09aa"-"\u09b0","\u09b2","\u09b6"-"\u09b9","\u09dc"-"\u09dd","\u09df"-"\u09e1","\u09f0"-"\u09f3","\u0a05"-"\u0a0a","\u0a0f"-"\u0a10","\u0a13"-"\u0a28","\u0a2a"-"\u0a30","\u0a32"-"\u0a33","\u0a35"-"\u0a36","\u0a38"-"\u0a39","\u0a59"-"\u0a5c","\u0a5e","\u0a72"-"\u0a74","\u0a85"-"\u0a8b","\u0a8d","\u0a8f"-"\u0a91","\u0a93"-"\u0aa8","\u0aaa"-"\u0ab0","\u0ab2"-"\u0ab3","\u0ab5"-"\u0ab9","\u0abd","\u0ad0","\u0ae0","\u0b05"-"\u0b0c","\u0b0f"-"\u0b10","\u0b13"-"\u0b28","\u0b2a"-"\u0b30","\u0b32"-"\u0b33","\u0b36"-"\u0b39","\u0b3d","\u0b5c"-"\u0b5d","\u0b5f"-"\u0b61","\u0b85"-"\u0b8a","\u0b8e"-"\u0b90","\u0b92"-"\u0b95","\u0b99"-"\u0b9a","\u0b9c","\u0b9e"-"\u0b9f","\u0ba3"-"\u0ba4","\u0ba8"-"\u0baa","\u0bae"-"\u0bb5","\u0bb7"-"\u0bb9","\u0c05"-"\u0c0c","\u0c0e"-"\u0c10","\u0c12"-"\u0c28","\u0c2a"-"\u0c33","\u0c35"-"\u0c39","\u0c60"-"\u0c61","\u0c85"-"\u0c8c","\u0c8e"-"\u0c90","\u0c92"-"\u0ca8","\u0caa"-"\u0cb3","\u0cb5"-"\u0cb9","\u0cde","\u0ce0"-"\u0ce1","\u0d05"-"\u0d0c","\u0d0e"-"\u0d10","\u0d12"-"\u0d28","\u0d2a"-"\u0d39","\u0d60"-"\u0d61","\u0d85"-"\u0d96","\u0d9a"-"\u0db1","\u0db3"-"\u0dbb","\u0dbd","\u0dc0"-"\u0dc6","\u0e01"-"\u0e30","\u0e32"-"\u0e33","\u0e3f"-"\u0e46","\u0e81"-"\u0e82","\u0e84","\u0e87"-"\u0e88","\u0e8a","\u0e8d","\u0e94"-"\u0e97","\u0e99"-"\u0e9f","\u0ea1"-"\u0ea3","\u0ea5","\u0ea7","\u0eaa"-"\u0eab","\u0ead"-"\u0eb0","\u0eb2"-"\u0eb3","\u0ebd","\u0ec0"-"\u0ec4","\u0ec6","\u0edc"-"\u0edd","\u0f00","\u0f40"-"\u0f47","\u0f49"-"\u0f6a","\u0f88"-"\u0f8b","\u1000"-"\u1021","\u1023"-"\u1027","\u1029"-"\u102a","\u1050"-"\u1055","\u10a0"-"\u10c5","\u10d0"-"\u10f6","\u1100"-"\u1159","\u115f"-"\u11a2","\u11a8"-"\u11f9","\u1200"-"\u1206","\u1208"-"\u1246","\u1248","\u124a"-"\u124d","\u1250"-"\u1256","\u1258","\u125a"-"\u125d","\u1260"-"\u1286","\u1288","\u128a"-"\u128d","\u1290"-"\u12ae","\u12b0","\u12b2"-"\u12b5","\u12b8"-"\u12be","\u12c0","\u12c2"-"\u12c5","\u12c8"-"\u12ce","\u12d0"-"\u12d6","\u12d8"-"\u12ee","\u12f0"-"\u130e","\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346","\u1348"-"\u135a","\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676","\u1681"-"\u169a","\u16a0"-"\u16ea","\u1780"-"\u17b3","\u17db","\u1820"-"\u1877","\u1880"-"\u18a8","\u1e00"-"\u1e9b","\u1ea0"-"\u1ef9","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d","\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4","\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3","\u1fd6"-"\u1fdb","\u1fe0"-"\u1fec","\u1ff2"-"\u1ff4","\u1ff6"-"\u1ffc","\u203f"-"\u2040","\u207f","\u20a0"-"\u20af","\u2102","\u2107","\u210a"-"\u2113","\u2115","\u2119"-"\u211d","\u2124","\u2126","\u2128","\u212a"-"\u212d","\u212f"-"\u2131","\u2133"-"\u2139","\u2160"-"\u2183","\u3005"-"\u3007","\u3021"-"\u3029","\u3031"-"\u3035","\u3038"-"\u303a","\u3041"-"\u3094","\u309d"-"\u309e","\u30a1"-"\u30fe","\u3105"-"\u312c","\u3131"-"\u318e","\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c","\uac00"-"\ud7a3","\uf900"-"\ufa2d","\ufb00"-"\ufb06","\ufb13"-"\ufb17","\ufb1d","\ufb1f"-"\ufb28","\ufb2a"-"\ufb36","\ufb38"-"\ufb3c","\ufb3e","\ufb40"-"\ufb41","\ufb43"-"\ufb44","\ufb46"-"\ufbb1","\ufbd3"-"\ufd3d","\ufd50"-"\ufd8f","\ufd92"-"\ufdc7","\ufdf0"-"\ufdfb","\ufe33"-"\ufe34","\ufe4d"-"\ufe4f","\ufe69","\ufe70"-"\ufe72","\ufe74","\ufe76"-"\ufefc","\uff04","\uff21"-"\uff3a","\uff3f","\uff41"-"\uff5a","\uff65"-"\uffbe","\uffc2"-"\uffc7","\uffca"-"\uffcf","\uffd2"-"\uffd7","\uffda"-"\uffdc","\uffe0"-"\uffe1","\uffe5"-"\uffe6"]> +| <#LETTER: ["$","A"-"Z","_","#","a"-"z","\u00a2"-"\u00a5","\u00aa","\u00b5","\u00ba","\u00c0"-"\u00d6","\u00d8"-"\u00f6","\u00f8"-"\u021f","\u0222"-"\u0233","\u0250"-"\u02ad","\u02b0"-"\u02b8","\u02bb"-"\u02c1","\u02d0"-"\u02d1","\u02e0"-"\u02e4","\u02ee","\u037a","\u0386","\u0388"-"\u038a","\u038c","\u038e"-"\u03a1","\u03a3"-"\u03ce","\u03d0"-"\u03d7","\u03da"-"\u03f3","\u0400"-"\u0481","\u048c"-"\u04c4","\u04c7"-"\u04c8","\u04cb"-"\u04cc","\u04d0"-"\u04f5","\u04f8"-"\u04f9","\u0531"-"\u0556","\u0559","\u0561"-"\u0587","\u05d0"-"\u05ea","\u05f0"-"\u05f2","\u0621"-"\u063a","\u0640"-"\u064a","\u0671"-"\u06d3","\u06d5","\u06e5"-"\u06e6","\u06fa"-"\u06fc","\u0710","\u0712"-"\u072c","\u0780"-"\u07a5","\u0905"-"\u0939","\u093d","\u0950","\u0958"-"\u0961","\u0985"-"\u098c","\u098f"-"\u0990","\u0993"-"\u09a8","\u09aa"-"\u09b0","\u09b2","\u09b6"-"\u09b9","\u09dc"-"\u09dd","\u09df"-"\u09e1","\u09f0"-"\u09f3","\u0a05"-"\u0a0a","\u0a0f"-"\u0a10","\u0a13"-"\u0a28","\u0a2a"-"\u0a30","\u0a32"-"\u0a33","\u0a35"-"\u0a36","\u0a38"-"\u0a39","\u0a59"-"\u0a5c","\u0a5e","\u0a72"-"\u0a74","\u0a85"-"\u0a8b","\u0a8d","\u0a8f"-"\u0a91","\u0a93"-"\u0aa8","\u0aaa"-"\u0ab0","\u0ab2"-"\u0ab3","\u0ab5"-"\u0ab9","\u0abd","\u0ad0","\u0ae0","\u0b05"-"\u0b0c","\u0b0f"-"\u0b10","\u0b13"-"\u0b28","\u0b2a"-"\u0b30","\u0b32"-"\u0b33","\u0b36"-"\u0b39","\u0b3d","\u0b5c"-"\u0b5d","\u0b5f"-"\u0b61","\u0b85"-"\u0b8a","\u0b8e"-"\u0b90","\u0b92"-"\u0b95","\u0b99"-"\u0b9a","\u0b9c","\u0b9e"-"\u0b9f","\u0ba3"-"\u0ba4","\u0ba8"-"\u0baa","\u0bae"-"\u0bb5","\u0bb7"-"\u0bb9","\u0c05"-"\u0c0c","\u0c0e"-"\u0c10","\u0c12"-"\u0c28","\u0c2a"-"\u0c33","\u0c35"-"\u0c39","\u0c60"-"\u0c61","\u0c85"-"\u0c8c","\u0c8e"-"\u0c90","\u0c92"-"\u0ca8","\u0caa"-"\u0cb3","\u0cb5"-"\u0cb9","\u0cde","\u0ce0"-"\u0ce1","\u0d05"-"\u0d0c","\u0d0e"-"\u0d10","\u0d12"-"\u0d28","\u0d2a"-"\u0d39","\u0d60"-"\u0d61","\u0d85"-"\u0d96","\u0d9a"-"\u0db1","\u0db3"-"\u0dbb","\u0dbd","\u0dc0"-"\u0dc6","\u0e01"-"\u0e30","\u0e32"-"\u0e33","\u0e3f"-"\u0e46","\u0e81"-"\u0e82","\u0e84","\u0e87"-"\u0e88","\u0e8a","\u0e8d","\u0e94"-"\u0e97","\u0e99"-"\u0e9f","\u0ea1"-"\u0ea3","\u0ea5","\u0ea7","\u0eaa"-"\u0eab","\u0ead"-"\u0eb0","\u0eb2"-"\u0eb3","\u0ebd","\u0ec0"-"\u0ec4","\u0ec6","\u0edc"-"\u0edd","\u0f00","\u0f40"-"\u0f47","\u0f49"-"\u0f6a","\u0f88"-"\u0f8b","\u1000"-"\u1021","\u1023"-"\u1027","\u1029"-"\u102a","\u1050"-"\u1055","\u10a0"-"\u10c5","\u10d0"-"\u10f6","\u1100"-"\u1159","\u115f"-"\u11a2","\u11a8"-"\u11f9","\u1200"-"\u1206","\u1208"-"\u1246","\u1248","\u124a"-"\u124d","\u1250"-"\u1256","\u1258","\u125a"-"\u125d","\u1260"-"\u1286","\u1288","\u128a"-"\u128d","\u1290"-"\u12ae","\u12b0","\u12b2"-"\u12b5","\u12b8"-"\u12be","\u12c0","\u12c2"-"\u12c5","\u12c8"-"\u12ce","\u12d0"-"\u12d6","\u12d8"-"\u12ee","\u12f0"-"\u130e","\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346","\u1348"-"\u135a","\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676","\u1681"-"\u169a","\u16a0"-"\u16ea","\u1780"-"\u17b3","\u17db","\u1820"-"\u1877","\u1880"-"\u18a8","\u1e00"-"\u1e9b","\u1ea0"-"\u1ef9","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d","\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4","\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3","\u1fd6"-"\u1fdb","\u1fe0"-"\u1fec","\u1ff2"-"\u1ff4","\u1ff6"-"\u1ffc","\u203f"-"\u2040","\u207f","\u20a0"-"\u20af","\u2102","\u2107","\u210a"-"\u2113","\u2115","\u2119"-"\u211d","\u2124","\u2126","\u2128","\u212a"-"\u212d","\u212f"-"\u2131","\u2133"-"\u2139","\u2160"-"\u2183","\u3005"-"\u3007","\u3021"-"\u3029","\u3031"-"\u3035","\u3038"-"\u303a","\u3041"-"\u3094","\u309d"-"\u309e","\u30a1"-"\u30fe","\u3105"-"\u312c","\u3131"-"\u318e","\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c","\uac00"-"\ud7a3","\uf900"-"\ufa2d","\ufb00"-"\ufb06","\ufb13"-"\ufb17","\ufb1d","\ufb1f"-"\ufb28","\ufb2a"-"\ufb36","\ufb38"-"\ufb3c","\ufb3e","\ufb40"-"\ufb41","\ufb43"-"\ufb44","\ufb46"-"\ufbb1","\ufbd3"-"\ufd3d","\ufd50"-"\ufd8f","\ufd92"-"\ufdc7","\ufdf0"-"\ufdfb","\ufe33"-"\ufe34","\ufe4d"-"\ufe4f","\ufe69","\ufe70"-"\ufe72","\ufe74","\ufe76"-"\ufefc","\uff04","\uff21"-"\uff3a","\uff3f","\uff41"-"\uff5a","\uff65"-"\uffbe","\uffc2"-"\uffc7","\uffca"-"\uffcf","\uffd2"-"\uffd7","\uffda"-"\uffdc","\uffe0"-"\uffe1","\uffe5"-"\uffe6"]> | <#PART_LETTER: ["\u0000"-"\b","\u000e"-"\u001b","$","#","@","0"-"9","A"-"Z","_","a"-"z","\u007f"-"\u009f","\u00a2"-"\u00a5","\u00aa","\u00b5","\u00ba","\u00c0"-"\u00d6","\u00d8"-"\u00f6","\u00f8"-"\u021f","\u0222"-"\u0233","\u0250"-"\u02ad","\u02b0"-"\u02b8","\u02bb"-"\u02c1","\u02d0"-"\u02d1","\u02e0"-"\u02e4","\u02ee","\u0300"-"\u034e","\u0360"-"\u0362","\u037a","\u0386","\u0388"-"\u038a","\u038c","\u038e"-"\u03a1","\u03a3"-"\u03ce","\u03d0"-"\u03d7","\u03da"-"\u03f3","\u0400"-"\u0481","\u0483"-"\u0486","\u048c"-"\u04c4","\u04c7"-"\u04c8","\u04cb"-"\u04cc","\u04d0"-"\u04f5","\u04f8"-"\u04f9","\u0531"-"\u0556","\u0559","\u0561"-"\u0587","\u0591"-"\u05a1","\u05a3"-"\u05b9","\u05bb"-"\u05bd","\u05bf","\u05c1"-"\u05c2","\u05c4","\u05d0"-"\u05ea","\u05f0"-"\u05f2","\u0621"-"\u063a","\u0640"-"\u0655","\u0660"-"\u0669","\u0670"-"\u06d3","\u06d5"-"\u06dc","\u06df"-"\u06e8","\u06ea"-"\u06ed","\u06f0"-"\u06fc","\u070f"-"\u072c","\u0730"-"\u074a","\u0780"-"\u07b0","\u0901"-"\u0903","\u0905"-"\u0939","\u093c"-"\u094d","\u0950"-"\u0954","\u0958"-"\u0963","\u0966"-"\u096f","\u0981"-"\u0983","\u0985"-"\u098c","\u098f"-"\u0990","\u0993"-"\u09a8","\u09aa"-"\u09b0","\u09b2","\u09b6"-"\u09b9","\u09bc","\u09be"-"\u09c4","\u09c7"-"\u09c8","\u09cb"-"\u09cd","\u09d7","\u09dc"-"\u09dd","\u09df"-"\u09e3","\u09e6"-"\u09f3","\u0a02","\u0a05"-"\u0a0a","\u0a0f"-"\u0a10","\u0a13"-"\u0a28","\u0a2a"-"\u0a30","\u0a32"-"\u0a33","\u0a35"-"\u0a36","\u0a38"-"\u0a39","\u0a3c","\u0a3e"-"\u0a42","\u0a47"-"\u0a48","\u0a4b"-"\u0a4d","\u0a59"-"\u0a5c","\u0a5e","\u0a66"-"\u0a74","\u0a81"-"\u0a83","\u0a85"-"\u0a8b","\u0a8d","\u0a8f"-"\u0a91","\u0a93"-"\u0aa8","\u0aaa"-"\u0ab0","\u0ab2"-"\u0ab3","\u0ab5"-"\u0ab9","\u0abc"-"\u0ac5","\u0ac7"-"\u0ac9","\u0acb"-"\u0acd","\u0ad0","\u0ae0","\u0ae6"-"\u0aef","\u0b01"-"\u0b03","\u0b05"-"\u0b0c","\u0b0f"-"\u0b10","\u0b13"-"\u0b28","\u0b2a"-"\u0b30","\u0b32"-"\u0b33","\u0b36"-"\u0b39","\u0b3c"-"\u0b43","\u0b47"-"\u0b48","\u0b4b"-"\u0b4d","\u0b56"-"\u0b57","\u0b5c"-"\u0b5d","\u0b5f"-"\u0b61","\u0b66"-"\u0b6f","\u0b82"-"\u0b83","\u0b85"-"\u0b8a","\u0b8e"-"\u0b90","\u0b92"-"\u0b95","\u0b99"-"\u0b9a","\u0b9c","\u0b9e"-"\u0b9f","\u0ba3"-"\u0ba4","\u0ba8"-"\u0baa","\u0bae"-"\u0bb5","\u0bb7"-"\u0bb9","\u0bbe"-"\u0bc2","\u0bc6"-"\u0bc8","\u0bca"-"\u0bcd","\u0bd7","\u0be7"-"\u0bef","\u0c01"-"\u0c03","\u0c05"-"\u0c0c","\u0c0e"-"\u0c10","\u0c12"-"\u0c28","\u0c2a"-"\u0c33","\u0c35"-"\u0c39","\u0c3e"-"\u0c44","\u0c46"-"\u0c48","\u0c4a"-"\u0c4d","\u0c55"-"\u0c56","\u0c60"-"\u0c61","\u0c66"-"\u0c6f","\u0c82"-"\u0c83","\u0c85"-"\u0c8c","\u0c8e"-"\u0c90","\u0c92"-"\u0ca8","\u0caa"-"\u0cb3","\u0cb5"-"\u0cb9","\u0cbe"-"\u0cc4","\u0cc6"-"\u0cc8","\u0cca"-"\u0ccd","\u0cd5"-"\u0cd6","\u0cde","\u0ce0"-"\u0ce1","\u0ce6"-"\u0cef","\u0d02"-"\u0d03","\u0d05"-"\u0d0c","\u0d0e"-"\u0d10","\u0d12"-"\u0d28","\u0d2a"-"\u0d39","\u0d3e"-"\u0d43","\u0d46"-"\u0d48","\u0d4a"-"\u0d4d","\u0d57","\u0d60"-"\u0d61","\u0d66"-"\u0d6f","\u0d82"-"\u0d83","\u0d85"-"\u0d96","\u0d9a"-"\u0db1","\u0db3"-"\u0dbb","\u0dbd","\u0dc0"-"\u0dc6","\u0dca","\u0dcf"-"\u0dd4","\u0dd6","\u0dd8"-"\u0ddf","\u0df2"-"\u0df3","\u0e01"-"\u0e3a","\u0e3f"-"\u0e4e","\u0e50"-"\u0e59","\u0e81"-"\u0e82","\u0e84","\u0e87"-"\u0e88","\u0e8a","\u0e8d","\u0e94"-"\u0e97","\u0e99"-"\u0e9f","\u0ea1"-"\u0ea3","\u0ea5","\u0ea7","\u0eaa"-"\u0eab","\u0ead"-"\u0eb9","\u0ebb"-"\u0ebd","\u0ec0"-"\u0ec4","\u0ec6","\u0ec8"-"\u0ecd","\u0ed0"-"\u0ed9","\u0edc"-"\u0edd","\u0f00","\u0f18"-"\u0f19","\u0f20"-"\u0f29","\u0f35","\u0f37","\u0f39","\u0f3e"-"\u0f47","\u0f49"-"\u0f6a","\u0f71"-"\u0f84","\u0f86"-"\u0f8b","\u0f90"-"\u0f97","\u0f99"-"\u0fbc","\u0fc6","\u1000"-"\u1021","\u1023"-"\u1027","\u1029"-"\u102a","\u102c"-"\u1032","\u1036"-"\u1039","\u1040"-"\u1049","\u1050"-"\u1059","\u10a0"-"\u10c5","\u10d0"-"\u10f6","\u1100"-"\u1159","\u115f"-"\u11a2","\u11a8"-"\u11f9","\u1200"-"\u1206","\u1208"-"\u1246","\u1248","\u124a"-"\u124d","\u1250"-"\u1256","\u1258","\u125a"-"\u125d","\u1260"-"\u1286","\u1288","\u128a"-"\u128d","\u1290"-"\u12ae","\u12b0","\u12b2"-"\u12b5","\u12b8"-"\u12be","\u12c0","\u12c2"-"\u12c5","\u12c8"-"\u12ce","\u12d0"-"\u12d6","\u12d8"-"\u12ee","\u12f0"-"\u130e","\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346","\u1348"-"\u135a","\u1369"-"\u1371","\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676","\u1681"-"\u169a","\u16a0"-"\u16ea","\u1780"-"\u17d3","\u17db","\u17e0"-"\u17e9","\u180b"-"\u180e","\u1810"-"\u1819","\u1820"-"\u1877","\u1880"-"\u18a9","\u1e00"-"\u1e9b","\u1ea0"-"\u1ef9","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d","\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4","\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3","\u1fd6"-"\u1fdb","\u1fe0"-"\u1fec","\u1ff2"-"\u1ff4","\u1ff6"-"\u1ffc","\u200c"-"\u200f","\u202a"-"\u202e","\u203f"-"\u2040","\u206a"-"\u206f","\u207f","\u20a0"-"\u20af","\u20d0"-"\u20dc","\u20e1","\u2102","\u2107","\u210a"-"\u2113","\u2115","\u2119"-"\u211d","\u2124","\u2126","\u2128","\u212a"-"\u212d","\u212f"-"\u2131","\u2133"-"\u2139","\u2160"-"\u2183","\u3005"-"\u3007","\u3021"-"\u302f","\u3031"-"\u3035","\u3038"-"\u303a","\u3041"-"\u3094","\u3099"-"\u309a","\u309d"-"\u309e","\u30a1"-"\u30fe","\u3105"-"\u312c","\u3131"-"\u318e","\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c","\uac00"-"\ud7a3","\uf900"-"\ufa2d","\ufb00"-"\ufb06","\ufb13"-"\ufb17","\ufb1d"-"\ufb28","\ufb2a"-"\ufb36","\ufb38"-"\ufb3c","\ufb3e","\ufb40"-"\ufb41","\ufb43"-"\ufb44","\ufb46"-"\ufbb1","\ufbd3"-"\ufd3d","\ufd50"-"\ufd8f","\ufd92"-"\ufdc7","\ufdf0"-"\ufdfb","\ufe20"-"\ufe23","\ufe33"-"\ufe34","\ufe4d"-"\ufe4f","\ufe69","\ufe70"-"\ufe72","\ufe74","\ufe76"-"\ufefc","\ufeff","\uff04","\uff10"-"\uff19","\uff21"-"\uff3a","\uff3f","\uff41"-"\uff5a","\uff65"-"\uffbe","\uffc2"-"\uffc7","\uffca"-"\uffcf","\uffd2"-"\uffd7","\uffda"-"\uffdc","\uffe0"-"\uffe1","\uffe5"-"\uffe6","\ufff9"-"\ufffb"]> -| < S_CHAR_LITERAL: ("'" ( | ~["'", "\\", "\n", "\r"] )* "'") | ("'" ("''" | ~["'"])* "'") > -| < S_QUOTED_IDENTIFIER: "\"" (~["\n","\r","\""])+ "\"" | ("`" (~["\n","\r","`"])+ "`") | ( "[" ~["0"-"9","]"] (~["\n","\r","]"])* "]" ) > +| < S_CHAR_LITERAL: (["U","E","N","R","B"]|"RB"|"_utf8")? (("'" ( | ~["'", "\\", "\n", "\r"] )* "'") | ("'" ("''" | ~["'"])* "'")) > +| < S_QUOTED_IDENTIFIER: "\"" (~["\n","\r","\""])* "\"" | ("`" (~["\n","\r","`"])+ "`") | ( "[" ~["0"-"9","]"] (~["\n","\r","]"])* "]" ) > + { if ( !allowSquareBracketQuotation && matchedToken.image.charAt(0) == '[' ) { + matchedToken.image = "["; + for (int i=0;i } Statement Statement() #Statement: -{ Statement stm; } +{ Statement stm = null; } { try { stm = SingleStatement() [] - { - return stm; - } } catch (ParseException e) { if (errorRecovery) { parseErrors.add(e); @@ -353,6 +394,10 @@ Statement Statement() #Statement: else throw e; } + + { + return stm; + } } Statement SingleStatement() : @@ -360,8 +405,11 @@ Statement SingleStatement() : { try { ( + LOOKAHEAD(3) stm = Select() | + stm = Values() + | stm = Update() | stm = Insert() @@ -370,6 +418,7 @@ Statement SingleStatement() : | stm = Delete() | + LOOKAHEAD(2) stm = Replace() | LOOKAHEAD(2) @@ -380,10 +429,10 @@ Statement SingleStatement() : LOOKAHEAD(CreateIndex()) stm = CreateIndex() | - LOOKAHEAD(2) + LOOKAHEAD(CreateTable()) stm = CreateTable() | - LOOKAHEAD(2) + LOOKAHEAD(CreateView()) stm = CreateView() | stm = AlterView() @@ -396,17 +445,62 @@ Statement SingleStatement() : | stm = Set() | + LOOKAHEAD(2) stm = ShowColumns() + | + stm = Show() + | + stm = Use() + | stm = Commit() + | + stm = Comment() + | + stm = Describe() + | + stm = Explain() + | + stm = Declare() ) + { return stm; } } catch (ParseException e) { if (errorRecovery) { parseErrors.add(e); error_skipto(ST_SEMICOLON); + return null; } else throw e; } - { return stm; } +} + +Block Block() #Block : { + Statements stmts = new Statements(); + List list = new ArrayList(); + Statement stm; + Block block = new Block(); +} +{ + +()* + try { + (stm = SingleStatement() | stm = Block()) { list.add(stm); } + ( (stm = SingleStatement() | stm = Block()) { list.add(stm); } )* + } catch (ParseException e) { + if (errorRecovery) { + parseErrors.add(e); + error_skipto(ST_SEMICOLON); + } + else + throw e; + } + { + stmts.setStatements(list); + block.setStatements(stmts); + } + + { + return block; + } } Statements Statements() #Statements : @@ -416,8 +510,8 @@ Statements Statements() #Statements : { ()* try { - stm = SingleStatement() { list.add(stm); } - ( [stm = SingleStatement() { list.add(stm); }] )* + (stm = SingleStatement() | stm = Block()) { list.add(stm); } + ( [(stm = SingleStatement() | stm = Block()) { list.add(stm); }] )* } catch (ParseException e) { if (errorRecovery) { @@ -436,22 +530,121 @@ Statements Statements() #Statements : JAVACODE void error_skipto(int kind) { ParseException e = generateParseException(); - System.out.println(e.toString()); Token t; do { t = getNextToken(); } while (t.kind != kind && t.kind != EOF); } +DeclareStatement Declare(): { + UserVariable userVariable; + ColDataType colDataType; + Expression defaultExpr = null; + DeclareStatement stmt = new DeclareStatement(); + String typeName; + String columnName; + ColumnDefinition colDef; +} { + userVariable = UserVariable() + ( + ( "(" colDef = ColumnDefinition() + { stmt.setUserVariable(userVariable); + stmt.setDeclareType(DeclareType.TABLE); + stmt.addColumnDefinition(colDef); } + ("," colDef = ColumnDefinition() { stmt.addColumnDefinition(colDef); })* ")" + ) + | + typeName = RelObjectName() + { stmt.setUserVariable(userVariable); + stmt.setDeclareType(DeclareType.AS); + stmt.setTypeName(typeName); } + | + (colDataType = ColDataType() ["=" defaultExpr = Expression()] + { stmt.setDeclareType(DeclareType.TYPE); + stmt.addType(userVariable, colDataType, defaultExpr); } + ("," userVariable = UserVariable() colDataType = ColDataType() { defaultExpr = null; } + ["=" defaultExpr = Expression()] { stmt.addType(userVariable, colDataType, defaultExpr); } )* + ) + ) + { + return stmt; + } +} + SetStatement Set(): { String name; Expression value; boolean useEqual = false; + SetStatement set; } { name = RelObjectNameExt() ["=" { useEqual=true; } ] value=SimpleExpression() + { set = new SetStatement(name,value).setUseEqual(useEqual); } + ( { useEqual=false; } "," name = RelObjectNameExt() ["=" { useEqual=true; } ] value=SimpleExpression() + { set.add(name, value, useEqual); } )* + + { return set; } +} + +DescribeStatement Describe(): { + Table table; +} { + table = Table() + { + return new DescribeStatement(table); + } +} + +ExplainStatement Explain(): { + Select select; +} { + select = Select() + { + return new ExplainStatement(select); + } +} + +UseStatement Use(): { + String name; +} +{ + name = RelObjectNameExt() + { + return new UseStatement(name); + } +} + +ShowColumnsStatement ShowColumns(): { + String tableName; +} +{ + tableName = RelObjectNameExt() + { + return new ShowColumnsStatement(tableName); + } +} + +ShowStatement Show(): { + String name; +} +{ + name = RelObjectNameExt() { - return new SetStatement(name,value).setUseEqual(useEqual); + return new ShowStatement(name); + } +} + +ValuesStatement Values(): { + List expList = new ArrayList(); + Expression exp; +} { + + "(" + exp=PrimaryExpression() { expList.add(exp); } + ("," exp=PrimaryExpression() { expList.add(exp); } )* + ")" + { + return new ValuesStatement(expList); } } @@ -459,7 +652,7 @@ Update Update(): { Update update = new Update(); Table table = null; - List
tables = new ArrayList
(); + List startJoins = null; Expression where = null; Column tableColumn = null; List expList = new ArrayList(); @@ -474,8 +667,9 @@ Update Update(): List returning = null; } { - table=TableWithAlias() { tables.add(table); } - ("," table=TableWithAlias() { tables.add(table); } )* + table=TableWithAlias() + startJoins=JoinsList() + ( LOOKAHEAD(3) tableColumn=Column() "=" value=SimpleExpression() { columns.add(tableColumn); expList.add(value); } @@ -483,7 +677,9 @@ Update Update(): | - ["(" { useColumnsBrackets = true; }] tableColumn=Column() { columns.add(tableColumn); } ("," tableColumn=Column() { columns.add(tableColumn); } )* [ ")" ] "=" + ( "(" { useColumnsBrackets = true; } tableColumn=Column() { columns.add(tableColumn); } ("," tableColumn=Column() { columns.add(tableColumn); } )* ")" + | tableColumn=Column() { columns.add(tableColumn); } ("," tableColumn=Column() { columns.add(tableColumn); } )* ) + "=" "(" ( { update.setUseSelect(true); } @@ -507,9 +703,10 @@ Update Update(): ] { - update.setColumns(columns); - update.setExpressions(expList); - update.setTables(tables); + update.setColumns(columns); + update.setExpressions(expList); + update.setTable(table); + update.setStartJoins(startJoins); update.setFromItem(fromItem); update.setJoins(joins); update.setSelect(select); @@ -528,11 +725,12 @@ Replace Replace(): List columns = new ArrayList(); List expList = new ArrayList(); + MultiExpressionList multiExpr = null; ItemsList itemsList = null; Expression exp = null; } { - [ { replace.setUseIntoTables(true); }] table=Table() + ( [LOOKAHEAD(2) { replace.setUseIntoTables(true); }] table=Table() ) ( ( @@ -549,6 +747,15 @@ Replace Replace(): ( LOOKAHEAD(2) [ | ] "(" exp=PrimaryExpression() { expList.add(exp); } ("," exp=PrimaryExpression() { expList.add(exp); } )* ")" { itemsList = new ExpressionList(expList); } + ("," "(" exp=SimpleExpression() { + if (multiExpr==null) { + multiExpr=new MultiExpressionList(); + multiExpr.addExpressionList((ExpressionList)itemsList); + itemsList = multiExpr; + } + expList = new ArrayList(); + expList.add(exp); } + ("," exp=SimpleExpression() { expList.add(exp); } )* ")" { multiExpr.addExpressionList(expList); } )* | { replace.setUseValues(false); } itemsList=SubSelect() @@ -583,13 +790,14 @@ Insert Insert(): Insert insert = new Insert(); Table table = null; Column tableColumn = null; - List columns = new ArrayList(); + List columns = new ArrayList(); List primaryExpList = new ArrayList(); ItemsList itemsList = null; Expression exp = null; MultiExpressionList multiExpr = null; List returning = null; Select select = null; + boolean useValues = true; boolean useSelectBrackets = false; boolean useDuplicate = false; List duplicateUpdateColumns = null; @@ -597,8 +805,14 @@ Insert Insert(): Token tk = null; InsertModifierPriority modifierPriority = null; boolean modifierIgnore = false; + boolean useSet = false; + List setColumns = new ArrayList(); + List setExpressionList = new ArrayList(); + String name = null; + boolean useAs = false; } { + [ WithList() ] [(tk = | tk = | tk = ) {if (tk!=null) @@ -606,7 +820,8 @@ Insert Insert(): }] [{ modifierIgnore = true; }] [] table=Table() - + + [ [ { useAs = true; } ] name=RelObjectNameWithoutValue() { table.setAlias(new Alias(name,useAs)); }] [LOOKAHEAD(2) "(" tableColumn=Column() { columns.add(tableColumn); } ("," tableColumn=Column() { columns.add(tableColumn); } )* ")" ] ( @@ -633,6 +848,26 @@ Insert Insert(): { insert.setUseValues(false); } select = Select() ) + + | + + + ( + { + useSet = true; + insert.setUseValues(false); + } + tableColumn=Column() "=" exp=SimpleExpression() + { + setColumns = new ArrayList(); + setExpressionList = new ArrayList(); + setColumns.add(tableColumn); + setExpressionList.add(exp); + } + ("," tableColumn=Column() "=" exp=SimpleExpression() + { setColumns.add(tableColumn); + setExpressionList.add(exp); } )* + ) ) [ @@ -668,6 +903,9 @@ Insert Insert(): insert.setReturningExpressionList(returning); insert.setModifierPriority(modifierPriority); insert.setModifierIgnore(modifierIgnore); + insert.setUseSet(useSet); + insert.setSetColumns(setColumns); + insert.setSetExpressionList(setExpressionList); return insert; } } @@ -844,7 +1082,7 @@ MergeInsert MergeInsertClause() : { } { - "(" col=Column() { columns.add(col); } ("," col=Column() { columns.add(col); } )* ")" + ["(" col=Column() { columns.add(col); } ("," col=Column() { columns.add(col); } )* ")"] "(" exp=SimpleExpression() { expList.add(exp); } ("," exp=SimpleExpression() { expList.add(exp); } )* ")" { mi.setColumns(columns); @@ -853,54 +1091,98 @@ MergeInsert MergeInsertClause() : { } } +List RelObjectNameList() : { + String token = null; + List data = new ArrayList(); +} { + token = RelObjectName() { data.add(token); } + ( LOOKAHEAD (2) "." ("." { data.add(null); })* token = RelObjectName() { data.add(token); } ) * + + { return data; } +} + // See: http://technet.microsoft.com/en-us/library/ms187879%28v=sql.105%29.aspx Column Column() #Column : { - String databaseName = null, schemaName = null, tableName = null, columnName = null; + //String databaseName = null, schemaName = null, tableName = null, columnName = null; + //String token = null; + List data = new ArrayList(); } { - ( - LOOKAHEAD(7) databaseName=RelObjectName() "." [schemaName=RelObjectName()] "." tableName=RelObjectName() "." columnName=RelObjectName() - | LOOKAHEAD(5) schemaName=RelObjectName() "." tableName=RelObjectName() "." columnName=RelObjectName() - | LOOKAHEAD(3) tableName=RelObjectName() "." columnName=RelObjectName() - | columnName=RelObjectName() - ) + data = RelObjectNameList() + { - final Database database = new Database(databaseName); - final Table table = new Table(database, schemaName, tableName); - Column col = new Column(table, columnName); + Column col = new Column(data); linkAST(col,jjtThis); return col; } } -String RelObjectName() : +/* +Not all names should be allowed for aliases. +*/ +String RelObjectNameWithoutValue() : { Token tk = null; } { - (tk= | tk= - | tk= | tk= | tk= | tk= | tk= + (tk= | tk= | tk= | tk= | tk= | tk= + | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= - | tk= | tk= | tk= | tk= | tk= + | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= - | tk= | tk= | tk= | tk= | tk= + | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= - | tk= + | tk= | tk= | tk= | tk= + | tk= + | tk= | tk= | tk= | tk= + | tk= | tk= | tk= | tk= | tk= + | tk= | tk= | tk= | tk= | tk= + | tk= | tk= | tk= +/* | tk= | tk= | tk= | tk= */ ) { return tk.image; } } /* -Extended usage of object names. +Normal names. +*/ +String RelObjectName() : +{ Token tk = null; String result = null; } +{ + (result = RelObjectNameWithoutValue() | tk= | tk= | tk= + | tk= | tk=) + + { + if (tk!=null) result=tk.image; + return result; + } +} + +String RelObjectNameWithoutStart() : +{ Token tk = null; String result = null; } +{ + (result = RelObjectNameWithoutValue() | tk= | tk= | tk= + | tk=) + + { + if (tk!=null) result=tk.image; + return result; + } +} + +/* +Extended version of object names. */ String RelObjectNameExt(): { Token tk = null; String result=null; } { - ( result=RelObjectName() | tk= | tk= | tk= | tk= | tk=) + ( result=RelObjectName() | tk= | tk= | tk= + | tk= | tk= | | tk= + | tk=) { if (tk!=null) result=tk.image; return result; @@ -915,7 +1197,7 @@ String RelObjectNameExt2(): String result=null; } { - ( result=RelObjectNameExt() | tk=) + ( result=RelObjectNameExt() | tk= | tk= ) { if (tk!=null) result=tk.image; return result; @@ -924,20 +1206,17 @@ String RelObjectNameExt2(): Table Table() #Table : { - String serverName = null, databaseName = null, schemaName = null, tableName = null; + //String serverName = null, databaseName = null, schemaName = null, tableName = null; + List data = new ArrayList(); + String token; } { - ( - LOOKAHEAD(7) serverName=RelObjectName() "." [databaseName=RelObjectName()] "." [schemaName=RelObjectName()] "." tableName=RelObjectName() - | LOOKAHEAD(5) databaseName=RelObjectName() "." [schemaName=RelObjectName()] "." tableName=RelObjectName() - | LOOKAHEAD(3) schemaName=RelObjectName() "." tableName=RelObjectName() - | tableName=RelObjectName() - ) + token = RelObjectName() { data.add(token); } + ( LOOKAHEAD(2) "." ("." { data.add(null); })* token = RelObjectName() { data.add(token); } ) * + { - final Server server = new Server(serverName); - final Database database = new Database(server, databaseName); - Table table = new Table(database, schemaName, tableName); - linkAST(table,jjtThis); + Table table = new Table(data); + linkAST(table,jjtThis); return table; } } @@ -974,7 +1253,7 @@ SelectBody SelectBody(): { return selectBody; } } -PlainSelect PlainSelect(): +PlainSelect PlainSelect() #PlainSelect: { PlainSelect plainSelect = new PlainSelect(); List selectItems = null; @@ -983,11 +1262,12 @@ PlainSelect PlainSelect(): List distinctOn = null; Expression where = null; List orderByElements; - List groupByColumnReferences = null; + GroupByElement groupBy = null; Expression having = null; Limit limit = null; Offset offset = null; Fetch fetch = null; + OptimizeFor optimize = null; Top top = null; Skip skip = null; First first = null; @@ -995,10 +1275,16 @@ PlainSelect PlainSelect(): List
intoTables = null; Table updateTable = null; Wait wait = null; + boolean mySqlSqlCalcFoundRows = false; + Token token; + KSQLWindow ksqlWindow = null; + boolean noWait = false; } { + [ { plainSelect.setMySqlHintStraightJoin(true); } ] + { plainSelect.setOracleHint(getOracleHint()); } [skip = Skip() { plainSelect.setSkip(skip); } ] @@ -1016,9 +1302,17 @@ PlainSelect PlainSelect(): ( { Distinct distinct = new Distinct(true); plainSelect.setDistinct(distinct); } ) + | + ( + { plainSelect.setMySqlSqlCalcFoundRows(true); } + ) + | + ( + { plainSelect.setMySqlSqlNoCache(true); } + ) ] - [top = Top() { plainSelect.setTop(top); } ] + [ LOOKAHEAD(2) top = Top() { plainSelect.setTop(top); } ] selectItems=SelectItemsList() @@ -1027,30 +1321,39 @@ PlainSelect PlainSelect(): fromItem=FromItem() joins=JoinsList() ] + [ ksqlWindow=KSQLWindowClause() { plainSelect.setKsqlWindow(ksqlWindow); } ] [ where=WhereClause() { plainSelect.setWhere(where); }] [ oracleHierarchicalQueryClause=OracleHierarchicalQueryClause() { plainSelect.setOracleHierarchical(oracleHierarchicalQueryClause); } ] - [ groupByColumnReferences=GroupByColumnReferences() { plainSelect.setGroupByColumnReferences(groupByColumnReferences); }] + [ groupBy=GroupByColumnReferences() { plainSelect.setGroupByElement(groupBy); }] [ having=Having() { plainSelect.setHaving(having); }] [LOOKAHEAD( ) orderByElements = OrderByElements() { plainSelect.setOracleSiblings(true); plainSelect.setOrderByElements(orderByElements); } ] [LOOKAHEAD( ) orderByElements = OrderByElements() { plainSelect.setOrderByElements(orderByElements); } ] [LOOKAHEAD() limit = LimitWithOffset() { plainSelect.setLimit(limit); } ] [LOOKAHEAD() offset = Offset() { plainSelect.setOffset(offset); } ] + [LOOKAHEAD(, { limit==null }) limit = LimitWithOffset() { plainSelect.setLimit(limit); } ] + [LOOKAHEAD() fetch = Fetch() { plainSelect.setFetch(fetch); } ] - [ { plainSelect.setForUpdate(true); } + [LOOKAHEAD(2) { plainSelect.setForUpdate(true); } [ updateTable = Table() { plainSelect.setForUpdateTable(updateTable); } ] - [ LOOKAHEAD() wait = Wait() { plainSelect.setWait(wait); } ] ] + [ LOOKAHEAD() wait = Wait() { plainSelect.setWait(wait); } ] + [ { plainSelect.setNoWait(true); } ] ] + + [LOOKAHEAD() optimize = OptimizeFor() { plainSelect.setOptimizeFor(optimize); } ] + + [ "(" token = ")" { plainSelect.setForXmlPath(token.image); } ] { plainSelect.setSelectItems(selectItems); plainSelect.setFromItem(fromItem); if (joins != null && joins.size() > 0) plainSelect.setJoins(joins); + linkAST(plainSelect,jjtThis); return plainSelect; } } -SelectBody SetOperationList(): +SelectBody SetOperationList() #SetOperationList: { SetOperationList list = new SetOperationList(); List orderByElements = null; @@ -1068,15 +1371,15 @@ SelectBody SetOperationList(): ( (("(" select=SelectBody() ")" { bracket=true;} ) - | select=PlainSelect() { bracket=false;} ) {selects.add(select);brackets.add(bracket); } + | ( select=PlainSelect() | select=Values() ) { bracket=false;} ) {selects.add(select);brackets.add(bracket); } ( - (( { UnionOp union = new UnionOp();operations.add(union); } [ { union.setAll(true); } | { union.setDistinct(true); } ]) + (( { UnionOp union = new UnionOp();linkAST(union,jjtThis);operations.add(union); } [ { union.setAll(true); } | { union.setDistinct(true); } ]) | { operations.add(new IntersectOp()); } | { operations.add(new MinusOp()); } | { operations.add(new ExceptOp()); } ) - (("(" select=SelectBody() ")" { bracket=true;} ) | select=PlainSelect() { bracket=false;} ) {selects.add(select);brackets.add(bracket);} + (("(" select=SelectBody() ")" { bracket=true;} ) | ( select=PlainSelect() | select=Values() ) { bracket=false;} ) {selects.add(select);brackets.add(bracket);} )* ) @@ -1087,11 +1390,18 @@ SelectBody SetOperationList(): ) { - if (selects.size()==1 && selects.get(0) instanceof PlainSelect) { + if (selects.size()==1 && selects.get(0) instanceof PlainSelect && orderByElements==null) { if (brackets.get(0)) - ((PlainSelect)selects.get(0)).setUseBrackets(true); + ((PlainSelect)selects.get(0)).setUseBrackets(true); return selects.get(0); } else { + if (selects.size()>1 && selects.get(selects.size()-1) instanceof PlainSelect) { + PlainSelect ps = (PlainSelect)selects.get(selects.size()-1); + if (ps.getOrderByElements() != null) { + list.setOrderByElements(ps.getOrderByElements()); + ps.setOrderByElements(null); + } + } list.setBracketsOpsAndSelects(brackets,selects,operations); return list; } @@ -1146,7 +1456,7 @@ SelectExpressionItem SelectExpressionItem(): [alias=Alias() { selectExpressionItem.setAlias(alias); }] { return selectExpressionItem; } } -SelectItem SelectItem(): +SelectItem SelectItem() #SelectItem: { SelectItem selectItem = null; } @@ -1157,6 +1467,7 @@ SelectItem SelectItem(): selectItem=SelectExpressionItem() ) { + linkAST(selectItem,jjtThis); return selectItem; } } @@ -1175,10 +1486,23 @@ AllTableColumns AllTableColumns(): Alias Alias(): { String name = null; - boolean useAs = false; } + Token token = null; + boolean useAs = false; + Alias alias; + String colname; + ColDataType colDataType = null; +} { - [ { useAs = true; } ] name=RelObjectName() - { return new Alias(name,useAs); } + [ { useAs = true; } ] + ( name=RelObjectNameWithoutStart() | token= { name=token.image; } ) + { alias = new Alias(name,useAs); } + + [ LOOKAHEAD(2) "(" { List list = new ArrayList(); } + colname = RelObjectName() [ colDataType = ColDataType() ] { list.add(new Alias.AliasColumn(colname, colDataType)); } + ("," { colDataType=null; } colname = RelObjectName() [ colDataType = ColDataType()] { list.add(new Alias.AliasColumn(colname, colDataType)); } )* + ")" { alias.setAliasColumns(list); } ] + + { return alias; } } MySQLIndexHint MySQLIndexHint(): @@ -1190,6 +1514,7 @@ MySQLIndexHint MySQLIndexHint(): } { (actionToken = + | actionToken = | actionToken = | actionToken = ) (indexToken = @@ -1294,6 +1619,7 @@ Pivot Pivot(): List forColumns; List singleInItems = null; List multiInItems = null; + Alias alias = null; } { "(" functionItems = PivotFunctionItems() @@ -1303,11 +1629,13 @@ Pivot Pivot(): | multiInItems = PivotMultiInItems() ) ")" ")" + [ alias = Alias() ] { retval.setFunctionItems(functionItems); retval.setForColumns(forColumns); retval.setSingleInItems(singleInItems); retval.setMultiInItems(multiInItems); + retval.setAlias(alias); return retval; } } @@ -1343,6 +1671,31 @@ PivotXml PivotXml(): } } +UnPivot UnPivot(): +{ + UnPivot retval = new UnPivot(); + Column unpivotClause; + List unpivotForClause; + List unpivotInClause; +} +{ + + [ ( { retval.setIncludeNulls(true); } + | { retval.setIncludeNulls(false); } ) ] + "(" unpivotClause = Column() + unpivotForClause = PivotForColumns() + "(" + unpivotInClause = PivotSingleInItems() + ")" + ")" + { + retval.setUnPivotClause(unpivotClause); + retval.setUnPivotForClause(unpivotForClause); + retval.setUnPivotInClause(unpivotInClause); + return retval; + } +} + List
IntoClause(): { List
tables = new ArrayList
(); @@ -1359,6 +1712,7 @@ FromItem FromItem(): { FromItem fromItem = null; Pivot pivot = null; + UnPivot unpivot = null; Alias alias = null; MySQLIndexHint indexHint = null; } @@ -1374,9 +1728,14 @@ FromItem FromItem(): LOOKAHEAD(SubJoin()) fromItem=SubJoin() | + LOOKAHEAD(3) fromItem=SubSelect() + | + fromItem=FromItem() + { fromItem = new ParenthesisFromItem(fromItem); } ) ")" + [ LOOKAHEAD(2) unpivot=UnPivot() { fromItem.setUnPivot(unpivot); } ] ) | LOOKAHEAD(TableFunction()) @@ -1386,8 +1745,9 @@ FromItem FromItem(): | fromItem=LateralSubSelect() ) - [(LOOKAHEAD(2) pivot=PivotXml()|pivot=Pivot()) { fromItem.setPivot(pivot); } ] [ alias=Alias() { fromItem.setAlias(alias); } ] + [ LOOKAHEAD(2) unpivot=UnPivot() { fromItem.setUnPivot(unpivot); } ] + [(LOOKAHEAD(2) pivot=PivotXml()|pivot=Pivot()) { fromItem.setPivot(pivot); } ] [ LOOKAHEAD(2) indexHint=MySQLIndexHint() { @@ -1445,15 +1805,15 @@ FromItem ValuesList(): LateralSubSelect LateralSubSelect(): { - LateralSubSelect lateralSubSelect = new LateralSubSelect(); + LateralSubSelect specialSubSelect; SubSelect subSelect = null; } { - + { specialSubSelect = new LateralSubSelect(); } "(" subSelect=SubSelect() ")" { - lateralSubSelect.setSubSelect(subSelect); - return lateralSubSelect; + specialSubSelect.setSubSelect(subSelect); + return specialSubSelect; } } @@ -1461,38 +1821,54 @@ FromItem SubJoin(): { FromItem fromItem = null; Join join = null; - SubJoin subJoin = new SubJoin(); + List joinList = null; } { - fromItem=FromItem() { subJoin.setLeft(fromItem); } - join=JoinerExpression() { subJoin.setJoin(join); } - + fromItem=FromItem() + joinList=SubJoinsList() { + SubJoin subJoin = new SubJoin(); + subJoin.setLeft(fromItem); + subJoin.setJoinList(joinList); return subJoin; } } -List JoinsList(): +List JoinsList(): { List joinsList = new ArrayList(); Join join = null; } { - (join=JoinerExpression() { joinsList.add(join); })* + { return joinsList; } +} +List SubJoinsList(): +{ + List joinsList = new ArrayList(); + Join join = null; +} +{ + + (join=JoinerExpression() { joinsList.add(join); })+ { return joinsList; } } -Join JoinerExpression(): + +Join JoinerExpression() #JoinerExpression: { Join join = new Join(); FromItem right = null; Expression onExpression = null; Column tableColumn; List columns = null; + KSQLJoinWindow joinWindow = null; + } { + + [ { join.setLeft(true); } [ { join.setSemi(true); } | { join.setOuter(true); } ] | ( { join.setRight(true); } @@ -1500,25 +1876,100 @@ Join JoinerExpression(): ) [ { join.setOuter(true); } ] | { join.setInner(true); } | { join.setNatural(true); } - | { join.setCross(true); } + | { join.setCross(true); } ] - ( | "," { join.setSimple(true); } ) + ( | "," { join.setSimple(true); } ( { join.setOuter(true); } )? + | { join.setStraight(true); } | {join.setApply(true); } ) right=FromItem() [ - LOOKAHEAD(2) (( onExpression=Expression() { join.setOnExpression(onExpression); } ) + LOOKAHEAD(2) ([ "(" joinWindow = JoinWindow() ")" {join.setJoinWindow(joinWindow);}] + ( onExpression=Expression() { join.setOnExpression(onExpression); }) | ( "(" tableColumn=Column() { columns = new ArrayList(); columns.add(tableColumn); } ("," tableColumn=Column() { columns.add(tableColumn); } )* ")" { join.setUsingColumns(columns); } )) ] { + linkAST(join,jjtThis); join.setRightItem(right); return join; } + +} + +KSQLJoinWindow JoinWindow(): +{ + KSQLJoinWindow retval = new KSQLJoinWindow(); + boolean beforeAfter; + Token beforeDurationToken = null; + Token beforeTimeUnitToken = null; + Token afterDurationToken = null; + Token afterTimeUnitToken = null; +} +{ + (beforeDurationToken= beforeTimeUnitToken= + [ "," afterDurationToken= afterTimeUnitToken= ] + { + if (afterDurationToken == null) { + retval.setDuration(Long.parseLong(beforeDurationToken.image)); + retval.setTimeUnit(KSQLJoinWindow.TimeUnit.valueOf(beforeTimeUnitToken.image)); + retval.setBeforeAfterWindow(false); + return retval; + } + retval.setBeforeDuration(Long.parseLong(beforeDurationToken.image)); + retval.setBeforeTimeUnit(KSQLJoinWindow.TimeUnit.valueOf(beforeTimeUnitToken.image)); + retval.setAfterDuration(Long.parseLong(afterDurationToken.image)); + retval.setAfterTimeUnit(KSQLJoinWindow.TimeUnit.valueOf(afterTimeUnitToken.image)); + retval.setBeforeAfterWindow(true); + return retval; + }) +} + +KSQLWindow KSQLWindowClause(): +{ + KSQLWindow retval = null; + Token sizeDurationToken = null; + Token sizeTimeUnitToken = null; + Token advanceDurationToken = null; + Token advanceTimeUnitToken = null; +} +{ + + { + retval=new KSQLWindow(); + retval.setHoppingWindow(false); + retval.setSessionWindow(false); + retval.setTumblingWindow(false); + } + ( + "(" + sizeDurationToken= sizeTimeUnitToken= "," + advanceDurationToken= advanceTimeUnitToken= ")" + { + retval.setHoppingWindow(true); + } | + "(" sizeDurationToken= sizeTimeUnitToken= ")" + { + retval.setSessionWindow(true); + } | + "(" sizeDurationToken= sizeTimeUnitToken= ")" + { + retval.setTumblingWindow(true); + } + ) + { + retval.setSizeDuration(Long.parseLong(sizeDurationToken.image)); + retval.setSizeTimeUnit(KSQLWindow.TimeUnit.valueOf(sizeTimeUnitToken.image)); + if (advanceDurationToken != null) { + retval.setAdvanceDuration(Long.parseLong(advanceDurationToken.image)); + retval.setAdvanceTimeUnit(KSQLWindow.TimeUnit.valueOf(advanceTimeUnitToken.image)); + } + return retval; + } } Expression WhereClause(): @@ -1553,16 +2004,31 @@ OracleHierarchicalExpression OracleHierarchicalQueryClause(): } } -List GroupByColumnReferences(): +GroupByElement GroupByColumnReferences(): { - Expression columnReference = null; - List columnReferences = new ArrayList(); + Expression columnReference; + GroupByElement groupBy = new GroupByElement(); + Expression expr; + ExpressionList list; } { - columnReference=SimpleExpression() {columnReferences.add(columnReference); } - ("," columnReference=SimpleExpression() {columnReferences.add(columnReference); } )* + + ( + columnReference=SimpleExpression() {groupBy.addGroupByExpression(columnReference); } + ("," columnReference=SimpleExpression() {groupBy.addGroupByExpression(columnReference); } )* + | + "(" + ( LOOKAHEAD(2) "(" ")" { groupBy.addGroupingSet(new ExpressionList()); } + | LOOKAHEAD(3) "(" list = SimpleExpressionList() ")" { groupBy.addGroupingSet(list); } + | expr = SimpleExpression() { groupBy.addGroupingSet(expr); } ) + + ( "," ( LOOKAHEAD(2) "(" ")" { groupBy.addGroupingSet(new ExpressionList()); } + | LOOKAHEAD(3) "(" list = SimpleExpressionList() ")" { groupBy.addGroupingSet(list); } + | expr = SimpleExpression() { groupBy.addGroupingSet(expr); } ) )* + ")" + ) { - return columnReferences; + return groupBy; } } @@ -1596,7 +2062,7 @@ OrderByElement OrderByElement(): Expression columnReference = null; } { - columnReference = SimpleExpression() + columnReference = Expression() [ ( | ( { orderByElement.setAsc(false); } )) { orderByElement.setAscDescPresent(true); } ] [ ( { orderByElement.setNullOrdering(OrderByElement.NullOrdering.NULLS_FIRST); } | @@ -1609,10 +2075,33 @@ OrderByElement OrderByElement(): } } -Limit LimitWithOffset(): +JdbcParameter SimpleJdbcParameter() : { + JdbcParameter retval; +} +{ + "?" { retval = new JdbcParameter(++jdbcParameterIndex, false); } + [ LOOKAHEAD(2) token = { retval.setUseFixedIndex(true); retval.setIndex(Integer.valueOf(token.image)); } ] + { + return retval; + } +} + +JdbcNamedParameter SimpleJdbcNamedParameter() : { + String name; +} +{ + ":" name = RelObjectNameExt() + { + return new JdbcNamedParameter(token.image); + } +} + +Limit LimitWithOffset() #LimitWithOffset: { Limit limit = new Limit(); Token token = null; + String name; + JdbcParameter jdbc = null; } { ( @@ -1622,9 +2111,9 @@ Limit LimitWithOffset(): ( token= { limit.setOffset(new LongValue(token.image)); } | - "?" { limit.setOffset(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = { ((JdbcParameter)limit.getOffset()).setUseFixedIndex(true); ((JdbcParameter)limit.getOffset()).setIndex(Integer.valueOf(token.image)); } ] + jdbc = SimpleJdbcParameter() { limit.setOffset(jdbc); } | - ":" { limit.setOffset(new JdbcNamedParameter()); } [ LOOKAHEAD(2) token = { ((JdbcNamedParameter)limit.getOffset()).setName(token.image); } ] + ":" { limit.setOffset(new JdbcNamedParameter()); } [ LOOKAHEAD(2) name = RelObjectNameExt() { ((JdbcNamedParameter)limit.getOffset()).setName(name); } ] ) "," @@ -1632,22 +2121,25 @@ Limit LimitWithOffset(): ( token= { limit.setRowCount(new LongValue(token.image)); } | - "?" { limit.setRowCount(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = { ((JdbcParameter)limit.getRowCount()).setUseFixedIndex(true); ((JdbcParameter)limit.getRowCount()).setIndex(Integer.valueOf(token.image)); } ] + jdbc = SimpleJdbcParameter() { limit.setRowCount(jdbc); } | - ":" { limit.setRowCount(new JdbcNamedParameter()); } [ LOOKAHEAD(2) token = { ((JdbcNamedParameter)limit.getRowCount()).setName(token.image); } ] + ":" { limit.setRowCount(new JdbcNamedParameter()); } [ LOOKAHEAD(2) name = RelObjectNameExt() { ((JdbcNamedParameter)limit.getRowCount()).setName(name); } ] ) | limit = PlainLimit() ) { + linkAST(limit,jjtThis); return limit; } } -Limit PlainLimit(): +Limit PlainLimit() #PlainLimit: { Limit limit = new Limit(); Token token = null; + JdbcParameter jdbc; + String name; } { // mysql-postgresql-> LIMIT (row_count | ALL | NULL) @@ -1655,15 +2147,16 @@ Limit PlainLimit(): ( token= { limit.setRowCount(new LongValue(token.image)); } | - "?" { limit.setRowCount(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = { ((JdbcParameter)limit.getRowCount()).setUseFixedIndex(true); ((JdbcParameter)limit.getRowCount()).setIndex(Integer.valueOf(token.image)); } ] + jdbc = SimpleJdbcParameter() { limit.setRowCount(jdbc); } | - ":" { limit.setRowCount(new JdbcNamedParameter()); } [ LOOKAHEAD(2) token = { ((JdbcNamedParameter)limit.getRowCount()).setName(token.image); } ] + ":" { limit.setRowCount(new JdbcNamedParameter()); } [ LOOKAHEAD(2) name = RelObjectNameExt() { ((JdbcNamedParameter)limit.getRowCount()).setName(name); } ] | { limit.setLimitAll(true);} | { limit.setLimitNull(true); } ) { + linkAST(limit,jjtThis); return limit; } } @@ -1672,6 +2165,8 @@ Offset Offset(): { Offset offset = new Offset(); Token token = null; + JdbcParameter jdbc; + JdbcNamedParameter jdbcNamed; } { ( @@ -1679,7 +2174,8 @@ Offset Offset(): // sqlserver-oracle-> OFFSET offset (ROW | ROWS) (token= { offset.setOffset(Long.parseLong(token.image)); } - | "?" { offset.setOffsetJdbcParameter(true); } ) + | jdbc = SimpleJdbcParameter() { offset.setOffsetJdbcParameter(jdbc); } + | jdbcNamed = SimpleJdbcNamedParameter() { offset.setOffsetJdbcParameter(jdbcNamed); }) [( { offset.setOffsetParam("ROWS"); } | { offset.setOffsetParam("ROW"); })] ) @@ -1692,6 +2188,7 @@ Fetch Fetch(): { Fetch fetch = new Fetch(); Token token = null; + JdbcParameter jdbc; } { ( @@ -1699,7 +2196,7 @@ Fetch Fetch(): ( { fetch.setFetchParamFirst(true); } | ) (token= { fetch.setRowCount(Long.parseLong(token.image)); } - | "?" { fetch.setFetchJdbcParameter(true); } ) + | jdbc = SimpleJdbcParameter() { fetch.setFetchJdbcParameter(jdbc); } ) /* "?" { fetch.setFetchJdbcParameter(true); } ) */ ( { fetch.setFetchParam("ROWS"); } | ) @@ -1709,19 +2206,33 @@ Fetch Fetch(): } } +OptimizeFor OptimizeFor(): +{ + Token token; + LongValue value; +} +{ + token= { value = new LongValue(token.image); } + { + return new OptimizeFor(value.getValue()); + } +} + // according to http://technet.microsoft.com/en-us/library/ms189463.aspx Top Top(): { Top top = new Top(); Token token = null; Expression expr = null; + JdbcParameter jdbc = null; } { ( token= { top.setExpression(new LongValue(token.image)); } | - "?" { top.setExpression(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = { ((JdbcParameter)(top.getExpression())).setUseFixedIndex(true); ((JdbcParameter)(top.getExpression())).setIndex(Integer.valueOf(token.image)); } ] + jdbc = SimpleJdbcParameter() { top.setExpression(jdbc); } + /*"?" { top.setExpression(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = { ((JdbcParameter)(top.getExpression())).setUseFixedIndex(true); ((JdbcParameter)(top.getExpression())).setIndex(Integer.valueOf(token.image)); } ]*/ | ":" { top.setExpression(new JdbcNamedParameter()); } [ LOOKAHEAD(2) token = { ((JdbcNamedParameter)top.getExpression()).setName(token.image); } ] | @@ -1740,13 +2251,15 @@ Skip Skip(): { Skip skip = new Skip(); Token token = null; + JdbcParameter jdbc; } { ( token= { skip.setRowCount(Long.parseLong(token.image)); } | token= { skip.setVariable(token.image); } - | "?" { skip.setJdbcParameter(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = { skip.getJdbcParameter().setUseFixedIndex(true); skip.getJdbcParameter().setIndex(Integer.valueOf(token.image)); } ] + | jdbc = SimpleJdbcParameter() { skip.setJdbcParameter(jdbc); } + /* "?" { skip.setJdbcParameter(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = { skip.getJdbcParameter().setUseFixedIndex(true); skip.getJdbcParameter().setIndex(Integer.valueOf(token.image)); } ] */ ) { return skip; @@ -1774,6 +2287,7 @@ First First(): { First first = new First(); Token token = null; + JdbcParameter jdbc; } { ( { first.setKeyword(First.Keyword.FIRST); } @@ -1782,7 +2296,8 @@ First First(): ( token= { first.setRowCount(Long.parseLong(token.image)); } | token= { first.setVariable(token.image); } - | "?" { first.setJdbcParameter(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = { first.getJdbcParameter().setUseFixedIndex(true); first.getJdbcParameter().setIndex(Integer.valueOf(token.image)); } ] + | jdbc = SimpleJdbcParameter() { first.setJdbcParameter(jdbc); } + /* "?" { first.setJdbcParameter(new JdbcParameter(++jdbcParameterIndex, false)); } [ LOOKAHEAD(2) token = { first.getJdbcParameter().setUseFixedIndex(true); first.getJdbcParameter().setIndex(Integer.valueOf(token.image)); } ] */ ) { return first; @@ -1825,25 +2340,26 @@ Expression AndExpression() : { Expression left, right, result; boolean not = false; + boolean exclamationMarkNot=false; } { ( LOOKAHEAD(Condition()) left=Condition() | - [ { not = true; } ] - "(" left=OrExpression() ")" {left = new Parenthesis(left); if (not) { ((Parenthesis)left).setNot(); not = false; } } + [ { not=true; } | "!" { not=true; exclamationMarkNot=true; } ] + "(" left=OrExpression() ")" {left = new Parenthesis(left); if (not) { left = new NotExpression(left, exclamationMarkNot); not = false; } } ) { result = left; } ( - + ( | ) ( LOOKAHEAD(Condition()) right=Condition() | - [ { not = true; } ] - "(" right=OrExpression() ")" {right = new Parenthesis(right); if (not) { ((Parenthesis)right).setNot(); not = false; } } + [ { not=true; } | "!" { not=true; exclamationMarkNot=true; } ] + "(" right=OrExpression() ")" {right = new Parenthesis(right); if (not) { right = new NotExpression(right, exclamationMarkNot); not = false; } } ) { result = new AndExpression(left, right); @@ -1859,32 +2375,31 @@ Expression Condition(): { Expression result; Token token; + boolean not = false; + boolean exclamationMarkNot = false; } { - (LOOKAHEAD(SQLCondition()) result=SQLCondition() - | LOOKAHEAD(RegularCondition()) result=RegularCondition() - | LOOKAHEAD(Function()) result=Function() - | result=Column() { result = new NotExpression(result); } - | result=Column() - | LOOKAHEAD({ "0".equals(getToken(1).image) || "1".equals(getToken(1).image) }) token= { result = new LongValue(token.image); } + [ LOOKAHEAD(2) ( { not=true; } | "!" { not=true; exclamationMarkNot=true; })] + ( + LOOKAHEAD(SQLCondition()) result=SQLCondition() + | LOOKAHEAD(RegularCondition()) result=RegularCondition() + | result=SimpleExpression() ) - { return result; } + { return not?new NotExpression(result, exclamationMarkNot):result; } } -Expression RegularCondition(): +Expression RegularCondition() #RegularCondition: { Expression result = null; Expression leftExpression; Expression rightExpression; - boolean not = false; int oracleJoin=EqualsTo.NO_ORACLE_JOIN; int oraclePrior=EqualsTo.NO_ORACLE_PRIOR; boolean binary = false; } { [ LOOKAHEAD(2) { oraclePrior = EqualsTo.ORACLE_PRIOR_START; }] - [ { not = true; } ] leftExpression=ComparisonItem() { result = leftExpression; } [ "(" "+" ")" { oracleJoin=EqualsTo.ORACLE_JOIN_RIGHT; } ] @@ -1900,6 +2415,7 @@ Expression RegularCondition(): | "@@" { result = new Matches(); } | "~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASESENSITIVE); } | [ { binary=true; } ] { result = new RegExpMySQLOperator(binary?RegExpMatchOperatorType.MATCH_CASESENSITIVE:RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); } + | [ { binary=true; } ] { result = new RegExpMySQLOperator(binary?RegExpMatchOperatorType.MATCH_CASESENSITIVE:RegExpMatchOperatorType.MATCH_CASEINSENSITIVE).useRLike(); } | "~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); } | "!~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASESENSITIVE); } | "!~*" { result = new RegExpMatchOperator(RegExpMatchOperatorType.NOT_MATCH_CASEINSENSITIVE); } @@ -1909,7 +2425,7 @@ Expression RegularCondition(): | "?" { result = new JsonOperator("?"); } | "?|" { result = new JsonOperator("?|"); } | "?&" { result = new JsonOperator("?&"); } - | "||" { result = new JsonOperator("||"); } + | { result = new JsonOperator("||"); } | "-" { result = new JsonOperator("-"); } | "-#" { result = new JsonOperator("-#"); } ) @@ -1923,8 +2439,6 @@ Expression RegularCondition(): BinaryExpression regCond = (BinaryExpression) result; regCond.setLeftExpression(leftExpression); regCond.setRightExpression(rightExpression); - if (not) - regCond.setNot(); if (oracleJoin>0) ((SupportsOldOracleJoinSyntax)result).setOldOracleJoinSyntax(oracleJoin); @@ -1933,25 +2447,33 @@ Expression RegularCondition(): ((SupportsOldOracleJoinSyntax)result).setOraclePriorPosition(oraclePrior); } - { return result; } + { + linkAST(result,jjtThis); + return result; + } } Expression SQLCondition(): { Expression result; + Expression left; } { ( - LOOKAHEAD(InExpression()) result=InExpression() - | LOOKAHEAD(Between()) result=Between() - | LOOKAHEAD(IsNullExpression()) result=IsNullExpression() - | LOOKAHEAD(ExistsExpression()) result=ExistsExpression() - | result=LikeExpression() + result=ExistsExpression() + | LOOKAHEAD(InExpression()) result=InExpression() + | left = SimpleExpression() + (LOOKAHEAD(2) result=Between(left) + | LOOKAHEAD(IsNullExpression()) result=IsNullExpression(left) + | LOOKAHEAD(IsBooleanExpression()) result=IsBooleanExpression(left) + | LOOKAHEAD(2) result=LikeExpression(left) + | result=SimilarToExpression(left) + ) ) { return result; } } -Expression InExpression() : +Expression InExpression() #InExpression : { InExpression result = new InExpression(); ItemsList leftItemsList = null; @@ -1973,19 +2495,18 @@ Expression InExpression() : [ { result.setNot(true); } ] "(" (LOOKAHEAD(3) rightItemsList=SubSelect() | rightItemsList=SimpleExpressionList() ) ")" { result.setRightItemsList(rightItemsList); + linkAST(result,jjtThis); return result; } } -Expression Between() : +Expression Between(Expression leftExpression) : { Between result = new Between(); - Expression leftExpression = null; Expression betweenExpressionStart = null; Expression betweenExpressionEnd = null; } { - leftExpression=SimpleExpression() [ { result.setNot(true); }] betweenExpressionStart=SimpleExpression() betweenExpressionEnd=SimpleExpression() @@ -1997,34 +2518,61 @@ Expression Between() : } } -Expression LikeExpression() : +Expression LikeExpression(Expression leftExpression) #LikeExpression: +{ + LikeExpression result = new LikeExpression(); + Expression rightExpression = null; +} +{ + [ { result.setNot(true); } ] ( | { result.setCaseInsensitive(true); } ) rightExpression=SimpleExpression() + [ token= { result.setEscape((new StringValue(token.image)).getValue()); }] + { + result.setLeftExpression(leftExpression); + result.setRightExpression(rightExpression); + linkAST(result,jjtThis); + return result; + } +} + +Expression SimilarToExpression(Expression leftExpression) #SimilarToExpression: +{ + SimilarToExpression result = new SimilarToExpression(); + Expression rightExpression = null; +} +{ + [ { result.setNot(true); } ] + + rightExpression=SimpleExpression() + [ token= { result.setEscape((new StringValue(token.image)).getValue()); }] + { + result.setLeftExpression(leftExpression); + result.setRightExpression(rightExpression); + linkAST(result,jjtThis); + return result; + } +} + +Expression IsNullExpression(Expression leftExpression): { - LikeExpression result = new LikeExpression(); - Expression leftExpression = null; - Expression rightExpression = null; + IsNullExpression result = new IsNullExpression(); } { - leftExpression=SimpleExpression() - [ { result.setNot(true); } ] ( | { result.setCaseInsensitive(true); } ) rightExpression=SimpleExpression() - [ token= { result.setEscape((new StringValue(token.image)).getValue()); }] + ( { result.setUseIsNull(true); } | [ { result.setNot(true); } ] ) + { result.setLeftExpression(leftExpression); - result.setRightExpression(rightExpression); return result; } } -Expression IsNullExpression(): +Expression IsBooleanExpression(Expression leftExpression): { - IsNullExpression result = new IsNullExpression(); - Expression leftExpression = null; + IsBooleanExpression result = new IsBooleanExpression(); } { - ( - { result.setNot(true); } leftExpression=SimpleExpression() - | - leftExpression=SimpleExpression() [ { result.setNot(true); } ] - ) + ( + [ { result.setNot(true); } ] ( { result.setIsTrue(true); } | { result.setIsTrue(false); }) + ) { result.setLeftExpression(leftExpression); @@ -2038,7 +2586,7 @@ Expression ExistsExpression(): Expression rightExpression = null; } { - [ { result.setNot(true); } ] rightExpression=SimpleExpression() + rightExpression=SimpleExpression() { result.setRightExpression(rightExpression); return result; @@ -2059,7 +2607,7 @@ ExpressionList SQLExpressionList(): } } -ExpressionList SimpleExpressionList(): +ExpressionList SimpleExpressionList() #ExpressionList: { ExpressionList retval = new ExpressionList(); List expressions = new ArrayList(); @@ -2073,6 +2621,97 @@ ExpressionList SimpleExpressionList(): } } +ExpressionList ComplexExpressionList() #ExpressionList: +{ + ExpressionList retval = new ExpressionList(); + List expressions = new ArrayList(); + Expression expr = null; +} +{ + expr=Expression() { expressions.add(expr); } ("," expr=Expression() { expressions.add(expr); })* + { + retval.setExpressions(expressions); + return retval; + } +} + +// trim( [leading|trailing|both] expr from expr) +// The [leading|trailing|both] token has already been consumed +NamedExpressionList NamedExpressionList1(): +{ + NamedExpressionList retval = new NamedExpressionList(); + List expressions = new ArrayList(); + List names = new ArrayList(); + Expression expr1 = null; + Expression expr2 = null; + String name = ""; + Token tk1 = null; + Token tk2 = null; +} +{ + ( + (tk1=|tk1=|tk1=) { names.add(tk1.image); } + expr1=SimpleExpression() + (tk2=|tk2=|tk2=) + expr2=SimpleExpression() + { expressions.add(expr1); names.add(tk2.image); expressions.add(expr2);} + ) + + { + retval.setNames(names); + retval.setExpressions(expressions); + return retval; + } +} + +// substring(expr1 from expr2) +// substring(expr1 from expr2 for expr3) +// trim(expr1 from expr2) +// position(expr1 in expr2) +// overlay(expr1 placing expr2 from expr3) +// overlay(expr1 placing expr2 from expr3 for expr4) +// expr1 has already been consumed +NamedExpressionList NamedExpressionListExprFirst(): +{ + NamedExpressionList retval = new NamedExpressionList(); + List expressions = new ArrayList(); + List names = new ArrayList(); + Expression expr1 = null; + Expression expr2 = null; + Expression expr3 = null; + Expression expr4 = null; + Token tk2 = null; + Token tk3 = null; + Token tk4 = null; +} +{ + expr1=SimpleExpression() + (tk2=|tk2=|tk2=) + { + names.add(""); + expressions.add(expr1); + names.add(tk2.image); + } + ( + expr2=SimpleExpression() { expressions.add(expr2);} + ( + (tk3=|tk3=) + expr3=SimpleExpression() {names.add(tk3.image); expressions.add(expr3);} + ( + (tk4=) + expr4=SimpleExpression() {names.add(tk4.image); expressions.add(expr4);} + )? + )? + ) + + { + retval.setNames(names); + retval.setExpressions(expressions); + return retval; + } +} + + ExpressionList SimpleExpressionListAtLeastTwoItems(): { ExpressionList retval = new ExpressionList(); @@ -2095,6 +2734,7 @@ Expression ComparisonItem() : ( retval=AllComparisonExpression() | LOOKAHEAD(3) retval=AnyComparisonExpression() + | LOOKAHEAD(ValueListExpression()) retval=ValueListExpression() | LOOKAHEAD(3) retval=SimpleExpression() | retval=RowConstructor() ) @@ -2136,7 +2776,7 @@ Expression SimpleExpression(): } { ( - retval=BitwiseAndOr() + retval=ConcatExpression() ) { @@ -2151,10 +2791,10 @@ Expression ConcatExpression(): Expression rightExpression = null; } { - leftExpression=AdditiveExpression() { result = leftExpression; } - (LOOKAHEAD(2) - "||" - rightExpression=AdditiveExpression() + leftExpression=BitwiseAndOr() { result = leftExpression; } + (LOOKAHEAD(3) + /* Oracle allows space between the bars. */ + rightExpression=BitwiseAndOr() { Concat binExp = new Concat(); binExp.setLeftExpression(leftExpression); @@ -2174,15 +2814,19 @@ Expression BitwiseAndOr(): Expression rightExpression = null; } { - leftExpression=ConcatExpression() { result = leftExpression; } + leftExpression=AdditiveExpression() { result = leftExpression; } ( ( - "|" { result = new BitwiseOr(); } - | - "&" { result = new BitwiseAnd(); } + "|" { result = new BitwiseOr(); } + | + "&" { result = new BitwiseAnd(); } + | + "<<" { result = new BitwiseLeftShift(); } + | + ">>" { result = new BitwiseRightShift(); } ) - rightExpression=ConcatExpression() + rightExpression=AdditiveExpression() { BinaryExpression binExp = (BinaryExpression) result; @@ -2233,6 +2877,7 @@ Expression MultiplicativeExpression(): ( LOOKAHEAD(2) ("*" { result = new Multiplication(); } | "/" { result = new Division(); } + | { result = new IntegerDivision(); } | "%" { result = new Modulo(); } ) @@ -2271,7 +2916,7 @@ Expression BitwiseXor(): { return result; } } -Expression PrimaryExpression(): +Expression PrimaryExpression() #PrimaryExpression: { Expression retval = null; CastExpression castExpr = null; @@ -2279,85 +2924,116 @@ Expression PrimaryExpression(): Token sign = null; String tmp = ""; ColDataType type = null; + boolean not = false; + boolean exclamationMarkNot = false; + boolean dateExpressionAllowed = true; + Expression idxExpr; } { -( - { retval = new NullValue(); } + [ { not=true; } | "!" { not=true; exclamationMarkNot=true; } ] + [sign="+" | sign="-" | sign="~"] + ( + { retval = new NullValue(); } + + | retval=CaseWhenExpression() + + | retval = SimpleJdbcParameter() - | retval=CaseWhenExpression() + | LOOKAHEAD(2) retval=JdbcNamedParameter() - | LOOKAHEAD(3) [sign="+" | sign="-"] "?" { retval = new JdbcParameter(++jdbcParameterIndex, false); } [ LOOKAHEAD(2) token = { ((JdbcParameter)retval).setUseFixedIndex(true); ((JdbcParameter)retval).setIndex(Integer.valueOf(token.image)); } ] + | retval=UserVariable() - | LOOKAHEAD(3) [sign="+" | sign="-"] retval=JdbcNamedParameter() + | LOOKAHEAD(2) retval=NumericBind() - | LOOKAHEAD(3) [sign="+" | sign="-"] retval=UserVariable() + | LOOKAHEAD(3) retval=ExtractExpression() - | LOOKAHEAD(3) [sign="+" | sign="-"] retval=NumericBind() + | retval=MySQLGroupConcat() - | LOOKAHEAD(AnalyticExpression()) retval=AnalyticExpression() + | LOOKAHEAD(JsonExpression()) retval=JsonExpression() - | LOOKAHEAD(WithinGroupExpression()) retval=WithinGroupExpression() + | LOOKAHEAD(FunctionWithCondParams()) retval = FunctionWithCondParams() - | LOOKAHEAD(3) retval=ExtractExpression() + | LOOKAHEAD(FullTextSearch()) retval = FullTextSearch() - | retval=MySQLGroupConcat() + | LOOKAHEAD(Function()) retval=Function() [ LOOKAHEAD(2) retval = AnalyticExpression((Function)retval) ] - | LOOKAHEAD([sign="+" | sign="-"] JsonExpression()) [sign="+" | sign="-"] retval=JsonExpression() + | LOOKAHEAD(2) retval = IntervalExpression() { dateExpressionAllowed = false; } - | LOOKAHEAD(["+" | "-"] Function()) [sign="+" | sign="-"] retval=Function() + | token= { retval = new DoubleValue(token.image); } - | LOOKAHEAD(2) [sign="+" | sign="-"] token= { retval = new DoubleValue(token.image); } + | token= { retval = new LongValue(token.image); } - | LOOKAHEAD(2) [sign="+" | sign="-"] token= { retval = new LongValue(token.image); } + | token= { retval = new HexValue(token.image); } - | LOOKAHEAD(2) [sign="+" | sign="-"] token= { retval = new HexValue(token.image); } + | LOOKAHEAD(2) retval=CastExpression() - | LOOKAHEAD(2) [sign="+" | sign="-"] retval=CastExpression() + // support timestamp expressions + | token= { retval = new TimeKeyExpression(token.image); } - // support timestamp expressions - | token= { retval = new TimeKeyExpression(token.image); } + | LOOKAHEAD(2) retval=DateTimeLiteralExpression() - | LOOKAHEAD(2) retval=DateTimeLiteralExpression() + | LOOKAHEAD(2) retval = NextValExpression() - | LOOKAHEAD(["+" | "-"] Column()) [sign="+" | sign="-"] retval=Column() + | retval=Column() - | LOOKAHEAD(["+" | "-"] "(" BitwiseAndOr() ")") [sign="+" | sign="-"] "(" retval=BitwiseAndOr() ")" {retval = new Parenthesis(retval); } + | LOOKAHEAD("(" retval=SubSelect() ")") "(" retval=SubSelect() ")" + + | "(" retval=SimpleExpression() ")" {retval = new Parenthesis(retval); } + + | token= { retval = new StringValue(token.image); linkAST(retval,jjtThis); } - | LOOKAHEAD(3) [sign="+" | sign="-"] "(" retval=SubSelect() ")" + | "{d" token= "}" { retval = new DateValue(token.image); } - | token= { retval = new StringValue(token.image); } + | "{t" token= "}" { retval = new TimeValue(token.image); } - | "{d" token= "}" { retval = new DateValue(token.image); } + | "{ts" token= "}" { retval = new TimestampValue(token.image); } + ) - | "{t" token= "}" { retval = new TimeValue(token.image); } + [ + token= { retval = new CollateExpression(retval, token.image); } + ] - | "{ts" token= "}" { retval = new TimestampValue(token.image); } + [ + LOOKAHEAD(2, { dateExpressionAllowed } ) retval = IntervalExpressionWithoutInterval(retval) + ] - | retval = IntervalExpression() -) + [ "[" idxExpr = SimpleExpression() "]" { retval = new ArrayExpression(retval, idxExpr); } ] -[ "::" type=ColDataType() { + ( "::" type=ColDataType() { castExpr = new CastExpression(); castExpr.setUseCastKeyword(false); castExpr.setLeftExpression(retval); castExpr.setType(type); retval=castExpr; -} ] - + } )* + { if (sign != null) { retval = new SignedExpression(sign.image.charAt(0), retval); } + if (not) { + retval = new NotExpression(retval, exclamationMarkNot); + } return retval; } } +NextValExpression NextValExpression() : { + List data = new ArrayList(); +} +{ + data = RelObjectNameList() + { + return new NextValExpression(data); + } +} + JdbcNamedParameter JdbcNamedParameter() : { JdbcNamedParameter parameter = new JdbcNamedParameter(); - Token token; + String name; } { - ":" token= { parameter.setName(token.image); } + ":" (name=RelObjectNameExt2() { parameter.setName(name); }) { return parameter; } @@ -2366,10 +3042,12 @@ JdbcNamedParameter JdbcNamedParameter() : { UserVariable UserVariable() : { UserVariable var = new UserVariable(); String varName; + String var2; } { ("@" | "@@" { var.setDoubleAdd(true);} ) varName=RelObjectNameExt2() + ( "." var2=RelObjectNameExt2() { varName+="." + var2; } )* { var.setName(varName); return var; @@ -2416,36 +3094,42 @@ JsonExpression JsonExpression() : { } IntervalExpression IntervalExpression() : { - IntervalExpression interval = new IntervalExpression(); - Token token; + IntervalExpression interval; + Token token = null; + Expression expr = null; boolean signed = false; } { - ["-" {signed=true;}] (token= | token= | token=) - { interval.setParameter((signed?"-":"") + token.image); } - [ LOOKAHEAD(2) token = { interval.setIntervalType(token.image); } ] + +{ interval = new IntervalExpression(); } + ["-" {signed=true;}] (token= | token= | token= | expr = Column()) + { + if (expr != null) { + if (signed) expr = new SignedExpression('-', expr); + interval.setExpression(expr); + } else { + interval.setParameter((signed?"-":"") + token.image); + } + } + [ LOOKAHEAD(2) (token = | token = ) { interval.setIntervalType(token.image); } ] { return interval; } } -WithinGroupExpression WithinGroupExpression() : -{ - Token token = null; - List orderByElements = null; - WithinGroupExpression result = new WithinGroupExpression(); - ExpressionList exprList; +IntervalExpression IntervalExpressionWithoutInterval(Expression expr) : { + IntervalExpression interval; + Token token; + boolean signed = false; } { - token = "(" exprList = SimpleExpressionList() ")" - - "(" orderByElements = OrderByElements() ")" - { - result.setName(token.image); - result.setExprList(exprList); - result.setOrderByElements(orderByElements); - return result; + interval = new IntervalExpression(false); + interval.setExpression(expr); + } + token = { interval.setIntervalType(token.image); } + { + return interval; } } @@ -2465,9 +3149,9 @@ KeepExpression KeepExpression() : { } } -AnalyticExpression AnalyticExpression() : +AnalyticExpression AnalyticExpression(Function function) : { - AnalyticExpression retval = new AnalyticExpression(); + AnalyticExpression retval = new AnalyticExpression(function); ExpressionList expressionList = null; List olist = null; Token token = null; @@ -2475,26 +3159,30 @@ AnalyticExpression AnalyticExpression() : Expression offset = null; Expression defaultValue = null; WindowElement windowElement = null; - KeepExpression keep = null; + //KeepExpression keep = null; + //boolean distinct = false; + boolean partitionByBrackets = false; + Expression filter = null; } { - token= { retval.setName(token.image); } - "(" [ expr=SimpleExpression() ["," offset=SimpleExpression() ["," defaultValue=SimpleExpression() ]] | "*" { retval.setAllColumns(true); } ] ")" - [ keep=KeepExpression() ] + [ "(" filter = Expression() ")" ] + + ( {retval.setType(AnalyticType.OVER);} + | {retval.setType(AnalyticType.WITHIN_GROUP);} ) - "(" - [ expressionList=SimpleExpressionList() ] - [olist=OrderByElements() [windowElement = WindowElement() ] ] + "(" + [ + (LOOKAHEAD(3) expressionList=SimpleExpressionList() | "(" {partitionByBrackets = true;} expressionList=SimpleExpressionList() ")" ) + ] + [olist=OrderByElements() ] + [windowElement = WindowElement() ] { - retval.setExpression(expr); - retval.setOffset(offset); - retval.setDefaultValue(defaultValue); - retval.setKeep(keep); - retval.setPartitionExpressionList(expressionList); + retval.setPartitionExpressionList(expressionList, partitionByBrackets); retval.setOrderByElements(olist); retval.setWindowElement(windowElement); + retval.setFilterExpression(filter); } ")" { @@ -2531,19 +3219,20 @@ WindowOffset WindowOffset(): } { ( - - ( { offset.setType(WindowOffset.Type.PRECEDING); return offset; } | - { offset.setType(WindowOffset.Type.FOLLOWING); return offset; } ) - ) - | - ( { offset.setType(WindowOffset.Type.CURRENT); return offset;} ) - | - ( expr = SimpleExpression() { - offset.setType(WindowOffset.Type.EXPR); - offset.setExpression(expr); - } - ( { offset.setType(WindowOffset.Type.PRECEDING); } | { offset.setType(WindowOffset.Type.FOLLOWING); } ) - ) + ( + ( { offset.setType(WindowOffset.Type.PRECEDING); } | + { offset.setType(WindowOffset.Type.FOLLOWING); } ) + ) + | + ( { offset.setType(WindowOffset.Type.CURRENT); } ) + | + ( expr = SimpleExpression() { + offset.setType(WindowOffset.Type.EXPR); + offset.setExpression(expr); + } + ( { offset.setType(WindowOffset.Type.PRECEDING); } | { offset.setType(WindowOffset.Type.FOLLOWING); } ) + ) + ) { return offset; @@ -2553,13 +3242,13 @@ WindowOffset WindowOffset(): ExtractExpression ExtractExpression() : { ExtractExpression retval = new ExtractExpression(); - Token token = null; + String token = null; Expression expr = null; } { "(" - token= { retval.setName(token.image); } + token=RelObjectName() { retval.setName(token); } expr=SimpleExpression() { retval.setExpression(expr); } ")" @@ -2590,7 +3279,7 @@ Expression CaseWhenExpression() #CaseWhenExpression: CaseExpression caseExp = new CaseExpression(); Expression switchExp = null; WhenClause clause; - List whenClauses = new ArrayList(); + List whenClauses = new ArrayList(); Expression elseExp = null; } { @@ -2598,10 +3287,10 @@ Expression CaseWhenExpression() #CaseWhenExpression: ( ( clause=WhenThenSearchCondition() { whenClauses.add(clause); } )+ | - (LOOKAHEAD(RegularCondition()) switchExp=RegularCondition() | switchExp=BitwiseAndOr()) + switchExp=Condition() ( clause=WhenThenValue() { whenClauses.add(clause); } )+ ) - [ elseExp=SimpleExpression()] + [ elseExp=Condition()] { caseExp.setSwitchExpression(switchExp); @@ -2618,7 +3307,8 @@ WhenClause WhenThenSearchCondition(): Expression thenExp = null; } { - (LOOKAHEAD(Expression()) whenExp=Expression() | whenExp=SimpleExpression()) thenExp=SimpleExpression() + (LOOKAHEAD(Expression()) whenExp=Expression() | whenExp=SimpleExpression()) + thenExp=Condition() { whenThen.setWhenExpression(whenExp); whenThen.setThenExpression(thenExp); @@ -2633,7 +3323,7 @@ WhenClause WhenThenValue(): Expression thenExp = null; } { - whenExp=PrimaryExpression() thenExp=SimpleExpression() + whenExp=SimpleExpression() thenExp=SimpleExpression() { whenThen.setWhenExpression(whenExp); whenThen.setThenExpression(thenExp); @@ -2645,8 +3335,6 @@ RowConstructor RowConstructor(): { ExpressionList list = null; RowConstructor rowConstructor = new RowConstructor(); } { - //("(" list =SimpleExpressionListAtLeastTwoItems() ")" - //| [ { rowConstructor.setName("ROW");} ] "(" list = SimpleExpressionList() @@ -2658,17 +3346,42 @@ RowConstructor RowConstructor(): { } } +EqualsTo VariableExpression(): { + Expression left; + Expression right; +} { + left = UserVariable() "=" right = SimpleExpression() + { + EqualsTo equals = new EqualsTo(); + equals.setLeftExpression(left); + equals.setRightExpression(right); + return equals; + } +} + Execute Execute(): { - String funcName = null; + List funcName; ExpressionList expressionList = null; Execute execute = new Execute(); + List namedExprList; + Expression expr; } { - ( | ) + ( { execute.setExecType(Execute.EXEC_TYPE.EXEC); } + | { execute.setExecType(Execute.EXEC_TYPE.EXECUTE); } + | { execute.setExecType(Execute.EXEC_TYPE.CALL); } ) - funcName=RelObjectName() { execute.setName(funcName); } + funcName=RelObjectNameList() { execute.setName(funcName); } - [ expressionList=SimpleExpressionList() ] + ( + LOOKAHEAD(3) ( expr = VariableExpression() { namedExprList = new ArrayList(); namedExprList.add( expr ); } + ( "," expr = VariableExpression() { namedExprList.add(expr); })* + { expressionList = new ExpressionList(namedExprList); } ) + | + LOOKAHEAD(3) expressionList=SimpleExpressionList() + | + ("(" expressionList=SimpleExpressionList() ")" { execute.setParenthesis(true); }) + )? { execute.setExprList(expressionList); @@ -2676,32 +3389,116 @@ Execute Execute(): { } } +FullTextSearch FullTextSearch() : { + Column col; + Token searchModifier; + Token againstValue; + FullTextSearch fs = new FullTextSearch(); + List matchedColumns = new ArrayList(); + List expList = new ArrayList(); +} +{ + "(" col=Column() { matchedColumns.add(col); } ("," col=Column() { matchedColumns.add(col); } )* ")" + "(" againstValue= { fs.setAgainstValue(new StringValue(againstValue.image)); } + [ + ( + searchModifier="IN NATURAL LANGUAGE MODE" + | searchModifier="IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION" + | searchModifier="IN BOOLEAN MODE" + | searchModifier="WITH QUERY EXPANSION" + ) + { fs.setSearchModifier(searchModifier.image); } + ] + ")" + { + fs.setMatchColumns(matchedColumns); + return fs; + } +} + +Function FunctionWithCondParams() #Function: { + Function retval = new Function(); + String funcName = null; + ExpressionList expressionList = null; + Token token = null; +} +{ + (token = | token = ) { funcName=token.image; } + + "(" + expressionList=ComplexExpressionList() + ")" + + { + retval.setParameters(expressionList); + retval.setName(funcName); + linkAST(retval,jjtThis); + return retval; + } +} + + Function Function() #Function: { Function retval = new Function(); +} +{ + ( + "{" { retval.setEscaped(true); } InternalFunction(retval) "}" + | InternalFunction(retval) + ) + { + linkAST(retval,jjtThis); + return retval; + } +} + +Function InternalFunction(Function retval) : +{ String funcName = null; String tmp = null; + List expressions = new ArrayList(); ExpressionList expressionList = null; + NamedExpressionList namedExpressionList = null; KeepExpression keep = null; + SubSelect expr = null; + Token tk1 = null; + Token tk2 = null; + Expression expr1 = null; + boolean ignoreNulls = false; } { - ["{fn" { retval.setEscaped(true); } ] - funcName=RelObjectNameExt() [ "." tmp=RelObjectNameExt() { funcName+= "." + tmp; } ["." tmp=RelObjectNameExt() { funcName+= "." + tmp; }]] - "(" [ [ { retval.setDistinct(true); } | { retval.setAllColumns(true); }] (expressionList=SimpleExpressionList() | "*" { retval.setAllColumns(true); }) ] ")" + "(" [ [ LOOKAHEAD(2)( { retval.setDistinct(true); } | { retval.setAllColumns(true); }) ] + ( LOOKAHEAD(4) + "*" { retval.setAllColumns(true); } + | + namedExpressionList=NamedExpressionList1() + | + LOOKAHEAD(NamedExpressionListExprFirst()) namedExpressionList = NamedExpressionListExprFirst() + | + LOOKAHEAD(3) expressionList=SimpleExpressionList() + | + expr = SubSelect() { expr.setUseBrackets(false); expressionList = new ExpressionList(expr); } + )] + [ {retval.setIgnoreNulls(true); }] + ")" - [ "." tmp=RelObjectName() { retval.setAttribute(tmp); }] + [ "." ( + LOOKAHEAD(2) expr1=Function() { retval.setAttribute(expr1); } + | tmp=RelObjectName() { retval.setAttributeName(tmp); } + ) + ] - [ keep = KeepExpression() ] + [ LOOKAHEAD(2) keep = KeepExpression() ] - ["}"] { retval.setParameters(expressionList); + retval.setNamedParameters(namedExpressionList); retval.setName(funcName); retval.setKeep(keep); - linkAST(retval,jjtThis); return retval; } } @@ -2725,6 +3522,19 @@ MySQLGroupConcat MySQLGroupConcat():{ } } +ValueListExpression ValueListExpression(): +{ + ValueListExpression retval = new ValueListExpression(); + ExpressionList expressionList = null; +} +{ + "(" expressionList = SimpleExpressionListAtLeastTwoItems() ")" + { + retval.setExpressionList(expressionList); + return retval; + } +} + TableFunction TableFunction(): { Alias alias = null; @@ -2748,6 +3558,7 @@ SubSelect SubSelect() #SubSelect: selectBody=SelectBody() { subSelect.setSelectBody(selectBody); + linkAST(subSelect,jjtThis); return subSelect; } } @@ -2758,6 +3569,7 @@ CreateIndex CreateIndex(): Table table = null; List colNames = new ArrayList(); Token columnName; + Token using; Index index = null; String name = null; List parameter = new ArrayList(); @@ -2775,6 +3587,8 @@ CreateIndex CreateIndex(): table=Table() + [ using= {index.setUsing(using.image);} ] + "(" (columnName= | @@ -2808,6 +3622,29 @@ CreateIndex CreateIndex(): } } +ColumnDefinition ColumnDefinition(): { + ColumnDefinition coldef; + String columnName; + ColDataType colDataType; + List columnSpecs = new ArrayList(); + List parameter; +} { + columnName=RelObjectName() + + colDataType = ColDataType() + + ( parameter=CreateParameter() { columnSpecs.addAll(parameter); } )* + + { + coldef = new ColumnDefinition(); + coldef.setColumnName(columnName); + coldef.setColDataType(colDataType); + if (columnSpecs.size() > 0) + coldef.setColumnSpecStrings(columnSpecs); + return coldef; + } +} + CreateTable CreateTable(): { CreateTable createTable = new CreateTable(); @@ -2849,8 +3686,9 @@ CreateTable CreateTable(): table=Table() [ ("(" - columnName=RelObjectName() + coldef = ColumnDefinition() + /* colDataType = ColDataType() { columnSpecs = new ArrayList(); @@ -2865,13 +3703,14 @@ CreateTable CreateTable(): if (columnSpecs.size() > 0) coldef.setColumnSpecStrings(columnSpecs); columnDefinitions.add(coldef); - } + }*/ + { columnDefinitions.add(coldef); } ( "," ( - ( + LOOKAHEAD(3) ( tk= sk3=RelObjectName() colNames=ColumnsNamesList() @@ -2961,6 +3800,10 @@ CreateTable CreateTable(): } | ( + + coldef = ColumnDefinition() + + /* columnName=RelObjectName() colDataType = ColDataType() @@ -2977,7 +3820,8 @@ CreateTable CreateTable(): if (columnSpecs.size() > 0) coldef.setColumnSpecStrings(columnSpecs); columnDefinitions.add(coldef); - } + } */ + { columnDefinitions.add(coldef); } ) ) )* @@ -3015,13 +3859,20 @@ ColDataType ColDataType(): List array = new ArrayList(); } { - ( (tk= | tk=) [tk2=] { colDataType.setDataType(tk.image + (tk2!=null?" " + tk2.image:"")); } - | tk= [LOOKAHEAD(2) tk2=] { colDataType.setDataType(tk.image + (tk2!=null?" " + tk2.image:"")); } - | ( tk= | tk= | tk= | tk= | tk= ) { colDataType.setDataType(tk.image); }) + ( + (tk= | tk=) [tk2=] { colDataType.setDataType(tk.image + (tk2!=null?" " + tk2.image:"")); } + | tk= [LOOKAHEAD(2) tk2=] { colDataType.setDataType(tk.image + (tk2!=null?" " + tk2.image:"")); } + | ( tk= | tk= | tk= | tk= | tk= | tk= | tk= | tk= ) + { colDataType.setDataType(tk.image); } + | tk= tk2= {colDataType.setDataType(tk.image + " " + tk2.image);} + | LOOKAHEAD(2) tk= tk2= {colDataType.setDataType(tk.image + " " + tk2.image);} + | tk= { colDataType.setDataType(tk.image);} + ) - [LOOKAHEAD(2) "(" ( (tk= | tk= | tk= ) { argumentsStringList.add(tk.image); } ["," {/*argumentsStringList.add(",");*/}] )* ")"] + [LOOKAHEAD(2) "(" {tk2 =null;} ( (tk= [ tk2= | tk2= ] | tk= | tk= ) + { argumentsStringList.add(tk.image + (tk2!=null?" " + tk2.image:"")); } ["," {/*argumentsStringList.add(",");*/}] )* ")"] [( "[" {tk=null;} [ tk= ] { array.add(tk!=null?Integer.valueOf(tk.image):null); } "]" )+ { colDataType.setArrayData(array); } ] - [ tk= { colDataType.setCharacterSet(tk.image); } ] + [LOOKAHEAD(2) tk= { colDataType.setCharacterSet(tk.image); } ] { if (argumentsStringList.size() > 0) @@ -3034,17 +3885,26 @@ CreateView CreateView(): { CreateView createView = new CreateView(); Table view = null; - SelectBody select = null; + Select select = null; List columnNames = null; } { [ { createView.setOrReplace(true);} ] + [ + { createView.setForce(ForceOption.NO_FORCE); } + | { createView.setForce(ForceOption.FORCE); } + ] + [ + { createView.setTemporary(TemporaryOption.TEMP); } + | { createView.setTemporary(TemporaryOption.TEMPORARY); } + ] [ { createView.setMaterialized(true);} ] view=Table() { createView.setView(view); } [ columnNames = ColumnsNamesList() { createView.setColumnNames(columnNames); } ] - select=SelectBody() { createView.setSelectBody(select); } + select=Select() { createView.setSelect(select); } + [ { createView.setWithReadOnly(true); } ] { return createView; } } @@ -3056,7 +3916,7 @@ AlterView AlterView(): List columnNames = null; } { - + ( ( ) | ( {alterView.setUseReplace(true);}) ) view=Table() { alterView.setView(view); } [ columnNames = ColumnsNamesList() { alterView.setColumnNames(columnNames); } ] @@ -3072,11 +3932,12 @@ List CreateParameter(): StringBuilder identifier = new StringBuilder(""); Expression exp = null; List param = new ArrayList(); + ColDataType colDataType; } { ( - ((tk= { identifier.append(tk.image); } - ["." tk2= { identifier.append("."); identifier.append(tk2.image); }]) + (((tk= | tk=) { identifier.append(tk.image); } + ["." (tk2= | tk2=) { identifier.append("."); identifier.append(tk2.image); }]) { param.add(identifier.toString()); }) | tk= { param.add(tk.image); } @@ -3134,7 +3995,28 @@ List CreateParameter(): tk= { param.add(tk.image); } | tk= { param.add(tk.image); } - + | + tk= { param.add(tk.image); } + | + tk= { param.add(tk.image); } + | + tk= { param.add(tk.image); } + | + tk= { param.add(tk.image); } + | + tk= { param.add(tk.image); } + | + tk= { param.add(tk.image); } + | + tk= { param.add(tk.image); } + | + tk= { param.add(tk.image); } + | + tk= { param.add(tk.image); } + | + tk= { param.add(tk.image); } + | + tk="::" colDataType = ColDataType() { param.add(tk.image); param.add(colDataType.toString()); } ) {return param;} } @@ -3148,7 +4030,7 @@ String AList(): { "(" - ( (tk= | tk= | tk= | tk=) { retval.append(tk.image); } + ( (tk= | tk= | tk= | tk= | tk=) { retval.append(tk.image); } [("," {retval.append(",");} | "=" {retval.append("=");})] )* ")" @@ -3158,16 +4040,28 @@ String AList(): } } +String ColumnsNamesListItem(): +{ + Token tk = null; + String item = null; +} +{ + ( item = RelObjectName() ) + [ "(" tk = ")" { item = item + "(" + tk.image + ")"; } ] + { + return item; + } +} + List ColumnsNamesList(): { List retval = new ArrayList(); - Token tk = null; + String img = null; } { "(" - - (tk= | tk=) { retval.add(tk.image); } - ( "," (tk= | tk=) { retval.add(tk.image); } )* + img=ColumnsNamesListItem() { retval.add(img); } + ( "," img=ColumnsNamesListItem() { retval.add(img); } )* ")" { @@ -3190,13 +4084,15 @@ Drop Drop(): tk= | tk= + | + tk= ) { drop.setType(tk.image); } [ {drop.setIfExists(true);} ] name = Table() { drop.setName(name); } - ((tk= | tk=) { dropArgs.add(tk.image); })* + ((tk= | tk= | tk= ) { dropArgs.add(tk.image); })* { if (dropArgs.size() > 0) @@ -3212,7 +4108,7 @@ Truncate Truncate(): } { - table=Table() { truncate.setTable(table); } + table=Table() { truncate.setTable(table); truncate.setCascade(false); } [ {truncate.setCascade(true);} ] { return truncate; } @@ -3222,16 +4118,18 @@ Truncate Truncate(): AlterExpression.ColumnDataType AlterExpressionColumnDataType(): { String columnName = null; + boolean withType = false; ColDataType dataType = null; List columnSpecs = null; List parameter = null; } { columnName = RelObjectName() + ( { withType = true; } )? dataType = ColDataType() { columnSpecs = new ArrayList(); } ( parameter = CreateParameter() { columnSpecs.addAll(parameter); } )* { - return new AlterExpression.ColumnDataType(columnName, dataType, columnSpecs); + return new AlterExpression.ColumnDataType(columnName, withType, dataType, columnSpecs); } } @@ -3278,20 +4176,41 @@ AlterExpression AlterExpression(): Token tk; Token tk2 = null; String sk3 = null; + String sk4 = null; ColDataType dataType; List columnNames = null; List constraints = null; ForeignKeyIndex fkIndex = null; - NamedConstraint index = null; + Index index = null; Table fkTable = null; AlterExpression.ColumnDataType alterExpressionColumnDataType = null; } { ( - (( { alterExp.setOperation(AlterOperation.ADD); } | { alterExp.setOperation(AlterOperation.MODIFY); }) - ( - ( (LOOKAHEAD(2) )? + (( { alterExp.setOperation(AlterOperation.ADD); } | { alterExp.setOperation(AlterOperation.ALTER); } | { alterExp.setOperation(AlterOperation.MODIFY); }) + ( + LOOKAHEAD(2) ( + columnNames=ColumnsNamesList() { alterExp.setPkColumns(columnNames); } + ) constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] + | + LOOKAHEAD(2) ( + (tk= { alterExp.setUk(true); } | tk=) + sk3 = RelObjectName() + columnNames = ColumnsNamesList() + { + index = new Index(); + index.setType(tk.image); + index.setName(sk3); + index.setColumnsNames(columnNames); + alterExp.setIndex(index); + } + constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] + ) + | + ( (LOOKAHEAD(2) )? alterExpressionColumnDataType = AlterExpressionColumnDataType() { alterExp.addColDataType(alterExpressionColumnDataType); } ) | @@ -3300,9 +4219,9 @@ AlterExpression AlterExpression(): ("," alterExpressionColumnDataType = AlterExpressionColumnDataType() { alterExp.addColDataType(alterExpressionColumnDataType); } )* ")" ) | - ( columnNames=ColumnsNamesList() { alterExp.setPkColumns(columnNames); } ) constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } - | - ( (tk= | tk=) columnNames=ColumnsNamesList() { alterExp.setUkName(tk.image); alterExp.setUkColumns(columnNames); } ) + ( (( { alterExp.setUk(true); } | ) (tk= | tk=) { alterExp.setUkName(tk.image); } )? + columnNames=ColumnsNamesList() { alterExp.setUkColumns(columnNames); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }]) | //following two choices regarding foreign keys should be merged ( columnNames=ColumnsNamesList() { alterExp.setFkColumns(columnNames); } @@ -3344,6 +4263,7 @@ AlterExpression AlterExpression(): alterExp.setIndex(index); } constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] ) | ( @@ -3353,24 +4273,80 @@ AlterExpression AlterExpression(): checkCs.setExpression(exp); alterExp.setIndex(checkCs); } - ) ) + ) + | + ( + tk= (tk2= { alterExp.setUk(true); } | tk2=)? + columnNames=ColumnsNamesList() + { + index = new NamedConstraint(); + index.setName(sk3); + index.setType(tk.image + (tk2!=null?" " + tk2.image:"")); + index.setColumnsNames(columnNames); + alterExp.setIndex(index); + } + constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + [ sk4=RelObjectName() { alterExp.addParameters("USING", sk4); }] + ) + | + ( + tk= + columnNames=ColumnsNamesList() + { + index = new NamedConstraint(); + index.setName(sk3); + index.setType(tk.image); + index.setColumnsNames(columnNames); + alterExp.setIndex(index); + } + constraints=AlterExpressionConstraintState() { alterExp.setConstraints(constraints); } + ) + ) ) ) ) | + ( + { + alterExp.setOperation(AlterOperation.CHANGE); + } + ( + { alterExp.setOptionalSpecifier("COLUMN"); } | {} + ) + ( + (tk= | tk=) + alterExpressionColumnDataType = AlterExpressionColumnDataType() { + alterExp.setColOldName(tk.image); + alterExp.addColDataType(alterExpressionColumnDataType); + } + ) + ) + | ( { alterExp.setOperation(AlterOperation.DROP); } ( - ( - (tk= | tk=) + ( (LOOKAHEAD(2) )? + (tk= | tk=) { alterExp.setColumnName(tk.image); } + [tk= { alterExp.addParameters(tk.image); } ] + + ) + | + ( tk= + (tk2= | tk2=) + { + index = new Index(); + index.setType(tk.image); + index.setName(tk2.image); + alterExp.setIndex(index); + } ) | - ( + ( [ { alterExp.setConstraintIfExists(true); } ] (tk= | tk=) { alterExp.setConstraintName(tk.image); @@ -3378,6 +4354,14 @@ AlterExpression AlterExpression(): ) ) ) + | + ( + { + alterExp.setOperation(AlterOperation.ALGORITHM); + } + ["=" { alterExp.setUseEqual(true);} ] + sk3 = RelObjectName() {alterExp.addParameters(sk3); } + ) ) { @@ -3429,3 +4413,27 @@ Commit Commit(): return commit; } } + +Comment Comment(): +{ + Comment result = new Comment(); + Table table; + Column column; + Token comment; +} +{ + + ( + ( + table = Table() { result.setTable(table); } + ) + | + ( + column = Column() { result.setColumn(column); } + ) + ) + comment= { result.setComment(new StringValue(comment.image)); } + { + return result; + } +} diff --git a/src/site/site.xml b/src/site/site.xml index 71ff205f..6d981191 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -1,4 +1,14 @@ + + @@ -6,7 +16,7 @@ xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0%20http://maven.apache%20%20%20%20%20%3Cskin%3E%20%20%20%20%20%20%20%20%20%3CgroupId%3Eorg.apache.maven.skins%3C/groupId%3E%20%20%20%20%20%20%20%20%20%3CartifactId%3Emaven-fluido-skin%3C/artifactId%3E-%20%20%20%20%20%20%20%20%3Cversion%3E1.3.0%3C/version%3E+%20%20%20%20%20%20%20%20%3Cversion%3E1.7%3C/version%3E%20%20%20%20%20%3C/skin%3E%20%20%20%20%20%20%3CbannerLeft%3E@@%20-22,4%20+32,4%20@@%20xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache - \ No newline at end of file + diff --git a/src/test/java/net/sf/jsqlparser/expression/ExpressionPrecedenceTest.java b/src/test/java/net/sf/jsqlparser/expression/ExpressionPrecedenceTest.java new file mode 100644 index 00000000..74516282 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/expression/ExpressionPrecedenceTest.java @@ -0,0 +1,32 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +import net.sf.jsqlparser.JSQLParserException; +import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd; +import net.sf.jsqlparser.expression.operators.arithmetic.Concat; +import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +/** + * + * @author tw + */ +public class ExpressionPrecedenceTest { + + @Test + public void testGetSign() throws JSQLParserException { + Expression expr = CCJSqlParserUtil.parseExpression("1&2||3"); + assertTrue(expr instanceof Concat); + assertTrue(((Concat) expr).getLeftExpression() instanceof BitwiseAnd); + assertTrue(((Concat) expr).getRightExpression() instanceof LongValue); + } +} diff --git a/src/test/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapterTest.java b/src/test/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapterTest.java index 465fbad4..7c78b669 100644 --- a/src/test/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapterTest.java +++ b/src/test/java/net/sf/jsqlparser/expression/ExpressionVisitorAdapterTest.java @@ -1,20 +1,11 @@ -/* - * Copyright (C) 2015 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.expression; @@ -209,5 +200,12 @@ public void testCaseWithoutElse3() throws JSQLParserException { ExpressionVisitorAdapter adapter = new ExpressionVisitorAdapter(); expr.accept(adapter); } + + @Test + public void testAnalyticFunctionWithoutExpression502() throws JSQLParserException { + Expression expr = CCJSqlParserUtil.parseExpression("row_number() over (order by c)"); + ExpressionVisitorAdapter adapter = new ExpressionVisitorAdapter(); + expr.accept(adapter); + } } diff --git a/src/test/java/net/sf/jsqlparser/expression/FunctionWithBooleanParameterTest.java b/src/test/java/net/sf/jsqlparser/expression/FunctionWithBooleanParameterTest.java new file mode 100644 index 00000000..9e377a32 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/expression/FunctionWithBooleanParameterTest.java @@ -0,0 +1,68 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +/** + * Test some cases linked to a boolean (condition) argument as function parameter. + * + * @author Denis Fulachier + * + */ +public class FunctionWithBooleanParameterTest { + + public FunctionWithBooleanParameterTest() { + } + + @Test + public void testParseOpLowerTotally() throws Exception { + Expression result = CCJSqlParserUtil.parseExpression("if(ab, c, d)"); + assertEquals("if(a > b, c, d)", result.toString()); + } + + @Test + public void testParseOpGreaterOrEqual() throws Exception { + Expression result = CCJSqlParserUtil.parseExpression("if(a>=b, c, d)"); + assertEquals("if(a >= b, c, d)", result.toString()); + } + + @Test + public void testParseOpEqual() throws Exception { + Expression result = CCJSqlParserUtil.parseExpression("if(a=b, c, d)"); + assertEquals("if(a = b, c, d)", result.toString()); + } + + @Test + public void testParseOpNotEqualStandard() throws Exception { + Expression result = CCJSqlParserUtil.parseExpression("if(a<>b, c, d)"); + assertEquals("if(a <> b, c, d)", result.toString()); + } + + @Test + public void testParseOpNotEqualBang() throws Exception { + Expression result = CCJSqlParserUtil.parseExpression("if(a!=b, c, d)"); + assertEquals("if(a != b, c, d)", result.toString()); + } +} diff --git a/src/test/java/net/sf/jsqlparser/expression/LongValueTest.java b/src/test/java/net/sf/jsqlparser/expression/LongValueTest.java index 1b952a7f..301aa65f 100644 --- a/src/test/java/net/sf/jsqlparser/expression/LongValueTest.java +++ b/src/test/java/net/sf/jsqlparser/expression/LongValueTest.java @@ -1,20 +1,11 @@ -/* - * Copyright (C) 2017 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.expression; diff --git a/src/test/java/net/sf/jsqlparser/expression/SignedExpressionTest.java b/src/test/java/net/sf/jsqlparser/expression/SignedExpressionTest.java index c190bc74..be0d1395 100644 --- a/src/test/java/net/sf/jsqlparser/expression/SignedExpressionTest.java +++ b/src/test/java/net/sf/jsqlparser/expression/SignedExpressionTest.java @@ -1,20 +1,11 @@ -/* - * Copyright (C) 2014 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.expression; diff --git a/src/test/java/net/sf/jsqlparser/expression/StringValueTest.java b/src/test/java/net/sf/jsqlparser/expression/StringValueTest.java index dd99d995..9fecd104 100644 --- a/src/test/java/net/sf/jsqlparser/expression/StringValueTest.java +++ b/src/test/java/net/sf/jsqlparser/expression/StringValueTest.java @@ -1,20 +1,11 @@ -/* - * Copyright (C) 2016 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.expression; @@ -76,4 +67,17 @@ public void testGetNotExcapedValue() { String result = instance.getNotExcapedValue(); assertEquals(expResult, result); } + + @Test + public void testPrefixes() { + checkStringValue("E'test'", "test", "E"); + checkStringValue("'test'", "test", null); + + } + + private void checkStringValue(String original, String expectedValue, String expectedPrefix) { + StringValue v = new StringValue(original); + assertEquals(expectedValue, v.getValue()); + assertEquals(expectedPrefix, v.getPrefix()); + } } diff --git a/src/test/java/net/sf/jsqlparser/expression/TimestampValueTest.java b/src/test/java/net/sf/jsqlparser/expression/TimestampValueTest.java new file mode 100644 index 00000000..b2d097b7 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/expression/TimestampValueTest.java @@ -0,0 +1,37 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression; + +import net.sf.jsqlparser.JSQLParserException; +import org.junit.Test; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +public class TimestampValueTest { + + @Test + public void testTimestampValue_issue525() throws JSQLParserException { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + String currentDate = dateFormat.format(new Date()); + TimestampValue tv = new TimestampValue(currentDate); + System.out.println(tv.toString()); + } + + @Test + public void testTimestampValueWithQuotation_issue525() throws JSQLParserException { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + String currentDate = dateFormat.format(new Date()); + TimestampValue tv = new TimestampValue("'" + currentDate + "'"); + System.out.println(tv.toString()); + } +} diff --git a/src/test/java/net/sf/jsqlparser/expression/mysql/MySqlSqlCalcFoundRowsTest.java b/src/test/java/net/sf/jsqlparser/expression/mysql/MySqlSqlCalcFoundRowsTest.java new file mode 100644 index 00000000..fd32a667 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/expression/mysql/MySqlSqlCalcFoundRowsTest.java @@ -0,0 +1,67 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression.mysql; + +import net.sf.jsqlparser.JSQLParserException; +import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import net.sf.jsqlparser.statement.Statement; +import net.sf.jsqlparser.statement.StatementVisitorAdapter; +import net.sf.jsqlparser.statement.select.PlainSelect; +import net.sf.jsqlparser.statement.select.Select; +import net.sf.jsqlparser.statement.select.SelectVisitorAdapter; +import org.junit.Test; + +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * @author sam + */ +public class MySqlSqlCalcFoundRowsTest { + @Test + public void testPossibleParsingWithSqlCalcFoundRowsHint() throws JSQLParserException { + MySqlSqlCalcFoundRowRef ref = new MySqlSqlCalcFoundRowRef(false); + String sqlCalcFoundRowsContainingSql = "SELECT SQL_CALC_FOUND_ROWS * FROM TABLE"; + String generalSql = "SELECT * FROM TABLE"; + + accept(CCJSqlParserUtil.parse(sqlCalcFoundRowsContainingSql), ref); + assertTrue(ref.sqlCalcFoundRows); + + accept(CCJSqlParserUtil.parse(generalSql), ref); + assertFalse(ref.sqlCalcFoundRows); + + assertSqlCanBeParsedAndDeparsed(sqlCalcFoundRowsContainingSql); + assertSqlCanBeParsedAndDeparsed(generalSql); + } + + private void accept(Statement statement, final MySqlSqlCalcFoundRowRef ref) { + statement.accept(new StatementVisitorAdapter() { + @Override + public void visit(Select select) { + select.getSelectBody().accept(new SelectVisitorAdapter() { + @Override + public void visit(PlainSelect plainSelect) { + ref.sqlCalcFoundRows = plainSelect.getMySqlSqlCalcFoundRows(); + } + }); + } + + }); + } +} + +class MySqlSqlCalcFoundRowRef { + public boolean sqlCalcFoundRows = false; + + public MySqlSqlCalcFoundRowRef(boolean sqlCalcFoundRows) { + this.sqlCalcFoundRows = sqlCalcFoundRows; + } +} diff --git a/src/test/java/net/sf/jsqlparser/expression/operators/relational/LikeExpressionTest.java b/src/test/java/net/sf/jsqlparser/expression/operators/relational/LikeExpressionTest.java new file mode 100644 index 00000000..0ae55966 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/expression/operators/relational/LikeExpressionTest.java @@ -0,0 +1,29 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.expression.operators.relational; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +/** + * + * @author Tobias Warneke (t.warneke@gmx.net) + */ +public class LikeExpressionTest { + + @Test + public void testLikeNotIssue660() { + LikeExpression instance = new LikeExpression(); + assertFalse(instance.isNot()); + instance.setNot(true); + assertTrue(instance.isNot()); + } +} diff --git a/src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java b/src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java index 868a2d61..6b458813 100644 --- a/src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java +++ b/src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java @@ -1,22 +1,35 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.parser; +import java.io.ByteArrayInputStream; +import java.io.StringReader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.LongValue; import net.sf.jsqlparser.expression.Parenthesis; import net.sf.jsqlparser.expression.operators.arithmetic.Addition; import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication; import net.sf.jsqlparser.schema.Column; +import net.sf.jsqlparser.statement.Statement; +import net.sf.jsqlparser.statement.Statements; import org.junit.After; import org.junit.AfterClass; +import static org.junit.Assert.*; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.*; -/** - * - * @author toben - */ public class CCJSqlParserUtilTest { public CCJSqlParserUtilTest() { @@ -61,9 +74,143 @@ public void testParseExpression2() throws Exception { assertTrue(mult.getRightExpression() instanceof Parenthesis); } + @Test(expected = JSQLParserException.class) + public void testParseExpressionNonPartial() throws Exception { + CCJSqlParserUtil.parseExpression("a+", false); + + } + + @Test(expected = JSQLParserException.class) + public void testParseExpressionFromStringFail() throws Exception { + CCJSqlParserUtil.parse("whatever$"); + } + + @Test(expected = JSQLParserException.class) + public void testParseExpressionFromRaderFail() throws Exception { + CCJSqlParserUtil.parse(new StringReader("whatever$")); + } + + @Test + public void testParseExpressionNonPartial2() throws Exception { + Expression result = CCJSqlParserUtil.parseExpression("a+", true); + assertEquals("a", result.toString()); + } + @Test public void testParseCondExpression() throws Exception { Expression result = CCJSqlParserUtil.parseCondExpression("a+b>5 and c<3"); assertEquals("a + b > 5 AND c < 3", result.toString()); } + + @Test(expected = JSQLParserException.class) + public void testParseCondExpressionFail() throws Exception { + CCJSqlParserUtil.parseCondExpression(";"); + + } + + @Test(expected = JSQLParserException.class) + public void testParseFromStreamFail() throws Exception { + CCJSqlParserUtil.parse(new ByteArrayInputStream("BLA".getBytes(StandardCharsets.UTF_8))); + + } + + @Test(expected = JSQLParserException.class) + public void testParseFromStreamWithEncodingFail() throws Exception { + CCJSqlParserUtil.parse(new ByteArrayInputStream("BLA".getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8.name()); + + } + + @Test + public void testParseCondExpressionNonPartial() throws Exception { + Expression result = CCJSqlParserUtil.parseCondExpression("x=92 and y=29", false); + assertEquals("x = 92 AND y = 29", result.toString()); + } + + @Test(expected = JSQLParserException.class) + public void testParseCondExpressionNonPartial2() throws Exception { + Expression result = CCJSqlParserUtil.parseCondExpression("x=92 lasd y=29", false); + System.out.println(result.toString()); + } + + @Test + public void testParseCondExpressionPartial2() throws Exception { + Expression result = CCJSqlParserUtil.parseCondExpression("x=92 lasd y=29", true); + assertEquals("x = 92", result.toString()); + } + + @Test + public void testParseCondExpressionIssue471() throws Exception { + Expression result = CCJSqlParserUtil.parseCondExpression("(SSN,SSM) IN ('11111111111111', '22222222222222')"); + assertEquals("(SSN, SSM) IN ('11111111111111', '22222222222222')", result.toString()); + } + + @Test + public void testParseStatementsIssue691() throws Exception { + Statements result = CCJSqlParserUtil.parseStatements( + "select * from dual;\n" + + "\n" + + "select\n" + + "*\n" + + "from\n" + + "dual;\n" + + "\n" + + "select *\n" + + "from dual;"); + assertEquals("SELECT * FROM dual;\n" + + "SELECT * FROM dual;\n" + + "SELECT * FROM dual;\n", result.toString()); + } + + @Test + public void testStreamStatementsIssue777() throws Exception { + final List list = new ArrayList<>(); + + CCJSqlParserUtil.streamStatements(new StatementListener() { + @Override + public void accept(Statement statement) { + list.add(statement); + } + }, new ByteArrayInputStream(("select * from dual;\n" + + "select\n" + + "*\n" + + "from\n" + + "dual;\n" + + "\n" + + "-- some comment\n" + + "select *\n" + + "from dual;").getBytes(StandardCharsets.UTF_8)), "UTF-8"); + + assertEquals(list.size(), 3); + } + + @Test(expected = JSQLParserException.class) + public void testParseStatementsFail() throws Exception { + CCJSqlParserUtil.parseStatements("select * from dual;WHATEVER!!"); + } + + @Test(expected = JSQLParserException.class) + public void testParseASTFail() throws Exception { + CCJSqlParserUtil.parseAST("select * from dual;WHATEVER!!"); + } + + @Test + public void testParseStatementsIssue691_2() throws Exception { + Statements result = CCJSqlParserUtil.parseStatements( + "select * from dual;\n" + + "---test"); + assertEquals("SELECT * FROM dual;\n", result.toString()); + } + + @Test + public void testParseStatementIssue742() throws Exception { + Statements result = CCJSqlParserUtil.parseStatements("CREATE TABLE `table_name` (\n" + + " `id` bigint(20) NOT NULL AUTO_INCREMENT,\n" + + " `another_column_id` bigint(20) NOT NULL COMMENT 'column id as sent by SYSTEM',\n" + + " PRIMARY KEY (`id`),\n" + + " UNIQUE KEY `uk_another_column_id` (`another_column_id`)\n" + + ")"); + assertEquals("CREATE TABLE `table_name` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `another_column_id` " + + "bigint (20) NOT NULL COMMENT 'column id as sent by SYSTEM', PRIMARY KEY (`id`), UNIQUE KEY `uk_another_column_id` " + + "(`another_column_id`));\n", result.toString()); + } } diff --git a/src/test/java/net/sf/jsqlparser/parser/JSQLParserExceptionTest.java b/src/test/java/net/sf/jsqlparser/parser/JSQLParserExceptionTest.java new file mode 100644 index 00000000..5b38f25b --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/parser/JSQLParserExceptionTest.java @@ -0,0 +1,93 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.parser; + +import net.sf.jsqlparser.JSQLParserException; +import org.junit.After; +import org.junit.AfterClass; + +import static org.junit.Assert.*; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; + +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author schwitters + */ +public class JSQLParserExceptionTest { + + public JSQLParserExceptionTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of parseExpression method, of class CCJSqlParserUtil. + */ + @Test + public void testExceptionWithCause() throws Exception { + IllegalArgumentException arg1 = new IllegalArgumentException(); + JSQLParserException ex1=new JSQLParserException("", arg1); + assertSame(arg1, ex1.getCause()); + } + @Test + public void testExceptionPrintStacktrace() throws Exception { + IllegalArgumentException arg1 = new IllegalArgumentException("BRATKARTOFFEL"); + JSQLParserException ex1=new JSQLParserException("", arg1); + StringWriter sw = new StringWriter(); + ex1.printStackTrace(new PrintWriter(sw, true)); + assertTrue(sw.toString().contains("BRATKARTOFFEL")); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ex1.printStackTrace(new PrintStream(bos, true)); + assertTrue(new String(bos.toByteArray(), StandardCharsets.UTF_8).contains("BRATKARTOFFEL")); + + } + + @Test + public void testExceptionPrintStacktraceNoCause() throws Exception { + JSQLParserException ex1=new JSQLParserException("", null); + StringWriter sw = new StringWriter(); + ex1.printStackTrace(new PrintWriter(sw, true)); + assertFalse(sw.toString().contains("BRATKARTOFFEL")); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ex1.printStackTrace(new PrintStream(bos, true)); + assertFalse(new String(bos.toByteArray(), StandardCharsets.UTF_8).contains("BRATKARTOFFEL")); + } + @Test + public void testExceptionDefaultContructorCauseInit() throws Exception { + JSQLParserException ex1=new JSQLParserException(); + assertNull(ex1.getCause()); + ex1=new JSQLParserException((Throwable) null); + assertNull(ex1.getCause()); + } + +} diff --git a/src/test/java/net/sf/jsqlparser/schema/ColumnTest.java b/src/test/java/net/sf/jsqlparser/schema/ColumnTest.java index a32808d9..d57c3d37 100644 --- a/src/test/java/net/sf/jsqlparser/schema/ColumnTest.java +++ b/src/test/java/net/sf/jsqlparser/schema/ColumnTest.java @@ -1,28 +1,14 @@ -/* - * Copyright (C) 2016 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.schema; -import net.sf.jsqlparser.expression.Alias; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; @@ -32,31 +18,16 @@ */ public class ColumnTest { - public ColumnTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - @Test - public void testMissingTableAlias() { - Table myTable = new Table("myTable"); - myTable.setAlias(new Alias("tb")); - Column myColumn = new Column(myTable, "myColumn"); - assertEquals("tb.myColumn", myColumn.toString()); + public void testCheckNonFinalClass() { + Column myColumn = new Column(null, "myColumn") { + @Override + public String toString() { + return "anonymous class"; + } + + }; + assertEquals("anonymous class", myColumn.toString()); } } diff --git a/src/test/java/net/sf/jsqlparser/schema/DatabaseTest.java b/src/test/java/net/sf/jsqlparser/schema/DatabaseTest.java new file mode 100644 index 00000000..86c54a28 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/schema/DatabaseTest.java @@ -0,0 +1,70 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.schema; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author schwitters + */ +public class DatabaseTest { + + public DatabaseTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + public void testDatabaseSimple() { + String databaseName = "db1"; + Database database = new Database(databaseName); + assertEquals(databaseName, database.getFullyQualifiedName()); + } + + @Test + public void testDatabaseAndServer() { + final Server server = new Server("SERVER", "INSTANCE"); + String databaseName = "db1"; + Database database = new Database(server, databaseName); + assertEquals("[SERVER\\INSTANCE].db1", database.getFullyQualifiedName()); + assertSame(server, database.getServer()); + assertEquals(databaseName, database.getDatabaseName()); + assertEquals("[SERVER\\INSTANCE].db1", database.toString()); + } + + @Test + public void testNullDatabaseAndServer() { + final Server server = new Server("SERVER", "INSTANCE"); + Database database = new Database(server, null); + assertEquals("[SERVER\\INSTANCE].", database.getFullyQualifiedName()); + assertSame(server, database.getServer()); + } + +} diff --git a/src/test/java/net/sf/jsqlparser/schema/ServerTest.java b/src/test/java/net/sf/jsqlparser/schema/ServerTest.java index 924492c7..741690fb 100644 --- a/src/test/java/net/sf/jsqlparser/schema/ServerTest.java +++ b/src/test/java/net/sf/jsqlparser/schema/ServerTest.java @@ -1,29 +1,17 @@ -package net.sf.jsqlparser.schema; - -import static org.junit.Assert.assertEquals; -import org.junit.Test; - -/* +/*- * #%L * JSQLParser library * %% - * Copyright (C) 2004 - 2013 JSQLParser + * Copyright (C) 2004 - 2019 JSQLParser * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * . + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 * #L% */ +package net.sf.jsqlparser.schema; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + public class ServerTest { @Test @@ -37,6 +25,7 @@ public void testServerNameParsing() throws Exception { assertEquals(fullServerName, server.toString()); } + @Test public void testServerNameAndInstanceParsing() throws Exception { final String serverName = "LOCALHOST"; final String serverInstanceName = "SQLSERVER"; @@ -49,4 +38,50 @@ public void testServerNameAndInstanceParsing() throws Exception { assertEquals(fullServerName, server.toString()); } + @Test + public void testServerNameAndInstanceParsing2() throws Exception { + String simpleName = "LOCALHOST"; + final Server server = new Server(simpleName); + assertEquals(simpleName, server.getFullyQualifiedName()); + } + @Test + public void testServerNameAndInstanceParsingNull() throws Exception { + final Server server = new Server(null); + assertEquals("", server.getFullyQualifiedName()); + } + @Test + public void testServerNameAndInstancePassValues() throws Exception { + final Server server = new Server("SERVER", "INSTANCE"); + assertEquals("SERVER", server.getServerName()); + assertEquals("INSTANCE", server.getInstanceName()); + assertEquals(String.format("[%s\\%s]", "SERVER", "INSTANCE"), server.getFullyQualifiedName()); + } + @Test + public void testServerNameNull() throws Exception { + final Server server = new Server(null, "INSTANCE"); + assertEquals(null, server.getServerName()); + assertEquals("INSTANCE", server.getInstanceName()); + assertEquals("", server.getFullyQualifiedName()); + } + @Test + public void testServerNameEmpty() throws Exception { + final Server server = new Server("", "INSTANCE"); + assertEquals("", server.getServerName()); + assertEquals("INSTANCE", server.getInstanceName()); + assertEquals("", server.getFullyQualifiedName()); + } + @Test + public void testInstanceNameNull() throws Exception { + final Server server = new Server("LOCALHOST", null); + assertEquals("LOCALHOST", server.getServerName()); + assertEquals(null, server.getInstanceName()); + assertEquals("[LOCALHOST]", server.getFullyQualifiedName()); + } + @Test + public void testInstanceNameEmpty() throws Exception { + final Server server = new Server("LOCALHOST", ""); + assertEquals("LOCALHOST", server.getServerName()); + assertEquals("", server.getInstanceName()); + assertEquals("[LOCALHOST]", server.getFullyQualifiedName()); + } } diff --git a/src/test/java/net/sf/jsqlparser/schema/TableTest.java b/src/test/java/net/sf/jsqlparser/schema/TableTest.java new file mode 100644 index 00000000..d07981c4 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/schema/TableTest.java @@ -0,0 +1,65 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.schema; + +import net.sf.jsqlparser.JSQLParserException; +import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import net.sf.jsqlparser.statement.select.PlainSelect; +import net.sf.jsqlparser.statement.select.Select; +import net.sf.jsqlparser.util.deparser.ExpressionDeParser; +import net.sf.jsqlparser.util.deparser.SelectDeParser; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +/** + * + * @author Tobias Warneke (t.warneke@gmx.net) + */ +public class TableTest { + + @Test + public void tableIndexException() { + Table table = new Table(); + table.setName("bla"); + table.setDatabase(new Database(new Server("server", "instance"), "db")); + } + + @Test + public void tableSetDatabase() { + Table table = new Table(); + table.setName("testtable"); + Database database = new Database("default"); + table.setDatabase(database); + assertEquals("default..testtable", table.toString()); + } + + @Test + public void tableSetDatabaseIssue812() throws JSQLParserException { + String sql = "SELECT * FROM MY_TABLE1 as T1, MY_TABLE2, (SELECT * FROM MY_DB.TABLE3) LEFT OUTER JOIN MY_TABLE4 " + + " WHERE ID = (SELECT MAX(ID) FROM MY_TABLE5) AND ID2 IN (SELECT * FROM MY_TABLE6)"; + + Select select = (Select) CCJSqlParserUtil.parse(sql); + StringBuilder buffer = new StringBuilder(); + ExpressionDeParser expressionDeParser = new ExpressionDeParser(); + final Database database = new Database("default"); + SelectDeParser deparser = new SelectDeParser(expressionDeParser, buffer) { + + @Override + public void visit(Table tableName) { + System.out.println(tableName); + tableName.setDatabase(database); // Exception + System.out.println(tableName.getDatabase()); + } + }; + + deparser.visit((PlainSelect) select.getSelectBody()); + + } +} diff --git a/src/test/java/net/sf/jsqlparser/statement/AdaptersTest.java b/src/test/java/net/sf/jsqlparser/statement/AdaptersTest.java index 9997d125..9eb5fa3e 100644 --- a/src/test/java/net/sf/jsqlparser/statement/AdaptersTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/AdaptersTest.java @@ -1,3 +1,12 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.statement; import net.sf.jsqlparser.JSQLParserException; @@ -16,9 +25,6 @@ import static org.junit.Assert.assertEquals; -/** - * @author aalmiray - */ public class AdaptersTest { /** diff --git a/src/test/java/net/sf/jsqlparser/statement/BlockTest.java b/src/test/java/net/sf/jsqlparser/statement/BlockTest.java new file mode 100644 index 00000000..e5d11d93 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/BlockTest.java @@ -0,0 +1,85 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import net.sf.jsqlparser.JSQLParserException; +import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author Tobias Warneke (t.warneke@gmx.net) + */ +public class BlockTest { + + public BlockTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getStatements method, of class Block. + */ + @Test + public void testGetStatements() throws JSQLParserException { + Statements stmts = CCJSqlParserUtil.parseStatements("begin\nselect * from feature;\nend"); + assertEquals("BEGIN\n" + + "SELECT * FROM feature;\n" + + "END;\n", stmts.toString()); + } + + @Test + public void testBlock2() throws JSQLParserException { + Statements stmts = CCJSqlParserUtil.parseStatements("begin\n" + + "update table1 set a = 'xx' where b = 'condition1';\n" + + "update table1 set a = 'xx' where b = 'condition2';\n" + + "end;"); + assertEquals("BEGIN\n" + + "UPDATE table1 SET a = 'xx' WHERE b = 'condition1';\n" + + "UPDATE table1 SET a = 'xx' WHERE b = 'condition2';\n" + + "END;\n" + + "", stmts.toString()); + + } + @Test + public void testBlock3() throws JSQLParserException { + Statements stmts = CCJSqlParserUtil.parseStatements("begin\nselect * from feature;\nend"); + Block block =(Block) stmts.getStatements().get(0); + assertFalse(block.getStatements().getStatements().isEmpty()); + } + @Test + public void testBlockToStringIsNullSafe() throws JSQLParserException { + Block block = new Block(); + block.setStatements(null); + assertEquals("BEGIN\n" + + "END", block.toString()); + } + +} diff --git a/src/test/java/net/sf/jsqlparser/statement/DeclareStatementTest.java b/src/test/java/net/sf/jsqlparser/statement/DeclareStatementTest.java new file mode 100644 index 00000000..3ca78c89 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/DeclareStatementTest.java @@ -0,0 +1,54 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import net.sf.jsqlparser.JSQLParserException; +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import org.junit.Test; + +/** + * + * @author tw + */ +public class DeclareStatementTest { + + public DeclareStatementTest() { + } + + @Test + public void testDeclareType() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DECLARE @find nvarchar (30)"); + } + + @Test + public void testDeclareTypeWithDefault() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DECLARE @find varchar (30) = 'Man%'"); + } + + @Test + public void testDeclareTypeList() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DECLARE @group nvarchar (50), @sales money"); + } + + @Test + public void testDeclareTypeList2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DECLARE @group nvarchar (50), @sales varchar (50)"); + } + + @Test + public void testDeclareTable() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DECLARE @MyTableVar TABLE (EmpID int NOT NULL, OldVacationHours int, NewVacationHours int, ModifiedDate datetime)"); + } + + @Test + public void testDeclareAs() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DECLARE @LocationTVP AS LocationTableType"); + } +} diff --git a/src/test/java/net/sf/jsqlparser/statement/DescribeTest.java b/src/test/java/net/sf/jsqlparser/statement/DescribeTest.java new file mode 100644 index 00000000..79e8b4f9 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/DescribeTest.java @@ -0,0 +1,22 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import net.sf.jsqlparser.JSQLParserException; +import static net.sf.jsqlparser.test.TestUtils.*; +import org.junit.Test; + +public class DescribeTest { + + @Test + public void testDescribe() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DESCRIBE foo.products"); + } +} diff --git a/src/test/java/net/sf/jsqlparser/statement/ExplainTest.java b/src/test/java/net/sf/jsqlparser/statement/ExplainTest.java new file mode 100644 index 00000000..1780f6d2 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/ExplainTest.java @@ -0,0 +1,22 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import net.sf.jsqlparser.JSQLParserException; +import static net.sf.jsqlparser.test.TestUtils.*; +import org.junit.Test; + +public class ExplainTest { + + @Test + public void testDescribe() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("EXPLAIN SELECT * FROM mytable"); + } +} diff --git a/src/test/java/net/sf/jsqlparser/statement/SetStatementTest.java b/src/test/java/net/sf/jsqlparser/statement/SetStatementTest.java index 8b360990..1b4a8d71 100644 --- a/src/test/java/net/sf/jsqlparser/statement/SetStatementTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/SetStatementTest.java @@ -1,29 +1,16 @@ -/* - * Copyright (C) 2015 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.statement; import net.sf.jsqlparser.JSQLParserException; import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; /** @@ -32,25 +19,6 @@ */ public class SetStatementTest { - public SetStatementTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - @Test public void testSimpleSet() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SET statement_timeout = 0"); @@ -65,4 +33,9 @@ public void testIssue373() throws JSQLParserException { public void testIssue373_2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SET tester 5"); } + + @Test + public void testMultiValue() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SET v = 1, c = 3"); + } } diff --git a/src/test/java/net/sf/jsqlparser/statement/ShowColumnsStatementTest.java b/src/test/java/net/sf/jsqlparser/statement/ShowColumnsStatementTest.java new file mode 100644 index 00000000..f246ac29 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/ShowColumnsStatementTest.java @@ -0,0 +1,28 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import net.sf.jsqlparser.JSQLParserException; +import org.junit.Test; + +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; + +/** + * + * @author oshai + */ +public class ShowColumnsStatementTest { + + + @Test + public void testSimpleUse() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SHOW COLUMNS FROM mydatabase"); + } +} diff --git a/src/test/java/net/sf/jsqlparser/statement/ShowStatementTest.java b/src/test/java/net/sf/jsqlparser/statement/ShowStatementTest.java new file mode 100644 index 00000000..143f2898 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/ShowStatementTest.java @@ -0,0 +1,31 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import net.sf.jsqlparser.JSQLParserException; +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import org.junit.Test; + +/** + * + * @author oshai + */ +public class ShowStatementTest { + + @Test + public void testSimpleUse() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SHOW mydatabase"); + } + + @Test + public void testSimpleUse2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SHOW transaction_isolation"); + } +} diff --git a/src/test/java/net/sf/jsqlparser/statement/StatementsTest.java b/src/test/java/net/sf/jsqlparser/statement/StatementsTest.java index 5d0c6e6c..5ae82d23 100644 --- a/src/test/java/net/sf/jsqlparser/statement/StatementsTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/StatementsTest.java @@ -1,10 +1,19 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.statement; -import java.io.StringReader; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParser; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.parser.ParseException; +import net.sf.jsqlparser.parser.StringProvider; import net.sf.jsqlparser.statement.select.Select; import org.junit.After; import org.junit.AfterClass; @@ -13,10 +22,6 @@ import org.junit.Test; import static org.junit.Assert.*; -/** - * - * @author toben - */ public class StatementsTest { public StatementsTest() { @@ -63,7 +68,7 @@ public void testStatementsProblem() throws JSQLParserException { @Test public void testStatementsErrorRecovery() throws JSQLParserException, ParseException { String sqls = "select * from mytable; select * from;"; - CCJSqlParser parser = new CCJSqlParser(new StringReader(sqls)); + CCJSqlParser parser = new CCJSqlParser(new StringProvider(sqls)); parser.setErrorRecovery(true); Statements parseStatements = parser.Statements(); @@ -76,7 +81,7 @@ public void testStatementsErrorRecovery() throws JSQLParserException, ParseExcep @Test public void testStatementsErrorRecovery2() throws JSQLParserException, ParseException { String sqls = "select * from1 table;"; - CCJSqlParser parser = new CCJSqlParser(new StringReader(sqls)); + CCJSqlParser parser = new CCJSqlParser(new StringProvider(sqls)); parser.setErrorRecovery(true); Statements parseStatements = parser.Statements(); @@ -89,7 +94,7 @@ public void testStatementsErrorRecovery2() throws JSQLParserException, ParseExce @Test public void testStatementsErrorRecovery3() throws JSQLParserException, ParseException { String sqls = "select * from mytable; select * from;select * from mytable2"; - CCJSqlParser parser = new CCJSqlParser(new StringReader(sqls)); + CCJSqlParser parser = new CCJSqlParser(new StringProvider(sqls)); parser.setErrorRecovery(true); Statements parseStatements = parser.Statements(); diff --git a/src/test/java/net/sf/jsqlparser/statement/UseStatementTest.java b/src/test/java/net/sf/jsqlparser/statement/UseStatementTest.java new file mode 100644 index 00000000..4ff5f387 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/UseStatementTest.java @@ -0,0 +1,27 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement; + +import net.sf.jsqlparser.JSQLParserException; +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import org.junit.Test; + +/** + * + * @author toben + */ +public class UseStatementTest { + + + @Test + public void testSimpleUse() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("USE mydatabase"); + } +} diff --git a/src/test/java/net/sf/jsqlparser/test/alter/AlterTest.java b/src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java similarity index 67% rename from src/test/java/net/sf/jsqlparser/test/alter/AlterTest.java rename to src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java index bd2b7731..fc671f2a 100644 --- a/src/test/java/net/sf/jsqlparser/test/alter/AlterTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/alter/AlterTest.java @@ -1,25 +1,31 @@ -package net.sf.jsqlparser.test.alter; - -import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; -import static net.sf.jsqlparser.test.TestUtils.assertStatementCanBeDeparsedAs; - +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.alter; + +import java.util.Arrays; import java.util.List; - -import junit.framework.TestCase; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.statement.Statement; -import net.sf.jsqlparser.statement.alter.Alter; -import net.sf.jsqlparser.statement.alter.AlterExpression; import net.sf.jsqlparser.statement.alter.AlterExpression.ColumnDataType; -import net.sf.jsqlparser.statement.alter.AlterOperation; - -public class AlterTest extends TestCase { +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import static net.sf.jsqlparser.test.TestUtils.assertStatementCanBeDeparsedAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import org.junit.Test; - public AlterTest(String arg0) { - super(arg0); - } +public class AlterTest { + @Test public void testAlterTableAddColumn() throws JSQLParserException { Statement stmt = CCJSqlParserUtil. parse("ALTER TABLE mytable ADD COLUMN mycolumn varchar (255)"); @@ -33,6 +39,7 @@ public void testAlterTableAddColumn() throws JSQLParserException { assertEquals("varchar (255)", colDataTypes.get(0).getColDataType().toString()); } + @Test public void testAlterTableAddColumn_ColumnKeyWordImplicit() throws JSQLParserException { Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE mytable ADD mycolumn varchar (255)"); assertTrue(stmt instanceof Alter); @@ -45,70 +52,92 @@ public void testAlterTableAddColumn_ColumnKeyWordImplicit() throws JSQLParserExc assertEquals("varchar (255)", colDataTypes.get(0).getColDataType().toString()); } + @Test public void testAlterTablePrimaryKey() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE animals ADD PRIMARY KEY (id)"); } + @Test public void testAlterTablePrimaryKeyDeferrable() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE animals ADD PRIMARY KEY (id) DEFERRABLE"); } + @Test public void testAlterTablePrimaryKeyNotDeferrable() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE animals ADD PRIMARY KEY (id) NOT DEFERRABLE"); } + @Test public void testAlterTablePrimaryKeyValidate() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE animals ADD PRIMARY KEY (id) VALIDATE"); } + @Test public void testAlterTablePrimaryKeyNoValidate() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE animals ADD PRIMARY KEY (id) NOVALIDATE"); } + @Test public void testAlterTablePrimaryKeyDeferrableValidate() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE animals ADD PRIMARY KEY (id) DEFERRABLE VALIDATE"); } + @Test public void testAlterTablePrimaryKeyDeferrableDisableNoValidate() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE animals ADD PRIMARY KEY (id) DEFERRABLE DISABLE NOVALIDATE"); } + @Test public void testAlterTableUniqueKey() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE `schema_migrations` ADD UNIQUE KEY `unique_schema_migrations` (`version`)"); } + @Test public void testAlterTableForgeignKey() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id) ON DELETE CASCADE"); } + @Test public void testAlterTableAddConstraint() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE RESOURCELINKTYPE ADD CONSTRAINT FK_RESOURCELINKTYPE_PARENTTYPE_PRIMARYKEY FOREIGN KEY (PARENTTYPE_PRIMARYKEY) REFERENCES RESOURCETYPE(PRIMARYKEY)"); } + @Test public void testAlterTableAddConstraintWithConstraintState() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE RESOURCELINKTYPE ADD CONSTRAINT FK_RESOURCELINKTYPE_PARENTTYPE_PRIMARYKEY FOREIGN KEY (PARENTTYPE_PRIMARYKEY) REFERENCES RESOURCETYPE(PRIMARYKEY) DEFERRABLE DISABLE NOVALIDATE"); } - + + @Test public void testAlterTableAddConstraintWithConstraintState2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE RESOURCELINKTYPE ADD CONSTRAINT RESOURCELINKTYPE_PRIMARYKEY PRIMARY KEY (PRIMARYKEY) DEFERRABLE NOVALIDATE"); } + + @Test + public void testAlterTableAddUniqueConstraint() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("ALTER TABLE Persons ADD UNIQUE (ID)"); + } + @Test public void testAlterTableForgeignKey2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id)"); } + @Test public void testAlterTableForgeignKey3() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id) ON DELETE RESTRICT"); } + @Test public void testAlterTableForgeignKey4() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE test ADD FOREIGN KEY (user_id) REFERENCES ra_user (id) ON DELETE SET NULL"); } + @Test public void testAlterTableDropColumn() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE test DROP COLUMN YYY"); } + @Test public void testAlterTableDropColumn2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE mytable DROP COLUMN col1, DROP COLUMN col2"); @@ -122,6 +151,7 @@ public void testAlterTableDropColumn2() throws JSQLParserException { assertEquals("col2", col2Exp.getColumnName()); } + @Test public void testAlterTableDropConstraint() throws JSQLParserException { final String sql = "ALTER TABLE test DROP CONSTRAINT YYY"; Statement stmt = CCJSqlParserUtil.parse(sql); @@ -130,6 +160,12 @@ public void testAlterTableDropConstraint() throws JSQLParserException { assertEquals(alterExpression.getConstraintName(), "YYY"); } + @Test + public void testAlterTableDropConstraintIfExists() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("ALTER TABLE Persons DROP CONSTRAINT IF EXISTS UC_Person"); + } + + @Test public void testAlterTablePK() throws JSQLParserException { final String sql = "ALTER TABLE `Author` ADD CONSTRAINT `AuthorPK` PRIMARY KEY (`ID`)"; Statement stmt = CCJSqlParserUtil.parse(sql); @@ -140,6 +176,7 @@ public void testAlterTablePK() throws JSQLParserException { assertEquals(alterExpression.getIndex().getColumnsNames().get(0), "`ID`"); } + @Test public void testAlterTableFK() throws JSQLParserException { String sql = "ALTER TABLE `Novels` ADD FOREIGN KEY (AuthorID) REFERENCES Author (ID)"; Statement stmt = CCJSqlParserUtil.parse(sql); @@ -152,18 +189,22 @@ public void testAlterTableFK() throws JSQLParserException { assertEquals(alterExpression.getFkSourceColumns().get(0), "ID"); } + @Test public void testAlterTableCheckConstraint() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE `Author` ADD CONSTRAINT name_not_empty CHECK (`NAME` <> '')"); } + @Test public void testAlterTableAddColumn2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE animals ADD (col1 integer, col2 integer)"); } + @Test public void testAlterTableAddColumn3() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE mytable ADD COLUMN mycolumn varchar (255)"); } + @Test public void testAlterTableAddColumn4() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE mytable ADD COLUMN col1 varchar (255), ADD COLUMN col2 integer"); @@ -181,6 +222,7 @@ public void testAlterTableAddColumn4() throws JSQLParserException { assertEquals("integer", col2DataTypes.get(0).getColDataType().toString()); } + @Test public void testAlterTableAddColumn5() throws JSQLParserException { Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE mytable ADD col1 timestamp (3)"); @@ -195,6 +237,7 @@ public void testAlterTableAddColumn5() throws JSQLParserException { assertEquals("timestamp (3)", col1DataTypes.get(0).getColDataType().toString()); } + @Test public void testAlterTableAddColumn6() throws JSQLParserException { final String sql = "ALTER TABLE mytable ADD COLUMN col1 timestamp (3) not null"; Statement stmt = CCJSqlParserUtil.parse(sql); @@ -206,10 +249,12 @@ public void testAlterTableAddColumn6() throws JSQLParserException { assertEquals("null", col1Exp.getColDataTypeList().get(0).getColumnSpecs().get(1)); } + @Test public void testAlterTableModifyColumn1() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE animals MODIFY (col1 integer, col2 number (8, 2))"); } + @Test public void testAlterTableModifyColumn2() throws JSQLParserException { Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE mytable modify col1 timestamp (6)"); @@ -219,7 +264,42 @@ public void testAlterTableModifyColumn2() throws JSQLParserException { assertEquals(AlterOperation.MODIFY, ((Alter) stmt).getAlterExpressions().get(0). getOperation()); } + + @Test + public void testAlterTableAlterColumn() throws JSQLParserException { + // http://www.postgresqltutorial.com/postgresql-change-column-type/ + assertSqlCanBeParsedAndDeparsed("ALTER TABLE table_name ALTER COLUMN column_name_1 TYPE TIMESTAMP, ALTER COLUMN column_name_2 TYPE BOOLEAN"); + } + + @Test + public void testAlterTableChangeColumn1() throws JSQLParserException { + Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE tb_test CHANGE COLUMN c1 c2 INT (10)"); + Alter alter = (Alter) stmt; + assertEquals(AlterOperation.CHANGE, alter.getAlterExpressions().get(0).getOperation()); + assertEquals("c1", alter.getAlterExpressions().get(0).getColOldName()); + assertEquals("COLUMN", alter.getAlterExpressions().get(0).getOptionalSpecifier()); + } + + @Test + public void testAlterTableChangeColumn2() throws JSQLParserException { + Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE tb_test CHANGE c1 c2 INT (10)"); + Alter alter = (Alter) stmt; + assertEquals(AlterOperation.CHANGE, alter.getAlterExpressions().get(0).getOperation()); + assertEquals("c1", alter.getAlterExpressions().get(0).getColOldName()); + assertNull(alter.getAlterExpressions().get(0).getOptionalSpecifier()); + } + @Test + public void testAlterTableChangeColumn3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("ALTER TABLE tb_test CHANGE COLUMN c1 c2 INT (10)"); + } + + @Test + public void testAlterTableChangeColumn4() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("ALTER TABLE tb_test CHANGE c1 c2 INT (10)"); + } + + @Test public void testAlterTableAddColumnWithZone() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE mytable ADD COLUMN col1 timestamp with time zone"); assertSqlCanBeParsedAndDeparsed("ALTER TABLE mytable ADD COLUMN col1 timestamp without time zone"); @@ -235,10 +315,77 @@ public void testAlterTableAddColumnWithZone() throws JSQLParserException { assertEquals("timestamp with time zone", col1DataTypes.get(0).getColDataType().toString()); } + @Test public void testAlterTableAddColumnKeywordTypes() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("ALTER TABLE mytable ADD COLUMN col1 xml"); assertSqlCanBeParsedAndDeparsed("ALTER TABLE mytable ADD COLUMN col1 interval"); assertSqlCanBeParsedAndDeparsed("ALTER TABLE mytable ADD COLUMN col1 bit varying"); } + @Test + public void testDropColumnRestrictIssue510() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("ALTER TABLE TABLE1 DROP COLUMN NewColumn CASCADE"); + } + + @Test + public void testDropColumnRestrictIssue551() throws JSQLParserException { + Statement stmt = CCJSqlParserUtil.parse("ALTER TABLE table1 DROP NewColumn"); + + // COLUMN keyword appears in deparsed statement, drop becomes all caps + assertStatementCanBeDeparsedAs(stmt, "ALTER TABLE table1 DROP COLUMN NewColumn"); + + } + + @Test + public void testAddConstraintKeyIssue320() throws JSQLParserException { + String tableName = "table1"; + String columnName1 = "col1"; + String columnName2 = "col2"; + String columnName3 = "col3"; + String columnName4 = "col4"; + String constraintName1 = "table1_constraint_1"; + String constraintName2 = "table1_constraint_2"; + + for (String constraintType : Arrays.asList("UNIQUE KEY", "KEY")) { + assertSqlCanBeParsedAndDeparsed("ALTER TABLE " + tableName + " ADD CONSTRAINT " + constraintName1 + " " + + constraintType + " (" + columnName1 + ")"); + + assertSqlCanBeParsedAndDeparsed("ALTER TABLE " + tableName + " ADD CONSTRAINT " + constraintName1 + " " + + constraintType + " (" + columnName1 + ", " + columnName2 + ")"); + + assertSqlCanBeParsedAndDeparsed("ALTER TABLE " + tableName + " ADD CONSTRAINT " + constraintName1 + " " + + constraintType + " (" + columnName1 + ", " + columnName2 + "), ADD CONSTRAINT " + + constraintName2 + " " + constraintType + " (" + columnName3 + ", " + columnName4 + ")"); + } + } + + @Test + public void testIssue633() throws JSQLParserException, JSQLParserException, JSQLParserException { + assertSqlCanBeParsedAndDeparsed("ALTER TABLE team_phases ADD CONSTRAINT team_phases_id_key UNIQUE (id)"); + } + + @Test + public void testIssue679() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("ALTER TABLE tb_session_status ADD INDEX idx_user_id_name (user_id, user_name(10)), ADD INDEX idx_user_name (user_name)"); + } + + @Test + public void testAlterTableIndex586() throws Exception { + Statement result = CCJSqlParserUtil.parse("ALTER TABLE biz_add_fee DROP INDEX operation_time, " + + "ADD UNIQUE INDEX operation_time (`operation_time`, `warehouse_code`, `customerid`, `fees_type`, `external_no`) " + + "USING BTREE, ALGORITHM = INPLACE"); + assertEquals("ALTER TABLE biz_add_fee DROP INDEX operation_time , " + + "ADD UNIQUE INDEX operation_time (`operation_time`, `warehouse_code`, `customerid`, `fees_type`, `external_no`) " + + "USING BTREE, ALGORITHM = INPLACE", result.toString()); + } + + @Test + public void testIssue259() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("ALTER TABLE feature_v2 ADD COLUMN third_user_id int (10) unsigned DEFAULT '0' COMMENT '第三方用户id' after kdt_id"); + } + + @Test + public void testIssue633_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE INDEX idx_american_football_action_plays_1 ON american_football_action_plays USING btree (play_type)"); + } } diff --git a/src/test/java/net/sf/jsqlparser/statement/comment/CommentTest.java b/src/test/java/net/sf/jsqlparser/statement/comment/CommentTest.java new file mode 100755 index 00000000..3f2fa060 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/comment/CommentTest.java @@ -0,0 +1,76 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.comment; + +import java.io.StringReader; +import net.sf.jsqlparser.JSQLParserException; +import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import net.sf.jsqlparser.schema.Column; +import net.sf.jsqlparser.schema.Table; +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +public class CommentTest { + + @Test + public void testCommentTable() throws JSQLParserException { + String statement = "COMMENT ON TABLE table1 IS 'comment1'"; + Comment comment = (Comment) CCJSqlParserUtil.parse(new StringReader(statement)); + Table table = comment.getTable(); + assertEquals("table1", table.getName()); + assertEquals("comment1", comment.getComment().getValue()); + assertEquals(statement, "" + comment); + } + + @Test + public void testCommentTable2() throws JSQLParserException { + String statement = "COMMENT ON TABLE schema1.table1 IS 'comment1'"; + Comment comment = (Comment) CCJSqlParserUtil.parse(new StringReader(statement)); + Table table = comment.getTable(); + assertEquals("schema1", table.getSchemaName()); + assertEquals("table1", table.getName()); + assertEquals("comment1", comment.getComment().getValue()); + assertEquals(statement, "" + comment); + } + + @Test + public void testCommentTableDeparse() throws JSQLParserException { + String statement = "COMMENT ON TABLE table1 IS 'comment1'"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test + public void testCommentColumn() throws JSQLParserException { + String statement = "COMMENT ON COLUMN table1.column1 IS 'comment1'"; + Comment comment = (Comment) CCJSqlParserUtil.parse(new StringReader(statement)); + Column column = comment.getColumn(); + assertEquals("table1", column.getTable().getName()); + assertEquals("column1", column.getColumnName()); + assertEquals("comment1", comment.getComment().getValue()); + assertEquals(statement, "" + comment); + } + + @Test + public void testCommentColumnDeparse() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("COMMENT ON COLUMN table1.column1 IS 'comment1'"); + } + + @Test + public void testToString() { + Comment comment = new Comment(); + assertEquals("COMMENT ON IS null", comment.toString()); + } + + @Test + public void testCommentColumnDeparseIssue696() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("COMMENT ON COLUMN hotels.hotelid IS 'Primary key of the table'"); + } +} diff --git a/src/test/java/net/sf/jsqlparser/statement/create/AlterViewTest.java b/src/test/java/net/sf/jsqlparser/statement/create/AlterViewTest.java new file mode 100644 index 00000000..3e706ef7 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/create/AlterViewTest.java @@ -0,0 +1,29 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.create; + +import net.sf.jsqlparser.JSQLParserException; +import static net.sf.jsqlparser.test.TestUtils.*; +import org.junit.Test; + +public class AlterViewTest { + + @Test + public void testAlterView() throws JSQLParserException { + String stmt = "ALTER VIEW myview AS SELECT * FROM mytab"; + assertSqlCanBeParsedAndDeparsed(stmt); + } + + @Test + public void testReplaceView() throws JSQLParserException { + String stmt = "REPLACE VIEW myview AS SELECT * FROM mytab"; + assertSqlCanBeParsedAndDeparsed(stmt); + } +} diff --git a/src/test/java/net/sf/jsqlparser/test/create/CreateIndexTest.java b/src/test/java/net/sf/jsqlparser/statement/create/CreateIndexTest.java similarity index 76% rename from src/test/java/net/sf/jsqlparser/test/create/CreateIndexTest.java rename to src/test/java/net/sf/jsqlparser/statement/create/CreateIndexTest.java index 2f0d6e62..545fd432 100644 --- a/src/test/java/net/sf/jsqlparser/test/create/CreateIndexTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/create/CreateIndexTest.java @@ -1,18 +1,24 @@ -package net.sf.jsqlparser.test.create; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.create; import java.io.StringReader; - import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserManager; import net.sf.jsqlparser.statement.create.index.CreateIndex; import static net.sf.jsqlparser.test.TestUtils.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import org.junit.Ignore; import org.junit.Test; -/** - * @author Raymond Augé - */ public class CreateIndexTest { private final CCJSqlParserManager parserManager = new CCJSqlParserManager(); @@ -84,4 +90,25 @@ public void testCreateIndex6() throws JSQLParserException { String stmt = "CREATE INDEX myindex ON mytab (mycol, mycol2)"; assertSqlCanBeParsedAndDeparsed(stmt); } + + @Test + public void testCreateIndex7() throws JSQLParserException { + String statement + = "CREATE INDEX myindex1 ON mytab USING GIST (mycol)"; + CreateIndex createIndex = (CreateIndex) parserManager.parse(new StringReader(statement)); + assertEquals(1, createIndex.getIndex().getColumnsNames().size()); + assertEquals("myindex1", createIndex.getIndex().getName()); + assertNull(createIndex.getIndex().getType()); + assertEquals("mytab", createIndex.getTable().getFullyQualifiedName()); + assertEquals("mycol", createIndex.getIndex().getColumnsNames().get(0)); + assertEquals("GIST", createIndex.getIndex().getUsing()); + assertEquals(statement, "" + createIndex); + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test + @Ignore + public void testCreateIndexIssue633() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE INDEX idx_american_football_action_plays_1 ON american_football_action_plays USING btree (play_type)"); + } } diff --git a/src/test/java/net/sf/jsqlparser/test/create/CreateTableTest.java b/src/test/java/net/sf/jsqlparser/statement/create/CreateTableTest.java similarity index 77% rename from src/test/java/net/sf/jsqlparser/test/create/CreateTableTest.java rename to src/test/java/net/sf/jsqlparser/statement/create/CreateTableTest.java index 27cbd5c6..c7dec0de 100644 --- a/src/test/java/net/sf/jsqlparser/test/create/CreateTableTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/create/CreateTableTest.java @@ -1,4 +1,13 @@ -package net.sf.jsqlparser.test.create; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.create; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -7,45 +16,49 @@ import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; - -import junit.framework.TestCase; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserManager; +import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.statement.create.table.ColumnDefinition; import net.sf.jsqlparser.statement.create.table.CreateTable; import net.sf.jsqlparser.statement.create.table.Index; import net.sf.jsqlparser.test.TestException; -import net.sf.jsqlparser.util.TablesNamesFinder; import static net.sf.jsqlparser.test.TestUtils.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.junit.Test; -public class CreateTableTest extends TestCase { - - private CCJSqlParserManager parserManager = new CCJSqlParserManager(); +public class CreateTableTest { - public CreateTableTest(String arg0) { - super(arg0); - } + private final CCJSqlParserManager parserManager = new CCJSqlParserManager(); + @Test public void testCreateTable2() throws JSQLParserException { String statement = "CREATE TABLE testtab (\"test\" varchar (255))"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testCreateTable3() throws JSQLParserException { String statement = "CREATE TABLE testtab (\"test\" varchar (255), \"test2\" varchar (255))"; assertSqlCanBeParsedAndDeparsed(statement); } - public void testCreateTableAsSelect() throws JSQLParserException { + @Test + public void testCreateTableAsSelect() throws JSQLParserException, JSQLParserException, JSQLParserException, JSQLParserException { String statement = "CREATE TABLE a AS SELECT col1, col2 FROM b"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testCreateTableAsSelect2() throws JSQLParserException { String statement = "CREATE TABLE newtable AS WITH a AS (SELECT col1, col3 FROM testtable) SELECT col1, col2, col3 FROM b INNER JOIN a ON b.col1 = a.col1"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testCreateTable() throws JSQLParserException { String statement = "CREATE TABLE mytab (mycol a (10, 20) c nm g, mycol2 mypar1 mypar2 (23,323,3) asdf ('23','123') dasd, " + "PRIMARY KEY (mycol2, mycol)) type = myisam"; @@ -61,6 +74,7 @@ public void testCreateTable() throws JSQLParserException { assertEquals(statement, "" + createTable); } + @Test public void testCreateTableUnlogged() throws JSQLParserException { String statement = "CREATE UNLOGGED TABLE mytab (mycol a (10, 20) c nm g, mycol2 mypar1 mypar2 (23,323,3) asdf ('23','123') dasd, " + "PRIMARY KEY (mycol2, mycol)) type = myisam"; @@ -76,72 +90,88 @@ public void testCreateTableUnlogged() throws JSQLParserException { assertEquals(statement, "" + createTable); } + @Test public void testCreateTableUnlogged2() throws JSQLParserException { String statement = "CREATE UNLOGGED TABLE mytab (mycol a (10, 20) c nm g, mycol2 mypar1 mypar2 (23,323,3) asdf ('23','123') dasd, PRIMARY KEY (mycol2, mycol))"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testCreateTableForeignKey() throws JSQLParserException { String statement = "CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR (20), user_id INT UNSIGNED, PRIMARY KEY (id), FOREIGN KEY (user_id) REFERENCES ra_user(id))"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testCreateTableForeignKey2() throws JSQLParserException { String statement = "CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR (20), user_id INT UNSIGNED, PRIMARY KEY (id), CONSTRAINT fkIdx FOREIGN KEY (user_id) REFERENCES ra_user(id))"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testCreateTableForeignKey3() throws JSQLParserException { String statement = "CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR (20), user_id INT UNSIGNED REFERENCES ra_user(id), PRIMARY KEY (id))"; assertSqlCanBeParsedAndDeparsed(statement, true); } + @Test public void testCreateTableForeignKey4() throws JSQLParserException { String statement = "CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR (20), user_id INT UNSIGNED FOREIGN KEY REFERENCES ra_user(id), PRIMARY KEY (id))"; assertSqlCanBeParsedAndDeparsed(statement, true); } + @Test public void testCreateTablePrimaryKey() throws JSQLParserException { String statement = "CREATE TABLE test (id INT UNSIGNED NOT NULL AUTO_INCREMENT, string VARCHAR (20), user_id INT UNSIGNED, CONSTRAINT pk_name PRIMARY KEY (id))"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testCreateTableParams() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TEMPORARY TABLE T1 (PROCESSID VARCHAR (32)) ON COMMIT PRESERVE ROWS"); } + @Test public void testCreateTableUniqueConstraint() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE Activities (_id INTEGER PRIMARY KEY AUTOINCREMENT,uuid VARCHAR(255),user_id INTEGER,sound_id INTEGER,sound_type INTEGER,comment_id INTEGER,type String,tags VARCHAR(255),created_at INTEGER,content_id INTEGER,sharing_note_text VARCHAR(255),sharing_note_created_at INTEGER,UNIQUE (created_at, type, content_id, sound_id, user_id))", true); } + @Test public void testCreateTableDefault() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE T1 (id integer default -1)"); } + @Test public void testCreateTableDefault2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE T1 (id integer default 1)"); } + @Test public void testCreateTableIfNotExists() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE IF NOT EXISTS animals (id INT NOT NULL)"); } + @Test public void testCreateTableInlinePrimaryKey() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE animals (id INT PRIMARY KEY NOT NULL)"); } + @Test public void testCreateTableWithRange() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE foo (name character varying (255), range character varying (255), start_range integer, end_range integer)"); } + @Test public void testCreateTableWithKey() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE bar (key character varying (255) NOT NULL)"); } + @Test public void testCreateTableWithUniqueKey() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE animals (id INT NOT NULL, name VARCHAR (100) UNIQUE KEY (id))"); } + @Test public void testCreateTableVeryComplex() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE `wp_commentmeta` ( `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0', `meta_key` varchar(255) DEFAULT NULL, `meta_value` longtext, PRIMARY KEY (`meta_id`), KEY `comment_id` (`comment_id`), KEY `meta_key` (`meta_key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8", true); assertSqlCanBeParsedAndDeparsed("CREATE TABLE `wp_comments` ( `comment_ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `comment_post_ID` bigint(20) unsigned NOT NULL DEFAULT '0', `comment_author` tinytext NOT NULL, `comment_author_email` varchar(100) NOT NULL DEFAULT '', `comment_author_url` varchar(200) NOT NULL DEFAULT '', `comment_author_IP` varchar(100) NOT NULL DEFAULT '', `comment_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `comment_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `comment_content` text NOT NULL, `comment_karma` int(11) NOT NULL DEFAULT '0', `comment_approved` varchar(20) NOT NULL DEFAULT '1', `comment_agent` varchar(255) NOT NULL DEFAULT '', `comment_type` varchar(20) NOT NULL DEFAULT '', `comment_parent` bigint(20) unsigned NOT NULL DEFAULT '0', `user_id` bigint(20) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`comment_ID`), KEY `comment_post_ID` (`comment_post_ID`), KEY `comment_approved_date_gmt` (`comment_approved`,`comment_date_gmt`), KEY `comment_date_gmt` (`comment_date_gmt`), KEY `comment_parent` (`comment_parent`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8", true); @@ -156,119 +186,190 @@ public void testCreateTableVeryComplex() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE `wp_users` ( `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `user_login` varchar(60) NOT NULL DEFAULT '', `user_pass` varchar(64) NOT NULL DEFAULT '', `user_nicename` varchar(50) NOT NULL DEFAULT '', `user_email` varchar(100) NOT NULL DEFAULT '', `user_url` varchar(100) NOT NULL DEFAULT '', `user_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `user_activation_key` varchar(60) NOT NULL DEFAULT '', `user_status` int(11) NOT NULL DEFAULT '0', `display_name` varchar(250) NOT NULL DEFAULT '', PRIMARY KEY (`ID`), KEY `user_login_key` (`user_login`), KEY `user_nicename` (`user_nicename`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", true); } + @Test public void testCreateTableArrays() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE sal_emp (name text, pay_by_quarter integer[], schedule text[][])"); } + @Test public void testCreateTableArrays2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE sal_emp (name text, pay_by_quarter integer[5], schedule text[3][2])"); } + @Test public void testCreateTableColumnValues() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE mytable1 (values INTEGER)"); } + @Test public void testCreateTableColumnValue() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE mytable1 (value INTEGER)"); } + @Test public void testCreateTableForeignKey5() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE IF NOT EXISTS table1 (id INTEGER PRIMARY KEY AUTO_INCREMENT, aid INTEGER REFERENCES accounts ON aid ON DELETE CASCADE, name STRING, lastname STRING)"); } + @Test public void testCreateTableForeignKey6() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE test (id long, fkey long references another_table (id))"); } + @Test public void testMySqlCreateTableOnUpdateCurrentTimestamp() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE test (applied timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)"); } + @Test public void testMySqlCreateTableWithConstraintWithCascade() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE table1 (id INT (10) UNSIGNED NOT NULL AUTO_INCREMENT, t2_id INT (10) UNSIGNED DEFAULT NULL, t3_id INT (10) UNSIGNED DEFAULT NULL, t4_id INT (10) UNSIGNED NOT NULL, PRIMARY KEY (id), KEY fkc_table1_t4 (t4_id), KEY fkc_table1_t2 (t2_id), KEY fkc_table1_t3 (t3_id), CONSTRAINT fkc_table1_t2 FOREIGN KEY (t2_id) REFERENCES table_two(t2o_id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fkc_table1_t3 FOREIGN KEY (t3_id) REFERENCES table_three(t3o_id) ON UPDATE CASCADE, CONSTRAINT fkc_table1_t4 FOREIGN KEY (t4_id) REFERENCES table_four(t4o_id) ON DELETE CASCADE) ENGINE = InnoDB AUTO_INCREMENT = 8761 DEFAULT CHARSET = utf8"); } + @Test public void testMySqlCreateTableWithConstraintWithNoAction() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE table1 (id INT (10) UNSIGNED NOT NULL AUTO_INCREMENT, t2_id INT (10) UNSIGNED DEFAULT NULL, t3_id INT (10) UNSIGNED DEFAULT NULL, t4_id INT (10) UNSIGNED NOT NULL, PRIMARY KEY (id), KEY fkc_table1_t4 (t4_id), KEY fkc_table1_t2 (t2_id), KEY fkc_table1_t3 (t3_id), CONSTRAINT fkc_table1_t2 FOREIGN KEY (t2_id) REFERENCES table_two(t2o_id) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fkc_table1_t3 FOREIGN KEY (t3_id) REFERENCES table_three(t3o_id) ON UPDATE NO ACTION, CONSTRAINT fkc_table1_t4 FOREIGN KEY (t4_id) REFERENCES table_four(t4o_id) ON DELETE NO ACTION) ENGINE = InnoDB AUTO_INCREMENT = 8761 DEFAULT CHARSET = utf8"); } + @Test public void testMySqlCreateTableWithTextIndexes() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE table2 (id INT (10) UNSIGNED NOT NULL AUTO_INCREMENT, name TEXT, url TEXT, created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), FULLTEXT KEY idx_table2_name (name)) ENGINE = InnoDB AUTO_INCREMENT = 7334 DEFAULT CHARSET = utf8"); } + @Test public void testCreateTableWithCheck() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE table2 (id INT (10) NOT NULL, name TEXT, url TEXT, CONSTRAINT name_not_empty CHECK (name <> ''))"); } + @Test + public void testCreateTableWithCheckNotNull() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE table2 (id INT (10) NOT NULL, name TEXT, url TEXT, CONSTRAINT name_not_null CHECK (name IS NOT NULL))"); + } + + @Test public void testCreateTableIssue270() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE item (i_item_sk integer NOT NULL, i_item_id character (16) NOT NULL, i_rec_start_date date, i_rec_end_date date, i_item_desc character varying(200), i_current_price numeric(7,2), i_wholesale_cost numeric(7,2), i_brand_id integer, i_brand character(50), i_class_id integer, i_class character(50), i_category_id integer, i_category character(50), i_manufact_id integer, i_manufact character(50), i_size character(20), i_formulation character(20), i_color character(20), i_units character(10), i_container character(10), i_manager_id integer, i_product_name character(50) )", true); } + @Test public void testCreateTableIssue270_1() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE item (i_item_sk integer NOT NULL, i_item_id character (16))"); } + @Test public void testCreateTempTableIssue293() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE GLOBAL TEMPORARY TABLE T1 (PROCESSID VARCHAR (32))"); } + @Test public void testCreateTableWithTablespaceIssue247() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE TABLE1 (COLUMN1 VARCHAR2 (15), COLUMN2 VARCHAR2 (15), CONSTRAINT P_PK PRIMARY KEY (COLUMN1) USING INDEX TABLESPACE \"T_INDEX\") TABLESPACE \"T_SPACE\""); } + @Test public void testCreateTableWithTablespaceIssue247_1() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE TABLE1 (COLUMN1 VARCHAR2 (15), COLUMN2 VARCHAR2 (15), CONSTRAINT P_PK PRIMARY KEY (COLUMN1) USING INDEX TABLESPACE \"T_INDEX\")"); } + @Test public void testOnDeleteSetNull() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE inventory (inventory_id INT PRIMARY KEY, product_id INT, CONSTRAINT fk_inv_product_id FOREIGN KEY (product_id) REFERENCES products(product_id) ON DELETE SET NULL)"); } + @Test public void testColumnCheck() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE table1 (col1 INTEGER CHECK (col1 > 100))"); } + @Test public void testTableReferenceWithSchema() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE table1 (col1 INTEGER REFERENCES schema1.table1)"); } + @Test public void testNamedColumnConstraint() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE foo (col1 integer CONSTRAINT no_null NOT NULL)"); } + @Test public void testColumnConstraintWith() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE foo (col1 integer) WITH (fillfactor=70)"); } + @Test public void testExcludeWhereConstraint() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE foo (col1 integer, EXCLUDE WHERE (col1 > 100))"); } + @Test public void testTimestampWithoutTimezone() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE abc.tabc (transaction_date TIMESTAMP WITHOUT TIME ZONE)"); } + @Test public void testCreateUnitonIssue402() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE temp.abc AS SELECT sku FROM temp.a UNION SELECT sku FROM temp.b"); } + @Test public void testCreateUnitonIssue402_2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("CREATE TABLE temp.abc AS (SELECT sku FROM temp.a UNION SELECT sku FROM temp.b)"); } - + + @Test public void testTimestampWithTimezone() throws JSQLParserException { - assertSqlCanBeParsedAndDeparsed("CREATE TABLE country_region (" + - "regionid BIGINT NOT NULL CONSTRAINT pk_auth_region PRIMARY KEY, " + - "region_name VARCHAR (100) NOT NULL, " + - "creation_date TIMESTAMP (0) WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP (0) NOT NULL, " + - "last_change_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP (0), " + - "CONSTRAINT region_name_unique UNIQUE (region_name))"); + assertSqlCanBeParsedAndDeparsed("CREATE TABLE country_region (" + + "regionid BIGINT NOT NULL CONSTRAINT pk_auth_region PRIMARY KEY, " + + "region_name VARCHAR (100) NOT NULL, " + + "creation_date TIMESTAMP (0) WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP (0) NOT NULL, " + + "last_change_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP (0), " + + "CONSTRAINT region_name_unique UNIQUE (region_name))"); } + @Test + public void testCreateTableAsSelect3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE public.sales1 AS (SELECT * FROM public.sales)"); + } + + @Test + public void testQuotedPKColumnsIssue491() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE `FOO` (`ID` INT64, `NAME` STRING (100)) PRIMARY KEY (`ID`)"); + } + + @Test + public void testQuotedPKColumnsIssue491_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE `FOO` (`ID` INT64, `NAME` STRING (100), PRIMARY KEY (`ID`))"); + } + + @Test + public void testKeySyntaxWithLengthColumnParameter() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE basic (BASIC_TITLE varchar (255) NOT NULL, KEY BASIC_TITLE (BASIC_TITLE(255)))"); + } + + @Test + public void testIssue273Varchar2Byte() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE IF NOT EXISTS \"TABLE_OK\" (\"SOME_FIELD\" VARCHAR2 (256 BYTE))"); + } + + @Test + public void testIssue273Varchar2Char() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE IF NOT EXISTS \"TABLE_OK\" (\"SOME_FIELD\" VARCHAR2 (256 CHAR))"); + } + + @Test + public void testIssue661Partition() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE T_TEST_PARTITION (PART_COLUMN VARCHAR2 (32) NOT NULL, OTHER_COLS VARCHAR2 (10) NOT NULL) TABLESPACE TBS_DATA_01 PARTITION BY HASH (PART_COLUMN) PARTITIONS 4 STORE IN (TBS_DATA_01) COMPRESS"); + } + + @Test + public void testIssue770Using() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE `department_region` (`ID` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增主键', `DEPARTMENT_ID` int(10) unsigned NOT NULL COMMENT '部门ID', PRIMARY KEY (`ID`) KEY `DISTRICT_CODE` (`DISTRICT_CODE`) USING BTREE) ENGINE=InnoDB AUTO_INCREMENT=420 DEFAULT CHARSET=utf8", true); + } + + @Test public void testRUBiSCreateList() throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(CreateTableTest.class. getResourceAsStream("/RUBiS-create-requests.txt"))); - TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); try { int numSt = 1; @@ -395,4 +496,77 @@ private String getLine(BufferedReader in) throws Exception { return line; } + + @Test + public void testCollateUtf8Issue785() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE DEMO_SQL (SHARE_PWD varchar (128) COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT 'COMMENT') ENGINE = InnoDB AUTO_INCREMENT = 34 DEFAULT CHARSET = utf8 COLLATE = utf8_bin COMMENT = 'COMMENT'"); + } + + @Test + public void testCreateTableWithSetTypeIssue796() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE `tables_priv` (`Host` char (60) COLLATE utf8_bin NOT NULL DEFAULT '', `Table_priv` set ('Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Grant', 'References', 'Index', 'Alter', 'Create View', 'Show view', 'Trigger') CHARACTER SET utf8 NOT NULL DEFAULT '') ENGINE = MyISAM DEFAULT CHARSET = utf8 COLLATE = utf8_bin COMMENT = 'Table privileges'"); + } + + @Test + public void testCreateTableIssue798() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE `comment` (`text_hash` varchar (32) COLLATE utf8_bin)"); + } + + @Test + public void testCreateTableIssue798_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE parent (\n" + + "PARENT_ID int(11) NOT NULL AUTO_INCREMENT,\n" + + "PCN varchar(100) NOT NULL,\n" + + "IS_DELETED char(1) NOT NULL,\n" + + "STRUCTURE_ID int(11) NOT NULL,\n" + + "DIRTY_STATUS char(1) NOT NULL,\n" + + "BIOLOGICAL char(1) NOT NULL,\n" + + "STRUCTURE_TYPE int(11) NOT NULL,\n" + + "CST_ORIGINAL varchar(1000) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,\n" + + "MWT decimal(14,6) DEFAULT NULL,\n" + + "RESTRICTED int(11) NOT NULL,\n" + + "INIT_DATE datetime DEFAULT NULL,\n" + + "MOD_DATE datetime DEFAULT NULL,\n" + + "CREATED_BY varchar(255) NOT NULL,\n" + + "MODIFIED_BY varchar(255) NOT NULL,\n" + + "CHEMIST_ID varchar(255) NOT NULL,\n" + + "UNKNOWN_ID int(11) DEFAULT NULL,\n" + + "STEREOCHEMISTRY varchar(256) DEFAULT NULL,\n" + + "GEOMETRIC_ISOMERISM varchar(256) DEFAULT NULL,\n" + + "PRIMARY KEY (PARENT_ID),\n" + + "UNIQUE KEY PARENT_PCN_IDX (PCN),\n" + + "KEY PARENT_SID_IDX (STRUCTURE_ID),\n" + + "KEY PARENT_DIRTY_IDX (DIRTY_STATUS)\n" + + ") ENGINE=InnoDB AUTO_INCREMENT=2663 DEFAULT CHARSET=utf8", true); + } + + @Test + public void testCreateTableIssue113() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE foo (reason character varying (255) DEFAULT 'Test' :: character varying NOT NULL)"); + } + + @Test + public void testCreateTableIssue830() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE testyesr (id int, yy year)"); + } + + @Test + public void testCreateTableIssue830_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TABLE testyesr (id int, yy year, mm month, dd day)"); + } + + @Test + public void testSettingCharacterSetIssue829() throws JSQLParserException { + String sql = "CREATE TABLE test (id int (11) NOT NULL, name varchar (64) CHARACTER SET GBK NOT NULL, age int (11) NOT NULL, score decimal (8, 2) DEFAULT NULL, description varchar (64) DEFAULT NULL, creationDate datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id)) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4"; + assertSqlCanBeParsedAndDeparsed(sql); + CreateTable stmt = (CreateTable) CCJSqlParserUtil.parse(sql); + + ColumnDefinition colName = stmt.getColumnDefinitions().stream() + .filter(col -> col.getColumnName().equals("name")) + .findFirst().orElse(null); + + assertNotNull(colName); + + assertEquals("GBK", colName.getColDataType().getCharacterSet()); + } } diff --git a/src/test/java/net/sf/jsqlparser/test/create/CreateViewTest.java b/src/test/java/net/sf/jsqlparser/statement/create/CreateViewTest.java similarity index 61% rename from src/test/java/net/sf/jsqlparser/test/create/CreateViewTest.java rename to src/test/java/net/sf/jsqlparser/statement/create/CreateViewTest.java index 10c4bc82..232e78ac 100644 --- a/src/test/java/net/sf/jsqlparser/test/create/CreateViewTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/create/CreateViewTest.java @@ -1,7 +1,15 @@ -package net.sf.jsqlparser.test.create; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.create; import java.io.StringReader; - import junit.framework.TestCase; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserManager; @@ -23,8 +31,7 @@ public void testCreateView() throws JSQLParserException { CreateView createView = (CreateView) parserManager.parse(new StringReader(statement)); assertFalse(createView.isOrReplace()); assertEquals("myview", createView.getView().getName()); - assertEquals("mytab", ((Table) ((PlainSelect) createView.getSelectBody()).getFromItem()). - getName()); + assertEquals("mytab", ((Table) ((PlainSelect) createView.getSelect().getSelectBody()).getFromItem()).getName()); assertEquals(statement, createView.toString()); } @@ -54,7 +61,7 @@ public void testCreateView5() throws JSQLParserException { CreateView createView = (CreateView) parserManager.parse(new StringReader(statement)); assertFalse(createView.isOrReplace()); assertEquals("myview", createView.getView().getName()); - assertEquals("mytab", ((Table) ((PlainSelect) createView.getSelectBody()).getFromItem()). + assertEquals("mytab", ((Table) ((PlainSelect) createView.getSelect().getSelectBody()).getFromItem()). getName()); assertEquals(statement2, createView.toString()); } @@ -68,4 +75,36 @@ public void testCreateMaterializedView() throws JSQLParserException { String stmt = "CREATE MATERIALIZED VIEW view1 AS SELECT a, b FROM testtab"; assertSqlCanBeParsedAndDeparsed(stmt); } + + public void testCreateForceView() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE FORCE VIEW view1 AS SELECT a, b FROM testtab"); + } + + public void testCreateForceView1() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE NO FORCE VIEW view1 AS SELECT a, b FROM testtab"); + } + + public void testCreateForceView2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE OR REPLACE FORCE VIEW view1 AS SELECT a, b FROM testtab"); + } + + public void testCreateForceView3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE OR REPLACE NO FORCE VIEW view1 AS SELECT a, b FROM testtab"); + } + + public void testCreateTemporaryViewIssue604() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TEMPORARY VIEW myview AS SELECT * FROM mytable"); + } + + public void testCreateTemporaryViewIssue604_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE TEMP VIEW myview AS SELECT * FROM mytable"); + } + + public void testCreateTemporaryViewIssue665() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE VIEW foo(\"BAR\") AS WITH temp AS (SELECT temp_bar FROM foobar) SELECT bar FROM temp"); + } + + public void testCreateWithReadOnlyViewIssue838() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CREATE VIEW v14(c1, c2) AS SELECT c1, C2 FROM t1 WITH READ ONLY"); + } } diff --git a/src/test/java/net/sf/jsqlparser/test/delete/DeleteTest.java b/src/test/java/net/sf/jsqlparser/statement/delete/DeleteTest.java similarity index 87% rename from src/test/java/net/sf/jsqlparser/test/delete/DeleteTest.java rename to src/test/java/net/sf/jsqlparser/statement/delete/DeleteTest.java index 0b23a302..f17af8ef 100644 --- a/src/test/java/net/sf/jsqlparser/test/delete/DeleteTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/delete/DeleteTest.java @@ -1,4 +1,13 @@ -package net.sf.jsqlparser.test.delete; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.delete; import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; @@ -8,7 +17,6 @@ import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserManager; -import net.sf.jsqlparser.statement.delete.Delete; import static org.junit.Assert.assertEquals; public class DeleteTest { @@ -71,4 +79,9 @@ public void testDeleteFromTableUsingInnerJoinToAnotherTableWithAlias() throws JS String stmt = "DELETE gc FROM guide_category AS gc LEFT JOIN guide AS g ON g.id_guide = gc.id_guide WHERE g.title IS NULL LIMIT 5"; assertSqlCanBeParsedAndDeparsed(stmt); } + + @Test + public void testDeleteMultiTableIssue878() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DELETE table1, table2 FROM table1, table2"); + } } diff --git a/src/test/java/net/sf/jsqlparser/test/drop/DropTest.java b/src/test/java/net/sf/jsqlparser/statement/drop/DropTest.java similarity index 69% rename from src/test/java/net/sf/jsqlparser/test/drop/DropTest.java rename to src/test/java/net/sf/jsqlparser/statement/drop/DropTest.java index 7ad4a6d5..9bbc7e92 100644 --- a/src/test/java/net/sf/jsqlparser/test/drop/DropTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/drop/DropTest.java @@ -1,10 +1,18 @@ -package net.sf.jsqlparser.test.drop; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.drop; import java.io.StringReader; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserManager; -import net.sf.jsqlparser.statement.drop.Drop; import static net.sf.jsqlparser.test.TestUtils.*; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -40,4 +48,19 @@ public void testDrop2() throws JSQLParserException { public void testDropIfExists() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("DROP TABLE IF EXISTS my_table"); } + + @Test + public void testDropRestrictIssue510() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DROP TABLE TABLE2 RESTRICT"); + } + + @Test + public void testDropViewIssue545() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DROP VIEW myview"); + } + + @Test + public void testDropViewIssue545_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("DROP VIEW IF EXISTS myview"); + } } diff --git a/src/test/java/net/sf/jsqlparser/statement/execute/ExecuteTest.java b/src/test/java/net/sf/jsqlparser/statement/execute/ExecuteTest.java index 214f7caf..f7e2348f 100644 --- a/src/test/java/net/sf/jsqlparser/statement/execute/ExecuteTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/execute/ExecuteTest.java @@ -1,30 +1,21 @@ -/* - * Copyright (C) 2014 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.statement.execute; import net.sf.jsqlparser.JSQLParserException; +import static net.sf.jsqlparser.test.TestUtils.*; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import static net.sf.jsqlparser.test.TestUtils.*; /** * @@ -57,7 +48,47 @@ public void tearDown() { * @throws net.sf.jsqlparser.JSQLParserException */ @Test - public void testAccept() throws JSQLParserException { + public void testAcceptExecute() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("EXECUTE myproc 'a', 2, 'b'"); } + + @Test + public void testAcceptExec() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("EXEC myproc 'a', 2, 'b'"); + } + + @Test + public void testAcceptCall() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CALL myproc 'a', 2, 'b'"); + } + + @Test + public void testCallWithMultiname() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CALL BAR.FOO"); + } + + @Test + public void testAcceptCallWithParenthesis() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("CALL myproc ('a', 2, 'b')"); + } + + @Test + public void testAcceptExecNamesParameters() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("EXEC procedure @param"); + } + + @Test + public void testAcceptExecNamesParameters2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("EXEC procedure @param = 1"); + } + + @Test + public void testAcceptExecNamesParameters3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("EXEC procedure @param = 'foo'"); + } + + @Test + public void testAcceptExecNamesParameters4() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("EXEC procedure @param = 'foo', @param2 = 'foo2'"); + } } diff --git a/src/test/java/net/sf/jsqlparser/test/insert/InsertTest.java b/src/test/java/net/sf/jsqlparser/statement/insert/InsertTest.java similarity index 57% rename from src/test/java/net/sf/jsqlparser/test/insert/InsertTest.java rename to src/test/java/net/sf/jsqlparser/statement/insert/InsertTest.java index 4413e380..9fd3279b 100644 --- a/src/test/java/net/sf/jsqlparser/test/insert/InsertTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/insert/InsertTest.java @@ -1,7 +1,15 @@ -package net.sf.jsqlparser.test.insert; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.insert; import java.io.StringReader; - import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.expression.DoubleValue; import net.sf.jsqlparser.expression.JdbcParameter; @@ -11,11 +19,10 @@ import net.sf.jsqlparser.parser.CCJSqlParserManager; import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.schema.Table; -import net.sf.jsqlparser.statement.insert.Insert; import net.sf.jsqlparser.statement.select.PlainSelect; import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; import static org.junit.Assert.*; - +import org.junit.Ignore; import org.junit.Test; public class InsertTest { @@ -84,6 +91,63 @@ public void testInsertFromSelect() throws JSQLParserException { assertEquals(statementToString, "" + insert); } + @Test + public void testInsertFromSet() throws JSQLParserException { + String statement = "INSERT INTO mytable SET col1 = 12, col2 = name1 * name2"; + Insert insert = (Insert) parserManager.parse(new StringReader(statement)); + assertEquals("mytable", insert.getTable().getName()); + assertEquals(2, insert.getSetColumns().size()); + assertEquals("col1", ((Column) insert.getSetColumns().get(0)).getColumnName()); + assertEquals("col2", ((Column) insert.getSetColumns().get(1)).getColumnName()); + assertEquals(2, insert.getSetExpressionList().size()); + assertEquals("12", insert.getSetExpressionList().get(0).toString()); + assertEquals("name1 * name2", insert.getSetExpressionList().get(1).toString()); + assertEquals(statement, "" + insert); + } + + @Test + public void testInsertValuesWithDuplicateElimination() throws JSQLParserException { + String statement = "INSERT INTO TEST (ID, COUNTER) VALUES (123, 0) " + + "ON DUPLICATE KEY UPDATE COUNTER = COUNTER + 1"; + Insert insert = (Insert) parserManager.parse(new StringReader(statement)); + assertEquals("TEST", insert.getTable().getName()); + assertEquals(2, insert.getColumns().size()); + assertTrue(insert.isUseValues()); + assertEquals("ID", ((Column) insert.getColumns().get(0)).getColumnName()); + assertEquals("COUNTER", ((Column) insert.getColumns().get(1)).getColumnName()); + assertEquals(2, ((ExpressionList) insert.getItemsList()).getExpressions().size()); + assertEquals(123, ((LongValue) ((ExpressionList) insert.getItemsList()).getExpressions(). + get(0)).getValue()); + assertEquals(0, ((LongValue) ((ExpressionList) insert.getItemsList()).getExpressions(). + get(1)).getValue()); + assertEquals(1, insert.getDuplicateUpdateColumns().size()); + assertEquals("COUNTER", ((Column) insert.getDuplicateUpdateColumns().get(0)).getColumnName()); + assertEquals(1, insert.getDuplicateUpdateExpressionList().size()); + assertEquals("COUNTER + 1", insert.getDuplicateUpdateExpressionList().get(0).toString()); + assertFalse(insert.isUseSelectBrackets()); + assertTrue(insert.isUseDuplicate()); + assertEquals(statement, "" + insert); + } + + @Test + public void testInsertFromSetWithDuplicateElimination() throws JSQLParserException { + String statement = "INSERT INTO mytable SET col1 = 122 " + + "ON DUPLICATE KEY UPDATE col2 = col2 + 1, col3 = 'saint'"; + Insert insert = (Insert) parserManager.parse(new StringReader(statement)); + assertEquals("mytable", insert.getTable().getName()); + assertEquals(1, insert.getSetColumns().size()); + assertEquals("col1", ((Column) insert.getSetColumns().get(0)).getColumnName()); + assertEquals(1, insert.getSetExpressionList().size()); + assertEquals("122", insert.getSetExpressionList().get(0).toString()); + assertEquals(2, insert.getDuplicateUpdateColumns().size()); + assertEquals("col2", ((Column) insert.getDuplicateUpdateColumns().get(0)).getColumnName()); + assertEquals("col3", ((Column) insert.getDuplicateUpdateColumns().get(1)).getColumnName()); + assertEquals(2, insert.getDuplicateUpdateExpressionList().size()); + assertEquals("col2 + 1", insert.getDuplicateUpdateExpressionList().get(0).toString()); + assertEquals("'saint'", insert.getDuplicateUpdateExpressionList().get(1).toString()); + assertEquals(statement, "" + insert); + } + @Test public void testInsertMultiRowValue() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("INSERT INTO mytable (col1, col2) VALUES (a, b), (d, e)"); @@ -191,4 +255,57 @@ public void testKeywordPrecisionIssue363() throws JSQLParserException { public void testWithDeparsingIssue406() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("insert into mytab3 (a,b,c) select a,b,c from mytab where exists(with t as (select * from mytab2) select * from t)", true); } + + @Test + public void testInsertSetInDeparsing() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("INSERT INTO mytable SET col1 = 12, col2 = name1 * name2"); + } + + @Test + public void testInsertValuesWithDuplicateEliminationInDeparsing() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("INSERT INTO TEST (ID, COUNTER) VALUES (123, 0) " + + "ON DUPLICATE KEY UPDATE COUNTER = COUNTER + 1"); + } + + @Test + public void testInsertSetWithDuplicateEliminationInDeparsing() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("INSERT INTO mytable SET col1 = 122 " + + "ON DUPLICATE KEY UPDATE col2 = col2 + 1, col3 = 'saint'"); + } + + @Test + public void testInsertTableWithAliasIssue526() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("INSERT INTO account t (name, addr, phone) SELECT * FROM user"); + } + + @Test + public void testInsertKeyWordEnableIssue592() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("INSERT INTO T_USER (ID, EMAIL_VALIDATE, ENABLE, PASSWORD) VALUES (?, ?, ?, ?)"); + } + + @Test + public void testInsertKeyWordIntervalIssue682() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("INSERT INTO BILLING_TASKS (TIMEOUT, INTERVAL, RETRY_UPON_FAILURE, END_DATE, MAX_RETRY_COUNT, CONTINUOUS, NAME, LAST_RUN, START_TIME, NEXT_RUN, ID, UNIQUE_NAME, INTERVAL_TYPE) VALUES (?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?)"); + } + + @Test + @Ignore + public void testWithAtFront() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("WITH foo AS ( SELECT attr FROM bar ) INSERT INTO lalelu (attr) SELECT attr FROM foo"); + } + + @Test + public void testNextVal() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("INSERT INTO tracker (monitor_id, user_id, module_name, item_id, item_summary, team_id, date_modified, action, visible, id) VALUES (?, ?, ?, ?, ?, ?, to_date(?, 'YYYY-MM-DD HH24:MI:SS'), ?, ?, NEXTVAL FOR TRACKER_ID_SEQ)"); + } + + @Test + public void testNextValIssue773() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("INSERT INTO tableA (ID, c1, c2) SELECT hibernate_sequence.nextval, c1, c2 FROM tableB"); + } + + @Test + public void testBackslashEscapingIssue827() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("INSERT INTO my_table (my_column_1, my_column_2) VALUES ('my_value_1\\\\', 'my_value_2')"); + } } diff --git a/src/test/java/net/sf/jsqlparser/test/merge/MergeTest.java b/src/test/java/net/sf/jsqlparser/statement/merge/MergeTest.java similarity index 90% rename from src/test/java/net/sf/jsqlparser/test/merge/MergeTest.java rename to src/test/java/net/sf/jsqlparser/statement/merge/MergeTest.java index 26de09ce..0cf0037b 100644 --- a/src/test/java/net/sf/jsqlparser/test/merge/MergeTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/merge/MergeTest.java @@ -1,29 +1,20 @@ -/* - * Copyright (C) 2015 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ -package net.sf.jsqlparser.test.merge; +package net.sf.jsqlparser.statement.merge; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.statement.Statement; -import org.junit.Test; import static net.sf.jsqlparser.test.TestUtils.*; import static org.junit.Assert.fail; +import org.junit.Test; /** * @@ -64,6 +55,21 @@ public void testMergeIssue232() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed(sql, true); } + @Test + public void testMergeIssue676() throws JSQLParserException { + String sql = "merge INTO M_KC21 USING\n" + + "(SELECT AAA, BBB FROM I_KC21 WHERE I_KC21.aaa = 'li_kun'\n" + + ") TEMP ON (TEMP.AAA = M_KC21.AAA)\n" + + "WHEN MATCHED THEN\n" + + "UPDATE SET M_KC21.BBB = 6 WHERE enterprise_id IN (0, 1)\n" + + "WHEN NOT MATCHED THEN\n" + + "INSERT VALUES\n" + + "(TEMP.AAA,TEMP.BBB\n" + + ")"; + + assertSqlCanBeParsedAndDeparsed(sql, true); + } + @Test public void testComplexOracleMergeIntoStatement() throws JSQLParserException { String sql = "MERGE INTO DestinationValue Dest USING\n" diff --git a/src/test/java/net/sf/jsqlparser/test/replace/ReplaceTest.java b/src/test/java/net/sf/jsqlparser/statement/replace/ReplaceTest.java similarity index 89% rename from src/test/java/net/sf/jsqlparser/test/replace/ReplaceTest.java rename to src/test/java/net/sf/jsqlparser/statement/replace/ReplaceTest.java index 7b0d00cd..3b93dafe 100644 --- a/src/test/java/net/sf/jsqlparser/test/replace/ReplaceTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/replace/ReplaceTest.java @@ -1,4 +1,13 @@ -package net.sf.jsqlparser.test.replace; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.replace; import java.io.StringReader; @@ -9,7 +18,6 @@ import net.sf.jsqlparser.expression.operators.relational.ExpressionList; import net.sf.jsqlparser.parser.CCJSqlParserManager; import net.sf.jsqlparser.schema.Column; -import net.sf.jsqlparser.statement.replace.Replace; import net.sf.jsqlparser.statement.select.SubSelect; import net.sf.jsqlparser.test.TestUtils; import static org.junit.Assert.assertEquals; @@ -76,4 +84,11 @@ public void testProblemMissingIntoIssue389() throws JSQLParserException { TestUtils. assertSqlCanBeParsedAndDeparsed("REPLACE INTO mytable (key, data) VALUES (1, \"aaa\")"); } + + + @Test + public void testMultipleValues() throws JSQLParserException { + TestUtils. + assertSqlCanBeParsedAndDeparsed("REPLACE INTO mytable (col1, col2, col3) VALUES (1, \"aaa\", now()), (2, \"bbb\", now())"); + } } diff --git a/src/test/java/net/sf/jsqlparser/test/select/HiveTest.java b/src/test/java/net/sf/jsqlparser/statement/select/HiveTest.java similarity index 86% rename from src/test/java/net/sf/jsqlparser/test/select/HiveTest.java rename to src/test/java/net/sf/jsqlparser/statement/select/HiveTest.java index 7ad06843..06251722 100644 --- a/src/test/java/net/sf/jsqlparser/test/select/HiveTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/select/HiveTest.java @@ -1,19 +1,23 @@ -package net.sf.jsqlparser.test.select; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.schema.Table; import net.sf.jsqlparser.statement.Statement; -import net.sf.jsqlparser.statement.select.PlainSelect; -import net.sf.jsqlparser.statement.select.Select; import static net.sf.jsqlparser.test.TestUtils.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Test; -/** - * Created by nhanitvn on 5/19/16. - */ public class HiveTest { @Test diff --git a/src/test/java/net/sf/jsqlparser/statement/select/KSQLTest.java b/src/test/java/net/sf/jsqlparser/statement/select/KSQLTest.java new file mode 100644 index 00000000..344e95e0 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/select/KSQLTest.java @@ -0,0 +1,156 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import net.sf.jsqlparser.schema.Table; +import net.sf.jsqlparser.statement.Statement; +import org.junit.Test; + +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import static net.sf.jsqlparser.test.TestUtils.assertStatementCanBeDeparsedAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class KSQLTest { + + @Test + public void testKSQLWindowedJoin() throws Exception { + String sql; + Statement statement; + + sql = "SELECT *\n" + + "FROM table1 t1\n" + + "INNER JOIN table2 t2\n" + + "WITHIN (5 HOURS)\n" + + "ON t1.id = t2.id\n"; + + statement = CCJSqlParserUtil.parse(sql); + + System.out.println(statement.toString()); + + Select select = (Select) statement; + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); + assertEquals(1, plainSelect.getJoins().size()); + assertEquals("table2", ((Table) plainSelect.getJoins().get(0).getRightItem()). + getFullyQualifiedName()); + assertTrue(plainSelect.getJoins().get(0).isWindowJoin()); + assertEquals(5L, plainSelect.getJoins().get(0).getJoinWindow().getDuration()); + assertEquals("HOURS", plainSelect.getJoins().get(0).getJoinWindow().getTimeUnit().toString()); + assertFalse(plainSelect.getJoins().get(0).getJoinWindow().isBeforeAfterWindow()); + assertStatementCanBeDeparsedAs(select, sql, true); + + assertSqlCanBeParsedAndDeparsed(sql, true); + } + + @Test + public void testKSQLBeforeAfterWindowedJoin() throws Exception { + String sql; + Statement statement; + sql = "SELECT *\n" + + "FROM table1 t1\n" + + "INNER JOIN table2 t2\n" + + "WITHIN (2 MINUTES, 5 MINUTES)\n" + + "ON t1.id = t2.id\n"; + + statement = CCJSqlParserUtil.parse(sql); + + System.out.println(statement.toString()); + + Select select = (Select) statement; + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); + assertEquals(1, plainSelect.getJoins().size()); + assertEquals("table2", ((Table) plainSelect.getJoins().get(0).getRightItem()). + getFullyQualifiedName()); + assertTrue(plainSelect.getJoins().get(0).isWindowJoin()); + assertEquals(2L, plainSelect.getJoins().get(0).getJoinWindow().getBeforeDuration()); + assertEquals("MINUTES", plainSelect.getJoins().get(0).getJoinWindow().getBeforeTimeUnit().toString()); + assertEquals(5L, plainSelect.getJoins().get(0).getJoinWindow().getAfterDuration()); + assertEquals("MINUTES", plainSelect.getJoins().get(0).getJoinWindow().getAfterTimeUnit().toString()); + assertTrue(plainSelect.getJoins().get(0).getJoinWindow().isBeforeAfterWindow()); + assertStatementCanBeDeparsedAs(select, sql, true); + + assertSqlCanBeParsedAndDeparsed(sql, true); + } + + @Test + public void testKSQLHoppingWindows() throws Exception { + String sql; + Statement statement; + sql = "SELECT *\n" + + "FROM table1 t1\n" + + "WINDOW HOPPING (SIZE 30 SECONDS, ADVANCE BY 10 MINUTES)\n" + + "GROUP BY region.id\n"; + + statement = CCJSqlParserUtil.parse(sql); + System.out.println(statement.toString()); + + Select select = (Select) statement; + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); + assertTrue(plainSelect.getKsqlWindow().isHoppingWindow()); + assertFalse(plainSelect.getKsqlWindow().isSessionWindow()); + assertFalse(plainSelect.getKsqlWindow().isTumblingWindow()); + assertEquals(30L, plainSelect.getKsqlWindow().getSizeDuration()); + assertEquals("SECONDS", plainSelect.getKsqlWindow().getSizeTimeUnit().toString()); + assertEquals(10L, plainSelect.getKsqlWindow().getAdvanceDuration()); + assertEquals("MINUTES", plainSelect.getKsqlWindow().getAdvanceTimeUnit().toString()); + assertStatementCanBeDeparsedAs(select, sql, true); + + assertSqlCanBeParsedAndDeparsed(sql, true); + } + + @Test + public void testKSQLSessionWindows() throws Exception { + String sql; + Statement statement; + sql = "SELECT *\n" + + "FROM table1 t1\n" + + "WINDOW SESSION (5 MINUTES)\n" + + "GROUP BY region.id\n"; + + statement = CCJSqlParserUtil.parse(sql); + System.out.println(statement.toString()); + + Select select = (Select) statement; + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); + assertTrue(plainSelect.getKsqlWindow().isSessionWindow()); + assertFalse(plainSelect.getKsqlWindow().isHoppingWindow()); + assertFalse(plainSelect.getKsqlWindow().isTumblingWindow()); + assertEquals(5L, plainSelect.getKsqlWindow().getSizeDuration()); + assertEquals("MINUTES", plainSelect.getKsqlWindow().getSizeTimeUnit().toString()); + + assertStatementCanBeDeparsedAs(select, sql, true); + assertSqlCanBeParsedAndDeparsed(sql, true); + } + + @Test + public void testKSQLTumblingWindows() throws Exception { + String sql; + Statement statement; + sql = "SELECT *\n" + + "FROM table1 t1\n" + + "WINDOW TUMBLING (SIZE 30 SECONDS)\n" + + "GROUP BY region.id\n"; + + statement = CCJSqlParserUtil.parse(sql); + System.out.println(statement.toString()); + Select select = (Select) statement; + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); + assertTrue(plainSelect.getKsqlWindow().isTumblingWindow()); + assertFalse(plainSelect.getKsqlWindow().isSessionWindow()); + assertFalse(plainSelect.getKsqlWindow().isHoppingWindow()); + assertEquals(30L, plainSelect.getKsqlWindow().getSizeDuration()); + assertEquals("SECONDS", plainSelect.getKsqlWindow().getSizeTimeUnit().toString()); + + assertStatementCanBeDeparsedAs(select, sql, true); + assertSqlCanBeParsedAndDeparsed(sql, true); + } +} diff --git a/src/test/java/net/sf/jsqlparser/statement/select/MemoryTest.java b/src/test/java/net/sf/jsqlparser/statement/select/MemoryTest.java new file mode 100644 index 00000000..e029bc70 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/select/MemoryTest.java @@ -0,0 +1,54 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import java.io.StringReader; + +import net.sf.jsqlparser.parser.CCJSqlParserManager; +import net.sf.jsqlparser.statement.Statement; + +public class MemoryTest { + + public static void main(String[] args) throws Exception { + System.gc(); + System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); + CCJSqlParserManager parserManager = new CCJSqlParserManager(); + + String longQuery = "select * from k where ID > 4"; + + /* + * String longQuery = "select * from ( SELECT intermediate.id as id , intermediate.date as " + * + "date FROM ( SELECT DISTINCT ( id ) FROM ( SELECT " + + * "wct_workflows.workflow_id as id , wct_transaction.date as date FROM " + + * "wct_audit_entry , wct_transaction , wct_workflows WHERE " + + * "( wct_audit_entry.privilege = 'W' or wct_audit_entry.privilege = " + "'C' ))))"; + */ + /* + * String longQuery = "select * from d WHERE " + + * "( wct_audit_entry.privilege = 'W' or wct_audit_entry.privilege = " + + * "'C' ) and wct_audit_entry.outcome = 't' and " + + * "wct_audit_entry.transaction_id = wct_transaction.transaction_id and " + + * "wct_transaction.user_id = 164 and wct_audit_entry.object_id = " + + * "wct_workflows.active_version_id "; + */ + StringReader stringReader = new StringReader(longQuery); + Statement statement = parserManager.parse(stringReader); + // stringReader = new StringReader(longQuery); + // Statement statement2 = parserManager.parse(stringReader); + // stringReader = null; + // statement2 = null; + statement = null; + parserManager = null; + longQuery = null; + System.gc(); + System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); + + } +} diff --git a/src/test/java/net/sf/jsqlparser/statement/select/NestedBracketsPerformanceTest.java b/src/test/java/net/sf/jsqlparser/statement/select/NestedBracketsPerformanceTest.java new file mode 100644 index 00000000..b9d9cec6 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/select/NestedBracketsPerformanceTest.java @@ -0,0 +1,94 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import net.sf.jsqlparser.JSQLParserException; +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import org.junit.Ignore; +import org.junit.Test; + +/** + * + * @author tw + */ +public class NestedBracketsPerformanceTest { + + @Test + public void testIssue766() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat('1','2'),'3'),'4'),'5'),'6'),'7'),'8'),'9'),'10'),'11'),'12'),'13'),'14'),'15'),'16'),'17'),'18'),'19'),'20'),'21'),col1 FROM tbl t1", true); + } + + @Test + public void testIssue766_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT concat(concat(concat('1', '2'), '3'), '4'), col1 FROM tbl t1"); + } + + @Test + public void testIssue235() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CASE WHEN ( CASE WHEN ( CASE WHEN ( CASE WHEN ( 1 ) THEN 0 END ) THEN 0 END ) THEN 0 END ) THEN 0 END FROM a", true); + } + + @Test(timeout = 100000) + @Ignore + public void testIssue496() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("select isNull(charLen(TEST_ID,0)+ isNull(charLen(TEST_DVC,0)+ isNull(charLen(TEST_NO,0)+ isNull(charLen(ATEST_ID,0)+ isNull(charLen(TESTNO,0)+ isNull(charLen(TEST_CTNT,0)+ isNull(charLen(TEST_MESG_CTNT,0)+ isNull(charLen(TEST_DTM,0)+ isNull(charLen(TEST_DTT,0)+ isNull(charLen(TEST_ADTT,0)+ isNull(charLen(TEST_TCD,0)+ isNull(charLen(TEST_PD,0)+ isNull(charLen(TEST_VAL,0)+ isNull(charLen(TEST_YN,0)+ isNull(charLen(TEST_DTACM,0)+ isNull(charLen(TEST_MST,0) from test_info_m"); + } + + @Test + public void testIssue856() throws JSQLParserException { + String sql = "SELECT " + buildRecursiveBracketExpression("if(month(today()) = 3, sum(\"Table5\".\"Month 002\"), $1)", "0", 5) + " FROM mytbl"; + assertSqlCanBeParsedAndDeparsed(sql); + } + + /** + * Try to avoid or border exceptionally big parsing time increments by adding more bracket constructs. + * + * @throws JSQLParserException + */ + @Test + public void testIncreaseOfParseTime() throws JSQLParserException { + long oldDurationTime = 1000; + int countProblematic = 0; + for (int i = 0; i < 20; i++) { + String sql = "SELECT " + buildRecursiveBracketExpression("concat($1,'B')", "'A'", i) + " FROM mytbl"; + long startTime = System.currentTimeMillis(); + assertSqlCanBeParsedAndDeparsed(sql, true); + long durationTime = System.currentTimeMillis() - startTime; + + if (i > 0) { + System.out.println("old duration " + oldDurationTime + " new duration time " + durationTime + " for " + sql); + } + if (oldDurationTime * 10 < durationTime) { + countProblematic++; + } + if (countProblematic > 5) { + fail("too large increment of parsing time"); + } + + oldDurationTime = Math.max(durationTime, 1); + } + } + + @Test + public void testRecursiveBracketExpression() { + assertEquals("concat('A','B')", buildRecursiveBracketExpression("concat($1,'B')", "'A'", 0)); + assertEquals("concat(concat('A','B'),'B')", buildRecursiveBracketExpression("concat($1,'B')", "'A'", 1)); + assertEquals("concat(concat(concat('A','B'),'B'),'B')", buildRecursiveBracketExpression("concat($1,'B')", "'A'", 2)); + } + + private String buildRecursiveBracketExpression(String template, String finalExpression, int depth) { + if (depth == 0) { + return template.replace("$1", finalExpression); + } + return template.replace("$1", buildRecursiveBracketExpression(template, finalExpression, depth - 1)); + } +} diff --git a/src/test/java/net/sf/jsqlparser/test/select/SelectASTTest.java b/src/test/java/net/sf/jsqlparser/statement/select/SelectASTTest.java similarity index 84% rename from src/test/java/net/sf/jsqlparser/test/select/SelectASTTest.java rename to src/test/java/net/sf/jsqlparser/statement/select/SelectASTTest.java index 0c964de1..3dd01df5 100644 --- a/src/test/java/net/sf/jsqlparser/test/select/SelectASTTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/select/SelectASTTest.java @@ -1,36 +1,22 @@ -/* - * Copyright (C) 2015 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ -package net.sf.jsqlparser.test.select; +package net.sf.jsqlparser.statement.select; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserDefaultVisitor; import net.sf.jsqlparser.parser.CCJSqlParserTreeConstants; import net.sf.jsqlparser.parser.CCJSqlParserUtil; -import net.sf.jsqlparser.schema.Column; -import net.sf.jsqlparser.parser.Token; import net.sf.jsqlparser.parser.SimpleNode; +import net.sf.jsqlparser.parser.Token; +import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.statement.Statement; -import net.sf.jsqlparser.statement.select.OrderByElement; -import net.sf.jsqlparser.statement.select.PlainSelect; -import net.sf.jsqlparser.statement.select.Select; -import net.sf.jsqlparser.statement.select.SelectExpressionItem; -import net.sf.jsqlparser.statement.select.SelectItem; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; @@ -99,7 +85,7 @@ public Object visit(SimpleNode node, Object data) { assertEquals(34, subSelectStart.beginColumn); assertEquals(62, subSelectEnd.endColumn); } - + @Test public void testSelectASTColumnLF() throws JSQLParserException { String sql = "SELECT a, b FROM mytable \n order by b, c"; @@ -122,7 +108,7 @@ public void testSelectASTColumnLF() throws JSQLParserException { } assertEquals("SELECT *, * FROM mytable \n order by #, #", b.toString()); } - + @Test public void testSelectASTCommentLF() throws JSQLParserException { String sql = "SELECT /* testcomment */ \n a, b FROM -- testcomment2 \n mytable \n order by b, c"; @@ -145,7 +131,7 @@ public void testSelectASTCommentLF() throws JSQLParserException { } assertEquals("SELECT /* testcomment */ \n *, * FROM -- testcomment2 \n mytable \n order by #, #", b.toString()); } - + @Test public void testSelectASTCommentCRLF() throws JSQLParserException { String sql = "SELECT /* testcomment */ \r\n a, b FROM -- testcomment2 \r\n mytable \r\n order by b, c"; @@ -168,4 +154,29 @@ public void testSelectASTCommentCRLF() throws JSQLParserException { } assertEquals("SELECT /* testcomment */ \r\n *, * FROM -- testcomment2 \r\n mytable \r\n order by #, #", b.toString()); } + + @Test + public void testDetectInExpressions() throws JSQLParserException { + String sql = "SELECT * FROM mytable WHERE a IN (1,2,3,4,5,6,7)"; + SimpleNode node = (SimpleNode) CCJSqlParserUtil.parseAST(sql); + node.dump("*"); + assertEquals(CCJSqlParserTreeConstants.JJTSTATEMENT, node.getId()); + node.jjtAccept(new CCJSqlParserDefaultVisitor() { + @Override + public Object visit(SimpleNode node, Object data) { + if (node.getId() == CCJSqlParserTreeConstants.JJTINEXPRESSION) { + subSelectStart = node.jjtGetFirstToken(); + subSelectEnd = node.jjtGetLastToken(); + return super.visit(node, data); + } else { + return super.visit(node, data); + } + } + }, null); + + assertNotNull(subSelectStart); + assertNotNull(subSelectEnd); + assertEquals(30, subSelectStart.beginColumn); + assertEquals(49, subSelectEnd.endColumn); + } } diff --git a/src/test/java/net/sf/jsqlparser/test/select/SelectTest.java b/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java similarity index 71% rename from src/test/java/net/sf/jsqlparser/test/select/SelectTest.java rename to src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java index a8c788e5..356a203b 100644 --- a/src/test/java/net/sf/jsqlparser/test/select/SelectTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java @@ -1,6 +1,16 @@ -package net.sf.jsqlparser.test.select; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; -import junit.framework.*; +import java.io.*; +import java.util.*; import net.sf.jsqlparser.*; import net.sf.jsqlparser.expression.*; import net.sf.jsqlparser.expression.operators.arithmetic.*; @@ -8,56 +18,70 @@ import net.sf.jsqlparser.parser.*; import net.sf.jsqlparser.schema.*; import net.sf.jsqlparser.statement.*; -import net.sf.jsqlparser.statement.select.*; +import static net.sf.jsqlparser.test.TestUtils.*; import org.apache.commons.io.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; -import java.io.*; -import java.util.*; - -import static net.sf.jsqlparser.test.TestUtils.*; +public class SelectTest { -public class SelectTest extends TestCase { + @Rule + public TestName name = new TestName(); - private CCJSqlParserManager parserManager = new CCJSqlParserManager(); + private final CCJSqlParserManager parserManager = new CCJSqlParserManager(); - public SelectTest(String arg0) { - super(arg0); + @Before + public void setup() { +// System.out.println(name.getMethodName()); } // From statement multipart + @Test public void testMultiPartTableNameWithServerNameAndDatabaseNameAndSchemaName() throws Exception { final String statement = "SELECT columnName FROM [server-name\\server-instance].databaseName.schemaName.tableName"; - Select select = (Select) parserManager.parse(new StringReader(statement)); - - assertStatementCanBeDeparsedAs(select, statement); + assertSqlCanBeParsedAndDeparsed(statement, false, + parser -> parser.withSquareBracketQuotation(true)); } + @Test public void testMultiPartTableNameWithServerNameAndDatabaseName() throws Exception { final String statement = "SELECT columnName FROM [server-name\\server-instance].databaseName..tableName"; - Select select = (Select) parserManager.parse(new StringReader(statement)); - assertStatementCanBeDeparsedAs(select, statement); + assertSqlCanBeParsedAndDeparsed(statement, false, + parser -> parser.withSquareBracketQuotation(true)); } + @Test public void testMultiPartTableNameWithServerNameAndSchemaName() throws Exception { final String statement = "SELECT columnName FROM [server-name\\server-instance]..schemaName.tableName"; - Select select = (Select) parserManager.parse(new StringReader(statement)); - - assertStatementCanBeDeparsedAs(select, statement); + assertSqlCanBeParsedAndDeparsed(statement, false, + parser -> parser.withSquareBracketQuotation(true)); } + @Test public void testMultiPartTableNameWithServerProblem() throws Exception { final String statement = "SELECT * FROM LINK_100.htsac.dbo.t_transfer_num a"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testMultiPartTableNameWithServerName() throws Exception { final String statement = "SELECT columnName FROM [server-name\\server-instance]...tableName"; - Select select = (Select) parserManager.parse(new StringReader(statement)); - - assertStatementCanBeDeparsedAs(select, statement); + assertSqlCanBeParsedAndDeparsed(statement, false, + parser -> parser.withSquareBracketQuotation(true)); } + @Test public void testMultiPartTableNameWithDatabaseNameAndSchemaName() throws Exception { final String statement = "SELECT columnName FROM databaseName.schemaName.tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -65,6 +89,7 @@ public void testMultiPartTableNameWithDatabaseNameAndSchemaName() throws Excepti assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testMultiPartTableNameWithDatabaseName() throws Exception { final String statement = "SELECT columnName FROM databaseName..tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -72,6 +97,7 @@ public void testMultiPartTableNameWithDatabaseName() throws Exception { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testMultiPartTableNameWithSchemaName() throws Exception { final String statement = "SELECT columnName FROM schemaName.tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -79,6 +105,7 @@ public void testMultiPartTableNameWithSchemaName() throws Exception { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testMultiPartTableNameWithColumnName() throws Exception { final String statement = "SELECT columnName FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -87,6 +114,7 @@ public void testMultiPartTableNameWithColumnName() throws Exception { } // Select statement statement multipart + @Test public void testMultiPartColumnNameWithDatabaseNameAndSchemaNameAndTableName() throws Exception { final String statement = "SELECT databaseName.schemaName.tableName.columnName FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -94,6 +122,8 @@ public void testMultiPartColumnNameWithDatabaseNameAndSchemaNameAndTableName() t assertStatementCanBeDeparsedAs(select, statement); } + @Test + @Ignore public void testMultiPartColumnNameWithDatabaseNameAndSchemaName() { final String statement = "SELECT databaseName.schemaName..columnName FROM tableName"; Select select; @@ -105,6 +135,7 @@ public void testMultiPartColumnNameWithDatabaseNameAndSchemaName() { } } + @Test public void testMultiPartColumnNameWithDatabaseNameAndTableName() throws Exception { final String statement = "SELECT databaseName..tableName.columnName FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -113,6 +144,8 @@ public void testMultiPartColumnNameWithDatabaseNameAndTableName() throws Excepti checkMultipartIdentifier(select, "columnName", "databaseName..tableName.columnName"); } + @Test + @Ignore public void testMultiPartColumnNameWithDatabaseName() { final String statement = "SELECT databaseName...columnName FROM tableName"; Select select; @@ -124,6 +157,7 @@ public void testMultiPartColumnNameWithDatabaseName() { } } + @Test public void testMultiPartColumnNameWithSchemaNameAndTableName() throws Exception { final String statement = "SELECT schemaName.tableName.columnName FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -132,6 +166,8 @@ public void testMultiPartColumnNameWithSchemaNameAndTableName() throws Exception checkMultipartIdentifier(select, "columnName", "schemaName.tableName.columnName"); } + @Test + @Ignore public void testMultiPartColumnNameWithSchemaName() { final String statement = "SELECT schemaName..columnName FROM tableName"; Select select; @@ -143,6 +179,7 @@ public void testMultiPartColumnNameWithSchemaName() { } } + @Test public void testMultiPartColumnNameWithTableName() throws Exception { final String statement = "SELECT tableName.columnName FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -151,6 +188,7 @@ public void testMultiPartColumnNameWithTableName() throws Exception { checkMultipartIdentifier(select, "columnName", "tableName.columnName"); } + @Test public void testMultiPartColumnName() throws Exception { final String statement = "SELECT columnName FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -168,6 +206,7 @@ void checkMultipartIdentifier(Select select, String columnName, String fullColum assertEquals(fullColumnName, col.getFullyQualifiedName()); } + @Test public void testAllColumnsFromTable() throws Exception { final String statement = "SELECT tableName.* FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -176,6 +215,7 @@ public void testAllColumnsFromTable() throws Exception { assertTrue(((PlainSelect) select.getSelectBody()).getSelectItems().get(0) instanceof AllTableColumns); } + @Test public void testSimpleSigns() throws JSQLParserException { final String statement = "SELECT +1, -1 FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -183,6 +223,7 @@ public void testSimpleSigns() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testSimpleAdditionsAndSubtractionsWithSigns() throws JSQLParserException { final String statement = "SELECT 1 - 1, 1 + 1, -1 - 1, -1 + 1, +1 + 1, +1 - 1 FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -190,6 +231,7 @@ public void testSimpleAdditionsAndSubtractionsWithSigns() throws JSQLParserExcep assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testOperationsWithSigns() throws JSQLParserException { Expression expr = CCJSqlParserUtil.parseExpression("1 - -1"); assertEquals("1 - -1", expr.toString()); @@ -203,6 +245,7 @@ public void testOperationsWithSigns() throws JSQLParserException { assertEquals("1", sexpr.getExpression().toString()); } + @Test public void testSignedColumns() throws JSQLParserException { final String statement = "SELECT -columnName, +columnName, +(columnName), -(columnName) FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -210,6 +253,7 @@ public void testSignedColumns() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testSigns() throws Exception { final String statement = "SELECT (-(1)), -(1), (-(columnName)), -(columnName), (-1), -1, (-columnName), -columnName FROM tableName"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -217,6 +261,7 @@ public void testSigns() throws Exception { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testLimit() throws JSQLParserException { String statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT 3, ?"; @@ -238,7 +283,7 @@ public void testLimit() throws JSQLParserException { assertNull(((PlainSelect) select.getSelectBody()).getLimit()); assertNotNull(((PlainSelect) select.getSelectBody()).getOffset()); - assertTrue(((PlainSelect) select.getSelectBody()).getOffset().isOffsetJdbcParameter()); + assertEquals("?", ((PlainSelect) select.getSelectBody()).getOffset().getOffsetJdbcParameter().toString()); assertStatementCanBeDeparsedAs(select, statement); statement = "(SELECT * FROM mytable WHERE mytable.col = 9 OFFSET ?) UNION " @@ -263,6 +308,7 @@ public void testLimit() throws JSQLParserException { } + @Test public void testLimit2() throws JSQLParserException { String statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT 3, ?"; @@ -293,6 +339,18 @@ public void testLimit2() throws JSQLParserException { assertTrue(((PlainSelect) select.getSelectBody()).getLimit().isLimitNull()); assertSqlCanBeParsedAndDeparsed(statement); + statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT ALL OFFSET 5"; + select = (Select) parserManager.parse(new StringReader(statement)); + offset = ((PlainSelect) select.getSelectBody()).getLimit().getOffset(); + rowCount = ((PlainSelect) select.getSelectBody()).getLimit().getRowCount(); + + assertNull(offset); + assertNull(rowCount); + assertEquals(5, ((PlainSelect) select.getSelectBody()).getOffset().getOffset()); + assertTrue(((PlainSelect) select.getSelectBody()).getLimit().isLimitAll()); + assertFalse(((PlainSelect) select.getSelectBody()).getLimit().isLimitNull()); + assertSqlCanBeParsedAndDeparsed(statement); + statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT 0 OFFSET 3"; select = (Select) parserManager.parse(new StringReader(statement)); offset = ((PlainSelect) select.getSelectBody()).getLimit().getOffset(); @@ -310,7 +368,7 @@ public void testLimit2() throws JSQLParserException { assertNull(((PlainSelect) select.getSelectBody()).getLimit()); assertNotNull(((PlainSelect) select.getSelectBody()).getOffset()); - assertTrue(((PlainSelect) select.getSelectBody()).getOffset().isOffsetJdbcParameter()); + assertEquals("?", ((PlainSelect) select.getSelectBody()).getOffset().getOffsetJdbcParameter().toString()); assertStatementCanBeDeparsedAs(select, statement); statement = "(SELECT * FROM mytable WHERE mytable.col = 9 OFFSET ?) UNION " @@ -331,6 +389,7 @@ public void testLimit2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testLimit3() throws JSQLParserException { String statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT ?1, 2"; @@ -389,6 +448,7 @@ public void testLimit3() throws JSQLParserException { assertFalse(((PlainSelect) select.getSelectBody()).getLimit().isLimitAll()); } + @Test public void testLimit4() throws JSQLParserException { String statement = "SELECT * FROM mytable WHERE mytable.col = 9 LIMIT :some_name, 2"; @@ -442,6 +502,7 @@ public void testLimit4() throws JSQLParserException { assertFalse(((PlainSelect) select.getSelectBody()).getLimit().isLimitAll()); } + @Test public void testLimitSqlServer1() throws JSQLParserException { String statement = "SELECT * FROM mytable WHERE mytable.col = 9 ORDER BY mytable.id OFFSET 3 ROWS FETCH NEXT 5 ROWS ONLY"; @@ -452,13 +513,14 @@ public void testLimitSqlServer1() throws JSQLParserException { assertNotNull(((PlainSelect) select.getSelectBody()).getFetch()); assertEquals("ROWS", ((PlainSelect) select.getSelectBody()).getFetch().getFetchParam()); assertFalse(((PlainSelect) select.getSelectBody()).getFetch().isFetchParamFirst()); - assertFalse(((PlainSelect) select.getSelectBody()).getOffset().isOffsetJdbcParameter()); - assertFalse(((PlainSelect) select.getSelectBody()).getFetch().isFetchJdbcParameter()); + assertNull(((PlainSelect) select.getSelectBody()).getOffset().getOffsetJdbcParameter()); + assertNull(((PlainSelect) select.getSelectBody()).getFetch().getFetchJdbcParameter()); assertEquals(3, ((PlainSelect) select.getSelectBody()).getOffset().getOffset()); assertEquals(5, ((PlainSelect) select.getSelectBody()).getFetch().getRowCount()); assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testLimitSqlServer2() throws JSQLParserException { // Alternative with the other keywords String statement = "SELECT * FROM mytable WHERE mytable.col = 9 ORDER BY mytable.id OFFSET 3 ROW FETCH FIRST 5 ROW ONLY"; @@ -475,6 +537,7 @@ public void testLimitSqlServer2() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testLimitSqlServer3() throws JSQLParserException { // Query with no Fetch String statement = "SELECT * FROM mytable WHERE mytable.col = 9 ORDER BY mytable.id OFFSET 3 ROWS"; @@ -488,6 +551,7 @@ public void testLimitSqlServer3() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testLimitSqlServer4() throws JSQLParserException { // For Oracle syntax, query with no offset String statement = "SELECT * FROM mytable WHERE mytable.col = 9 ORDER BY mytable.id FETCH NEXT 5 ROWS ONLY"; @@ -502,6 +566,7 @@ public void testLimitSqlServer4() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testLimitSqlServerJdbcParameters() throws JSQLParserException { String statement = "SELECT * FROM mytable WHERE mytable.col = 9 ORDER BY mytable.id OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; @@ -512,16 +577,38 @@ public void testLimitSqlServerJdbcParameters() throws JSQLParserException { assertNotNull(((PlainSelect) select.getSelectBody()).getFetch()); assertEquals("ROWS", ((PlainSelect) select.getSelectBody()).getFetch().getFetchParam()); assertFalse(((PlainSelect) select.getSelectBody()).getFetch().isFetchParamFirst()); - assertTrue(((PlainSelect) select.getSelectBody()).getOffset().isOffsetJdbcParameter()); - assertTrue(((PlainSelect) select.getSelectBody()).getFetch().isFetchJdbcParameter()); + assertEquals("?", ((PlainSelect) select.getSelectBody()).getOffset().getOffsetJdbcParameter().toString()); + assertEquals("?", ((PlainSelect) select.getSelectBody()).getFetch().getFetchJdbcParameter().toString()); assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testLimitPR404() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE mytable.col = 9 LIMIT ?1"); assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE mytable.col = 9 LIMIT :param_name"); } + @Test + public void testLimitOffsetIssue462() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable LIMIT ?1"); + } + + @Test + public void testLimitOffsetIssue462_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable LIMIT ?1 OFFSET ?2"); + } + + @Test + public void testLimitOffsetKeyWordAsNamedParameter() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable LIMIT :limit"); + } + + @Test + public void testLimitOffsetKeyWordAsNamedParameter2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable LIMIT :limit OFFSET :offset"); + } + + @Test public void testTop() throws JSQLParserException { String statement = "SELECT TOP 3 * FROM mytable WHERE mytable.col = 9"; @@ -537,6 +624,7 @@ public void testTop() throws JSQLParserException { getValue()); } + @Test public void testTopWithParenthesis() throws JSQLParserException { final String firstColumnName = "alias.columnName1"; final String secondColumnName = "alias.columnName2"; @@ -558,6 +646,7 @@ public void testTopWithParenthesis() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testTopWithJdbcParameter() throws JSQLParserException { String statement = "SELECT TOP ?1 * FROM mytable WHERE mytable.col = 9"; @@ -580,6 +669,7 @@ public void testTopWithJdbcParameter() throws JSQLParserException { isUseFixedIndex()); } + @Test public void testSkip() throws JSQLParserException { final String firstColumnName = "alias.columnName1"; final String secondColumnName = "alias.columnName2"; @@ -618,6 +708,7 @@ public void testSkip() throws JSQLParserException { assertStatementCanBeDeparsedAs(select2, statement2); } + @Test public void testFirst() throws JSQLParserException { final String firstColumnName = "alias.columnName1"; final String secondColumnName = "alias.columnName2"; @@ -656,6 +747,7 @@ public void testFirst() throws JSQLParserException { assertStatementCanBeDeparsedAs(select2, statement2); } + @Test public void testFirstWithKeywordLimit() throws JSQLParserException { final String firstColumnName = "alias.columnName1"; final String secondColumnName = "alias.columnName2"; @@ -679,6 +771,7 @@ public void testFirstWithKeywordLimit() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testSkipFirst() throws JSQLParserException { final String statement = "SELECT SKIP ?1 FIRST f1 c1, c2 FROM t1"; final Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -704,6 +797,7 @@ public void testSkipFirst() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testSelectItems() throws JSQLParserException { String statement = "SELECT myid AS MYID, mycol, tab.*, schema.tab.*, mytab.mycol2, myschema.mytab.mycol, myschema.mytab.* FROM mytable WHERE mytable.col = 9"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -740,6 +834,7 @@ public void testSelectItems() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testUnion() throws JSQLParserException { String statement = "SELECT * FROM mytable WHERE mytable.col = 9 UNION " + "SELECT * FROM mytable3 WHERE mytable3.col = ? UNION " + "SELECT * FROM mytable2 LIMIT 3, 4"; @@ -764,6 +859,7 @@ public void testUnion() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statementToString); } + @Test public void testUnion2() throws JSQLParserException { String statement = "SELECT * FROM mytable WHERE mytable.col = 9 UNION " + "SELECT * FROM mytable3 WHERE mytable3.col = ? UNION " + "SELECT * FROM mytable2 LIMIT 3 OFFSET 4"; @@ -790,6 +886,7 @@ public void testUnion2() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statementToString); } + @Test public void testDistinct() throws JSQLParserException { String statement = "SELECT DISTINCT ON (myid) myid, mycol FROM mytable WHERE mytable.col = 9"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -804,6 +901,7 @@ public void testDistinct() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testDistinctTop() throws JSQLParserException { String statement = "SELECT DISTINCT TOP 5 myid, mycol FROM mytable WHERE mytable.col = 9"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -819,6 +917,7 @@ public void testDistinctTop() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testDistinctTop2() { String statement = "SELECT TOP 5 DISTINCT myid, mycol FROM mytable WHERE mytable.col = 9"; try { @@ -829,6 +928,7 @@ public void testDistinctTop2() { } } + @Test public void testFrom() throws JSQLParserException { String statement = "SELECT * FROM mytable as mytable0, mytable1 alias_tab1, mytable2 as alias_tab2, (SELECT * FROM mytable3) AS mytable4 WHERE mytable.col = 9"; String statementToString = "SELECT * FROM mytable AS mytable0, mytable1 alias_tab1, mytable2 AS alias_tab2, (SELECT * FROM mytable3) AS mytable4 WHERE mytable.col = 9"; @@ -843,6 +943,7 @@ public void testFrom() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statementToString); } + @Test public void testJoin() throws JSQLParserException { String statement = "SELECT * FROM tab1 LEFT OUTER JOIN tab2 ON tab1.id = tab2.id"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -902,9 +1003,18 @@ public void testJoin() throws JSQLParserException { statement = "SELECT * FROM foo AS f LEFT OUTER JOIN (bar AS b RIGHT OUTER JOIN baz AS z ON f.id = z.id) ON f.id = b.id"; select = (Select) parserManager.parse(new StringReader(statement)); assertStatementCanBeDeparsedAs(select, statement); - + statement = "SELECT * FROM foo AS f, OUTER bar AS b WHERE f.id = b.id"; + select = (Select) parserManager.parse(new StringReader(statement)); + assertStatementCanBeDeparsedAs(select, statement); + plainSelect = (PlainSelect) select.getSelectBody(); + assertEquals(1, plainSelect.getJoins().size()); + assertTrue(plainSelect.getJoins().get(0).isOuter()); + assertTrue(plainSelect.getJoins().get(0).isSimple()); + assertEquals("bar", ((Table) plainSelect.getJoins().get(0).getRightItem()).getFullyQualifiedName()); + assertEquals("b", ((Table) plainSelect.getJoins().get(0).getRightItem()).getAlias().getName()); } + @Test public void testFunctions() throws JSQLParserException { String statement = "SELECT MAX(id) AS max FROM mytable WHERE mytable.col = 9"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -913,6 +1023,10 @@ public void testFunctions() throws JSQLParserException { getName()); assertStatementCanBeDeparsedAs(select, statement); + statement = "SELECT substring(id, 2, 3), substring(id from 2 for 3), substring(id from 2), trim(BOTH ' ' from 'foo bar '), trim(LEADING ' ' from 'foo bar '), trim(TRAILING ' ' from 'foo bar '), trim(' ' from 'foo bar '), position('foo' in 'bar'), overlay('foo' placing 'bar' from 1), overlay('foo' placing 'bar' from 1 for 2) FROM my table"; + select = (Select) parserManager.parse(new StringReader(statement)); + assertStatementCanBeDeparsedAs(select, statement); + statement = "SELECT MAX(id), AVG(pro) AS myavg FROM mytable WHERE mytable.col = 9 GROUP BY pro"; select = (Select) parserManager.parse(new StringReader(statement)); plainSelect = (PlainSelect) select.getSelectBody(); @@ -962,6 +1076,32 @@ public void testFunctions() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test + public void testEscapedFunctionsIssue647() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT {fn test(0)} AS COL"); + //assertSqlCanBeParsedAndDeparsed("SELECT {fn current_timestamp(0)} AS COL"); + assertSqlCanBeParsedAndDeparsed("SELECT {fn concat(a, b)} AS COL"); + } + + @Test + public void testEscapedFunctionsIssue753() throws JSQLParserException { + Statement stmt = CCJSqlParserUtil.parse("SELECT { fn test(0)} AS COL"); + assertEquals("SELECT {fn test(0)} AS COL", stmt.toString()); + assertSqlCanBeParsedAndDeparsed("SELECT fn FROM fn"); + } + + @Test + public void testNamedParametersPR702() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT substring(id, 2, 3), substring(id from 2 for 3), substring(id from 2), trim(BOTH ' ' from 'foo bar '), trim(LEADING ' ' from 'foo bar '), trim(TRAILING ' ' from 'foo bar '), trim(' ' from 'foo bar '), position('foo' in 'bar'), overlay('foo' placing 'bar' from 1), overlay('foo' placing 'bar' from 1 for 2) FROM my table"); + } + + @Test + public void testNamedParametersPR702_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT substring(id, 2, 3) FROM mytable"); + assertSqlCanBeParsedAndDeparsed("SELECT substring(id from 2 for 3) FROM mytable"); + } + + @Test public void testWhere() throws JSQLParserException { final String statement = "SELECT * FROM tab1 WHERE"; @@ -1005,24 +1145,26 @@ public void testWhere() throws JSQLParserException { assertEquals(statement + whereToString, plainSelect.toString()); } + @Test public void testGroupBy() throws JSQLParserException { String statement = "SELECT * FROM tab1 WHERE a > 34 GROUP BY tab1.b"; Select select = (Select) parserManager.parse(new StringReader(statement)); PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); - assertEquals(1, plainSelect.getGroupByColumnReferences().size()); - assertEquals("tab1.b", ((Column) plainSelect.getGroupByColumnReferences().get(0)). + assertEquals(1, plainSelect.getGroupBy().getGroupByExpressions().size()); + assertEquals("tab1.b", ((Column) plainSelect.getGroupBy().getGroupByExpressions().get(0)). getFullyQualifiedName()); assertStatementCanBeDeparsedAs(select, statement); statement = "SELECT * FROM tab1 WHERE a > 34 GROUP BY 2, 3"; select = (Select) parserManager.parse(new StringReader(statement)); plainSelect = (PlainSelect) select.getSelectBody(); - assertEquals(2, plainSelect.getGroupByColumnReferences().size()); - assertEquals(2, ((LongValue) plainSelect.getGroupByColumnReferences().get(0)).getValue()); - assertEquals(3, ((LongValue) plainSelect.getGroupByColumnReferences().get(1)).getValue()); + assertEquals(2, plainSelect.getGroupBy().getGroupByExpressions().size()); + assertEquals(2, ((LongValue) plainSelect.getGroupBy().getGroupByExpressions().get(0)).getValue()); + assertEquals(3, ((LongValue) plainSelect.getGroupBy().getGroupByExpressions().get(1)).getValue()); assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testHaving() throws JSQLParserException { String statement = "SELECT MAX(tab1.b) FROM tab1 WHERE a > 34 GROUP BY tab1.b HAVING MAX(tab1.b) > 56"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -1037,6 +1179,7 @@ public void testHaving() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testExists() throws JSQLParserException { String statement = "SELECT * FROM tab1 WHERE "; String where = "EXISTS (SELECT * FROM tab2)"; @@ -1049,6 +1192,7 @@ public void testExists() throws JSQLParserException { assertExpressionCanBeDeparsedAs(plainSelect.getWhere(), where); } + @Test public void testOrderBy() throws JSQLParserException { // TODO: should there be a DESC marker in the OrderByElement class? String statement = "SELECT * FROM tab1 WHERE a > 34 GROUP BY tab1.b ORDER BY tab1.a DESC, tab1.b ASC"; @@ -1077,11 +1221,19 @@ public void testOrderBy() throws JSQLParserException { } + @Test public void testOrderByNullsFirst() throws JSQLParserException { String statement = "SELECT a FROM tab1 ORDER BY a NULLS FIRST"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test + public void testOrderByWithComplexExpression() throws JSQLParserException { + String statement = "SELECT col FROM tbl tbl_alias ORDER BY tbl_alias.id = 1 DESC"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test public void testTimestamp() throws JSQLParserException { String statement = "SELECT * FROM tab1 WHERE a > {ts '2004-04-30 04:05:34.56'}"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -1092,6 +1244,7 @@ public void testTimestamp() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testTime() throws JSQLParserException { String statement = "SELECT * FROM tab1 WHERE a > {t '04:05:34'}"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -1102,10 +1255,12 @@ public void testTime() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testBetweenDate() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE col BETWEEN {d '2015-09-19'} AND {d '2015-09-24'}"); } + @Test public void testCase() throws JSQLParserException { String statement = "SELECT a, CASE b WHEN 1 THEN 2 END FROM tab1"; assertSqlCanBeParsedAndDeparsed(statement); @@ -1142,22 +1297,37 @@ public void testCase() throws JSQLParserException { } + @Test public void testIssue371SimplifiedCase() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT CASE col + 4 WHEN 2 THEN 1 ELSE 0 END"); } + @Test public void testIssue371SimplifiedCase2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT CASE col > 4 WHEN true THEN 1 ELSE 0 END"); } + @Test public void testIssue235SimplifiedCase3() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT CASE WHEN (CASE WHEN (CASE WHEN (1) THEN 0 END) THEN 0 END) THEN 0 END FROM a"); } + @Test public void testIssue235SimplifiedCase4() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT CASE WHEN (CASE WHEN (CASE WHEN (CASE WHEN (1) THEN 0 END) THEN 0 END) THEN 0 END) THEN 0 END FROM a"); } + @Test + public void testIssue862CaseWhenConcat() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT c1, CASE c1 || c2 WHEN '091' THEN '2' ELSE '1' END AS c11 FROM T2"); + } + + @Test + public void testExpressionsInIntervalExpression() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT DATE_SUB(mydate, INTERVAL DAY(anotherdate) - 1 DAY) FROM tbl"); + } + + @Test public void testReplaceAsFunction() throws JSQLParserException { String statement = "SELECT REPLACE(a, 'b', c) FROM tab1"; assertSqlCanBeParsedAndDeparsed(statement); @@ -1175,6 +1345,7 @@ public void testReplaceAsFunction() throws JSQLParserException { assertEquals(3, func.getParameters().getExpressions().size()); } + @Test public void testLike() throws JSQLParserException { String statement = "SELECT * FROM tab1 WHERE a LIKE 'test'"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -1192,16 +1363,46 @@ public void testLike() throws JSQLParserException { assertEquals("test2", ((LikeExpression) plainSelect.getWhere()).getEscape()); } + @Test + public void testNotLike() throws JSQLParserException { + String statement = "SELECT * FROM tab1 WHERE a NOT LIKE 'test'"; + Select select = (Select) parserManager.parse(new StringReader(statement)); + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); + assertEquals("test", ((StringValue) ((LikeExpression) plainSelect.getWhere()). + getRightExpression()).getValue()); + assertEquals(true, (boolean) ((LikeExpression) plainSelect.getWhere()).isNot()); + } + + @Test + public void testNotLikeWithNotBeforeExpression() throws JSQLParserException { + String statement = "SELECT * FROM tab1 WHERE NOT a LIKE 'test'"; + Select select = (Select) parserManager.parse(new StringReader(statement)); + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); + assertTrue(plainSelect.getWhere() instanceof NotExpression); + NotExpression notExpr = (NotExpression) plainSelect.getWhere(); + assertEquals("test", ((StringValue) ((LikeExpression) notExpr.getExpression()). + getRightExpression()).getValue()); + assertEquals(false, (boolean) ((LikeExpression) notExpr.getExpression()).isNot()); + } + + @Test + public void testNotLikeIssue775() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mybatisplus WHERE id NOT LIKE ?"); + } + + @Test public void testIlike() throws JSQLParserException { String statement = "SELECT col1 FROM table1 WHERE col1 ILIKE '%hello%'"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testSelectOrderHaving() throws JSQLParserException { String statement = "SELECT units, count(units) AS num FROM currency GROUP BY units HAVING count(units) > 1 ORDER BY num"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testDouble() throws JSQLParserException { String statement = "SELECT 1e2, * FROM mytable WHERE mytable.col = 9"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -1236,6 +1437,7 @@ public void testDouble() throws JSQLParserException { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testDouble2() throws JSQLParserException { String statement = "SELECT 1.e22 FROM mytable"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -1245,6 +1447,7 @@ public void testDouble2() throws JSQLParserException { .getSelectItems().get(0)).getExpression()).getValue(), 0); } + @Test public void testDouble3() throws JSQLParserException { String statement = "SELECT 1. FROM mytable"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -1254,6 +1457,7 @@ public void testDouble3() throws JSQLParserException { .getSelectItems().get(0)).getExpression()).getValue(), 0); } + @Test public void testDouble4() throws JSQLParserException { String statement = "SELECT 1.2e22 FROM mytable"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -1263,6 +1467,7 @@ public void testDouble4() throws JSQLParserException { .getSelectItems().get(0)).getExpression()).getValue(), 0); } + @Test public void testWith() throws JSQLParserException { String statement = "WITH DINFO (DEPTNO, AVGSALARY, EMPCOUNT) AS " + "(SELECT OTHERS.WORKDEPT, AVG(OTHERS.SALARY), COUNT(*) FROM EMPLOYEE AS OTHERS " @@ -1273,26 +1478,31 @@ public void testWith() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testWithRecursive() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("WITH RECURSIVE t (n) AS ((SELECT 1) UNION ALL (SELECT n + 1 FROM t WHERE n < 100)) SELECT sum(n) FROM t"); } + @Test public void testSelectAliasInQuotes() throws JSQLParserException { String statement = "SELECT mycolumn AS \"My Column Name\" FROM mytable"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testSelectAliasWithoutAs() throws JSQLParserException { String statement = "SELECT mycolumn \"My Column Name\" FROM mytable"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testSelectJoinWithComma() throws JSQLParserException { String statement = "SELECT cb.Genus, cb.Species FROM Coleccion_de_Briofitas AS cb, unigeoestados AS es " + "WHERE es.nombre = \"Tamaulipas\" AND cb.the_geom = es.geom"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testDeparser() throws JSQLParserException { String statement = "SELECT a.OWNERLASTNAME, a.OWNERFIRSTNAME " + "FROM ANTIQUEOWNERS AS a, ANTIQUES AS b " + "WHERE b.BUYERID = a.OWNERID AND b.ITEM = 'Chair'"; @@ -1305,21 +1515,25 @@ public void testDeparser() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testCount2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT count(ALL col1 + col2) FROM mytable"); } + @Test public void testMysqlQuote() throws JSQLParserException { String statement = "SELECT `a.OWNERLASTNAME`, `OWNERFIRSTNAME` " + "FROM `ANTIQUEOWNERS` AS a, ANTIQUES AS b " + "WHERE b.BUYERID = a.OWNERID AND b.ITEM = 'Chair'"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testConcat() throws JSQLParserException { String statement = "SELECT a || b || c + 4 FROM t"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testConcatProblem2() throws JSQLParserException { String stmt = "SELECT MAX(((((" + "(SPA.SOORTAANLEVERPERIODE)::VARCHAR (2) || (VARCHAR(SPA.AANLEVERPERIODEJAAR))::VARCHAR (4)" @@ -1329,72 +1543,86 @@ public void testConcatProblem2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testConcatProblem2_1() throws JSQLParserException { String stmt = "SELECT TO_CHAR(SPA.AANLEVERPERIODEVOLGNR, 'FM09'::VARCHAR) FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testConcatProblem2_2() throws JSQLParserException { String stmt = "SELECT MAX((SPA.SOORTAANLEVERPERIODE)::VARCHAR (2) || (VARCHAR(SPA.AANLEVERPERIODEJAAR))::VARCHAR (4)) AS GESLACHT_TMP FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testConcatProblem2_3() throws JSQLParserException { String stmt = "SELECT TO_CHAR((10000 - SPA.VERSCHIJNINGSVOLGNR), 'FM0999'::VARCHAR) FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testConcatProblem2_4() throws JSQLParserException { String stmt = "SELECT (SPA.GESLACHT)::VARCHAR (1) FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testConcatProblem2_5() throws JSQLParserException { String stmt = "SELECT max((a || b) || c) FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testConcatProblem2_5_1() throws JSQLParserException { String stmt = "SELECT (a || b) || c FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testConcatProblem2_5_2() throws JSQLParserException { String stmt = "SELECT (a + b) + c FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testConcatProblem2_6() throws JSQLParserException { String stmt = "SELECT max(a || b || c) FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testMatches() throws JSQLParserException { String statement = "SELECT * FROM team WHERE team.search_column @@ to_tsquery('new & york & yankees')"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testGroupByExpression() throws JSQLParserException { String statement = "SELECT col1, col2, col1 + col2, sum(col8)" + " FROM table1 " + "GROUP BY col1, col2, col1 + col2"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testBitwise() throws JSQLParserException { String statement = "SELECT col1 & 32, col2 ^ col1, col1 | col2" + " FROM table1"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testSelectFunction() throws JSQLParserException { String statement = "SELECT 1 + 2 AS sum"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testWeirdSelect() throws JSQLParserException { String sql = "select r.reviews_id, substring(rd.reviews_text, 100) as reviews_text, r.reviews_rating, r.date_added, r.customers_name from reviews r, reviews_description rd where r.products_id = '19' and r.reviews_id = rd.reviews_id and rd.languages_id = '1' and r.reviews_status = 1 order by r.reviews_id desc limit 0, 6"; parserManager.parse(new StringReader(sql)); } + @Test public void testCast() throws JSQLParserException { String stmt = "SELECT CAST(a AS varchar) FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); @@ -1402,218 +1630,338 @@ public void testCast() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCastInCast() throws JSQLParserException { String stmt = "SELECT CAST(CAST(a AS numeric) AS varchar) FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCastInCast2() throws JSQLParserException { String stmt = "SELECT CAST('test' + CAST(assertEqual AS numeric) AS varchar) FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCastTypeProblem() throws JSQLParserException { String stmt = "SELECT CAST(col1 AS varchar (256)) FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCastTypeProblem2() throws JSQLParserException { String stmt = "SELECT col1::varchar FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test + public void testMySQLHintStraightJoin() throws JSQLParserException { + String stmt = "SELECT col FROM tbl STRAIGHT_JOIN tbl2 ON tbl.id = tbl2.id"; + assertSqlCanBeParsedAndDeparsed(stmt); + } + + @Test + public void testStraightJoinInSelect() throws JSQLParserException { + String stmt = "SELECT STRAIGHT_JOIN col, col2 FROM tbl INNER JOIN tbl2 ON tbl.id = tbl2.id"; + assertSqlCanBeParsedAndDeparsed(stmt); + } + + @Test public void testCastTypeProblem3() throws JSQLParserException { String stmt = "SELECT col1::varchar (256) FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCastTypeProblem4() throws JSQLParserException { String stmt = "SELECT 5::varchar (256) FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCastTypeProblem5() throws JSQLParserException { String stmt = "SELECT 5.67::varchar (256) FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCastTypeProblem6() throws JSQLParserException { String stmt = "SELECT 'test'::character varying FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCastTypeProblem7() throws JSQLParserException { String stmt = "SELECT CAST('test' AS character varying) FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCastTypeProblem8() throws JSQLParserException { String stmt = "SELECT CAST('123' AS double precision) FROM tabelle1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testCaseElseAddition() throws JSQLParserException { String stmt = "SELECT CASE WHEN 1 + 3 > 20 THEN 0 ELSE 1000 + 1 END AS d FROM dual"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testBrackets() throws JSQLParserException { String stmt = "SELECT table_a.name AS [Test] FROM table_a"; - assertSqlCanBeParsedAndDeparsed(stmt); + assertSqlCanBeParsedAndDeparsed(stmt, false, + parser -> parser.withSquareBracketQuotation(true)); } + @Test public void testBrackets2() throws JSQLParserException { String stmt = "SELECT [a] FROM t"; - assertSqlCanBeParsedAndDeparsed(stmt); + assertSqlCanBeParsedAndDeparsed(stmt, false, + parser -> parser.withSquareBracketQuotation(true)); } + @Test + public void testBrackets3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM \"2016\""); + } + + @Test public void testProblemSqlServer_Modulo_Proz() throws Exception { String stmt = "SELECT 5 % 2 FROM A"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlServer_Modulo_mod() throws Exception { String stmt = "SELECT mod(5, 2) FROM A"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlServer_Modulo() throws Exception { String stmt = "SELECT convert(varchar(255), DATEDIFF(month, year1, abc_datum) / 12) + ' year, ' + convert(varchar(255), DATEDIFF(month, year2, abc_datum) % 12) + ' month' FROM test_table"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testIsNot() throws JSQLParserException { String stmt = "SELECT * FROM test WHERE a IS NOT NULL"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testIsNot2() throws JSQLParserException { //the deparser delivers always a IS NOT NULL even for NOT a IS NULL String stmt = "SELECT * FROM test WHERE NOT a IS NULL"; Statement parsed = parserManager.parse(new StringReader(stmt)); - assertStatementCanBeDeparsedAs(parsed, "SELECT * FROM test WHERE a IS NOT NULL"); + assertStatementCanBeDeparsedAs(parsed, "SELECT * FROM test WHERE NOT a IS NULL"); } + @Test public void testProblemSqlAnalytic() throws JSQLParserException { String stmt = "SELECT a, row_number() OVER (ORDER BY a) AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic2() throws JSQLParserException { String stmt = "SELECT a, row_number() OVER (ORDER BY a, b) AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic3() throws JSQLParserException { String stmt = "SELECT a, row_number() OVER (PARTITION BY c ORDER BY a, b) AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic4EmptyOver() throws JSQLParserException { String stmt = "SELECT a, row_number() OVER () AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic5AggregateColumnValue() throws JSQLParserException { String stmt = "SELECT a, sum(b) OVER () AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic6AggregateColumnValue() throws JSQLParserException { String stmt = "SELECT a, sum(b + 5) OVER (ORDER BY a) AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic7Count() throws JSQLParserException { String stmt = "SELECT count(*) OVER () AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic8Complex() throws JSQLParserException { String stmt = "SELECT ID, NAME, SALARY, SUM(SALARY) OVER () AS SUM_SAL, AVG(SALARY) OVER () AS AVG_SAL, MIN(SALARY) OVER () AS MIN_SAL, MAX(SALARY) OVER () AS MAX_SAL, COUNT(*) OVER () AS ROWS2 FROM STAFF WHERE ID < 60 ORDER BY ID"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic9CommaListPartition() throws JSQLParserException { String stmt = "SELECT a, row_number() OVER (PARTITION BY c, d ORDER BY a, b) AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic10Lag() throws JSQLParserException { String stmt = "SELECT a, lag(a, 1) OVER (PARTITION BY c ORDER BY a, b) AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemSqlAnalytic11Lag() throws JSQLParserException { String stmt = "SELECT a, lag(a, 1, 0) OVER (PARTITION BY c ORDER BY a, b) AS n FROM table1"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testAnalyticFunction12() throws JSQLParserException { String statement = "SELECT SUM(a) OVER (PARTITION BY b ORDER BY c) FROM tab1"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testAnalyticFunction13() throws JSQLParserException { String statement = "SELECT SUM(a) OVER () FROM tab1"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testAnalyticFunction14() throws JSQLParserException { String statement = "SELECT SUM(a) OVER (PARTITION BY b ) FROM tab1"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testAnalyticFunction15() throws JSQLParserException { String statement = "SELECT SUM(a) OVER (ORDER BY c) FROM tab1"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testAnalyticFunction16() throws JSQLParserException { String statement = "SELECT SUM(a) OVER (ORDER BY c NULLS FIRST) FROM tab1"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testAnalyticFunction17() throws JSQLParserException { String statement = "SELECT AVG(sal) OVER (PARTITION BY deptno ORDER BY sal ROWS BETWEEN 0 PRECEDING AND 0 PRECEDING) AS avg_of_current_sal FROM emp"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testAnalyticFunction18() throws JSQLParserException { String statement = "SELECT AVG(sal) OVER (PARTITION BY deptno ORDER BY sal RANGE CURRENT ROW) AS avg_of_current_sal FROM emp"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testAnalyticFunctionProblem1() throws JSQLParserException { String statement = "SELECT last_value(s.revenue_hold) OVER (PARTITION BY s.id_d_insertion_order, s.id_d_product_ad_attr, trunc(s.date_id, 'mm') ORDER BY s.date_id) AS col FROM s"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test + public void testAnalyticFunction19() throws JSQLParserException { + String statement = "SELECT count(DISTINCT CASE WHEN client_organic_search_drop_flag = 1 THEN brand END) OVER (PARTITION BY client, category_1, category_2, category_3, category_4 ) AS client_brand_org_drop_count FROM sometable"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test public void testAnalyticFunctionProblem1b() throws JSQLParserException { String statement = "SELECT last_value(s.revenue_hold) OVER (PARTITION BY s.id_d_insertion_order, s.id_d_product_ad_attr, trunc(s.date_id, 'mm') ORDER BY s.date_id ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS col FROM s"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test + public void testAnalyticFunctionIssue670() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT last_value(some_column IGNORE NULLS) OVER (PARTITION BY some_other_column_1, some_other_column_2 ORDER BY some_other_column_3 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) column_alias FROM some_table"); + } + + @Test + public void testAnalyticFunctionFilterIssue866() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT COUNT(*) FILTER (WHERE name = 'Raj') OVER (PARTITION BY name ) FROM table"); + } + + @Test public void testFunctionLeft() throws JSQLParserException { String statement = "SELECT left(table1.col1, 4) FROM table1"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test public void testFunctionRight() throws JSQLParserException { String statement = "SELECT right(table1.col1, 4) FROM table1"; assertSqlCanBeParsedAndDeparsed(statement); } + @Test + public void testOneColumnFullTextSearchMySQL() throws JSQLParserException { + String statement = "SELECT MATCH (col1) AGAINST ('test' IN NATURAL LANGUAGE MODE) relevance FROM tbl"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test + public void testSeveralColumnsFullTextSearchMySQL() throws JSQLParserException { + String statement = "SELECT MATCH (col1,col2,col3) AGAINST ('test' IN NATURAL LANGUAGE MODE) relevance FROM tbl"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test + public void testFullTextSearchInDefaultMode() throws JSQLParserException { + String statement = "SELECT col FROM tbl WHERE MATCH (col1,col2,col3) AGAINST ('test') ORDER BY col"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test + public void testIsTrue() throws JSQLParserException { + String statement = "SELECT col FROM tbl WHERE col IS TRUE"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test + public void testIsFalse() throws JSQLParserException { + String statement = "SELECT col FROM tbl WHERE col IS FALSE"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test + public void testIsNotTrue() throws JSQLParserException { + String statement = "SELECT col FROM tbl WHERE col IS NOT TRUE"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test + public void testIsNotFalse() throws JSQLParserException { + String statement = "SELECT col FROM tbl WHERE col IS NOT FALSE"; + assertSqlCanBeParsedAndDeparsed(statement); + } + + @Test public void testOracleJoin() throws JSQLParserException { String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a = tabelle2.b(+)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleJoin2() throws JSQLParserException { String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a(+) = tabelle2.b"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleJoin2_1() throws JSQLParserException { String[] values = new String[]{"(+)", "( +)", "(+ )", "( + )", " (+) "}; for (String value : values) { @@ -1621,6 +1969,7 @@ public void testOracleJoin2_1() throws JSQLParserException { } } + @Test public void testOracleJoin2_2() throws JSQLParserException { String[] values = new String[]{"(+)", "( +)", "(+ )", "( + )", " (+) "}; for (String value : values) { @@ -1628,25 +1977,30 @@ public void testOracleJoin2_2() throws JSQLParserException { } } + @Test public void testOracleJoin3() throws JSQLParserException { String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a(+) > tabelle2.b"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleJoin3_1() throws JSQLParserException { String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a > tabelle2.b(+)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleJoin4() throws JSQLParserException { String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a(+) = tabelle2.b AND tabelle1.b(+) IN ('A', 'B')"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleJoinIssue318() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM TBL_A, TBL_B, TBL_C WHERE TBL_A.ID(+) = TBL_B.ID AND TBL_C.ROOM(+) = TBL_B.ROOM"); } + @Test public void testProblemSqlIntersect() throws Exception { String stmt = "(SELECT * FROM a) INTERSECT (SELECT * FROM b)"; assertSqlCanBeParsedAndDeparsed(stmt); @@ -1656,6 +2010,13 @@ public void testProblemSqlIntersect() throws Exception { assertStatementCanBeDeparsedAs(parsed, "SELECT * FROM a INTERSECT SELECT * FROM b"); } + @Test + public void testIntegerDivOperator() throws Exception { + String stmt = "SELECT col DIV 3"; + assertSqlCanBeParsedAndDeparsed(stmt); + } + + @Test public void testProblemSqlExcept() throws Exception { String stmt = "(SELECT * FROM a) EXCEPT (SELECT * FROM b)"; assertSqlCanBeParsedAndDeparsed(stmt); @@ -1665,6 +2026,7 @@ public void testProblemSqlExcept() throws Exception { assertStatementCanBeDeparsedAs(parsed, "SELECT * FROM a EXCEPT SELECT * FROM b"); } + @Test public void testProblemSqlMinus() throws Exception { String stmt = "(SELECT * FROM a) MINUS (SELECT * FROM b)"; assertSqlCanBeParsedAndDeparsed(stmt); @@ -1674,61 +2036,84 @@ public void testProblemSqlMinus() throws Exception { assertStatementCanBeDeparsedAs(parsed, "SELECT * FROM a MINUS SELECT * FROM b"); } + @Test public void testProblemSqlCombinedSets() throws Exception { String stmt = "(SELECT * FROM a) INTERSECT (SELECT * FROM b) UNION (SELECT * FROM c)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testWithStatement() throws JSQLParserException { String stmt = "WITH test AS (SELECT mslink FROM feature) SELECT * FROM feature WHERE mslink IN (SELECT mslink FROM test)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test + public void testSubjoinWithJoins() throws JSQLParserException { + String stmt = "SELECT COUNT(DISTINCT `tbl1`.`id`) FROM (`tbl1`, `tbl2`, `tbl3`)"; + assertSqlCanBeParsedAndDeparsed(stmt); + } + + @Test public void testWithUnionProblem() throws JSQLParserException { String stmt = "WITH test AS ((SELECT mslink FROM tablea) UNION (SELECT mslink FROM tableb)) SELECT * FROM tablea WHERE mslink IN (SELECT mslink FROM test)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testWithUnionAllProblem() throws JSQLParserException { String stmt = "WITH test AS ((SELECT mslink FROM tablea) UNION ALL (SELECT mslink FROM tableb)) SELECT * FROM tablea WHERE mslink IN (SELECT mslink FROM test)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testWithUnionProblem3() throws JSQLParserException { String stmt = "WITH test AS ((SELECT mslink, CAST(tablea.fname AS varchar) FROM tablea INNER JOIN tableb ON tablea.mslink = tableb.mslink AND tableb.deleted = 0 WHERE tablea.fname IS NULL AND 1 = 0) UNION ALL (SELECT mslink FROM tableb)) SELECT * FROM tablea WHERE mslink IN (SELECT mslink FROM test)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testWithUnionProblem4() throws JSQLParserException { String stmt = "WITH hist AS ((SELECT gl.mslink, ba.gl_name AS txt, ba.gl_nummer AS nr, 0 AS level, CAST(gl.mslink AS VARCHAR) AS path, ae.feature FROM tablea AS gl INNER JOIN tableb AS ba ON gl.mslink = ba.gl_mslink INNER JOIN tablec AS ae ON gl.mslink = ae.mslink AND ae.deleted = 0 WHERE gl.parent IS NULL AND gl.mslink <> 0) UNION ALL (SELECT gl.mslink, ba.gl_name AS txt, ba.gl_nummer AS nr, hist.level + 1 AS level, CAST(hist.path + '.' + CAST(gl.mslink AS VARCHAR) AS VARCHAR) AS path, ae.feature FROM tablea AS gl INNER JOIN tableb AS ba ON gl.mslink = ba.gl_mslink INNER JOIN tablec AS ae ON gl.mslink = ae.mslink AND ae.deleted = 0 INNER JOIN hist ON gl.parent = hist.mslink WHERE gl.mslink <> 0)) SELECT mslink, space(level * 4) + txt AS txt, nr, feature, path FROM hist WHERE EXISTS (SELECT feature FROM tablec WHERE mslink = 0 AND ((feature IN (1, 2) AND hist.feature = 3) OR (feature IN (4) AND hist.feature = 2)))"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testWithUnionProblem5() throws JSQLParserException { String stmt = "WITH hist AS ((SELECT gl.mslink, ba.gl_name AS txt, ba.gl_nummer AS nr, 0 AS level, CAST(gl.mslink AS VARCHAR) AS path, ae.feature FROM tablea AS gl INNER JOIN tableb AS ba ON gl.mslink = ba.gl_mslink INNER JOIN tablec AS ae ON gl.mslink = ae.mslink AND ae.deleted = 0 WHERE gl.parent IS NULL AND gl.mslink <> 0) UNION ALL (SELECT gl.mslink, ba.gl_name AS txt, ba.gl_nummer AS nr, hist.level + 1 AS level, CAST(hist.path + '.' + CAST(gl.mslink AS VARCHAR) AS VARCHAR) AS path, 5 AS feature FROM tablea AS gl INNER JOIN tableb AS ba ON gl.mslink = ba.gl_mslink INNER JOIN tablec AS ae ON gl.mslink = ae.mslink AND ae.deleted = 0 INNER JOIN hist ON gl.parent = hist.mslink WHERE gl.mslink <> 0)) SELECT * FROM hist"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testExtractFrom1() throws JSQLParserException { String stmt = "SELECT EXTRACT(month FROM datecolumn) FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testExtractFrom2() throws JSQLParserException { String stmt = "SELECT EXTRACT(year FROM now()) FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testExtractFrom3() throws JSQLParserException { String stmt = "SELECT EXTRACT(year FROM (now() - 2)) FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testExtractFrom4() throws JSQLParserException { String stmt = "SELECT EXTRACT(minutes FROM now() - '01:22:00') FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } +// @Test +// public void testExtractFromIssue673() throws JSQLParserException { +// String stmt = "select EXTRACT(DAY FROM (SYSDATE - to_date('20180101', 'YYYYMMDD' ) ) DAY TO SECOND) from dual"; +// assertSqlCanBeParsedAndDeparsed(stmt); +// } + @Test public void testProblemFunction() throws JSQLParserException { String stmt = "SELECT test() FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); @@ -1741,16 +2126,19 @@ public void testProblemFunction() throws JSQLParserException { assertEquals("test", ((Function) item.getExpression()).getName()); } + @Test public void testProblemFunction2() throws JSQLParserException { String stmt = "SELECT sysdate FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testProblemFunction3() throws JSQLParserException { String stmt = "SELECT TRUNCATE(col) FROM testtable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testAdditionalLettersGerman() throws JSQLParserException { String stmt = "SELECT colä, colö, colü FROM testtableäöü"; assertSqlCanBeParsedAndDeparsed(stmt); @@ -1765,26 +2153,31 @@ public void testAdditionalLettersGerman() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testAdditionalLettersSpanish() throws JSQLParserException { String stmt = "SELECT * FROM años"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testMultiTableJoin() throws JSQLParserException { String stmt = "SELECT * FROM taba INNER JOIN tabb ON taba.a = tabb.a, tabc LEFT JOIN tabd ON tabc.c = tabd.c"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testTableCrossJoin() throws JSQLParserException { String stmt = "SELECT * FROM taba CROSS JOIN tabb"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testLateral1() throws JSQLParserException { String stmt = "SELECT O.ORDERID, O.CUSTNAME, OL.LINETOTAL FROM ORDERS AS O, LATERAL(SELECT SUM(NETAMT) AS LINETOTAL FROM ORDERLINES AS LINES WHERE LINES.ORDERID = O.ORDERID) AS OL"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testLateralComplex1() throws IOException, JSQLParserException { String stmt = IOUtils.toString(SelectTest.class. getResourceAsStream("complex-lateral-select-request.txt")); @@ -1793,41 +2186,55 @@ public void testLateralComplex1() throws IOException, JSQLParserException { toString()); } + @Test public void testValues() throws JSQLParserException { String stmt = "SELECT * FROM (VALUES (1, 2), (3, 4)) AS test"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testValues2() throws JSQLParserException { String stmt = "SELECT * FROM (VALUES 1, 2, 3, 4) AS test"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testValues3() throws JSQLParserException { String stmt = "SELECT * FROM (VALUES 1, 2, 3, 4) AS test(a)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testValues4() throws JSQLParserException { String stmt = "SELECT * FROM (VALUES (1, 2), (3, 4)) AS test(a, b)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testValues5() throws JSQLParserException { String stmt = "SELECT X, Y FROM (VALUES (0, 'a'), (1, 'b')) AS MY_TEMP_TABLE(X, Y)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testValues6BothVariants() throws JSQLParserException { String stmt = "SELECT I FROM (VALUES 1, 2, 3) AS MY_TEMP_TABLE(I) WHERE I IN (SELECT * FROM (VALUES 1, 2) AS TEST)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test + public void testIntervalWithColumn() throws JSQLParserException { + String stmt = "SELECT DATE_ADD(start_date, INTERVAL duration MINUTE) AS end_datetime FROM appointment"; + assertSqlCanBeParsedAndDeparsed(stmt); + } + + @Test public void testInterval1() throws JSQLParserException { String stmt = "SELECT 5 + INTERVAL '3 days'"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testInterval2() throws JSQLParserException { String stmt = "SELECT to_timestamp(to_char(now() - INTERVAL '45 MINUTE', 'YYYY-MM-DD-HH24:')) AS START_TIME FROM tab1"; assertSqlCanBeParsedAndDeparsed(stmt); @@ -1856,104 +2263,160 @@ public void testInterval2() throws JSQLParserException { assertEquals("'45 MINUTE'", iexpr.getParameter()); } + @Test public void testInterval3() throws JSQLParserException { String stmt = "SELECT 5 + INTERVAL '3' day"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testInterval4() throws JSQLParserException { String stmt = "SELECT '2008-12-31 23:59:59' + INTERVAL 1 SECOND"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testInterval5_Issue228() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT ADDDATE(timeColumn1, INTERVAL 420 MINUTES) AS timeColumn1 FROM tbl"); assertSqlCanBeParsedAndDeparsed("SELECT ADDDATE(timeColumn1, INTERVAL -420 MINUTES) AS timeColumn1 FROM tbl"); } + @Test public void testMultiValueIn() throws JSQLParserException { String stmt = "SELECT * FROM mytable WHERE (a, b, c) IN (SELECT a, b, c FROM mytable2)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testMultiValueIn2() throws JSQLParserException { String stmt = "SELECT * FROM mytable WHERE (trim(a), trim(b)) IN (SELECT a, b FROM mytable2)"; assertSqlCanBeParsedAndDeparsed(stmt); } +// @Test +// public void testMultiValueIn3() throws JSQLParserException { +// String stmt = "SELECT * FROM mytable WHERE (SSN,SSM) IN (('11111111111111', '22222222222222'))"; +// assertSqlCanBeParsedAndDeparsed(stmt); +// } + @Test public void testPivot1() throws JSQLParserException { String stmt = "SELECT * FROM mytable PIVOT (count(a) FOR b IN ('val1'))"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPivot2() throws JSQLParserException { String stmt = "SELECT * FROM mytable PIVOT (count(a) FOR b IN (10, 20, 30))"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPivot3() throws JSQLParserException { String stmt = "SELECT * FROM mytable PIVOT (count(a) AS vals FOR b IN (10 AS d1, 20, 30 AS d3))"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPivot4() throws JSQLParserException { String stmt = "SELECT * FROM mytable PIVOT (count(a), sum(b) FOR b IN (10, 20, 30))"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPivot5() throws JSQLParserException { String stmt = "SELECT * FROM mytable PIVOT (count(a) FOR (b, c) IN ((10, 'a'), (20, 'b'), (30, 'c')))"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPivotXml1() throws JSQLParserException { String stmt = "SELECT * FROM mytable PIVOT XML (count(a) FOR b IN ('val1'))"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPivotXml2() throws JSQLParserException { String stmt = "SELECT * FROM mytable PIVOT XML (count(a) FOR b IN (SELECT vals FROM myothertable))"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPivotXml3() throws JSQLParserException { String stmt = "SELECT * FROM mytable PIVOT XML (count(a) FOR b IN (ANY))"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPivotXmlSubquery1() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM (SELECT times_purchased, state_code FROM customers t) PIVOT (count(state_code) FOR state_code IN ('NY', 'CT', 'NJ', 'FL', 'MO')) ORDER BY times_purchased"); } + @Test public void testPivotFunction() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT to_char((SELECT col1 FROM (SELECT times_purchased, state_code FROM customers t) PIVOT (count(state_code) FOR state_code IN ('NY', 'CT', 'NJ', 'FL', 'MO')) ORDER BY times_purchased)) FROM DUAL"); } + @Test + public void testPivotWithAlias() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM (SELECT * FROM mytable LEFT JOIN mytable2 ON Factor_ID = Id) f PIVOT (max(f.value) FOR f.factoryCode IN (ZD, COD, SW, PH))"); + } + + @Test + public void testPivotWithAlias2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM (SELECT * FROM mytable LEFT JOIN mytable2 ON Factor_ID = Id) f PIVOT (max(f.value) FOR f.factoryCode IN (ZD, COD, SW, PH)) d"); + } + + @Test + public void testPivotWithAlias3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM (SELECT * FROM mytable LEFT JOIN mytable2 ON Factor_ID = Id) PIVOT (max(f.value) FOR f.factoryCode IN (ZD, COD, SW, PH)) d"); + } + + @Test + public void testPivotWithAlias4() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM (" + + "SELECT a.Station_ID stationId, b.Factor_Code factoryCode, a.Value value" + + " FROM T_Data_Real a" + + " LEFT JOIN T_Bas_Factor b ON a.Factor_ID = b.Id" + + ") f " + + "PIVOT (max(f.value) FOR f.factoryCode IN (ZD, COD, SW, PH)) d"); + } + + @Test public void testRegexpLike1() throws JSQLParserException { String stmt = "SELECT * FROM mytable WHERE REGEXP_LIKE(first_name, '^Ste(v|ph)en$')"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testRegexpLike2() throws JSQLParserException { String stmt = "SELECT CASE WHEN REGEXP_LIKE(first_name, '^Ste(v|ph)en$') THEN 1 ELSE 2 END FROM mytable"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testRegexpMySQL() throws JSQLParserException { String stmt = "SELECT * FROM mytable WHERE first_name REGEXP '^Ste(v|ph)en$'"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testRegexpBinaryMySQL() throws JSQLParserException { String stmt = "SELECT * FROM mytable WHERE first_name REGEXP BINARY '^Ste(v|ph)en$'"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test + public void testRlike() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE first_name RLIKE '^Ste(v|ph)en$'"); + } + + @Test public void testBooleanFunction1() throws JSQLParserException { String stmt = "SELECT * FROM mytable WHERE test_func(col1)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testNamedParameter() throws JSQLParserException { String stmt = "SELECT * FROM mytable WHERE b = :param"; assertSqlCanBeParsedAndDeparsed(stmt); @@ -1968,6 +2431,7 @@ public void testNamedParameter() throws JSQLParserException { } + @Test public void testNamedParameter2() throws JSQLParserException { String stmt = "SELECT * FROM mytable WHERE a = :param OR a = :param2 AND b = :param3"; assertSqlCanBeParsedAndDeparsed(stmt); @@ -1998,81 +2462,102 @@ public void testNamedParameter2() throws JSQLParserException { assertEquals("param3", namedParameter3.getName()); } + @Test + public void testNamedParameter3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM t WHERE c = :from"); + } + + @Test public void testComplexUnion1() throws IOException, JSQLParserException { String stmt = "(SELECT 'abc-' || coalesce(mytab.a::varchar, '') AS a, mytab.b, mytab.c AS st, mytab.d, mytab.e FROM mytab WHERE mytab.del = 0) UNION (SELECT 'cde-' || coalesce(mytab2.a::varchar, '') AS a, mytab2.b, mytab2.bezeichnung AS c, 0 AS d, 0 AS e FROM mytab2 WHERE mytab2.del = 0)"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleHierarchicalQuery() throws JSQLParserException { String stmt = "SELECT last_name, employee_id, manager_id FROM employees CONNECT BY employee_id = manager_id ORDER BY last_name"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleHierarchicalQuery2() throws JSQLParserException { String stmt = "SELECT employee_id, last_name, manager_id FROM employees CONNECT BY PRIOR employee_id = manager_id"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleHierarchicalQuery3() throws JSQLParserException { String stmt = "SELECT last_name, employee_id, manager_id, LEVEL FROM employees START WITH employee_id = 100 CONNECT BY PRIOR employee_id = manager_id ORDER SIBLINGS BY last_name"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleHierarchicalQuery4() throws JSQLParserException { String stmt = "SELECT last_name, employee_id, manager_id, LEVEL FROM employees CONNECT BY PRIOR employee_id = manager_id START WITH employee_id = 100 ORDER SIBLINGS BY last_name"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testOracleHierarchicalQueryIssue196() throws JSQLParserException { String stmt = "SELECT num1, num2, level FROM carol_tmp START WITH num2 = 1008 CONNECT BY num2 = PRIOR num1 ORDER BY level DESC"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPostgreSQLRegExpCaseSensitiveMatch() throws JSQLParserException { String stmt = "SELECT a, b FROM foo WHERE a ~ '[help].*'"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPostgreSQLRegExpCaseSensitiveMatch2() throws JSQLParserException { String stmt = "SELECT a, b FROM foo WHERE a ~* '[help].*'"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPostgreSQLRegExpCaseSensitiveMatch3() throws JSQLParserException { String stmt = "SELECT a, b FROM foo WHERE a !~ '[help].*'"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testPostgreSQLRegExpCaseSensitiveMatch4() throws JSQLParserException { String stmt = "SELECT a, b FROM foo WHERE a !~* '[help].*'"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testReservedKeyword() throws JSQLParserException { final String statement = "SELECT cast, do, extract, first, following, last, materialized, nulls, partition, range, row, rows, siblings, value, xml FROM tableName"; // all of these are legal in SQL server; 'row' and 'rows' are not legal on Oracle, though; final Select select = (Select) parserManager.parse(new StringReader(statement)); assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testReservedKeyword2() throws JSQLParserException { final String stmt = "SELECT open FROM tableName"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testReservedKeyword3() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable1 t JOIN mytable2 AS prior ON t.id = prior.id"); } + @Test public void testCharacterSetClause() throws JSQLParserException { String stmt = "SELECT DISTINCT CAST(`view0`.`nick2` AS CHAR (8000) CHARACTER SET utf8) AS `v0` FROM people `view0` WHERE `view0`.`nick2` IS NOT NULL"; assertSqlCanBeParsedAndDeparsed(stmt); } + @Test public void testNotEqualsTo() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM foo WHERE a != b"); assertSqlCanBeParsedAndDeparsed("SELECT * FROM foo WHERE a <> b"); } + @Test public void testJsonExpression() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT data->'images'->'thumbnail'->'url' AS thumb FROM instagram"); assertSqlCanBeParsedAndDeparsed("SELECT * FROM sales WHERE sale->'items'->>'description' = 'milk'"); @@ -2094,18 +2579,27 @@ public void testJsonExpression() throws JSQLParserException { } } + @Test + public void testSqlNoCache() throws JSQLParserException { + String stmt = "SELECT SQL_NO_CACHE sales.date FROM sales"; + assertSqlCanBeParsedAndDeparsed(stmt); + } + public void testSelectInto1() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * INTO user_copy FROM user"); } + @Test public void testSelectForUpdate() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM user_table FOR UPDATE"); } + @Test public void testSelectForUpdate2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM emp WHERE empno = ? FOR UPDATE"); } + @Test public void testSelectJoin() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT pg_class.relname, pg_attribute.attname, pg_constraint.conname " + "FROM pg_constraint JOIN pg_class ON pg_class.oid = pg_constraint.conrelid" @@ -2114,118 +2608,147 @@ public void testSelectJoin() throws JSQLParserException { + " ORDER BY pg_constraint.conname"); } + @Test public void testSelectJoin2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM pg_constraint WHERE pg_attribute.attnum = ANY(pg_constraint.conkey)"); } + @Test public void testAnyConditionSubSelect() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT e1.empno, e1.sal FROM emp e1 WHERE e1.sal > ANY (SELECT e2.sal FROM emp e2 WHERE e2.deptno = 10)"); } - + + @Test public void testAllConditionSubSelect() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT e1.empno, e1.sal FROM emp e1 WHERE e1.sal > ALL (SELECT e2.sal FROM emp e2 WHERE e2.deptno = 10)"); } + @Test public void testSelectOracleColl() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM the_table tt WHERE TT.COL1 = lines(idx).COL1"); } + @Test public void testSelectInnerWith() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM (WITH actor AS (SELECT 'a' aid FROM DUAL) SELECT aid FROM actor)"); } + @Test public void testSelectWithinGroup() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT LISTAGG(col1, '##') WITHIN GROUP (ORDER BY col1) FROM table1"); } + @Test public void testSelectUserVariable() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT @col FROM t1"); } + @Test public void testSelectNumericBind() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT a FROM b WHERE c = :1"); } + @Test public void testSelectBrackets() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT avg((123.250)::numeric)"); } + @Test public void testSelectBrackets2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT (EXTRACT(epoch FROM age(d1, d2)) / 2)::numeric"); } + @Test public void testSelectBrackets3() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT avg((EXTRACT(epoch FROM age(d1, d2)) / 2)::numeric)"); } + @Test public void testSelectBrackets4() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT (1 / 2)::numeric"); } + @Test public void testSelectForUpdateOfTable() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT foo.*, bar.* FROM foo, bar WHERE foo.id = bar.foo_id FOR UPDATE OF foo"); } + @Test public void testSelectWithBrackets() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("(SELECT 1 FROM mytable)"); } + @Test public void testSelectWithBrackets2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("(SELECT 1)"); } + @Test public void testSelectWithoutFrom() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT footable.foocolumn"); } + @Test public void testSelectKeywordPercent() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT percent FROM MY_TABLE"); } + @Test public void testSelectJPQLPositionalParameter() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT email FROM users WHERE (type LIKE 'B') AND (username LIKE ?1)"); } + @Test public void testSelectKeep() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT col1, min(col2) KEEP (DENSE_RANK FIRST ORDER BY col3), col4 FROM table1 GROUP BY col5 ORDER BY col3"); } + @Test public void testSelectKeepOver() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) OVER (PARTITION BY department_id ) \"Worst\" FROM employees ORDER BY department_id, salary"); } + @Test public void testGroupConcat() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT student_name, GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ') FROM student GROUP BY student_name"); } + @Test public void testRowConstructor1() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM t1 WHERE (col1, col2) = (SELECT col3, col4 FROM t2 WHERE id = 10)"); } + @Test public void testRowConstructor2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM t1 WHERE ROW(col1, col2) = (SELECT col3, col4 FROM t2 WHERE id = 10)"); } + @Test public void testIssue154() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT d.id, d.uuid, d.name, d.amount, d.percentage, d.modified_time FROM discount d LEFT OUTER JOIN discount_category dc ON d.id = dc.discount_id WHERE merchant_id = ? AND deleted = ? AND dc.discount_id IS NULL AND modified_time < ? AND modified_time >= ? ORDER BY modified_time"); } + @Test public void testIssue154_2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT r.id, r.uuid, r.name, r.system_role FROM role r WHERE r.merchant_id = ? AND r.deleted_time IS NULL ORDER BY r.id DESC"); } + @Test public void testIssue160_signedParameter() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT start_date WHERE start_date > DATEADD(HH, -?, GETDATE())"); } + @Test public void testIssue160_signedParameter2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE -? = 5"); } + @Test public void testIssue162_doubleUserVar() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT @@SPID AS ID, SYSTEM_USER AS \"Login Name\", USER AS \"User Name\""); } + @Test public void testIssue167_singleQuoteEscape() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT 'a'"); assertSqlCanBeParsedAndDeparsed("SELECT ''''"); @@ -2234,22 +2757,23 @@ public void testIssue167_singleQuoteEscape() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT 'ab\\'ab'"); } - /** - * These are accepted due to reading one backslash and a double quote. - */ + @Test public void testIssue167_singleQuoteEscape2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT '\\'''"); assertSqlCanBeParsedAndDeparsed("SELECT '\\\\\\''"); } + @Test public void testIssue77_singleQuoteEscape2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT 'test\\'' FROM dual"); } + @Test public void testIssue223_singleQuoteEscape() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT '\\'test\\''"); } + @Test public void testOracleHint() throws JSQLParserException { assertOracleHintExists("SELECT /*+ SOMEHINT */ * FROM mytable", true, "SOMEHINT"); assertOracleHintExists("SELECT /*+ MORE HINTS POSSIBLE */ * FROM mytable", true, "MORE HINTS POSSIBLE"); @@ -2283,6 +2807,7 @@ public void testOracleHint() throws JSQLParserException { } + @Test public void testOracleHintExpression() throws JSQLParserException { String statement = "SELECT --+ HINT\n * FROM tab1"; Statement parsed = parserManager.parse(new StringReader(statement)); @@ -2292,6 +2817,7 @@ public void testOracleHintExpression() throws JSQLParserException { assertExpressionCanBeDeparsedAs(plainSelect.getOracleHint(), "--+ HINT\n"); } + @Test public void testTableFunctionWithNoParams() throws Exception { final String statement = "SELECT f2 FROM SOME_FUNCTION()"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -2307,6 +2833,7 @@ public void testTableFunctionWithNoParams() throws Exception { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testTableFunctionWithParams() throws Exception { final String statement = "SELECT f2 FROM SOME_FUNCTION(1, 'val')"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -2337,6 +2864,7 @@ public void testTableFunctionWithParams() throws Exception { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testTableFunctionWithAlias() throws Exception { final String statement = "SELECT f2 FROM SOME_FUNCTION() AS z"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -2354,133 +2882,179 @@ public void testTableFunctionWithAlias() throws Exception { assertStatementCanBeDeparsedAs(select, statement); } + @Test public void testIssue151_tableFunction() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM tables a LEFT JOIN getdata() b ON a.id = b.id"); } + @Test public void testIssue217_keywordSeparator() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT Separator"); } + @Test public void testIssue215_possibleEndlessParsing() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT (CASE WHEN ((value LIKE '%t1%') OR (value LIKE '%t2%')) THEN 't1s' WHEN ((((((((((((((((((((((((((((value LIKE '%t3%') OR (value LIKE '%t3%')) OR (value LIKE '%t3%')) OR (value LIKE '%t4%')) OR (value LIKE '%t4%')) OR (value LIKE '%t5%')) OR (value LIKE '%t6%')) OR (value LIKE '%t6%')) OR (value LIKE '%t7%')) OR (value LIKE '%t7%')) OR (value LIKE '%t7%')) OR (value LIKE '%t8%')) OR (value LIKE '%t8%')) OR (value LIKE '%CTO%')) OR (value LIKE '%cto%')) OR (value LIKE '%Cto%')) OR (value LIKE '%t9%')) OR (value LIKE '%t9%')) OR (value LIKE '%COO%')) OR (value LIKE '%coo%')) OR (value LIKE '%Coo%')) OR (value LIKE '%t10%')) OR (value LIKE '%t10%')) OR (value LIKE '%CIO%')) OR (value LIKE '%cio%')) OR (value LIKE '%Cio%')) OR (value LIKE '%t11%')) OR (value LIKE '%t11%')) THEN 't' WHEN ((((value LIKE '%t12%') OR (value LIKE '%t12%')) OR (value LIKE '%VP%')) OR (value LIKE '%vp%')) THEN 'Vice t12s' WHEN ((((((value LIKE '% IT %') OR (value LIKE '%t13%')) OR (value LIKE '%t13%')) OR (value LIKE '% it %')) OR (value LIKE '%tech%')) OR (value LIKE '%Tech%')) THEN 'IT' WHEN ((((value LIKE '%Analyst%') OR (value LIKE '%t14%')) OR (value LIKE '%Analytic%')) OR (value LIKE '%analytic%')) THEN 'Analysts' WHEN ((value LIKE '%Manager%') OR (value LIKE '%manager%')) THEN 't15' ELSE 'Other' END) FROM tab1"); } + @Test public void testIssue215_possibleEndlessParsing2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT (CASE WHEN ((value LIKE '%t1%') OR (value LIKE '%t2%')) THEN 't1s' ELSE 'Other' END) FROM tab1"); } + @Test public void testIssue215_possibleEndlessParsing3() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE ((((((((((((((((((((((((((((value LIKE '%t3%') OR (value LIKE '%t3%')) OR (value LIKE '%t3%')) OR (value LIKE '%t4%')) OR (value LIKE '%t4%')) OR (value LIKE '%t5%')) OR (value LIKE '%t6%')) OR (value LIKE '%t6%')) OR (value LIKE '%t7%')) OR (value LIKE '%t7%')) OR (value LIKE '%t7%')) OR (value LIKE '%t8%')) OR (value LIKE '%t8%')) OR (value LIKE '%CTO%')) OR (value LIKE '%cto%')) OR (value LIKE '%Cto%')) OR (value LIKE '%t9%')) OR (value LIKE '%t9%')) OR (value LIKE '%COO%')) OR (value LIKE '%coo%')) OR (value LIKE '%Coo%')) OR (value LIKE '%t10%')) OR (value LIKE '%t10%')) OR (value LIKE '%CIO%')) OR (value LIKE '%cio%')) OR (value LIKE '%Cio%')) OR (value LIKE '%t11%')) OR (value LIKE '%t11%'))"); } + @Test public void testIssue215_possibleEndlessParsing4() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE ((value LIKE '%t3%') OR (value LIKE '%t3%'))"); } + @Test public void testIssue215_possibleEndlessParsing5() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE ((((((value LIKE '%t3%') OR (value LIKE '%t3%')) OR (value LIKE '%t3%')) OR (value LIKE '%t4%')) OR (value LIKE '%t4%')) OR (value LIKE '%t5%'))"); } + @Test public void testIssue215_possibleEndlessParsing6() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE (((((((((((((value LIKE '%t3%') OR (value LIKE '%t3%')) OR (value LIKE '%t3%')) OR (value LIKE '%t4%')) OR (value LIKE '%t4%')) OR (value LIKE '%t5%')) OR (value LIKE '%t6%')) OR (value LIKE '%t6%')) OR (value LIKE '%t7%')) OR (value LIKE '%t7%')) OR (value LIKE '%t7%')) OR (value LIKE '%t8%')) OR (value LIKE '%t8%'))"); } + @Test public void testIssue215_possibleEndlessParsing7() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE (((((((((((((((((((((value LIKE '%t3%') OR (value LIKE '%t3%')) OR (value LIKE '%t3%')) OR (value LIKE '%t4%')) OR (value LIKE '%t4%')) OR (value LIKE '%t5%')) OR (value LIKE '%t6%')) OR (value LIKE '%t6%')) OR (value LIKE '%t7%')) OR (value LIKE '%t7%')) OR (value LIKE '%t7%')) OR (value LIKE '%t8%')) OR (value LIKE '%t8%')) OR (value LIKE '%CTO%')) OR (value LIKE '%cto%')) OR (value LIKE '%Cto%')) OR (value LIKE '%t9%')) OR (value LIKE '%t9%')) OR (value LIKE '%COO%')) OR (value LIKE '%coo%')) OR (value LIKE '%Coo%'))"); } + @Test public void testIssue230_cascadeKeyword() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT t.cascade AS cas FROM t"); } + @Test public void testBooleanValue() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT col FROM t WHERE a"); } + @Test public void testBooleanValue2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT col FROM t WHERE 3 < 5 AND a"); } + @Test public void testNotWithoutParenthesisIssue234() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT count(*) FROM \"Persons\" WHERE NOT \"F_NAME\" = 'John'"); } + @Test public void testWhereIssue240_1() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT count(*) FROM mytable WHERE 1"); } + @Test public void testWhereIssue240_0() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT count(*) FROM mytable WHERE 0"); } - public void testWhereIssue240_notBoolean() { - try { - CCJSqlParserUtil.parse("SELECT count(*) FROM mytable WHERE 5"); - fail("should not be parsed"); - } catch (JSQLParserException ex) { - //expected to fail - } + @Test + public void testCastToSignedInteger() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CAST(contact_id AS SIGNED INTEGER) FROM contact WHERE contact_id = 20"); } + @Test + public void testCastToSigned() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CAST(contact_id AS SIGNED) FROM contact WHERE contact_id = 20"); + } + +// @Test +// public void testWhereIssue240_notBoolean() { +// try { +// CCJSqlParserUtil.parse("SELECT count(*) FROM mytable WHERE 5"); +// fail("should not be parsed"); +// } catch (JSQLParserException ex) { +// //expected to fail +// } +// } + @Test public void testWhereIssue240_true() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT count(*) FROM mytable WHERE true"); } + @Test public void testWhereIssue240_false() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT count(*) FROM mytable WHERE false"); } + @Test public void testWhereIssue241KeywordEnd() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT l.end FROM lessons l"); } + @Test public void testSpeedTestIssue235() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM tbl WHERE (ROUND((((((period_diff(date_format(tbl.CD, '%Y%m'), date_format(SUBTIME(CURRENT_TIMESTAMP(), 25200), '%Y%m')) + month(SUBTIME(CURRENT_TIMESTAMP(), 25200))) - MONTH('2012-02-01')) - 1) / 3) - ROUND((((month(SUBTIME(CURRENT_TIMESTAMP(),25200)) - MONTH('2012-02-01')) - 1) / 3)))) = -3)", true); } + @Test public void testSpeedTestIssue235_2() throws IOException, JSQLParserException { String stmt = IOUtils.toString(SelectTest.class. getResourceAsStream("large-sql-issue-235.txt")); assertSqlCanBeParsedAndDeparsed(stmt, true); } + @Test public void testCastVarCharMaxIssue245() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT CAST('foo' AS NVARCHAR (MAX))"); } + @Test public void testNestedFunctionCallIssue253() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT (replace_regex(replace_regex(replace_regex(get_json_string(a_column, 'value'), '\\n', ' '), '\\r', ' '), '\\\\', '\\\\\\\\')) FROM a_table WHERE b_column = 'value'"); } + @Test public void testEscapedBackslashIssue253() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT replace_regex('test', '\\\\', '\\\\\\\\')"); } + @Test public void testKeywordTableIssue261() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT column_value FROM table(VARCHAR_LIST_TYPE())"); } + @Test public void testTopExpressionIssue243() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT TOP (? + 1) * FROM MyTable"); } + @Test public void testTopExpressionIssue243_2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT TOP (CAST(? AS INT)) * FROM MyTable"); } + @Test public void testFunctionIssue284() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT NVL((SELECT 1 FROM DUAL), 1) AS A FROM TEST1"); } + @Test public void testFunctionDateTimeValues() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM tab1 WHERE a > TIMESTAMP '2004-04-30 04:05:34.56'"); } + @Test + public void testPR73() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT date_part('day', TIMESTAMP '2001-02-16 20:38:40')"); + assertSqlCanBeParsedAndDeparsed("SELECT EXTRACT(year FROM DATE '2001-02-16')"); + } + + @Test public void testUniqueInsteadOfDistinctIssue299() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT UNIQUE trunc(timez(ludate)+ 8/24) bus_dt, j.object j_name , timez(j.starttime) START_TIME , timez(j.endtime) END_TIME FROM TEST_1 j", true); } + @Test public void testProblemSqlIssue265() throws IOException, JSQLParserException { String sqls = IOUtils.toString(SelectTest.class. getResourceAsStream("large-sql-with-issue-265.txt")); @@ -2488,43 +3062,51 @@ public void testProblemSqlIssue265() throws IOException, JSQLParserException { assertEquals(2, stmts.getStatements().size()); } + @Test public void testProblemSqlIssue330() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT COUNT(*) FROM C_Invoice WHERE IsSOTrx='Y' AND (Processed='N' OR Updated>(current_timestamp - CAST('90 days' AS interval))) AND C_Invoice.AD_Client_ID IN(0,1010016) AND C_Invoice.AD_Org_ID IN(0,1010053,1010095,1010094)", true); } + @Test public void testProblemSqlIssue330_2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT CAST('90 days' AS interval)"); } // won't fix due to lookahead impact on parser -// public void testKeywordOrderAsColumnnameIssue333() throws JSQLParserException { +// @Test public void testKeywordOrderAsColumnnameIssue333() throws JSQLParserException { // assertSqlCanBeParsedAndDeparsed("SELECT choice.response_choice_id AS uuid, choice.digit AS digit, choice.text_response AS textResponse, choice.voice_prompt AS voicePrompt, choice.action AS action, choice.contribution AS contribution, choice.order_num AS order, choice.description AS description, choice.is_join_conference AS joinConference, choice.voice_prompt_language_code AS voicePromptLanguageCode, choice.text_response_language_code AS textResponseLanguageCode, choice.description_language_code AS descriptionLanguageCode, choice.rec_phrase AS recordingPhrase FROM response_choices choice WHERE choice.presentation_id = ? ORDER BY choice.order_num", true); // } + @Test public void testProblemKeywordCommitIssue341() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT id, commit FROM table1"); } + @Test public void testProblemSqlIssue352() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT @rowNO from (SELECT @rowNO from dual) r", true); } + @Test public void testProblemIsIssue331() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT C_DocType.C_DocType_ID,NULL,COALESCE(C_DocType_Trl.Name,C_DocType.Name) AS Name,C_DocType.IsActive FROM C_DocType LEFT JOIN C_DocType_TRL ON (C_DocType.C_DocType_ID=C_DocType_Trl.C_DocType_ID AND C_DocType_Trl.AD_Language='es_AR') WHERE C_DocType.AD_Client_ID=1010016 AND C_DocType.AD_Client_ID IN (0,1010016) AND C_DocType.c_doctype_id in ( select c_doctype2.c_doctype_id from c_doctype as c_doctype2 where substring( c_doctype2.printname,6, length(c_doctype2.printname) ) = ( select letra from c_letra_comprobante as clc where clc.c_letra_comprobante_id = 1010039) ) AND ( (1010094!=0 AND C_DocType.ad_org_id = 1010094) OR 1010094=0 ) ORDER BY 3 LIMIT 2000", true); } + @Test public void testProblemIssue375() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("select n.nspname, c.relname, a.attname, a.atttypid, t.typname, a.attnum, a.attlen, a.atttypmod, a.attnotnull, c.relhasrules, c.relkind, c.oid, pg_get_expr(d.adbin, d.adrelid), case t.typtype when 'd' then t.typbasetype else 0 end, t.typtypmod, c.relhasoids from (((pg_catalog.pg_class c inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace and c.relname = 'business' and n.nspname = 'public') inner join pg_catalog.pg_attribute a on (not a.attisdropped) and a.attnum > 0 and a.attrelid = c.oid) inner join pg_catalog.pg_type t on t.oid = a.atttypid) left outer join pg_attrdef d on a.atthasdef and d.adrelid = a.attrelid and d.adnum = a.attnum order by n.nspname, c.relname, attnum", true); } + @Test public void testProblemIssue375Simplified() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("select * from (((pg_catalog.pg_class c inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace and c.relname = 'business' and n.nspname = 'public') inner join pg_catalog.pg_attribute a on (not a.attisdropped) and a.attnum > 0 and a.attrelid = c.oid) inner join pg_catalog.pg_type t on t.oid = a.atttypid) left outer join pg_attrdef d on a.atthasdef and d.adrelid = a.attrelid and d.adnum = a.attnum order by n.nspname, c.relname, attnum", true); } + @Test public void testProblemIssue375Simplified2() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("select * from (pg_catalog.pg_class c inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace and c.relname = 'business' and n.nspname = 'public') inner join pg_catalog.pg_attribute a on (not a.attisdropped) and a.attnum > 0 and a.attrelid = c.oid", true); } -// public void testProblemIssue377() throws Exception { +// @Test public void testProblemIssue377() throws Exception { // try { // assertSqlCanBeParsedAndDeparsed("select 'yelp'::name as pktable_cat, n2.nspname as pktable_schem, c2.relname as pktable_name, a2.attname as pkcolumn_name, 'yelp'::name as fktable_cat, n1.nspname as fktable_schem, c1.relname as fktable_name, a1.attname as fkcolumn_name, i::int2 as key_seq, case ref.confupdtype when 'c' then 0::int2 when 'n' then 2::int2 when 'd' then 4::int2 when 'r' then 1::int2 else 3::int2 end as update_rule, case ref.confdeltype when 'c' then 0::int2 when 'n' then 2::int2 when 'd' then 4::int2 when 'r' then 1::int2 else 3::int2 end as delete_rule, ref.conname as fk_name, cn.conname as pk_name, case when ref.condeferrable then case when ref.condeferred then 5::int2 else 6::int2 end else 7::int2 end as deferrablity from ((((((( (select cn.oid, conrelid, conkey, confrelid, confkey, generate_series(array_lower(conkey, 1), array_upper(conkey, 1)) as i, confupdtype, confdeltype, conname, condeferrable, condeferred from pg_catalog.pg_constraint cn, pg_catalog.pg_class c, pg_catalog.pg_namespace n where contype = 'f' and conrelid = c.oid and relname = 'business' and n.oid = c.relnamespace and n.nspname = 'public' ) ref inner join pg_catalog.pg_class c1 on c1.oid = ref.conrelid) inner join pg_catalog.pg_namespace n1 on n1.oid = c1.relnamespace) inner join pg_catalog.pg_attribute a1 on a1.attrelid = c1.oid and a1.attnum = conkey[i]) inner join pg_catalog.pg_class c2 on c2.oid = ref.confrelid) inner join pg_catalog.pg_namespace n2 on n2.oid = c2.relnamespace) inner join pg_catalog.pg_attribute a2 on a2.attrelid = c2.oid and a2.attnum = confkey[i]) left outer join pg_catalog.pg_constraint cn on cn.conrelid = ref.confrelid and cn.contype = 'p') order by ref.oid, ref.i", true); // } catch (Exception ex) { @@ -2532,19 +3114,23 @@ public void testProblemIssue375Simplified2() throws JSQLParserException { // throw ex; // } // } + @Test public void testProblemInNotInProblemIssue379() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT rank FROM DBObjects WHERE rank NOT IN (0, 1)"); assertSqlCanBeParsedAndDeparsed("SELECT rank FROM DBObjects WHERE rank IN (0, 1)"); } + @Test public void testProblemLargeNumbersIssue390() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM student WHERE student_no = 20161114000000035001"); } + @Test public void testKeyWorkInsertIssue393() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT insert(\"aaaabbb\", 4, 4, \"****\")"); } + @Test public void testKeyWorkReplaceIssue393() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT replace(\"aaaabbb\", 4, 4, \"****\")"); } @@ -2552,6 +3138,7 @@ public void testKeyWorkReplaceIssue393() throws JSQLParserException { /** * Validates that a SELECT with FOR UPDATE WAIT can be parsed and deparsed */ + @Test public void testForUpdateWaitParseDeparse() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable FOR UPDATE WAIT 60"); } @@ -2560,6 +3147,7 @@ public void testForUpdateWaitParseDeparse() throws JSQLParserException { * Validates that a SELECT with FOR UPDATE WAIT correctly sets a {@link Wait} with the * correct timeout value. */ + @Test public void testForUpdateWaitWithTimeout() throws JSQLParserException { String statement = "SELECT * FROM mytable FOR UPDATE WAIT 60"; Select select = (Select) parserManager.parse(new StringReader(statement)); @@ -2571,41 +3159,826 @@ public void testForUpdateWaitWithTimeout() throws JSQLParserException { assertEquals("wait time should be 60", waitTime, 60L); } -// public void testSubSelectFailsIssue394() throws JSQLParserException { + @Test + public void testForUpdateNoWait() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable FOR UPDATE NOWAIT"); + } + +// @Test public void testSubSelectFailsIssue394() throws JSQLParserException { // assertSqlCanBeParsedAndDeparsed("select aa.* , t.* from accenter.all aa, (select a.* from pacioli.emc_plan a) t"); // } // -// public void testSubSelectFailsIssue394_2() throws JSQLParserException { +// @Test public void testSubSelectFailsIssue394_2() throws JSQLParserException { // assertSqlCanBeParsedAndDeparsed("select * from all"); // } - + @Test public void testMysqlIndexHints() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT column FROM testtable AS t0 USE INDEX (index1)"); assertSqlCanBeParsedAndDeparsed("SELECT column FROM testtable AS t0 IGNORE INDEX (index1)"); assertSqlCanBeParsedAndDeparsed("SELECT column FROM testtable AS t0 FORCE INDEX (index1)"); } + @Test public void testMysqlIndexHintsWithJoins() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT column FROM table0 t0 INNER JOIN table1 t1 USE INDEX (index1)"); assertSqlCanBeParsedAndDeparsed("SELECT column FROM table0 t0 INNER JOIN table1 t1 IGNORE INDEX (index1)"); assertSqlCanBeParsedAndDeparsed("SELECT column FROM table0 t0 INNER JOIN table1 t1 FORCE INDEX (index1)"); } + @Test public void testMysqlMultipleIndexHints() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT column FROM testtable AS t0 USE INDEX (index1,index2)"); assertSqlCanBeParsedAndDeparsed("SELECT column FROM testtable AS t0 IGNORE INDEX (index1,index2)"); assertSqlCanBeParsedAndDeparsed("SELECT column FROM testtable AS t0 FORCE INDEX (index1,index2)"); } - + + @Test public void testProblemIssue435() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT if(z, 'a', 'b') AS business_type FROM mytable1"); } - + + @Test public void testProblemIssue437Index() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("select count(id) from p_custom_data ignore index(pri) where tenant_id=28257 and entity_id=92609 and delete_flg=0 and ( (dbc_relation_2 = 52701) and (dbc_relation_2 in ( select id from a_order where tenant_id = 28257 and 1=1 ) ) ) order by id desc, id desc", true); } - + + @Test public void testProblemIssue445() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("SELECT E.ID_NUMBER, row_number() OVER (PARTITION BY E.ID_NUMBER ORDER BY E.DEFINED_UPDATED DESC) rn FROM T_EMPLOYMENT E"); } + + @Test + public void testProblemIssue485Date() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM tab WHERE tab.date = :date"); + } + + @Test + public void testGroupByProblemIssue482() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT SUM(orderTotalValue) AS value, MONTH(invoiceDate) AS month, YEAR(invoiceDate) AS year FROM invoice.Invoices WHERE projectID = 1 GROUP BY MONTH(invoiceDate), YEAR(invoiceDate) ORDER BY YEAR(invoiceDate) DESC, MONTH(invoiceDate) DESC"); + } + + @Test + public void testIssue512() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM #tab1"); + assertSqlCanBeParsedAndDeparsed("SELECT * FROM tab#tab1"); + } + + @Test + public void testIssue512_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM $tab1"); + assertSqlCanBeParsedAndDeparsed("SELECT * FROM #$tab#tab1"); + assertSqlCanBeParsedAndDeparsed("SELECT * FROM #$tab1#"); + assertSqlCanBeParsedAndDeparsed("SELECT * FROM $#tab1#"); + } + + @Test + public void testIssue514() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT listagg(c1, ';') WITHIN GROUP (PARTITION BY 1 ORDER BY 1) col FROM dual"); + } + + @Test + public void testIssue508LeftRightBitwiseShift() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT 1 << 1"); + assertSqlCanBeParsedAndDeparsed("SELECT 1 >> 1"); + } + + @Test + public void testIssue522() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CASE mr.required_quantity - mr.quantity_issued WHEN 0 THEN NULL ELSE CASE SIGN(mr.required_quantity) WHEN -1 * SIGN(mr.quantity_issued) THEN mr.required_quantity - mr.quantity_issued ELSE CASE SIGN(ABS(mr.required_quantity) - ABS(mr.quantity_issued)) WHEN -1 THEN NULL ELSE mr.required_quantity - mr.quantity_issued END END END quantity_open FROM mytable", true); + } + + @Test + public void testIssue522_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT -1 * SIGN(mr.quantity_issued) FROM mytable"); + } + + @Test + public void testIssue522_3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CASE SIGN(mr.required_quantity) WHEN -1 * SIGN(mr.quantity_issued) THEN mr.required_quantity - mr.quantity_issued ELSE 5 END quantity_open FROM mytable", true); + } + + @Test + public void testIssue522_4() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CASE a + b WHEN -1 * 5 THEN 1 ELSE CASE b + c WHEN -1 * 6 THEN 2 ELSE 3 END END"); + } + + @Test + public void testIssue554() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT T.INDEX AS INDEX133_ FROM myTable T"); + } + + @Test + public void testIssue567KeywordPrimary() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT primary, secondary FROM info"); + } + + @Test + public void testIssue572TaskReplacement() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT task_id AS \"Task Id\" FROM testtable"); + } + + @Test + public void testIssue566LargeView() throws IOException, JSQLParserException { + String stmt = IOUtils.toString(SelectTest.class.getResourceAsStream("large-sql-issue-566.txt")); + assertSqlCanBeParsedAndDeparsed(stmt, true); + } + + @Test + public void testIssue566PostgreSQLEscaped() throws IOException, JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT E'test'"); + } + + @Test + public void testEscaped() throws IOException, JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT _utf8'testvalue'"); + } + + @Test + public void testIssue563MultiSubJoin() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT c FROM ((SELECT a FROM t) JOIN (SELECT b FROM t2) ON a = B JOIN (SELECT c FROM t3) ON b = c)"); + } + + @Test + public void testIssue563MultiSubJoin_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT c FROM ((SELECT a FROM t))"); + } + + @Test + public void testIssue582NumericConstants() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT x'009fd'"); + assertSqlCanBeParsedAndDeparsed("SELECT X'009fd'"); + } + + @Test + public void testIssue583CharacterLiteralAsAlias() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CASE WHEN T.ISC = 1 THEN T.EXTDESC WHEN T.b = 2 THEN '2' ELSE T.C END AS 'Test' FROM T"); + } + + @Test + public void testIssue266KeywordTop() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT @top"); + assertSqlCanBeParsedAndDeparsed("SELECT @TOP"); + } + + @Test + public void testIssue584MySQLValueListExpression() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT a, b FROM T WHERE (T.a, T.b) = (c, d)"); + assertSqlCanBeParsedAndDeparsed("SELECT a FROM T WHERE (T.a) = (SELECT b FROM T, c, d)"); + } + + @Test + public void testIssue588NotNull() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE col1 ISNULL"); + } + + @Test + public void testParenthesisAroundFromItem() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM (mytable)"); + } + + @Test + public void testParenthesisAroundFromItem2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM (mytable myalias)"); + } + + @Test + public void testParenthesisAroundFromItem3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM (mytable) myalias"); + } + + @Test + public void testJoinerExpressionIssue596() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM a JOIN (b JOIN c ON b.id = c.id) ON a.id = c.id"); + } + +// @Test public void testJoinerExpressionIssue596_2() throws JSQLParserException { +// assertSqlCanBeParsedAndDeparsed("SELECT * FROM a JOIN b JOIN c ON b.id = c.id ON a.id = c.id"); +// } + @Test + public void testProblemSqlIssue603() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CASE WHEN MAX(CAST(a.jobNum AS INTEGER)) IS NULL THEN '1000' ELSE MAX(CAST(a.jobNum AS INTEGER)) + 1 END FROM user_employee a"); + } + + @Test + public void testProblemSqlIssue603_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CAST(col1 AS UNSIGNED INTEGER) FROM mytable"); + } + + @Test + public void testProblemSqlFuncParamIssue605() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT p.id, pt.name, array_to_string( array( select pc.name from product_category pc ), ',' ) AS categories FROM product p", true); + } + + @Test + public void testProblemSqlFuncParamIssue605_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT func(SELECT col1 FROM mytable)"); + } + + @Test + public void testSqlContainIsNullFunctionShouldBeParsed() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT name, age, ISNULL(home, 'earn more money') FROM person"); + } + + @Test + public void testNestedCast() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT acolumn::bit (64)::bigint FROM mytable"); + } + + @Test + public void testAndOperator() throws JSQLParserException { + String stmt = "SELECT name from customers where name = 'John' && lastname = 'Doh'"; + Statement parsed = parserManager.parse(new StringReader(stmt)); + assertStatementCanBeDeparsedAs(parsed, "SELECT name FROM customers WHERE name = 'John' AND lastname = 'Doh'"); + } + + @Test + public void testNamedParametersIssue612() throws Exception { + assertSqlCanBeParsedAndDeparsed("SELECT a FROM b LIMIT 10 OFFSET :param"); + } + + @Test + public void testMissingOffsetIssue620() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT a, b FROM test OFFSET 0"); + assertSqlCanBeParsedAndDeparsed("SELECT a, b FROM test LIMIT 1 OFFSET 0"); + } + + @Test + public void testMultiPartNames1() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT a.b"); + } + + @Test + public void testMultiPartNames2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT a.b.*"); + } + + @Test + public void testMultiPartNames3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT a.*"); + } + + @Test + public void testMultiPartNames4() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT a.b.c.d.e.f.g.h"); + } + + @Test + public void testMultiPartNames5() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM a.b.c.d.e.f.g.h"); + } + + @Test + public void testMultiPartNamesIssue163() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT mymodel.name FROM com.myproject.MyModelClass AS mymodel"); + } + + @Test + public void testMultiPartNamesIssue608() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT @@sessions.tx_read_only"); + } + +// Teradata allows SEL to be used in place of SELECT +// Deparse to the non-contracted form + @Test + public void testSelContraction() throws JSQLParserException { + final String statementSrc = "SEL name, age FROM person"; + final String statementTgt = "SELECT name, age FROM person"; + Select select = (Select) parserManager.parse(new StringReader(statementSrc)); + assertStatementCanBeDeparsedAs(select, statementTgt); + } + + @Test + public void testMultiPartNamesIssue643() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT id, bid, pid, devnum, pointdesc, sysid, zone, sort FROM fault ORDER BY id DESC LIMIT ?, ?"); + } + + @Test + public void testNotNotIssue() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT VALUE1, VALUE2 FROM FOO WHERE NOT BAR LIKE '*%'"); + } + + @Test + public void testCharNotParsedIssue718() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT a FROM x WHERE a LIKE '%' + char(9) + '%'"); + } + + @Test + public void testTrueFalseLiteral() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM tbl WHERE true OR clm1 = 3"); + } + + @Test + public void testTopKeyWord() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT top.date AS mycol1 FROM mytable top WHERE top.myid = :myid AND top.myid2 = 123"); + } + + @Test + public void testTopKeyWord2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT top.date"); + } + + @Test + public void testTopKeyWord3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable top"); + } + + @Test + public void testNotProblem1() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytab WHERE NOT v IN (1, 2, 3, 4, 5, 6, 7)"); + } + + @Test + public void testNotProblem2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytab WHERE NOT func(5)"); + } + + @Test + public void testCaseThenCondition() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE CASE WHEN a = 'c' THEN a IN (1, 2, 3) END = 1"); + } + + @Test + public void testCaseThenCondition2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE CASE WHEN a = 'c' THEN a IN (1, 2, 3) END"); + } + + @Test + public void testCaseThenCondition3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CASE WHEN a > 0 THEN b + a ELSE 0 END p FROM mytable"); + } + + @Test + public void testCaseThenCondition4() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM col WHERE CASE WHEN a = 'c' THEN a IN (SELECT id FROM mytable) END"); + } + + @Test + public void testCaseThenCondition5() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM col WHERE CASE WHEN a = 'c' THEN a IN (SELECT id FROM mytable) ELSE b IN (SELECT id FROM mytable) END"); + } + + @Test + public void testOptimizeForIssue348() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM EMP ORDER BY SALARY DESC OPTIMIZE FOR 20 ROWS"); + } + + @Test + public void testFuncConditionParameter() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT if(a < b)"); + } + + @Test + public void testFuncConditionParameter2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT if(a < b, c)"); + } + + @Test + public void testFuncConditionParameter3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CAST((MAX(CAST(IIF(isnumeric(license_no) = 1, license_no, 0) AS INT)) + 2) AS varchar) FROM lcps.t_license WHERE profession_id = 60 and license_type = 100 and YEAR(issue_date) % 2 = case when YEAR(issue_date) % 2 = 0 then 0 else 1 end and ISNUMERIC(license_no) = 1", true); + } + + @Test + public void testSqlContainIsNullFunctionShouldBeParsed3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT name, age FROM person WHERE NOT ISNULL(home, 'earn more money')"); + } + + @Test + public void testForXmlPath() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT '|' + person_name FROM person JOIN person_group ON person.person_id = person_group.person_id WHERE person_group.group_id = 1 FOR XML PATH('')"); + } + +// @Test +// public void testForXmlPath2() throws JSQLParserException { +// assertSqlCanBeParsedAndDeparsed("SELECT ( STUFF( (SELECT '|' + person_name FROM person JOIN person_group ON person.person_id = person_group.person_id WHERE person_group.group_id = 1 FOR XML PATH(''), TYPE).value('.', 'varchar(max)'),1,1,'')) AS person_name"); +// } + @Test + public void testChainedunctions() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT func('').func2('') AS foo FROM some_tables"); + } + + @Test + public void testCollateExprIssue164() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT u.name COLLATE Latin1_General_CI_AS AS User FROM users u"); + } + +// @Test +// public void testIntervalExpression() throws JSQLParserException { +// assertSqlCanBeParsedAndDeparsed("SELECT count(emails.id) FROM emails WHERE (emails.date_entered + 30 DAYS) > CURRENT_DATE"); +// } + @Test + public void testNotVariant() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT ! (1 + 1)"); + } + + @Test + public void testNotVariant2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT ! 1 + 1"); + } + + @Test + public void testNotVariant3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT NOT (1 + 1)"); + } + + @Test + public void testNotVariant4() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE NOT (1 = 1)"); + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE ! (1 = 1)"); + } + + @Test + public void testNotVariantIssue850() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE id = 1 AND ! (id = 1 AND id = 2)"); + } + + @Test + public void testDateArithmentic() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CURRENT_DATE + (1 DAY) FROM SYSIBM.SYSDUMMY1"); + } + + @Test + public void testDateArithmentic2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CURRENT_DATE + 1 DAY AS NEXT_DATE FROM SYSIBM.SYSDUMMY1"); + } + + @Test + public void testDateArithmentic3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CURRENT_DATE + 1 DAY NEXT_DATE FROM SYSIBM.SYSDUMMY1"); + } + + @Test + public void testDateArithmentic4() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CURRENT_DATE - 1 DAY + 1 YEAR - 1 MONTH FROM SYSIBM.SYSDUMMY1"); + } + + @Test + public void testDateArithmentic5() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CASE WHEN CURRENT_DATE BETWEEN (CURRENT_DATE - 1 DAY) AND ('2019-01-01') THEN 1 ELSE 0 END FROM SYSIBM.SYSDUMMY1"); + } + + @Test + public void testDateArithmentic6() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CURRENT_DATE + HOURS_OFFSET HOUR AS NEXT_DATE FROM SYSIBM.SYSDUMMY1"); + } + + @Test + public void testDateArithmentic7() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CURRENT_DATE + MINUTE_OFFSET MINUTE AS NEXT_DATE FROM SYSIBM.SYSDUMMY1"); + } + + @Test + public void testDateArithmentic8() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CURRENT_DATE + SECONDS_OFFSET SECOND AS NEXT_DATE FROM SYSIBM.SYSDUMMY1"); + } + + @Test + public void testNotProblemIssue721() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM dual WHERE NOT regexp_like('a', '[\\w]+')"); + } + + @Test + @Ignore + public void testIssue699() throws JSQLParserException { + String sql = "SELECT count(1) " + + "FROM table_name " + + "WHERE 1 = 1 " + + "AN D uid = 1 " + + "AND type IN (1, 2, 3) " + + "AND time >= TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL 2 DAY),'00:00:00') " + + "AND time < TIMESTAMP(DATE_SUB(CURDATE(),INTERVAL (2 - 1) DAY),'00:00:00')"; + assertSqlCanBeParsedAndDeparsed(sql); + } + + @Test + public void testDateArithmentic9() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT CURRENT_DATE + (RAND() * 12 MONTH) AS new_date FROM mytable"); + } + + @Test + public void testDateArithmentic10() throws JSQLParserException { + String sql = "select CURRENT_DATE + CASE WHEN CAST(RAND() * 3 AS INTEGER) = 1 THEN 100 ELSE 0 END DAY AS NEW_DATE from mytable"; + assertSqlCanBeParsedAndDeparsed(sql, true); + Select select = (Select) CCJSqlParserUtil.parse(sql); + + } + + @Test + public void testDateArithmentic11() throws JSQLParserException { + String sql = "select CURRENT_DATE + (dayofweek(MY_DUE_DATE) + 5) DAY FROM mytable"; + assertSqlCanBeParsedAndDeparsed(sql, true); + Select select = (Select) CCJSqlParserUtil.parse(sql); + final List list = new ArrayList<>(); + select.getSelectBody().accept(new SelectVisitorAdapter() { + @Override + public void visit(PlainSelect plainSelect) { + list.addAll(plainSelect.getSelectItems()); + } + }); + + assertEquals(1, list.size()); + assertTrue(list.get(0) instanceof SelectExpressionItem); + SelectExpressionItem item = (SelectExpressionItem) list.get(0); + assertTrue(item.getExpression() instanceof Addition); + Addition add = (Addition) item.getExpression(); + + assertTrue(add.getRightExpression() instanceof IntervalExpression); + } + + @Test + public void testDateArithmentic12() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("select CASE WHEN CAST(RAND() * 3 AS INTEGER) = 1 THEN NULL ELSE CURRENT_DATE + (month_offset MONTH) END FROM mytable", true); + } + + @Test + public void testDateArithmentic13() throws JSQLParserException { + String sql = "SELECT INTERVAL 5 MONTH MONTH FROM mytable"; + assertSqlCanBeParsedAndDeparsed(sql); + Select select = (Select) CCJSqlParserUtil.parse(sql); + final List list = new ArrayList<>(); + select.getSelectBody().accept(new SelectVisitorAdapter() { + @Override + public void visit(PlainSelect plainSelect) { + list.addAll(plainSelect.getSelectItems()); + } + }); + + assertEquals(1, list.size()); + assertTrue(list.get(0) instanceof SelectExpressionItem); + SelectExpressionItem item = (SelectExpressionItem) list.get(0); + assertTrue(item.getExpression() instanceof IntervalExpression); + IntervalExpression interval = (IntervalExpression) item.getExpression(); + assertEquals("INTERVAL 5 MONTH", interval.toString()); + assertEquals("MONTH", item.getAlias().getName()); + } + + @Test + public void testRawStringExpressionIssue656() throws JSQLParserException { + for (String c : new String[]{"u", "e", "n", "r", "b", "rb"}) { + final String prefix = c; + String sql = "select " + c + "'test' from foo"; + Statement statement = CCJSqlParserUtil.parse(sql); + assertNotNull(statement); + statement.accept(new StatementVisitorAdapter() { + @Override + public void visit(Select select) { + select.getSelectBody().accept(new SelectVisitorAdapter() { + @Override + public void visit(PlainSelect plainSelect) { + SelectExpressionItem typedExpression + = (SelectExpressionItem) plainSelect.getSelectItems().get(0); + assertNotNull(typedExpression); + assertNull(typedExpression.getAlias()); + StringValue value = (StringValue) typedExpression.getExpression(); + assertEquals(prefix.toUpperCase(), value.getPrefix()); + assertEquals("test", value.getValue()); + } + }); + } + }); + } + } + + @Test + public void testGroupingSets1() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT COL_1, COL_2, COL_3, COL_4, COL_5, COL_6 FROM TABLE_1 " + + "GROUP BY " + + "GROUPING SETS ((COL_1, COL_2, COL_3, COL_4), (COL_5, COL_6))"); + } + + @Test + public void testGroupingSets2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT COL_1 FROM TABLE_1 GROUP BY GROUPING SETS (COL_1)"); + } + + @Test + public void testGroupingSets3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT COL_1 FROM TABLE_1 GROUP BY GROUPING SETS (COL_1, ())"); + } + + @Test + public void testLongQualifiedNamesIssue763() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT mongodb.test.test.intField, postgres.test.test.intField, postgres.test.test.datefield FROM mongodb.test.test JOIN postgres.postgres.test.test ON mongodb.test.test.intField = postgres.test.test.intField WHERE mongodb.test.test.intField = 123"); + } + + @Test + public void testLongQualifiedNamesIssue763_2() throws JSQLParserException { + Statement parse = CCJSqlParserUtil.parse(new StringReader("SELECT mongodb.test.test.intField, postgres.test.test.intField, postgres.test.test.datefield FROM mongodb.test.test JOIN postgres.postgres.test.test ON mongodb.test.test.intField = postgres.test.test.intField WHERE mongodb.test.test.intField = 123")); + System.out.println(parse.toString()); + } + + @Test + public void testSubQueryAliasIssue754() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT C0 FROM T0 INNER JOIN T1 ON C1 = C0 INNER JOIN (SELECT W1 FROM T2) S1 ON S1.W1 = C0 ORDER BY C0"); + } + + @Test + public void testSimilarToIssue789() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE (w_id SIMILAR TO '/foo/__/bar/(left|right)/[0-9]{4}-[0-9]{2}-[0-9]{2}(/[0-9]*)?')"); + } + + @Test + public void testSimilarToIssue789_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE (w_id NOT SIMILAR TO '/foo/__/bar/(left|right)/[0-9]{4}-[0-9]{2}-[0-9]{2}(/[0-9]*)?')"); + } + + @Test + public void testCaseWhenExpressionIssue262() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT X1, (CASE WHEN T.ID IS NULL THEN CASE P.WEIGHT * SUM(T.QTY) WHEN 0 THEN NULL ELSE P.WEIGHT END ELSE SUM(T.QTY) END) AS W FROM A LEFT JOIN T ON T.ID = ? RIGHT JOIN P ON P.ID = ?"); + } + + @Test + public void testCaseWhenExpressionIssue200() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM t1, t2 WHERE CASE WHEN t1.id = 1 THEN t2.name = 'Marry' WHEN t1.id = 2 THEN t2.age = 10 END"); + } + + @Test + public void testKeywordDuplicate() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT mytable.duplicate FROM mytable"); + } + + @Test + public void testKeywordDuplicate2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE duplicate = 5"); + } + + @Test + public void testEmptyDoubleQuotes() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE col = \"\""); + } + + @Test + public void testEmptyDoubleQuotes_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE col = \" \""); + } + + @Test + public void testInnerWithBlock() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("select 1 from (with mytable1 as (select 2 ) select 3 from mytable1 ) first", true); + } + + @Test + public void testArrayIssue648() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("select * from a join b on a.id = b.id[1]", true); + } + + @Test + public void testArrayIssue638() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT PAYLOAD[0] FROM MYTABLE"); + } + + @Test + public void testArrayIssue489() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT name[1] FROM MYTABLE"); + } + + @Test + public void testArrayIssue377() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("select 'yelp'::name as pktable_cat, n2.nspname as pktable_schem, c2.relname as pktable_name, a2.attname as pkcolumn_name, 'yelp'::name as fktable_cat, n1.nspname as fktable_schem, c1.relname as fktable_name, a1.attname as fkcolumn_name, i::int2 as key_seq, case ref.confupdtype when 'c' then 0::int2 when 'n' then 2::int2 when 'd' then 4::int2 when 'r' then 1::int2 else 3::int2 end as update_rule, case ref.confdeltype when 'c' then 0::int2 when 'n' then 2::int2 when 'd' then 4::int2 when 'r' then 1::int2 else 3::int2 end as delete_rule, ref.conname as fk_name, cn.conname as pk_name, case when ref.condeferrable then case when ref.condeferred then 5::int2 else 6::int2 end else 7::int2 end as deferrablity from ((((((( (select cn.oid, conrelid, conkey, confrelid, confkey, generate_series(array_lower(conkey, 1), array_upper(conkey, 1)) as i, confupdtype, confdeltype, conname, condeferrable, condeferred from pg_catalog.pg_constraint cn, pg_catalog.pg_class c, pg_catalog.pg_namespace n where contype = 'f' and conrelid = c.oid and relname = 'business' and n.oid = c.relnamespace and n.nspname = 'public' ) ref inner join pg_catalog.pg_class c1 on c1.oid = ref.conrelid) inner join pg_catalog.pg_namespace n1 on n1.oid = c1.relnamespace) inner join pg_catalog.pg_attribute a1 on a1.attrelid = c1.oid and a1.attnum = conkey[i]) inner join pg_catalog.pg_class c2 on c2.oid = ref.confrelid) inner join pg_catalog.pg_namespace n2 on n2.oid = c2.relnamespace) inner join pg_catalog.pg_attribute a2 on a2.attrelid = c2.oid and a2.attnum = confkey[i]) left outer join pg_catalog.pg_constraint cn on cn.conrelid = ref.confrelid and cn.contype = 'p') order by ref.oid, ref.i", true); + } + + @Test + public void testArrayIssue378() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("select ta.attname, ia.attnum, ic.relname, n.nspname, tc.relname from pg_catalog.pg_attribute ta, pg_catalog.pg_attribute ia, pg_catalog.pg_class tc, pg_catalog.pg_index i, pg_catalog.pg_namespace n, pg_catalog.pg_class ic where tc.relname = 'business' and n.nspname = 'public' and tc.oid = i.indrelid and n.oid = tc.relnamespace and i.indisprimary = 't' and ia.attrelid = i.indexrelid and ta.attrelid = i.indrelid and ta.attnum = i.indkey[ia.attnum-1] and (not ta.attisdropped) and (not ia.attisdropped) and ic.oid = i.indexrelid order by ia.attnum", true); + } + + @Test + public void testIssue842() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT a.id lendId, " + + "a.lend_code lendCode, " + + "a.amount, " + + "a.remaining_principal remainingPrincipal, " + + "a.interest_rate interestRate, " + + "date_add(a.lend_time, INTERVAL a.repayment_period DAY) lendEndTime, " + + "a.lend_time lendTime " + + "FROM risk_lend a " + + "WHERE a.loan_id = 1", true); + } + + @Test + public void testIssue842_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT INTERVAL a.repayment_period DAY"); + } + + @Test + public void testIssue848() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT IF(USER_ID > 10 AND SEX = 1, 1, 0)"); + } + + @Test + public void testIssue848_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT IF(USER_ID > 10, 1, 0)"); + } + + @Test + public void testIssue848_3() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT c1, multiset(SELECT * FROM mytable WHERE cond = 10) FROM T1 WHERE cond2 = 20"); + } + + @Test + public void testIssue848_4() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("select c1 from T1 where someFunc(select f1 from t2 where t2.id = T1.key) = 10", true); + } + + @Test + public void testMultiColumnAliasIssue849() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable AS mytab2(col1, col2)"); + } + + @Test + public void testMultiColumnAliasIssue849_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM crosstab('select rowid, attribute, value from ct where attribute = ''att2'' or attribute = ''att3'' order by 1,2') AS ct(row_name text, category_1 text, category_2 text, category_3 text)"); + } + + @Test + public void testLimitClauseDroppedIssue845() throws JSQLParserException { + assertEquals( + "SELECT * FROM employee ORDER BY emp_id LIMIT 10 OFFSET 2", + CCJSqlParserUtil.parse("SELECT * FROM employee ORDER BY emp_id OFFSET 2 LIMIT 10").toString()); + } + + @Test + public void testLimitClauseDroppedIssue845_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM employee ORDER BY emp_id LIMIT 10 OFFSET 2"); + } + + @Test + public void testChangeKeywordIssue859() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT * FROM CHANGE.TEST"); + } + + @Test + public void testEndKeyword() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT end AS end_6 FROM mytable"); + } + + @Test + public void testStartKeyword() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT c0_.start AS start_5 FROM mytable"); + } + + @Test + public void testSizeKeywordIssue867() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT size FROM mytable"); + } + + @Test + public void testPartitionByWithBracketsIssue865() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT subject_id, student_id, sum(mark) OVER (PARTITION BY subject_id, student_id ) FROM marks"); + assertSqlCanBeParsedAndDeparsed("SELECT subject_id, student_id, sum(mark) OVER (PARTITION BY (subject_id, student_id) ) FROM marks"); + } + + @Test + public void testWithAsRecursiveIssue874() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("WITH rn AS (SELECT rownum rn FROM dual CONNECT BY level <= (SELECT max(cases) FROM t1)) SELECT pname FROM t1, rn WHERE rn <= cases ORDER BY pname"); + } + + @Test + public void testSessionKeywordIssue876() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT ID_COMPANY FROM SESSION.COMPANY"); + } + + @Test + public void testWindowClauseWithoutOrderByIssue869() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT subject_id, student_id, mark, sum(mark) OVER (PARTITION BY (subject_id) ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM marks"); + } + + @Test + public void testKeywordSizeIssue880() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT b.pattern_size_id, b.pattern_id, b.variation, b.measure_remark, b.pake_name, b.ident_size, CONCAT( GROUP_CONCAT(a.size) ) AS 'title', CONCAT( '[', GROUP_CONCAT( '{\"patternSizeDetailId\":', a.pattern_size_detail_id, ',\"patternSizeId\":', a.pattern_size_id, ',\"size\":\"', a.size, '\",\"sizeValue\":', a.size_value SEPARATOR '},' ), '}]' ) AS 'designPatternSizeDetailJson' FROM design_pattern_size_detail a LEFT JOIN design_pattern_size b ON a.pattern_size_id = b.pattern_size_id WHERE b.pattern_id = 792679713905573986 GROUP BY b.pake_name,b.pattern_size_id", true); + } + + @Test + public void testKeywordCharacterIssue884() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("SELECT Character, Duration FROM actor"); + } + + @Test + public void testCrossApplyIssue344() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("select s.*, c.*, calc2.summary\n" + + "from student s\n" + + "join class c on s.class_id = c.id\n" + + "cross apply (\n" + + " select s.first_name + ' ' + s.last_name + ' (' + s.sex + ')' as student_full_name\n" + + ") calc1\n" + + "cross apply (\n" + + " select case c.some_styling_type when 'A' then c.name + ' - ' + calc1.student_full_name\n" + + " when 'B' then calc1.student_full_name + ' - ' + c.name\n" + + " else calc1.student_full_name end as summary\n" + + ") calc2", true); + } + + @Test + public void testWrongParseTreeIssue89() throws JSQLParserException { + Select unionQuery = (Select) CCJSqlParserUtil.parse("SELECT * FROM table1 UNION SELECT * FROM table2 ORDER BY col"); + SetOperationList unionQueries = (SetOperationList) unionQuery.getSelectBody(); + + assertThat(unionQueries.getSelects()) + .extracting(select -> (PlainSelect) select).allSatisfy(ps -> assertNull(ps.getOrderByElements())); + + assertThat(unionQueries.getOrderByElements()) + .isNotNull() + .hasSize(1) + .extracting(item -> item.toString()) + .contains("col"); + } } diff --git a/src/test/java/net/sf/jsqlparser/statement/select/SpecialOracleTest.java b/src/test/java/net/sf/jsqlparser/statement/select/SpecialOracleTest.java new file mode 100644 index 00000000..e0db6530 --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/select/SpecialOracleTest.java @@ -0,0 +1,316 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.sf.jsqlparser.JSQLParserException; +import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import net.sf.jsqlparser.statement.Statement; +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import org.apache.commons.io.FileUtils; +import static org.junit.Assert.assertTrue; +import org.junit.ComparisonFailure; +import org.junit.Test; + +/** + * Tries to parse and deparse all statments in net.sf.jsqlparser.test.oracle-tests. + * + * As a matter of fact there are a lot of files that can still not processed. Here a step by step + * improvement is the way to go. + * + * The test ensures, that the successfull parsed file count does not decrease. + * + * @author toben + */ +public class SpecialOracleTest { + + private static final File SQLS_DIR = new File("target/test-classes/net/sf/jsqlparser/statement/oracle-tests"); + private static final Logger LOG = Logger.getLogger(SpecialOracleTest.class.getName()); + + private final List successes = Arrays.asList("aggregate01.sql", + "analytic_query06.sql", + "analytic_query08.sql", + "analytic_query09.sql", + "analytic_query10.sql", + "bindvar01.sql", + "bindvar02.sql", + "case_when01.sql", + "case_when02.sql", + "case_when03.sql", + "case_when04.sql", + "case_when05.sql", + "cast_multiset01.sql", + "cast_multiset02.sql", + "cast_multiset03.sql", + "cast_multiset04.sql", + "cast_multiset05.sql", + "cast_multiset06.sql", + "cast_multiset08.sql", + "cast_multiset10.sql", + "cast_multiset11.sql", + "cast_multiset12.sql", + "cast_multiset16.sql", + "cast_multiset17.sql", + "cast_multiset20.sql", + "cast_multiset21.sql", + "cast_multiset23.sql", + "cast_multiset25.sql", + "cast_multiset28.sql", + "cast_multiset29.sql", + "cast_multiset30.sql", + "cast_multiset31.sql", + "cast_multiset32.sql", + "cast_multiset33.sql", + "cast_multiset35.sql", + "cast_multiset36.sql", + "cast_multiset40.sql", + "cast_multiset41.sql", + "cast_multiset42.sql", + "cast_multiset43.sql", + "columns01.sql", + "condition01.sql", + "condition02.sql", + "condition03.sql", + "condition04.sql", + "condition05.sql", + "condition07.sql", + "condition09.sql", + "condition10.sql", + "condition12.sql", + "condition14.sql", + "condition20.sql", + "connect_by02.sql", + "connect_by03.sql", + "connect_by04.sql", + "connect_by05.sql", + "connect_by07.sql", + "datetime02.sql", + "datetime04.sql", + "datetime05.sql", + "datetime06.sql", + "dblink01.sql", + "for_update01.sql", + "for_update02.sql", + "for_update03.sql", + "for_update05.sql", + "function01.sql", + "function02.sql", + "groupby01.sql", + "groupby02.sql", + "groupby03.sql", + "groupby04.sql", + "groupby05.sql", + "groupby06.sql", + "groupby08.sql", + "groupby09.sql", + "groupby10.sql", + "groupby11.sql", + "groupby12.sql", + "groupby13.sql", + "groupby14.sql", + "groupby19.sql", + "groupby20.sql", + "groupby21.sql", + "groupby22.sql", + "groupby23.sql", + "interval02.sql", + "interval04.sql", + "join01.sql", + "join02.sql", + "join03.sql", + "join04.sql", + "join06.sql", + "join07.sql", + "join08.sql", + "join09.sql", + "join10.sql", + "join11.sql", + "join12.sql", + "join14.sql", + "join15.sql", + "join16.sql", + "join18.sql", + "join19.sql", + "join20.sql", + "join21.sql", + "keywordasidentifier01.sql", + "keywordasidentifier02.sql", + "keywordasidentifier03.sql", + "keywordasidentifier05.sql", + "lexer02.sql", + "lexer03.sql", + "lexer04.sql", + "lexer05.sql", + "like01.sql", + "order_by01.sql", + "order_by02.sql", + "order_by03.sql", + "order_by04.sql", + "order_by05.sql", + "order_by06.sql", + "pivot01.sql", + "pivot02.sql", + "pivot03.sql", + "pivot05.sql", + "pivot06.sql", + "pivot07.sql", + "pivot08.sql", + "pivot09.sql", + "pivot11.sql", + "query_factoring01.sql", + "query_factoring02.sql", + "query_factoring03.sql", + "query_factoring06.sql", + "query_factoring08.sql", + "query_factoring09.sql", + "query_factoring11.sql", + "query_factoring12.sql", + "set01.sql", + "set02.sql", + "simple02.sql", + "simple03.sql", + "simple06.sql", + "simple07.sql", + "simple08.sql", + "simple09.sql", + "simple10.sql", + "simple11.sql", + "simple12.sql", + "simple13.sql", + "union01.sql", + "union02.sql", + "union03.sql", + "union04.sql", + "union05.sql", + "union06.sql", + "union07.sql", + "union08.sql", + "union09.sql", + "union10.sql", + "xmltable02.sql"); + + @Test + public void testAllSqlsParseDeparse() throws IOException { + int count = 0; + int success = 0; + File[] sqlTestFiles = SQLS_DIR.listFiles(); + + for (File file : sqlTestFiles) { + if (file.isFile()) { + count++; + LOG.log(Level.INFO, "testing {0}", file.getName()); + String sql = FileUtils.readFileToString(file); + boolean parsed = false; + try { + assertSqlCanBeParsedAndDeparsed(sql, true); + success++; + parsed = true; + LOG.info(" -> SUCCESS"); + } catch (JSQLParserException ex) { + ex.printStackTrace(); + //LOG.log(Level.SEVERE, null, ex); + LOG.log(Level.INFO, " -> PROBLEM {0}", ex.toString()); + } catch (Exception ex) { + LOG.log(Level.INFO, " -> PROBLEM {0}", ex.toString()); + } catch (ComparisonFailure ex) { + LOG.log(Level.INFO, " -> PROBLEM {0}", ex.toString()); + } + + if (!parsed && successes.contains(file.getName())) { + LOG.log(Level.WARNING, " -> regression on file {0}", file.getName()); + } else if (parsed && !successes.contains(file.getName())) { + LOG.log(Level.WARNING, " -> not logged success on file {0}", file.getName()); + } + } + } + + LOG. + log(Level.INFO, "tested {0} files. got {1} correct parse results", new Object[]{count, success}); + assertTrue(success >= 162); + } + + @Test + public void testAllSqlsOnlyParse() throws IOException { + File[] sqlTestFiles = new File(SQLS_DIR, "only-parse-test").listFiles(); + + for (File file : sqlTestFiles) { + LOG.log(Level.INFO, "testing {0}", file.getName()); + String sql = FileUtils.readFileToString(file); + try { + CCJSqlParserUtil.parse(sql); + + LOG.info(" -> SUCCESS"); + } catch (JSQLParserException ex) { + LOG.log(Level.SEVERE, null, ex); + } + } + } + + @Test + public void testOperatorsWithSpaces() throws Exception { + String sql; + Statement statement; + + // First, the regular way (normal for most databases). + sql = "SELECT\n" + + " Something\n" + + "FROM\n" + + " Sometable\n" + + "WHERE\n" + + " Somefield >= Somevalue\n" + + " AND Somefield <= Somevalue\n" + + " AND Somefield <> Somevalue\n" + + " AND Somefield != Somevalue\n"; + + statement = CCJSqlParserUtil.parse(sql); + + System.out.println(statement.toString()); + + assertSqlCanBeParsedAndDeparsed(sql, true); + + // Second, the special crap Oracle lets you get away with. + sql = "SELECT\n" + + " Something\n" + + "FROM\n" + + " Sometable\n" + + "WHERE\n" + + " Somefield > = Somevalue\n" + + " AND Somefield < = Somevalue\n" + + " AND Somefield < > Somevalue\n"; + + // Note, we do not (currently) test the "!=" with spaces in between -- Postgresql deals with this as two operators, "factorial" and "equals". + statement = CCJSqlParserUtil.parse(sql); + + System.out.println(statement.toString()); + + assertSqlCanBeParsedAndDeparsed(sql, true); + + // And then with multiple whitespace + sql = "SELECT\n" + + " Something\n" + + "FROM\n" + + " Sometable\n" + + "WHERE\n" + + " Somefield > \t = Somevalue\n" + + " AND Somefield < = Somevalue\n" + + " AND Somefield <\t\t> Somevalue\n"; + + statement = CCJSqlParserUtil.parse(sql); + + System.out.println(statement.toString()); + + assertSqlCanBeParsedAndDeparsed(sql, true); + } +} diff --git a/src/test/java/net/sf/jsqlparser/test/select/SpeedTest.java b/src/test/java/net/sf/jsqlparser/statement/select/SpeedTest.java similarity index 95% rename from src/test/java/net/sf/jsqlparser/test/select/SpeedTest.java rename to src/test/java/net/sf/jsqlparser/statement/select/SpeedTest.java index 8c1f4b54..116a2ee7 100644 --- a/src/test/java/net/sf/jsqlparser/test/select/SpeedTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/select/SpeedTest.java @@ -1,4 +1,13 @@ -package net.sf.jsqlparser.test.select; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.select; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -11,9 +20,8 @@ import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserManager; import net.sf.jsqlparser.statement.Statement; -import net.sf.jsqlparser.statement.select.Select; import net.sf.jsqlparser.test.TestException; -import net.sf.jsqlparser.test.simpleparsing.CCJSqlParserManagerTest; +import net.sf.jsqlparser.statement.simpleparsing.CCJSqlParserManagerTest; import net.sf.jsqlparser.util.TablesNamesFinder; import org.junit.Test; diff --git a/src/test/java/net/sf/jsqlparser/test/simpleparsing/CCJSqlParserManagerTest.java b/src/test/java/net/sf/jsqlparser/statement/simpleparsing/CCJSqlParserManagerTest.java similarity index 88% rename from src/test/java/net/sf/jsqlparser/test/simpleparsing/CCJSqlParserManagerTest.java rename to src/test/java/net/sf/jsqlparser/statement/simpleparsing/CCJSqlParserManagerTest.java index 0f4d8faf..3222f01c 100644 --- a/src/test/java/net/sf/jsqlparser/test/simpleparsing/CCJSqlParserManagerTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/simpleparsing/CCJSqlParserManagerTest.java @@ -1,4 +1,13 @@ -package net.sf.jsqlparser.test.simpleparsing; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.simpleparsing; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -7,7 +16,7 @@ import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.parser.CCJSqlParserManager; import net.sf.jsqlparser.test.TestException; -import net.sf.jsqlparser.test.create.CreateTableTest; +import net.sf.jsqlparser.statement.create.CreateTableTest; import org.junit.Test; public class CCJSqlParserManagerTest { diff --git a/src/test/java/net/sf/jsqlparser/test/truncate/TruncateTest.java b/src/test/java/net/sf/jsqlparser/statement/truncate/TruncateTest.java similarity index 57% rename from src/test/java/net/sf/jsqlparser/test/truncate/TruncateTest.java rename to src/test/java/net/sf/jsqlparser/statement/truncate/TruncateTest.java index 916bdc83..e558f07f 100644 --- a/src/test/java/net/sf/jsqlparser/test/truncate/TruncateTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/truncate/TruncateTest.java @@ -1,9 +1,20 @@ -package net.sf.jsqlparser.test.truncate; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.truncate; import java.io.StringReader; +import static net.sf.jsqlparser.test.TestUtils.*; +import net.sf.jsqlparser.*; + import net.sf.jsqlparser.parser.CCJSqlParserManager; -import net.sf.jsqlparser.statement.truncate.Truncate; import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -24,5 +35,20 @@ public void testTruncate() throws Exception { truncate = (Truncate) parserManager.parse(new StringReader(statement)); assertEquals("mytab", truncate.getTable().getName()); assertEquals(toStringStatement.toUpperCase(), truncate.toString().toUpperCase()); + + statement = "TRUNCATE TABLE mytab CASCADE"; + truncate = (Truncate) parserManager.parse(new StringReader(statement)); + assertEquals(statement, truncate.toString()); + } + + @Test + public void testTruncateDeparse() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("TRUNCATE TABLE foo"); } + + @Test + public void testTruncateCascadeDeparse() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("TRUNCATE TABLE foo CASCADE"); + } + } diff --git a/src/test/java/net/sf/jsqlparser/test/update/UpdateTest.java b/src/test/java/net/sf/jsqlparser/statement/update/UpdateTest.java similarity index 75% rename from src/test/java/net/sf/jsqlparser/test/update/UpdateTest.java rename to src/test/java/net/sf/jsqlparser/statement/update/UpdateTest.java index 3bd63335..49ffd3ac 100644 --- a/src/test/java/net/sf/jsqlparser/test/update/UpdateTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/update/UpdateTest.java @@ -1,4 +1,13 @@ -package net.sf.jsqlparser.test.update; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.update; import java.io.StringReader; @@ -9,7 +18,6 @@ import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals; import net.sf.jsqlparser.parser.CCJSqlParserManager; import net.sf.jsqlparser.schema.Column; -import net.sf.jsqlparser.statement.update.Update; import static net.sf.jsqlparser.test.TestUtils.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -23,7 +31,7 @@ public class UpdateTest { public void testUpdate() throws JSQLParserException { String statement = "UPDATE mytable set col1='as', col2=?, col3=565 Where o >= 3"; Update update = (Update) parserManager.parse(new StringReader(statement)); - assertEquals("mytable", update.getTables().get(0).getName()); + assertEquals("mytable", update.getTable().toString()); assertEquals(3, update.getColumns().size()); assertEquals("col1", ((Column) update.getColumns().get(0)).getColumnName()); assertEquals("col2", ((Column) update.getColumns().get(1)).getColumnName()); @@ -111,4 +119,40 @@ public void testUpdateDoesNotAllowLimitOffset() throws JSQLParserException { public void testUpdateWithFunctions() throws JSQLParserException { assertSqlCanBeParsedAndDeparsed("UPDATE tablename SET col = SUBSTRING(col2, 1, 2)"); } + + @Test + public void testUpdateIssue508LeftShift() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("UPDATE user SET num = 1 << 1 WHERE id = 1"); + } + + @Test + public void testUpdateIssue338() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("UPDATE mytable SET status = (status & ~1)"); + } + + @Test + public void testUpdateIssue338_1() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("UPDATE mytable SET status = (status & 1)"); + } + + @Test + public void testUpdateIssue338_2() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("UPDATE mytable SET status = (status + 1)"); + } + + @Test + public void testUpdateIssue826() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("update message_topic inner join message_topic_config on\n" + + " message_topic.id=message_topic_config.topic_id \n" + + "set message_topic_config.enable_flag='N', \n" + + "message_topic_config.updated_by='test', \n" + + "message_topic_config.update_at='2019-07-16' \n" + + "where message_topic.name='test' \n" + + "AND message_topic_config.enable_flag='Y'", true); + } + + @Test + public void testUpdateIssue750() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("update a,(select * from c) b set a.id=b.id where a.id=b.id", true); + } } diff --git a/src/test/java/net/sf/jsqlparser/test/upsert/UpsertTest.java b/src/test/java/net/sf/jsqlparser/statement/upsert/UpsertTest.java similarity index 97% rename from src/test/java/net/sf/jsqlparser/test/upsert/UpsertTest.java rename to src/test/java/net/sf/jsqlparser/statement/upsert/UpsertTest.java index 8788f25d..55f2a024 100644 --- a/src/test/java/net/sf/jsqlparser/test/upsert/UpsertTest.java +++ b/src/test/java/net/sf/jsqlparser/statement/upsert/UpsertTest.java @@ -1,4 +1,13 @@ -package net.sf.jsqlparser.test.upsert; +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.upsert; import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; import static org.junit.Assert.*; @@ -15,7 +24,6 @@ import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.schema.Table; import net.sf.jsqlparser.statement.select.PlainSelect; -import net.sf.jsqlparser.statement.upsert.Upsert; public class UpsertTest { diff --git a/src/test/java/net/sf/jsqlparser/statement/values/ValuesTest.java b/src/test/java/net/sf/jsqlparser/statement/values/ValuesTest.java new file mode 100644 index 00000000..36d9262a --- /dev/null +++ b/src/test/java/net/sf/jsqlparser/statement/values/ValuesTest.java @@ -0,0 +1,27 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ +package net.sf.jsqlparser.statement.values; + +import net.sf.jsqlparser.JSQLParserException; +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; +import org.junit.Test; + +public class ValuesTest { + + @Test + public void testDuplicateKey() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("VALUES (1, 2, 'test')"); + } + + @Test + public void testComplexWithQueryIssue561() throws JSQLParserException { + assertSqlCanBeParsedAndDeparsed("WITH split (word, str, hascomma) AS (VALUES ('', 'Auto,A,1234444', 1) UNION ALL SELECT substr(str, 0, CASE WHEN instr(str, ',') THEN instr(str, ',') ELSE length(str) + 1 END), ltrim(substr(str, instr(str, ',')), ','), instr(str, ',') FROM split WHERE hascomma) SELECT trim(word) FROM split WHERE word != ''"); + } +} diff --git a/src/test/java/net/sf/jsqlparser/test/CommitTest.java b/src/test/java/net/sf/jsqlparser/test/CommitTest.java index 0188cdd6..79e2348e 100644 --- a/src/test/java/net/sf/jsqlparser/test/CommitTest.java +++ b/src/test/java/net/sf/jsqlparser/test/CommitTest.java @@ -1,3 +1,12 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.test; import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; diff --git a/src/test/java/net/sf/jsqlparser/test/TestException.java b/src/test/java/net/sf/jsqlparser/test/TestException.java index 282bbe6b..92eb2720 100644 --- a/src/test/java/net/sf/jsqlparser/test/TestException.java +++ b/src/test/java/net/sf/jsqlparser/test/TestException.java @@ -1,8 +1,14 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.test; -/** - * An exception class with stack trace informations - */ public class TestException extends Exception { private Throwable cause = null; diff --git a/src/test/java/net/sf/jsqlparser/test/TestUtils.java b/src/test/java/net/sf/jsqlparser/test/TestUtils.java index cf93755a..5b8d0fad 100644 --- a/src/test/java/net/sf/jsqlparser/test/TestUtils.java +++ b/src/test/java/net/sf/jsqlparser/test/TestUtils.java @@ -1,32 +1,20 @@ -/* - * Copyright (C) 2013 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.test; -import java.io.StringReader; +import java.util.function.Consumer; import java.util.regex.Pattern; - -import org.junit.Assert; -import org.junit.Test; - import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.OracleHint; +import net.sf.jsqlparser.parser.CCJSqlParser; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.statement.Statement; import net.sf.jsqlparser.statement.select.PlainSelect; @@ -35,8 +23,10 @@ import net.sf.jsqlparser.util.deparser.ExpressionDeParser; import net.sf.jsqlparser.util.deparser.SelectDeParser; import net.sf.jsqlparser.util.deparser.StatementDeParser; +import org.junit.Assert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import org.junit.Test; /** * @@ -55,12 +45,16 @@ public static void assertSqlCanBeParsedAndDeparsed(String statement) throws JSQL * Tries to parse and deparse the given statement. * * @param statement - * @param laxDeparsingCheck removes all linefeeds from the original and removes all double - * spaces. The check is caseinsensitive. + * @param laxDeparsingCheck removes all linefeeds from the original and + * removes all double spaces. The check is caseinsensitive. * @throws JSQLParserException */ public static void assertSqlCanBeParsedAndDeparsed(String statement, boolean laxDeparsingCheck) throws JSQLParserException { - Statement parsed = CCJSqlParserUtil.parse(new StringReader(statement)); + assertSqlCanBeParsedAndDeparsed(statement, laxDeparsingCheck, null); + } + + public static void assertSqlCanBeParsedAndDeparsed(String statement, boolean laxDeparsingCheck, Consumer consumer) throws JSQLParserException { + Statement parsed = CCJSqlParserUtil.parse(statement, consumer); assertStatementCanBeDeparsedAs(parsed, statement, laxDeparsingCheck); } diff --git a/src/test/java/net/sf/jsqlparser/test/create/AlterViewTest.java b/src/test/java/net/sf/jsqlparser/test/create/AlterViewTest.java deleted file mode 100644 index 99984b6d..00000000 --- a/src/test/java/net/sf/jsqlparser/test/create/AlterViewTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.sf.jsqlparser.test.create; - -import net.sf.jsqlparser.JSQLParserException; -import static net.sf.jsqlparser.test.TestUtils.*; -import org.junit.Test; - -public class AlterViewTest { - - @Test - public void testAlterView() throws JSQLParserException { - String stmt = "ALTER VIEW myview AS SELECT * FROM mytab"; - assertSqlCanBeParsedAndDeparsed(stmt); - } -} diff --git a/src/test/java/net/sf/jsqlparser/test/select/MemoryTest.java b/src/test/java/net/sf/jsqlparser/test/select/MemoryTest.java deleted file mode 100644 index b4cc9854..00000000 --- a/src/test/java/net/sf/jsqlparser/test/select/MemoryTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package net.sf.jsqlparser.test.select; - -import java.io.StringReader; - -import net.sf.jsqlparser.parser.CCJSqlParserManager; -import net.sf.jsqlparser.statement.Statement; - -public class MemoryTest { - - public static void main(String[] args) throws Exception { - System.gc(); - System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); - CCJSqlParserManager parserManager = new CCJSqlParserManager(); - - /* - * String longQuery = new String( - * "select * from ( SELECT intermediate.id as id , intermediate.date as " + - * "date FROM ( SELECT DISTINCT ( id ) FROM ( SELECT " + - * "wct_workflows.workflow_id as id , wct_transaction.date as date FROM " + - * "wct_audit_entry , wct_transaction , wct_workflows WHERE " + - * "( wct_audit_entry.privilege = 'W' or wct_audit_entry.privilege = " + - * "'C' ) and wct_audit_entry.outcome = 't' and " + - * "wct_audit_entry.transaction_id = wct_transaction.transaction_id and " + - * "wct_transaction.user_id = 164 and wct_audit_entry.object_id = " + - * "wct_workflows.active_version_id ))) UNION SELECT wct_workflows.workflow_id as " + - * "id , wct_transaction.date as date FROM wct_audit_entry , " + - * "wct_transaction , wct_workflows WHERE ( wct_audit_entry.privilege = " + - * "'W' or wct_audit_entry.privilege = 'C' ) and wct_audit_entry.outcome " + - * "= 't' and wct_audit_entry.transaction_id = " + - * "wct_transaction.transaction_id and wct_transaction.user_id = 164 and " + - * "afdf= ( select wct_audit_entry.object_id from wct_audit_entry , " + - * "wct_workflow_archive where wct_audit_entry.object_id = " + - * "wct_workflow_archive.archive_id and wct_workflows.workflow_id = " + - * "wct_workflow_archive.workflow_id ) " + - * "UNION SELECT wct_workflows.workflow_id " + - * "as id , wct_transaction.date as date FROM wct_audit_entry , " + - * "wct_transaction , wct_workflows WHERE ( wct_audit_entry.privilege = " + - * "'W' OR wct_audit_entry.privilege = 'E' OR wct_audit_entry.privilege = " + - * "'A' ) and wct_audit_entry.outcome = 't' and " + - * "wct_audit_entry.transaction_id = wct_transaction.transaction_id and " + - * "wct_transaction.user_id = 164 and wct_audit_entry.object_id = " + - * "wct_workflows.workflow_id UNION SELECT * FROM interm2 , wct_workflow_docs WHERE " + - * "interm2.id = wct_workflow_docs.document_id ORDER BY id , date DESC "); - */ - String longQuery = "select * from k where ID > 4"; - - /* - * String longQuery = "select * from ( SELECT intermediate.id as id , intermediate.date as " - * + "date FROM ( SELECT DISTINCT ( id ) FROM ( SELECT " + - * "wct_workflows.workflow_id as id , wct_transaction.date as date FROM " + - * "wct_audit_entry , wct_transaction , wct_workflows WHERE " + - * "( wct_audit_entry.privilege = 'W' or wct_audit_entry.privilege = " + "'C' ))))"; - */ - /* - * String longQuery = "select * from d WHERE " + - * "( wct_audit_entry.privilege = 'W' or wct_audit_entry.privilege = " + - * "'C' ) and wct_audit_entry.outcome = 't' and " + - * "wct_audit_entry.transaction_id = wct_transaction.transaction_id and " + - * "wct_transaction.user_id = 164 and wct_audit_entry.object_id = " + - * "wct_workflows.active_version_id "; - */ - StringReader stringReader = new StringReader(longQuery); - Statement statement = parserManager.parse(stringReader); - // stringReader = new StringReader(longQuery); - // Statement statement2 = parserManager.parse(stringReader); - // stringReader = null; - // statement2 = null; - statement = null; - parserManager = null; - longQuery = null; - System.gc(); - System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); - - } -} diff --git a/src/test/java/net/sf/jsqlparser/test/select/SpecialOracleTest.java b/src/test/java/net/sf/jsqlparser/test/select/SpecialOracleTest.java deleted file mode 100644 index 58e519ad..00000000 --- a/src/test/java/net/sf/jsqlparser/test/select/SpecialOracleTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (C) 2014 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package net.sf.jsqlparser.test.select; - -import java.io.File; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.sf.jsqlparser.JSQLParserException; -import net.sf.jsqlparser.parser.CCJSqlParserUtil; -import net.sf.jsqlparser.statement.Statement; -import net.sf.jsqlparser.parser.TokenMgrError; - -import static net.sf.jsqlparser.test.TestUtils.*; -import org.apache.commons.io.FileUtils; -import static org.junit.Assert.assertTrue; -import org.junit.ComparisonFailure; -import org.junit.Test; - -/** - * Tries to parse and deparse all statments in net.sf.jsqlparser.test.oracle-tests. - * - * As a matter of fact there are a lot of files that can still not processed. Here a step by step - * improvement is the way to go. - * - * The test ensures, that the successfull parsed file count does not decrease. - * - * @author toben - */ -public class SpecialOracleTest { - - private static final File SQLS_DIR = new File("target/test-classes/net/sf/jsqlparser/test/oracle-tests"); - private static final Logger LOG = Logger.getLogger(SpecialOracleTest.class.getName()); - - @Test - public void testAllSqlsParseDeparse() throws IOException { - int count = 0; - int success = 0; - File[] sqlTestFiles = SQLS_DIR.listFiles(); - - for (File file : sqlTestFiles) { - if (file.isFile()) { - count++; - LOG.log(Level.INFO, "testing {0}", file.getName()); - String sql = FileUtils.readFileToString(file); - try { - assertSqlCanBeParsedAndDeparsed(sql, true); - success++; - LOG.info(" -> SUCCESS"); - } catch (JSQLParserException ex) { - //LOG.log(Level.SEVERE, null, ex); - LOG.log(Level.INFO, " -> PROBLEM {0}", ex.toString()); - } catch (TokenMgrError ex) { - //LOG.log(Level.SEVERE, null, ex); - LOG.log(Level.INFO, " -> PROBLEM {0}", ex.toString()); - } catch (Exception ex) { - LOG.log(Level.INFO, " -> PROBLEM {0}", ex.toString()); - } catch (ComparisonFailure ex) { - LOG.log(Level.INFO, " -> PROBLEM {0}", ex.toString()); - } - } - } - - LOG. - log(Level.INFO, "tested {0} files. got {1} correct parse results", new Object[]{count, success}); - assertTrue(success >= 140); - } - - @Test - public void testAllSqlsOnlyParse() throws IOException { - File[] sqlTestFiles = new File(SQLS_DIR, "only-parse-test").listFiles(); - - for (File file : sqlTestFiles) { - LOG.log(Level.INFO, "testing {0}", file.getName()); - String sql = FileUtils.readFileToString(file); - try { - CCJSqlParserUtil.parse(sql); - - LOG.info(" -> SUCCESS"); - } catch (JSQLParserException ex) { - LOG.log(Level.SEVERE, null, ex); - } - } - } - - @Test - public void testOperatorsWithSpaces() throws Exception { - String sql; - Statement statement; - - // First, the regular way (normal for most databases). - sql = "SELECT\n" - + " Something\n" - + "FROM\n" - + " Sometable\n" - + "WHERE\n" - + " Somefield >= Somevalue\n" - + " AND Somefield <= Somevalue\n" - + " AND Somefield <> Somevalue\n" - + " AND Somefield != Somevalue\n"; - - statement = CCJSqlParserUtil.parse(sql); - - System.out.println(statement.toString()); - - assertSqlCanBeParsedAndDeparsed(sql, true); - - // Second, the special crap Oracle lets you get away with. - sql = "SELECT\n" - + " Something\n" - + "FROM\n" - + " Sometable\n" - + "WHERE\n" - + " Somefield > = Somevalue\n" - + " AND Somefield < = Somevalue\n" - + " AND Somefield < > Somevalue\n"; - - // Note, we do not (currently) test the "!=" with spaces in between -- Postgresql deals with this as two operators, "factorial" and "equals". - statement = CCJSqlParserUtil.parse(sql); - - System.out.println(statement.toString()); - - assertSqlCanBeParsedAndDeparsed(sql, true); - - // And then with multiple whitespace - sql = "SELECT\n" - + " Something\n" - + "FROM\n" - + " Sometable\n" - + "WHERE\n" - + " Somefield > \t = Somevalue\n" - + " AND Somefield < = Somevalue\n" - + " AND Somefield <\t\t> Somevalue\n"; - - statement = CCJSqlParserUtil.parse(sql); - - System.out.println(statement.toString()); - - assertSqlCanBeParsedAndDeparsed(sql, true); - } -} diff --git a/src/test/java/net/sf/jsqlparser/util/AddAliasesVisitorTest.java b/src/test/java/net/sf/jsqlparser/util/AddAliasesVisitorTest.java index ccf141ef..f685b452 100644 --- a/src/test/java/net/sf/jsqlparser/util/AddAliasesVisitorTest.java +++ b/src/test/java/net/sf/jsqlparser/util/AddAliasesVisitorTest.java @@ -1,3 +1,12 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.util; import java.io.StringReader; @@ -11,10 +20,6 @@ import org.junit.Test; import static org.junit.Assert.*; -/** - * - * @author tw - */ public class AddAliasesVisitorTest { public AddAliasesVisitorTest() { diff --git a/src/test/java/net/sf/jsqlparser/util/ConnectExpressionsVisitorTest.java b/src/test/java/net/sf/jsqlparser/util/ConnectExpressionsVisitorTest.java index 2f47a619..608a4ffe 100644 --- a/src/test/java/net/sf/jsqlparser/util/ConnectExpressionsVisitorTest.java +++ b/src/test/java/net/sf/jsqlparser/util/ConnectExpressionsVisitorTest.java @@ -1,3 +1,12 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.util; import java.io.StringReader; @@ -9,15 +18,11 @@ import net.sf.jsqlparser.statement.select.Select; import org.junit.After; import org.junit.AfterClass; +import static org.junit.Assert.*; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.*; -/** - * - * @author tw - */ public class ConnectExpressionsVisitorTest { public ConnectExpressionsVisitorTest() { diff --git a/src/test/java/net/sf/jsqlparser/util/SelectUtilsTest.java b/src/test/java/net/sf/jsqlparser/util/SelectUtilsTest.java index 1d117644..332fa945 100644 --- a/src/test/java/net/sf/jsqlparser/util/SelectUtilsTest.java +++ b/src/test/java/net/sf/jsqlparser/util/SelectUtilsTest.java @@ -1,3 +1,12 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.util; import java.util.Arrays; @@ -22,10 +31,6 @@ import org.junit.Test; import static org.junit.Assert.*; -/** - * - * @author toben - */ public class SelectUtilsTest { public SelectUtilsTest() { diff --git a/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java b/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java index 8219860e..7cc6e1b2 100644 --- a/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java +++ b/src/test/java/net/sf/jsqlparser/util/TablesNamesFinderTest.java @@ -1,29 +1,39 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.util; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.StringReader; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.StringTokenizer; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.OracleHint; - import net.sf.jsqlparser.parser.CCJSqlParserManager; import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import net.sf.jsqlparser.schema.Column; +import net.sf.jsqlparser.schema.Table; +import net.sf.jsqlparser.statement.DescribeStatement; import net.sf.jsqlparser.statement.Statement; +import net.sf.jsqlparser.statement.comment.Comment; import net.sf.jsqlparser.statement.create.table.CreateTable; import net.sf.jsqlparser.statement.delete.Delete; import net.sf.jsqlparser.statement.insert.Insert; import net.sf.jsqlparser.statement.merge.Merge; import net.sf.jsqlparser.statement.replace.Replace; import net.sf.jsqlparser.statement.select.Select; +import net.sf.jsqlparser.statement.simpleparsing.CCJSqlParserManagerTest; import net.sf.jsqlparser.statement.update.Update; import net.sf.jsqlparser.statement.upsert.Upsert; import net.sf.jsqlparser.test.TestException; -import net.sf.jsqlparser.test.simpleparsing.CCJSqlParserManagerTest; import static org.junit.Assert.*; import org.junit.Test; @@ -47,8 +57,8 @@ public void testComplexMergeExamples() throws Exception { } private void runTestOnResource(String resPath) throws Exception { - BufferedReader in = new BufferedReader(new InputStreamReader(TablesNamesFinderTest.class. - getResourceAsStream(resPath))); + BufferedReader in = new BufferedReader( + new InputStreamReader(TablesNamesFinderTest.class.getResourceAsStream(resPath))); TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); try { @@ -88,20 +98,14 @@ private void runTestOnResource(String resPath) throws Exception { String type = getLine(in); try { Statement statement = pm.parse(new StringReader(query)); - StringTokenizer tokenizer = new StringTokenizer(tables, " "); - List tablesList = new ArrayList(); - while (tokenizer.hasMoreTokens()) { - tablesList.add(tokenizer.nextToken()); - } - String[] tablesArray = (String[]) tablesList.toArray(new String[tablesList. - size()]); + String[] tablesArray = tables.split("\\s+"); List tableListRetr = tablesNamesFinder.getTableList(statement); assertEquals("stm num:" + numSt, tablesArray.length, tableListRetr.size()); for (int i = 0; i < tablesArray.length; i++) { - assertEquals("stm num:" + numSt, tablesArray[i], tableListRetr.get(i)); + assertTrue("stm num:" + numSt, tableListRetr.contains(tablesArray[i])); } } catch (Exception e) { throw new TestException("error at stm num: " + numSt + " in file " + resPath, e); @@ -122,8 +126,10 @@ public void testGetTableList() throws Exception { + " WHERE ID = (SELECT MAX(ID) FROM MY_TABLE5) AND ID2 IN (SELECT * FROM MY_TABLE6)"; net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReader(sql)); - // now you should use a class that implements StatementVisitor to decide what to do - // based on the kind of the statement, that is SELECT or INSERT etc. but here we are only + // now you should use a class that implements StatementVisitor to decide what to + // do + // based on the kind of the statement, that is SELECT or INSERT etc. but here we + // are only // interested in SELECTS if (statement instanceof Select) { Select selectStatement = (Select) statement; @@ -201,6 +207,27 @@ public void testGetTableListFromDelete2() throws Exception { assertTrue(tableList.contains("MY_TABLE1")); } + @Test + public void testGetTableListFromTruncate() throws Exception { + String sql = "TRUNCATE TABLE MY_TABLE1"; + List tables = new TablesNamesFinder().getTableList(pm.parse(new StringReader(sql))); + assertEquals(1, tables.size()); + assertTrue(tables.contains("MY_TABLE1")); + } + + @Test + public void testGetTableListFromDeleteWithJoin() throws Exception { + String sql = "DELETE t1, t2 FROM MY_TABLE1 t1 JOIN MY_TABLE2 t2 ON t1.id = t2.id"; + net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReader(sql)); + + Delete deleteStatement = (Delete) statement; + TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); + List tableList = tablesNamesFinder.getTableList(deleteStatement); + assertEquals(2, tableList.size()); + assertTrue(tableList.contains("MY_TABLE1")); + assertTrue(tableList.contains("MY_TABLE2")); + } + @Test public void testGetTableListFromInsert() throws Exception { String sql = "INSERT INTO MY_TABLE1 (a) VALUES ((SELECT a from MY_TABLE2 WHERE a = 1))"; @@ -386,8 +413,8 @@ public void testGetTableListIssue284() throws Exception { @Test public void testUpdateGetTableListIssue295() throws JSQLParserException { - Update statement = (Update) CCJSqlParserUtil. - parse("UPDATE component SET col = 0 WHERE (component_id,ver_num) IN (SELECT component_id,ver_num FROM component_temp)"); + Update statement = (Update) CCJSqlParserUtil.parse( + "UPDATE component SET col = 0 WHERE (component_id,ver_num) IN (SELECT component_id,ver_num FROM component_temp)"); TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); List tableList = tablesNamesFinder.getTableList(statement); assertEquals(2, tableList.size()); @@ -415,7 +442,7 @@ public void testGetTableListForMergeUsingQuery() throws Exception { assertEquals("employees", (String) tableList.get(0)); assertEquals("hr_records", (String) tableList.get(1)); } - + @Test public void testUpsertValues() throws Exception { String sql = "UPSERT INTO MY_TABLE1 (a) VALUES (5)"; @@ -427,7 +454,7 @@ public void testUpsertValues() throws Exception { assertEquals(1, tableList.size()); assertTrue(tableList.contains("MY_TABLE1")); } - + @Test public void testUpsertSelect() throws Exception { String sql = "UPSERT INTO mytable (mycolumn) SELECT mycolumn FROM mytable2"; @@ -440,5 +467,131 @@ public void testUpsertSelect() throws Exception { assertTrue(tableList.contains("mytable")); assertTrue(tableList.contains("mytable2")); } - + + @Test + public void testCaseWhenSubSelect() throws JSQLParserException { + String sql = "select case (select count(*) from mytable2) when 1 then 0 else -1 end"; + Statement stmt = CCJSqlParserUtil.parse(sql); + TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); + List tableList = tablesNamesFinder.getTableList(stmt); + assertEquals(1, tableList.size()); + assertTrue(tableList.contains("mytable2")); + } + + @Test + public void testCaseWhenSubSelect2() throws JSQLParserException { + String sql = "select case when (select count(*) from mytable2) = 1 then 0 else -1 end"; + Statement stmt = CCJSqlParserUtil.parse(sql); + TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); + List tableList = tablesNamesFinder.getTableList(stmt); + assertEquals(1, tableList.size()); + assertTrue(tableList.contains("mytable2")); + } + + @Test + public void testCaseWhenSubSelect3() throws JSQLParserException { + String sql = "select case when 1 = 2 then 0 else (select count(*) from mytable2) end"; + Statement stmt = CCJSqlParserUtil.parse(sql); + TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); + List tableList = tablesNamesFinder.getTableList(stmt); + assertEquals(1, tableList.size()); + assertTrue(tableList.contains("mytable2")); + } + + @Test + public void testExpressionIssue515() throws JSQLParserException { + TablesNamesFinder finder = new TablesNamesFinder(); + List tableList = finder.getTableList(CCJSqlParserUtil.parseCondExpression("SOME_TABLE.COLUMN = 'A'")); + assertEquals(1, tableList.size()); + assertTrue(tableList.contains("SOME_TABLE")); + } + + @Test + public void testSelectHavingSubquery() throws Exception { + String sql = "SELECT * FROM TABLE1 GROUP BY COL1 HAVING SUM(COL2) > (SELECT COUNT(*) FROM TABLE2)"; + net.sf.jsqlparser.statement.Statement statement = pm.parse(new StringReader(sql)); + + Select selectStmt = (Select) statement; + TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); + List tableList = tablesNamesFinder.getTableList(selectStmt); + assertEquals(2, tableList.size()); + assertTrue(tableList.contains("TABLE1")); + assertTrue(tableList.contains("TABLE2")); + } + + @Test + public void testMySQLValueListExpression() throws JSQLParserException { + String sql = "SELECT * FROM TABLE1 WHERE (a, b) = (c, d)"; + TablesNamesFinder finder = new TablesNamesFinder(); + List tableList = finder.getTableList(CCJSqlParserUtil.parse(sql)); + assertEquals(1, tableList.size()); + assertTrue(tableList.contains("TABLE1")); + } + + @Test + public void testSkippedSchemaIssue600() throws JSQLParserException { + String sql = "delete from schema.table where id = 1"; + TablesNamesFinder finder = new TablesNamesFinder(); + List tableList = finder.getTableList(CCJSqlParserUtil.parse(sql)); + assertEquals(1, tableList.size()); + assertTrue(tableList.contains("schema.table")); + } + + @Test + public void testCommentTable() throws JSQLParserException { + String sql = "comment on table schema.table is 'comment1'"; + TablesNamesFinder finder = new TablesNamesFinder(); + List tableList = finder.getTableList(CCJSqlParserUtil.parse(sql)); + assertEquals(1, tableList.size()); + assertTrue(tableList.contains("schema.table")); + } + + @Test + public void testCommentColumn() throws JSQLParserException { + String sql = "comment on column schema.table.column1 is 'comment1'"; + TablesNamesFinder finder = new TablesNamesFinder(); + List tableList = finder.getTableList(CCJSqlParserUtil.parse(sql)); + assertEquals(1, tableList.size()); + assertTrue(tableList.contains("schema.table")); + } + + @Test + public void testCommentColumn2() throws JSQLParserException { + Comment comment = new Comment(); + comment.setColumn(new Column()); + TablesNamesFinder finder = new TablesNamesFinder(); + List tableList = finder.getTableList(comment); + assertEquals(0, tableList.size()); + } + + @Test + public void testDescribe() throws JSQLParserException { + DescribeStatement describe = new DescribeStatement(new Table("foo", "product")); + TablesNamesFinder finder = new TablesNamesFinder(); + List tableList = finder.getTableList(describe); + assertEquals(1, tableList.size()); + assertEquals("foo.product", tableList.get(0)); + } + + @Test + public void testBetween() throws JSQLParserException { + String sql = "mycol BETWEEN (select col2 from mytable) AND (select col3 from mytable2)"; + Expression expr = (Expression) CCJSqlParserUtil.parseCondExpression(sql); + TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); + List tableList = tablesNamesFinder.getTableList(expr); + assertEquals(2, tableList.size()); + assertTrue(tableList.contains("mytable")); + assertTrue(tableList.contains("mytable2")); + + } + + @Test + public void testRemoteLink() throws JSQLParserException { + String sql = "select * from table1@remote"; + Statement stmt = CCJSqlParserUtil.parse(sql); + TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); + List tableList = tablesNamesFinder.getTableList(stmt); + assertEquals(1, tableList.size()); + assertTrue(tableList.contains("table1@remote")); + } } diff --git a/src/test/java/net/sf/jsqlparser/util/cnfexpression/CNFTest.java b/src/test/java/net/sf/jsqlparser/util/cnfexpression/CNFTest.java index 3f8563a2..33894d1b 100644 --- a/src/test/java/net/sf/jsqlparser/util/cnfexpression/CNFTest.java +++ b/src/test/java/net/sf/jsqlparser/util/cnfexpression/CNFTest.java @@ -1,359 +1,255 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.util.cnfexpression; -import static org.junit.Assert.*; - -import org.junit.Test; - import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.parser.CCJSqlParserUtil; +import static org.junit.Assert.*; +import org.junit.Test; -/** - * this class is mainly used for testing whether we generate the - * correct CNF form of an expression tree. We use the name of - * variables that is reflected in the steps defined in the class. - * @author messfish - * - */ public class CNFTest { - + /** - * The purpose of this method is to check when there is a Not Operator - * at the root. Which means the root must be switched. - * + * The purpose of this method is to check when there is a Not Operator at the root. Which means + * the root must be switched. + * * Here is the expression tree: - * - * NOT - * | - * ( ) - * | - * AND - * / \ - * ( ) ( ) - * | | - * OR OR - * / \ / \ - * < = != >= - * / \ / \ / \ / \ - * 1.2 2.3 3.5 4.6 1.1 2.5 8.0 7.2 - * + * + * NOT | ( ) | AND / \ ( ) ( ) | | OR OR / \ / \ + * < = != >= / \ / \ / \ / \ 1.2 2.3 3.5 4.6 1.1 2.5 8.0 7.2 + * * Here is the converted expression tree: - * - * AND - * / \ - * AND ( ) - * / \ | - * AND ( ) OR - * / \ | / \ - * ( ) ( ) OR NOT NOT - * | | / \ | | - * OR OR NOT NOT = >= - * / \ / \ | | / \ / \ - * NOT NOT NOT NOT = != 3.5 4.6 8.0 7.2 - * | | | | / \ / \ - * < != < >= - * / \ / \ / \ / \ - * 1.2 2.3 1.1 2.5 1.2 2.3 8.0 7.2 - * + * + * AND / \ AND ( ) / \ | AND ( ) OR / \ | / \ ( ) ( ) OR NOT NOT | | / \ | | OR OR NOT NOT = >= + * / \ / \ | | / \ / \ NOT NOT NOT NOT = != 3.5 4.6 8.0 7.2 | | | | / \ / \ < != < >= / \ / \ / + * \ / \ 1.2 2.3 1.1 2.5 1.2 2.3 8.0 7.2 + * */ @Test public void test1() throws Exception { Expression expr = CCJSqlParserUtil.parseCondExpression( - "NOT ((1.2 < 2.3 OR 3.5 = 4.6) AND (1.1 <> 2.5 OR 8.0 >= 7.2))"); + "NOT ((1.2 < 2.3 OR 3.5 = 4.6) AND (1.1 <> 2.5 OR 8.0 >= 7.2))"); Expression expected = CCJSqlParserUtil.parseCondExpression( "(NOT 1.2 < 2.3 OR NOT 1.1 <> 2.5) AND (NOT 1.2 < 2.3 OR NOT 8.0 >= 7.2) AND" + " (NOT 3.5 = 4.6 OR NOT 1.1 <> 2.5) AND (NOT 3.5 = 4.6 OR NOT 8.0 >= 7.2)"); Expression result = CNFConverter.convertToCNF(expr); assertEquals(expected.toString(), result.toString()); } - + /** - * The purpose is to test the double negation law. As you can - * see when you build the tree, there will be two Not Operators - * together on the line. It is there when we use the double negation law. - * - * Here is the expression tree: - * ( ) - * | - * OR - * / \ - * ( ) ( ) - * | | - * NOT AND - * | / \ - * ( ) LIKE = - * | / \ / \ - * OR S.A "%%%" S.B "orz" - * / \ - * NOT < + * The purpose is to test the double negation law. As you can see when you build the tree, there + * will be two Not Operators together on the line. It is there when we use the double negation + * law. + * + * Here is the expression tree: ( ) | OR / \ ( ) ( ) | | NOT AND | / \ ( ) LIKE = | / \ / \ OR + * S.A "%%%" S.B "orz" / \ NOT < * | / \ - * >= 3.3 4.5 - * / \ - * 1.1 2.3 - * + * >= 3.3 4.5 / \ 1.1 2.3 + * * Here is the converted expression tree: - * - * AND - * / \ - * AND ( ) - * / \ | - * AND ( ) OR - * / \ | / \ - * ( ) ( ) OR NOT = - * | | / \ | / \ - * OR OR NOT LIKE < S.B "orz" - * / \ / \ | / \ / \ - * >= LIKE >= = < S.A "%%%" 3.3 4.5 - * / \ / \ / \ / \ - * 1.1 2.3 S.A "%%%" 1.1 2.3 S.B "orz" - * + * + * AND / \ AND ( ) / \ | AND ( ) OR / \ | / \ ( ) ( ) OR NOT = | | / \ | / \ OR OR NOT LIKE < S.B "orz" + * / \ / \ | / \ / \ + * >= LIKE >= = < S.A "%%%" 3.3 4.5 / \ / \ / \ / \ 1.1 2.3 S.A "%%%" 1.1 2.3 S.B "orz" + * */ @Test public void test2() throws Exception { - Expression expr = CCJSqlParserUtil.parseCondExpression( + Expression expr = CCJSqlParserUtil.parseCondExpression( "((NOT (NOT 1.1 >= 2.3 OR 3.3 < 4.5)) OR " + "(S.A LIKE '\"%%%\"' AND S.B = '\"orz\"'))"); - Expression expected = CCJSqlParserUtil.parseCondExpression( + Expression expected = CCJSqlParserUtil.parseCondExpression( "(1.1 >= 2.3 OR S.A LIKE '\"%%%\"') AND (1.1 >= 2.3 OR S.B = '\"orz\"')" + " AND (NOT 3.3 < 4.5 OR S.A LIKE '\"%%%\"') AND (NOT 3.3 < 4.5 OR S.B = '\"orz\"')"); Expression result = CNFConverter.convertToCNF(expr); assertEquals(expected.toString(), result.toString()); } - + /** - * This is the case when we test a more complex tree structure, - * Notice you could see the amount of line to build up the CNF tree. - * You could tell how complicated the CNF could be. - * - * OR - * / \ - * ( ) ( ) - * | | - * AND OR - * / \ / \ - * >= <= ( ) NOT - * / \ / \ | | - * 7.0 8.0 9.0 10.0 AND OR - * / \ / \ - * ( ) = != ( ) - * | / \ / \ | - * AND 11.0 12.0 13.0 14.0 AND - * / \ / \ - * < > = ( ) - * / \ / \ / \ | - * 7.0 8.0 9.0 10.0 15.0 16.0 OR - * / \ - * = > - * / \ / \ - * 17.0 18.0 19.0 20.0 - * + * This is the case when we test a more complex tree structure, Notice you could see the amount + * of line to build up the CNF tree. You could tell how complicated the CNF could be. + * + * OR / \ ( ) ( ) | | AND OR / \ / \ >= <= ( ) NOT / \ / \ | | 7.0 8.0 9.0 10.0 AND OR / \ / \ ( + * ) = != ( ) | / \ / \ | AND 11.0 12.0 13.0 14.0 AND / \ / \ < > = ( ) + * / \ / \ / \ | + * 7.0 8.0 9.0 10.0 15.0 16.0 OR / \ = > / \ / \ 17.0 18.0 19.0 20.0 + * * Here is the converted expression tree: - * - * AND - * / \ - * AND ( ) - * / \ | - * AND ( ) part18 - * / \ | - * AND ( ) part17 - * / \ | - * AND ( ) part16 - * / \ | - * AND ( ) part15 - * / \ | - * AND ( ) part14 - * / \ | - * AND ( ) part13 - * / \ | - * AND ( ) part12 - * / \ | - * AND ( ) part11 - * / \ | - * AND ( ) part10 - * / \ | - * AND ( ) part9 - * / \ | - * AND ( ) part8 - * / \ | - * AND ( ) part7 - * / \ | - * AND ( ) part6 - * / \ | - * AND ( ) part5 - * / \ | - * AND ( ) part4 - * / \ | - * ( ) ( ) part3 - * | | - * part1 part2 - * - * part1: OR - * / \ - * OR NOT - * / \ | - * >= < != + * + * AND / \ AND ( ) / \ | AND ( ) part18 / \ | AND ( ) part17 / \ | AND ( ) part16 / \ | AND ( ) + * part15 / \ | AND ( ) part14 / \ | AND ( ) part13 / \ | AND ( ) part12 / \ | AND ( ) part11 / + * \ | AND ( ) part10 / \ | AND ( ) part9 / \ | AND ( ) part8 / \ | AND ( ) part7 / \ | AND ( ) + * part6 / \ | AND ( ) part5 / \ | AND ( ) part4 / \ | ( ) ( ) part3 | | part1 part2 + * + * part1: OR / \ OR NOT / \ | >= < != * / \ / \ / \ * 3.0 4.0 7.0 8.0 13.0 14.0 - * + * * part2: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 17.0 18.0 + * >= < = 17.0 18.0 * / \ / \ / \ * 3.0 4.0 7.0 8.0 15.0 16.0 - * + * * part3: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 19.0 20.0 + * >= < = 19.0 20.0 * / \ / \ / \ - * 3.0 4.0 7.0 8.0 15.0 16.0 - * + * 3.0 4.0 7.0 8.0 15.0 16.0 + * * part4: OR * / \ * OR NOT * / \ | - * >= < != + * >= < != * / \ / \ / \ * 3.0 4.0 9.0 10.0 13.0 14.0 - * + * * part5: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 17.0 18.0 + * >= < = 17.0 18.0 * / \ / \ / \ - * 3.0 4.0 9.0 10.0 15.0 16.0 - * + * 3.0 4.0 9.0 10.0 15.0 16.0 + * * part6: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 19.0 20.0 + * >= < = 19.0 20.0 * / \ / \ / \ - * 3.0 4.0 9.0 10.0 15.0 16.0 - * + * 3.0 4.0 9.0 10.0 15.0 16.0 + * * part7: OR * / \ * OR NOT * / \ | - * >= < != + * >= < != * / \ / \ / \ - * 3.0 4.0 11.0 12.0 13.0 14.0 - * + * 3.0 4.0 11.0 12.0 13.0 14.0 + * * part8: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 17.0 18.0 + * >= < = 17.0 18.0 * / \ / \ / \ - * 3.0 4.0 11.0 12.0 15.0 16.0 - * + * 3.0 4.0 11.0 12.0 15.0 16.0 + * * part9: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 19.0 20.0 + * >= < = 19.0 20.0 * / \ / \ / \ - * 3.0 4.0 11.0 12.0 15.0 16.0 - * + * 3.0 4.0 11.0 12.0 15.0 16.0 + * * part10: OR * / \ * OR NOT * / \ | - * >= < != + * >= < != * / \ / \ / \ - * 5.0 6.0 7.0 8.0 13.0 14.0 - * + * 5.0 6.0 7.0 8.0 13.0 14.0 + * * part11: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 17.0 18.0 + * >= < = 17.0 18.0 * / \ / \ / \ - * 5.0 6.0 7.0 8.0 15.0 16.0 - * + * 5.0 6.0 7.0 8.0 15.0 16.0 + * * part12: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 19.0 20.0 + * >= < = 19.0 20.0 * / \ / \ / \ - * 5.0 6.0 7.0 8.0 15.0 16.0 - * + * 5.0 6.0 7.0 8.0 15.0 16.0 + * * part13: OR * / \ * OR NOT * / \ | - * >= < != + * >= < != * / \ / \ / \ * 5.0 6.0 9.0 10.0 13.0 14.0 - * + * * part14: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 17.0 18.0 + * >= < = 17.0 18.0 * / \ / \ / \ - * 5.0 6.0 9.0 10.0 15.0 16.0 - * + * 5.0 6.0 9.0 10.0 15.0 16.0 + * * part15: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 19.0 20.0 + * >= < = 19.0 20.0 * / \ / \ / \ - * 5.0 6.0 9.0 10.0 15.0 16.0 - * + * 5.0 6.0 9.0 10.0 15.0 16.0 + * * part16: OR * / \ * OR NOT * / \ | - * >= < != + * >= < != * / \ / \ / \ - * 5.0 6.0 11.0 12.0 13.0 14.0 - * + * 5.0 6.0 11.0 12.0 13.0 14.0 + * * part17: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 17.0 18.0 + * >= < = 17.0 18.0 * / \ / \ / \ - * 5.0 6.0 11.0 12.0 15.0 16.0 - * + * 5.0 6.0 11.0 12.0 15.0 16.0 + * * part18: OR * / \ * OR NOT * / \ | * OR NOT = * / \ | / \ - * >= < = 19.0 20.0 - * / \ / \ / \ - * 5.0 6.0 11.0 12.0 15.0 16.0 - * + * >= < = 19.0 20.0 / \ / \ / \ 5.0 6.0 11.0 12.0 15.0 16.0 + * */ @Test public void test3() throws Exception { @@ -363,47 +259,39 @@ public void test3() throws Exception { + "NOT (13.0 <> 14.0 OR (15.0 = 16.0 AND (17.0 = 18.0 OR 19.0 > 20.0))))"); Expression expected = CCJSqlParserUtil.parseCondExpression( "(3.0 >= 4.0 OR 7.0 < 8.0 OR NOT 13.0 <> 14.0) AND " - + "(3.0 >= 4.0 OR 7.0 < 8.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " - + "(3.0 >= 4.0 OR 7.0 < 8.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " - + "(3.0 >= 4.0 OR 9.0 > 10.0 OR NOT 13.0 <> 14.0) AND " - + "(3.0 >= 4.0 OR 9.0 > 10.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " - + "(3.0 >= 4.0 OR 9.0 > 10.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " - + "(3.0 >= 4.0 OR 11.0 = 12.0 OR NOT 13.0 <> 14.0) AND " - + "(3.0 >= 4.0 OR 11.0 = 12.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " - + "(3.0 >= 4.0 OR 11.0 = 12.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " - + "(5.0 <= 6.0 OR 7.0 < 8.0 OR NOT 13.0 <> 14.0) AND " - + "(5.0 <= 6.0 OR 7.0 < 8.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " - + "(5.0 <= 6.0 OR 7.0 < 8.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " - + "(5.0 <= 6.0 OR 9.0 > 10.0 OR NOT 13.0 <> 14.0) AND " - + "(5.0 <= 6.0 OR 9.0 > 10.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " - + "(5.0 <= 6.0 OR 9.0 > 10.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " - + "(5.0 <= 6.0 OR 11.0 = 12.0 OR NOT 13.0 <> 14.0) AND " - + "(5.0 <= 6.0 OR 11.0 = 12.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " - + "(5.0 <= 6.0 OR 11.0 = 12.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0)"); + + "(3.0 >= 4.0 OR 7.0 < 8.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " + + "(3.0 >= 4.0 OR 7.0 < 8.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " + + "(3.0 >= 4.0 OR 9.0 > 10.0 OR NOT 13.0 <> 14.0) AND " + + "(3.0 >= 4.0 OR 9.0 > 10.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " + + "(3.0 >= 4.0 OR 9.0 > 10.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " + + "(3.0 >= 4.0 OR 11.0 = 12.0 OR NOT 13.0 <> 14.0) AND " + + "(3.0 >= 4.0 OR 11.0 = 12.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " + + "(3.0 >= 4.0 OR 11.0 = 12.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " + + "(5.0 <= 6.0 OR 7.0 < 8.0 OR NOT 13.0 <> 14.0) AND " + + "(5.0 <= 6.0 OR 7.0 < 8.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " + + "(5.0 <= 6.0 OR 7.0 < 8.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " + + "(5.0 <= 6.0 OR 9.0 > 10.0 OR NOT 13.0 <> 14.0) AND " + + "(5.0 <= 6.0 OR 9.0 > 10.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " + + "(5.0 <= 6.0 OR 9.0 > 10.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0) AND " + + "(5.0 <= 6.0 OR 11.0 = 12.0 OR NOT 13.0 <> 14.0) AND " + + "(5.0 <= 6.0 OR 11.0 = 12.0 OR NOT 15.0 = 16.0 OR NOT 17.0 = 18.0) AND " + + "(5.0 <= 6.0 OR 11.0 = 12.0 OR NOT 15.0 = 16.0 OR NOT 19.0 > 20.0)"); Expression result = CNFConverter.convertToCNF(expr); assertEquals(expected.toString(), result.toString()); } - + /** - * This is the case when we test a very simple tree structure that - * has neither AND operator or OR operator. - * + * This is the case when we test a very simple tree structure that has neither AND operator or + * OR operator. + * * Here is the expression tree: - * - * NOT - * | - * > - * / \ - * S.D {d '2017-03-25'} - * + * + * NOT | > / \ S.D {d '2017-03-25'} + * * Here is the converted expression tree: - * - * NOT - * | - * > - * / \ - * S.D {d '2017-03-25'} - * + * + * NOT | > / \ S.D {d '2017-03-25'} + * */ @Test public void test4() throws Exception { @@ -412,40 +300,26 @@ public void test4() throws Exception { Expression result = CNFConverter.convertToCNF(expr); assertEquals(expected.toString(), result.toString()); } - + /** - * This is the case when we test the tree that only contains AND - * operator without having an OR operator. - * - * Here is the original expression tree: - * NOT - * | - * ( ) - * | - * OR - * / \ - * ( ) ( ) - * | | - * NOT OR - * | / \ - * AND LIKE = - * / \ / \ / \ - * > < S.C "%%" S.D {t '12:04:34'} + * This is the case when we test the tree that only contains AND operator without having an OR + * operator. + * + * Here is the original expression tree: NOT | ( ) | OR / \ ( ) ( ) | | NOT OR | / \ AND LIKE = + * / \ / \ / \ > < S.C "%%" S.D {t '12:04:34'} * / \ / \ * S.A 3.5 S.B 4 - * + * * Here is the converted expression tree: - * + * * AND * / \ * AND = * / \ / \ * AND NOT LIKE S.D {t '12:04:34'} * / \ / \ - * > < S.C "%%" - * / \ / \ - * S.A 3.5 S.B 4 - * + * > < S.C "%%" / \ / \ S.A 3.5 S.B 4 + * */ @Test public void test5() throws Exception { @@ -453,10 +327,10 @@ public void test5() throws Exception { "NOT ((NOT (S.A > 3.5 AND S.B < 4)) OR " + "(S.C LIKE '\"%%\"' OR S.D = {t '12:04:34'}))"); Expression expected = CCJSqlParserUtil.parseCondExpression( - "S.A > 3.5 AND S.B < 4 AND S.C NOT LIKE '\"%%\"' " - + "AND NOT S.D = {t '12:04:34'}"); + "S.A > 3.5 AND S.B < 4 AND NOT S.C LIKE '\"%%\"' " + + "AND NOT S.D = {t '12:04:34'}"); Expression result = CNFConverter.convertToCNF(expr); assertEquals(expected.toString(), result.toString()); } - + } diff --git a/src/test/java/net/sf/jsqlparser/util/deparser/CreateViewDeParserTest.java b/src/test/java/net/sf/jsqlparser/util/deparser/CreateViewDeParserTest.java index 5288e571..647726f7 100644 --- a/src/test/java/net/sf/jsqlparser/util/deparser/CreateViewDeParserTest.java +++ b/src/test/java/net/sf/jsqlparser/util/deparser/CreateViewDeParserTest.java @@ -1,20 +1,11 @@ -/* - * Copyright (C) 2015 JSQLParser. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% */ package net.sf.jsqlparser.util.deparser; diff --git a/src/test/java/net/sf/jsqlparser/util/deparser/ExecuteDeParserTest.java b/src/test/java/net/sf/jsqlparser/util/deparser/ExecuteDeParserTest.java index 47a7a04d..23b88e09 100644 --- a/src/test/java/net/sf/jsqlparser/util/deparser/ExecuteDeParserTest.java +++ b/src/test/java/net/sf/jsqlparser/util/deparser/ExecuteDeParserTest.java @@ -1,3 +1,12 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.util.deparser; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/net/sf/jsqlparser/util/deparser/ExpressionDeParserTest.java b/src/test/java/net/sf/jsqlparser/util/deparser/ExpressionDeParserTest.java index 89176200..a02db08a 100644 --- a/src/test/java/net/sf/jsqlparser/util/deparser/ExpressionDeParserTest.java +++ b/src/test/java/net/sf/jsqlparser/util/deparser/ExpressionDeParserTest.java @@ -1,3 +1,12 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.util.deparser; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/net/sf/jsqlparser/util/deparser/StatementDeParserTest.java b/src/test/java/net/sf/jsqlparser/util/deparser/StatementDeParserTest.java index 7dcd59aa..724e1f89 100644 --- a/src/test/java/net/sf/jsqlparser/util/deparser/StatementDeParserTest.java +++ b/src/test/java/net/sf/jsqlparser/util/deparser/StatementDeParserTest.java @@ -1,19 +1,21 @@ +/*- + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2019 JSQLParser + * %% + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 + * #L% + */ package net.sf.jsqlparser.util.deparser; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.hamcrest.MockitoHamcrest.argThat; import java.util.ArrayList; import java.util.List; -import org.hamcrest.CustomTypeSafeMatcher; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.StringDescription; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -23,7 +25,6 @@ import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; -import net.sf.jsqlparser.expression.operators.relational.ItemsList; import net.sf.jsqlparser.schema.Column; import net.sf.jsqlparser.schema.Table; import net.sf.jsqlparser.statement.SetStatement; @@ -151,20 +152,20 @@ public void shouldUseProvidedDeParsersWhenDeParsingReplaceWithoutItemsList() { then(expression2).should().accept(expressionDeParser); } - @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - public void shouldUseProvidedDeParsersWhenDeParsingReplaceWithItemsList() { - Replace replace = new Replace(); - Table table = new Table(); - ItemsList itemsList = mock(ItemsList.class); - - replace.setTable(table); - replace.setItemsList(itemsList); - - statementDeParser.visit(replace); - - then(itemsList).should().accept(argThat(is(replaceDeParserWithDeParsers(equalTo(expressionDeParser), equalTo(selectDeParser))))); - } +// @Test +// @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") +// public void shouldUseProvidedDeParsersWhenDeParsingReplaceWithItemsList() { +// Replace replace = new Replace(); +// Table table = new Table(); +// ItemsList itemsList = mock(ItemsList.class); +// +// replace.setTable(table); +// replace.setItemsList(itemsList); +// +// statementDeParser.visit(replace); +// +// then(itemsList).should().accept(argThat(is(replaceDeParserWithDeParsers(equalTo(expressionDeParser), equalTo(selectDeParser))))); +// } @Test @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") @@ -299,19 +300,19 @@ public void shouldUseProvidedDeParserWhenDeParsingSetStatement() { then(expression).should().accept(expressionDeParser); } - private Matcher replaceDeParserWithDeParsers(final Matcher expressionDeParserMatcher, final Matcher selectDeParserMatcher) { - Description description = new StringDescription(); - description.appendText("replace de-parser with expression de-parser "); - expressionDeParserMatcher.describeTo(description); - description.appendText(" and select de-parser "); - selectDeParserMatcher.describeTo(description); - return new CustomTypeSafeMatcher(description.toString()) { - @Override - public boolean matchesSafely(ReplaceDeParser item) { - return expressionDeParserMatcher.matches(item.getExpressionVisitor()) && selectDeParserMatcher.matches(item.getSelectVisitor()); - } - }; - } +// private Matcher replaceDeParserWithDeParsers(final Matcher expressionDeParserMatcher, final Matcher selectDeParserMatcher) { +// Description description = new StringDescription(); +// description.appendText("replace de-parser with expression de-parser "); +// expressionDeParserMatcher.describeTo(description); +// description.appendText(" and select de-parser "); +// selectDeParserMatcher.describeTo(description); +// return new CustomTypeSafeMatcher(description.toString()) { +// @Override +// public boolean matchesSafely(ReplaceDeParser item) { +// return expressionDeParserMatcher.matches(item.getExpressionVisitor()) && selectDeParserMatcher.matches(item.getSelectVisitor()); +// } +// }; +// } @Test @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/aggregate01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/aggregate01.sql similarity index 95% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/aggregate01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/aggregate01.sql index 12da1b1e..9707c206 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/aggregate01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/aggregate01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with codes2codelocales as ( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query02.sql similarity index 77% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query02.sql index 798824bc..fb4050c1 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select time_id, product , last_value(quantity ignore nulls) over (partition by product order by time_id) quantity , last_value(quantity respect nulls) over (partition by product order by time_id) quantity diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query03.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query03.sql index 24bd7953..dad46d57 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select times.time_id, product, quantity from inventory partition by (product) right outer join times on (times.time_id = inventory.time_id) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query04.sql new file mode 100644 index 00000000..b4acaba8 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query04.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno + , ename + , hiredate + , listagg(ename, ',') within group (order by hiredate) over (partition by deptno) as employees +from emp diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query05.sql similarity index 91% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query05.sql index 85336bb4..bb015c11 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select metric_id ,bsln_guid ,timegroup ,obs_value as obs_value , cume_dist () over (partition by metric_id, bsln_guid, timegroup order by obs_value ) as cume_dist , count(1) over (partition by metric_id, bsln_guid, timegroup ) as n diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query06.sql new file mode 100644 index 00000000..cdb2f2dc --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query06.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select trim(both ' ' from ' a ') from dual where trim(:a) is not null diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query07.sql similarity index 87% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query07.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query07.sql index 78c9df3d..bb1a26f5 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query07.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query07.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with clus_tab as ( select id, diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query08.sql new file mode 100644 index 00000000..b4ba2328 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query08.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select manager_id, last_name, hire_date, + count(*) over (partition by manager_id order by hire_date + range numtodsinterval(100, 'day') preceding) as t_count + from employees diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query09.sql similarity index 61% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query09.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query09.sql index bd38cc4d..6ef2aa82 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query09.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query09.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select listagg(column_value, ',') within group (order by column_value) from @@ -10,4 +19,4 @@ from ) as t_str ) ) - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query10.sql similarity index 76% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query10.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query10.sql index 2fd86c3c..97b2378b 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query10.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/analytic_query10.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- SELECT STALENESS, OSIZE, OBJ#, TYPE#, @@ -9,4 +18,4 @@ SELECT STALENESS, :B5 SID, :B4 SERIAL#, PART#, BO#, LOC_STALE_PCT FROM -A \ No newline at end of file +A diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar01.sql new file mode 100644 index 00000000..32c78f73 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar01.sql @@ -0,0 +1,23 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +insert into p +( +a1, +b2, +c3, +d4, +e5, +f6, +g7, +h8 +) +values +( :b1, :b2, :b3, :b4, :5, :6, :7, :8) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar02.sql new file mode 100644 index 00000000..fe118679 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar02.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * +from a +where a=:3 +and b= :4 +and c= :5 and :a = :b + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar03.sql similarity index 77% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar03.sql index d5c2bb73..7c869902 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select count(*), max(scn) from ( diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar04.sql new file mode 100644 index 00000000..695e9e26 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar04.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * +from +( + select * + from "rme" "rm" + where "rm".a-interval:"sys_b_07" day(:"sys_b_08") to second(:"sys_b_09") +) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar05.sql similarity index 72% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar05.sql index 92b3e25c..a1f35335 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/bindvar05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select object_name, object_id, decode(status, 'INVALID', 'TRUE', 'FALSE') invalid, 'TRUE' runnable, @@ -11,4 +20,4 @@ and object_type = 'PACKAGE' and subobject_name is null and object_id not in ( select purge_object from recyclebin ) and upper(object_name) in upper(:name) - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when01.sql new file mode 100644 index 00000000..ec29206c --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when01.sql @@ -0,0 +1,18 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select +ROOT,LEV,OBJ,LinK,PaTH,cycle, + case + when (LEV - LEaD(LEV) over (order by orD)) < 0 then 0 + else 1 + end is_LEaF +from T + + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when02.sql similarity index 84% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when02.sql index a307d2cc..59f752de 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select STaLENESS, OSIZE, OBJ#, TYPE#, case diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when03.sql new file mode 100644 index 00000000..8d596755 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when03.sql @@ -0,0 +1,18 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select +case (STaTUS) +when 'N' then 1 +when 'B' then 2 +when 'a' then 3 +end as STaTE +from VaLUE +where KID=:B2 and RID=:B1 + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when04.sql new file mode 100644 index 00000000..82205dd7 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when04.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select +case when row_number() over (partition by bo# order by staleness, osize, obj#) = 1 then 32 else 0 end + 64 aflags +from f diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when05.sql similarity index 69% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when05.sql index 60cca13e..e26343e3 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/case_when05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select staleness , osize, obj# , type# @@ -9,4 +18,4 @@ select staleness , :b3 sid , :b2 serial# , part#, bo# -from st0 \ No newline at end of file +from st0 diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset01.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset01.sql index 13eafc52..74f979df 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select t1.department_id, t2.* from hr_info t1, table diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset02.sql new file mode 100644 index 00000000..3e438f7d --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset02.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- + select title + from + table(select courses from department where name = 'history') + where name like '%etruscan%' + + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset03.sql new file mode 100644 index 00000000..455d829a --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset03.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- + select + 1 + , cursor(select 1 from dual) c1 + , cursor(select 2, 3 from dual) as c2 + from + table(select 1 from dual) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset04.sql new file mode 100644 index 00000000..454ac2fd --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset04.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select e1.last_name from employees e1 + where f( cursor(select e2.hire_date from employees e2 where e1.employee_id = e2.manager_id), e1.hire_date) = 1 +order by last_name diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset05.sql new file mode 100644 index 00000000..523e6bad --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset05.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * +from + table + ( + function_name() + ) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset06.sql new file mode 100644 index 00000000..f8416988 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset06.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select + cast(collect(cattr(aname, op, to_char(val), support, confidence)) as cattrs) cl_attrs +from a + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset07.sql similarity index 80% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset07.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset07.sql index 49fd2fb8..018a4834 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset07.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset07.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select "a3"."r_id" "r_id" from diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset08.sql new file mode 100644 index 00000000..9948f32f --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset08.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from table (cast (f_int_date_varchar2() as table_int_date_varchar2)) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset09.sql new file mode 100644 index 00000000..ec95c0da --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset09.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +update customers_demo +set cust_address_ntab = cust_address_ntab multiset union cust_address_ntab diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset10.sql new file mode 100644 index 00000000..6bea7535 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset10.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select cast(powermultiset(cust_address_ntab) +as cust_address_tab_tab_typ) +from customers_demo diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset11.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset11.sql new file mode 100644 index 00000000..65ffb267 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset11.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +update table_name +set row = array_of_records(i) +where 1=1 + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset12.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset12.sql similarity index 60% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset12.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset12.sql index 3974ec00..85dcc395 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset12.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset12.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- update customers_demo cd set cust_address2_ntab = cast(multiset(select cust_address diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset13.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset13.sql new file mode 100644 index 00000000..69b1e444 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset13.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select customer_id, cust_address_ntab +multiset except distinct cust_address2_ntab multiset_except +from customers_demo diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset14.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset14.sql new file mode 100644 index 00000000..7e2ccfce --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset14.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select customer_id, cust_address_ntab +multiset intersect all cust_address2_ntab multiset_intersect +from customers_demo +order by customer_id diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset15.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset15.sql new file mode 100644 index 00000000..31b2c964 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset15.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select customer_id, cust_address_ntab +multiset union cust_address2_ntab multiset_union +from customers_demo +order by customer_id diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset16.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset16.sql new file mode 100644 index 00000000..62854def --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset16.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno + , collect(ename) as emps + from emp + group by + deptno + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset17.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset17.sql new file mode 100644 index 00000000..eb3ae9c0 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset17.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno + , cast(collect(ename) as varchar2_ntt) as emps + from emp + group by + deptno diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset18.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset18.sql similarity index 53% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset18.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset18.sql index cfe41df1..8066d08c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset18.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset18.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select deptno , cast( collect(ename order by ename) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset19.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset19.sql similarity index 54% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset19.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset19.sql index 97b764dd..705a9688 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset19.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset19.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select deptno , cast( collect(ename order by hiredate) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset20.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset20.sql new file mode 100644 index 00000000..844e00b8 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset20.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno + , cast(collect(job) as varchar2_ntt) as jobs + from emp + group by + deptno diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset21.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset21.sql new file mode 100644 index 00000000..fa5e5dc7 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset21.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno + , cast( + collect(distinct job) + as varchar2_ntt) as distinct_jobs + from emp + group by + deptno diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset22.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset22.sql new file mode 100644 index 00000000..71d722da --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset22.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno + , cast( + collect(unique job) + as varchar2_ntt) as distinct_jobs + from emp + group by + deptno diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset23.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset23.sql new file mode 100644 index 00000000..3437b972 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset23.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno + , cast( + collect(all job) + as varchar2_ntt) as distinct_jobs + from emp + group by + deptno diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset24.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset24.sql similarity index 54% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset24.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset24.sql index 90541118..69c5cc2c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset24.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset24.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select deptno , cast( collect( @@ -6,4 +15,4 @@ select deptno ) as varchar2_ntt) as distinct_ordered_jobs from emp group by - deptno \ No newline at end of file + deptno diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset25.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset25.sql similarity index 50% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset25.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset25.sql index 38a017f3..0e540d15 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset25.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset25.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select deptno , cast( collect( @@ -5,4 +14,4 @@ select deptno ) as empsal_ntt) as empsals from emp group by - deptno \ No newline at end of file + deptno diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset26.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset26.sql similarity index 51% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset26.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset26.sql index 61bae8f4..bb72ff8e 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset26.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset26.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select deptno , cast( collect( @@ -5,4 +14,4 @@ select deptno ) as empsal_ntt) as empsals from emp group by - deptno \ No newline at end of file + deptno diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset27.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset27.sql similarity index 61% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset27.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset27.sql index 01705a35..ecc78ee4 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset27.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset27.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select deptno , cast( collect( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset28.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset28.sql similarity index 51% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset28.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset28.sql index 86dd3cc1..1d1bd489 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset28.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset28.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select deptno , cast( collect( @@ -5,4 +14,4 @@ select deptno ) as empsal_ntt) as empsals from emp group by - deptno \ No newline at end of file + deptno diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset29.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset29.sql new file mode 100644 index 00000000..64683ad7 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset29.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select cast( + collect( + distinct empsal_ot(ename, sal) + ) as empsal_ntt) as empsals + from emp diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset30.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset30.sql new file mode 100644 index 00000000..405ebbe9 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset30.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select cast( + collect( + distinct empsal_ot(ename, sal) + ) as empsal_ntt) as empsals + from emp + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset31.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset31.sql similarity index 67% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset31.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset31.sql index 6b253fb1..9e6c60ce 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset31.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset31.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select e.deptno , cast( multiset( @@ -11,4 +20,4 @@ select e.deptno group by e.deptno order by - e.deptno \ No newline at end of file + e.deptno diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset32.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset32.sql new file mode 100644 index 00000000..32cefcda --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset32.sql @@ -0,0 +1,17 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno + , set( + cast( + collect(job) + as varchar2_ntt)) as distinct_jobs + from emp + group by + deptno diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset33.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset33.sql new file mode 100644 index 00000000..eedb32d7 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset33.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno + , cast( + set(collect(job)) + as varchar2_ntt) as distinct_jobs + from emp + group by + deptno diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset34.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset34.sql similarity index 53% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset34.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset34.sql index 41769aa6..b2abfb16 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset34.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset34.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select deptno , cast( collect(job) @@ -5,4 +14,4 @@ select deptno ) multiset union distinct varchar2_ntt() as distinct_jobs from emp group by - deptno \ No newline at end of file + deptno diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset35.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset35.sql similarity index 53% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset35.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset35.sql index a3983c81..b253b68b 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset35.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset35.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select owner , object_type , cast( @@ -6,4 +15,4 @@ select owner from all_objects group by owner - , object_type \ No newline at end of file + , object_type diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset36.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset36.sql similarity index 55% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset36.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset36.sql index 76b56b97..818c5790 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset36.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset36.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select owner , object_type , set( @@ -7,4 +16,4 @@ select owner from all_objects group by owner - , object_type \ No newline at end of file + , object_type diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset37.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset37.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset37.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset37.sql index c8e7cd0e..1127899b 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset37.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset37.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select owner , object_type , cast( diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset38.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset38.sql new file mode 100644 index 00000000..e32fe76e --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset38.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * + from table( varchar2_ntt('a','b','c') + multiset union distinct + varchar2_ntt('b','c','d') ) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset39.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset39.sql new file mode 100644 index 00000000..4f42a749 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset39.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select varchar2_ntt('a','b','c') + multiset except + varchar2_ntt('b','c','d') as multiset_except + from dual diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset40.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset40.sql new file mode 100644 index 00000000..2c56bb62 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset40.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select cast( + powermultiset( + varchar2_ntt('a','b','c')) as varchar2_ntts) as pwrmltset + from dual diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset41.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset41.sql new file mode 100644 index 00000000..f73942ec --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset41.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * + from table( + powermultiset_by_cardinality( + varchar2_ntt('a','b','c','d','d'), 3)) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset42.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset42.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset42.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset42.sql index 308bc17c..8adb10f9 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset42.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset42.sql @@ -1,6 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from table( set( complex_ntt(complex_ot('data', 'more data', 1), complex_ot('data', 'some data', 2), complex_ot('data', 'dupe data', 3), - complex_ot('data', 'dupe data', 3)) )) \ No newline at end of file + complex_ot('data', 'dupe data', 3)) )) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset43.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset43.sql new file mode 100644 index 00000000..61514d71 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cast_multiset43.sql @@ -0,0 +1,18 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select deptno +, avg(sal) avg_sal +, cast + ( collect(ename) + as ename_type + ) enames +from emp +group +by deptno diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cluster_set01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cluster_set01.sql similarity index 87% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/cluster_set01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cluster_set01.sql index dd06e45d..ca13bf49 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cluster_set01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/cluster_set01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with clus_tab as ( select id, diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/columns01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/columns01.sql new file mode 100644 index 00000000..f8f47efd --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/columns01.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select a, b, +a d, +ddd as ddd, +ddd as "dfdf", +x as x +from dual + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition01.sql similarity index 53% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition01.sql index df5362c7..9a7fc9bc 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select department_id, last_name, salary from employees x where salary > (select avg(salary) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition02.sql similarity index 54% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition02.sql index 07188ef0..e1210ef3 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from employees x where salary > (select avg(salary) from x) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition03.sql similarity index 57% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition03.sql index 5aa4cba8..1cc52f1b 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from employees x where salary > (select avg(salary) from x) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition04.sql similarity index 84% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition04.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition04.sql index e5463cb7..c314b37f 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition04.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition04.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from t where diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition05.sql similarity index 81% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition05.sql index e9bb8642..ba5215ac 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from t where diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition06.sql similarity index 75% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition06.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition06.sql index fccc0f96..aedda4b6 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition06.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition06.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from t1, t2 where (trunc(t1.timestamp) between to_date('110226','yymmdd') and to_date('110326','yymmdd')) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition07.sql new file mode 100644 index 00000000..e3bd02b7 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition07.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * +from append +where +-- note space between '>' and '=' +(length(w.numer) > = 8) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition08.sql new file mode 100644 index 00000000..fbf79904 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition08.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * +from "p" +where +-- note there are no parens around 231092 +( ( "p"."id" in 231092 ) ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition09.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition09.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition09.sql index 4d1f738c..a7ff8fb5 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition09.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition09.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select sum(nvl(pl.qty,0)) from diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition10.sql new file mode 100644 index 00000000..1ff4d72d --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition10.sql @@ -0,0 +1,24 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select department_id, last_name, salary + from employees x + where + 1 = 1 + and + ( + ( + HI + ) + > + ( + .1 * T.ROWCNT + ) + ) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition11.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition11.sql new file mode 100644 index 00000000..23be3d86 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition11.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select distinct X +from X,Y,Z +where + X.id = Z.id (+) +and nvl(X.cid, '^') = nvl(Y.clientid (+), '^') +and 0 = Lib.SKU(X.sid, nvl(Z.cid, '^')) + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition12.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition12.sql similarity index 53% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition12.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition12.sql index 71a5428e..29041d1c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition12.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition12.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from v.e where cid <> rid diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition14.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition14.sql new file mode 100644 index 00000000..8ba03db3 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition14.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual where trim(sxhnode_key) is not null + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition15.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition15.sql similarity index 51% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition15.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition15.sql index a7c15137..d79d29a2 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition15.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition15.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select "a3"."r_id" "r_id" from diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition16.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition16.sql new file mode 100644 index 00000000..8c2039b1 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition16.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from persons p + where value(p) is of type(only employee_t) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition17.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition17.sql new file mode 100644 index 00000000..6c71acc8 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition17.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +delete from table_name +where current of cursor_name diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition18.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition18.sql new file mode 100644 index 00000000..457f74ff --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition18.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +update tab1 +set c1 = 'x' +where current of c_cur1 + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition19.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition19.sql new file mode 100644 index 00000000..d3e618ca --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition19.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from employees + where (salary, salary) >= + some ( 1400, 3000) + order by employee_id + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition20.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition20.sql new file mode 100644 index 00000000..cdecbaac --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/condition20.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from employees + where (salary, salary) >= + some ( select 1, 2 from dual ) + order by employee_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by01.sql similarity index 75% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by01.sql index 2dd3cd19..c51aaf56 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with o as ( select 'a' obj, 'b' link from dual union all diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by02.sql similarity index 56% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by02.sql index f960c524..1b97f3b8 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select lpad(' ',2*(level-1)) || last_name org_chart, employee_id, manager_id, job_id from employees diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by03.sql similarity index 59% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by03.sql index 2f8d7d32..68af1278 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select lpad(' ',2*(level-1)) || last_name org_chart, employee_id, manager_id, job_id from employees diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by04.sql similarity index 55% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by04.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by04.sql index e4b82990..bc334ae0 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by04.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by04.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select lpad(' ',2*(level-1)) || last_name org_chart, employee_id, manager_id, job_id from employees diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by05.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by05.sql index 72e565aa..6e6716cb 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with liste as ( select substr(:liste, instr(','||:liste||',', ',', 1, rn), instr(','||:liste||',', ',', 1, rn+1) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by06.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by06.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by06.sql index fbe3b0cb..6b7ed37c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by06.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by06.sql @@ -1,7 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select last_name "Employee", connect_by_root last_name "Manager", level-1 "Pathlen", sys_connect_by_path(last_name, '/') "Path" from employees where level > 1 and department_id = 110 connect by prior employee_id = manager_id order by "Employee", "Manager", "Pathlen", "Path" - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by07.sql new file mode 100644 index 00000000..8b4520eb --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/connect_by07.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select t.*, connect_by_root id +from test t +start with t.id = 1 +connect by prior t.id = t.parent_id +order siblings by t.some_text diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime01.sql similarity index 52% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime01.sql index 2d9e99d8..afebc11c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime01.sql @@ -1 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select from_tz(cast(to_date('1999-12-01 11:00:00','yyyy-mm-dd hh:mi:ss') as timestamp), 'america/new_york') at time zone 'america/los_angeles' "west coast time" from dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime02.sql similarity index 89% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime02.sql index d001db41..36bfd127 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select dbin.db_name, dbin.instance_name, diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime03.sql new file mode 100644 index 00000000..1423abf2 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime03.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select +timestamp '2009-10-29 01:30:00' at time zone 'us/pacific'from dual + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime04.sql new file mode 100644 index 00000000..2ecaaa9b --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime04.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select +timestamp '2009-10-29 01:30:00' +from dual + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime05.sql new file mode 100644 index 00000000..dd3e7144 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime05.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select date '1900-01-01' from dual diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime06.sql new file mode 100644 index 00000000..0c6dfc6c --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/datetime06.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual where sysdate > date '2013-04-10' diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/dblink01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/dblink01.sql new file mode 100644 index 00000000..a97586ec --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/dblink01.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select last_name, department_name + from employees@remote, departments + where employees.department_id = departments.department_id + + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/explain01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/explain01.sql similarity index 62% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/explain01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/explain01.sql index 49537cb8..a8a85937 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/explain01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/explain01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- explain plan set statement_id = 'raise in tokyo' into plan_table diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/flashback01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/flashback01.sql new file mode 100644 index 00000000..b40320c3 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/flashback01.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select value(p$) from "XDB"."XDB$SCHEMA" as of snapshot(:2) p$ where SYS_NC_OID$ = :1 diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update01.sql new file mode 100644 index 00000000..cdf9ec5e --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update01.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select employee_id from (select * from employees) + for update of employee_id + + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update02.sql new file mode 100644 index 00000000..ba4d1ab7 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update02.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select employee_id from (select employee_id+1 as employee_id from employees) + for update + + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update03.sql new file mode 100644 index 00000000..e567c0df --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update03.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select employee_id from (select employee_id+1 as employee_id from employees) + for update of employee_id + + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update04.sql new file mode 100644 index 00000000..be02fab8 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update04.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select employee_id from (select employee_id+1 as employee_id from employees) + for update of employee_id nowait + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update05.sql new file mode 100644 index 00000000..cdc28192 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update05.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select employee_id from (select employee_id+1 as employee_id from employees) + for update of employee_id wait 10 + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update06.sql new file mode 100644 index 00000000..a4db0e5d --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update06.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select employee_id from (select employee_id+1 as employee_id from employees) + for update of employee_id skip locked + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update07.sql new file mode 100644 index 00000000..49ac51d7 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update07.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select employee_id from (select employee_id+1 as employee_id from employees) + for update of a, b.c, d skip locked + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update08.sql new file mode 100644 index 00000000..f3068fbd --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/for_update08.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select su.ttype ,su.cid ,su.s_id ,sessiontimezone +from sku su +where (nvl(su.up,'n')='n' and su.ttype=:b0) +for update of su.up +order by su.d diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function01.sql new file mode 100644 index 00000000..ff286529 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function01.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select decode(decode(decode( (select count(1) from dual), a, 1, 0), 0, 1), 1, 0) from dual diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function02.sql new file mode 100644 index 00000000..d6832f33 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function02.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select set(x) from dual diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function03.sql new file mode 100644 index 00000000..f93b63aa --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function03.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select trim(both from con.ke) +from dual + + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function04.sql new file mode 100644 index 00000000..77262351 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function04.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select lnnvl( 2 > 1) from dual diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function05.sql new file mode 100644 index 00000000..b023c7ef --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function05.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select count(*) + from employees + where lnnvl(commission_pct >= .2) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function06.sql new file mode 100644 index 00000000..c44dad72 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function06.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +call dbms_scheduler.auto_purge ( ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function07.sql similarity index 61% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/function07.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function07.sql index 82169ce1..a529757b 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function07.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/function07.sql @@ -1,7 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select cust_gender, count(*) as cnt, round(avg(age)) as avg_age from mining_data_apply_v where prediction(dt_sh_clas_sample cost model using cust_marital_status, education, household_size) = 1 group by cust_gender order by cust_gender - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby01.sql similarity index 82% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby01.sql index fb6f3619..eecd8b67 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select :b3 as l_snap_id , :b2 as p_dbid , :b1 as p_instance_number , nvl(pid, -9) pid , nvl(serial#, -9) serial# , decode(pid, null, null, max(spid)) spid , decode(pid, null, null, max(program)) program , decode(pid, null, null, max(background)) background , sum(pga_used_mem) pga_used_mem , sum(pga_alloc_mem) pga_alloc_mem , sum(pga_freeable_mem) pga_freeable_mem , max(pga_alloc_mem) max_pga_alloc_mem , max(pga_max_mem) max_pga_max_mem , diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby02.sql similarity index 77% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby02.sql index bb36a568..7d4e38ee 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select decode(pid, null, null, max(program)) program , decode(pid, null, null, max(background)) background , sum(pga_used_mem) pga_used_mem , sum(pga_alloc_mem) pga_alloc_mem , sum(pga_freeable_mem) pga_freeable_mem , max(pga_alloc_mem) max_pga_alloc_mem , max(pga_max_mem) max_pga_max_mem , @@ -8,4 +17,4 @@ where program != 'pseudo' group by grouping sets ( (), ((pid+1), serial#) ) - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby03.sql new file mode 100644 index 00000000..144442b1 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby03.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from x +group by grouping sets +( a, 1 ) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby04.sql new file mode 100644 index 00000000..21370b98 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby04.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from x +group by grouping sets +( (a),1 ) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby05.sql new file mode 100644 index 00000000..3305ad15 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby05.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from x +group by grouping sets +( ((a),b), ((a),b) ) + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby06.sql similarity index 77% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby06.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby06.sql index 04330a87..0288b556 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby06.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby06.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select prod_category, prod_subcategory, country_id, cust_city, count(*) from products, sales, customers diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby07.sql similarity index 57% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby07.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby07.sql index 0c43829a..6accaf85 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby07.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby07.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select decode((tt || tc), '56', count(distinct cn), '57', sum(nu)) as q from t where tt='500' diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby08.sql similarity index 83% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby08.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby08.sql index d40e47d0..d543c517 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby08.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby08.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select c.constraint_name , max(r.constraint_name) as r_constraint_name @@ -15,4 +24,4 @@ select a.r_owner = :f1 and a.constraint_type = 'r' group by c.constraint_name, rollup (c.column_name) - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby09.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby09.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby09.sql index e67b35e9..4dac65c9 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby09.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby09.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_1_id, fact_2_id, sum(sales_value) as sales_value, diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby10.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby10.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby10.sql index 8de57ab4..c41556f8 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby10.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby10.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_1_id, fact_2_id, sum(sales_value) as sales_value, diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby11.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby11.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby11.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby11.sql index d6643660..b53ee5fe 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby11.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby11.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_1_id, fact_2_id, sum(sales_value) as sales_value, diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby12.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby12.sql similarity index 54% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby12.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby12.sql index 8c75f15f..3e61a048 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby12.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby12.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_1_id, fact_2_id, fact_3_id, @@ -5,4 +14,4 @@ select fact_1_id, grouping_id(fact_1_id, fact_2_id, fact_3_id) as grouping_id from dimension_tab group by cube(fact_1_id, fact_2_id, fact_3_id) -order by fact_1_id, fact_2_id, fact_3_id \ No newline at end of file +order by fact_1_id, fact_2_id, fact_3_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby13.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby13.sql similarity index 56% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby13.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby13.sql index 6633347a..9c055ef7 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby13.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby13.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_1_id, fact_2_id, fact_3_id, @@ -5,4 +14,4 @@ select fact_1_id, grouping_id(fact_1_id, fact_2_id, fact_3_id) as grouping_id from dimension_tab group by grouping sets((fact_1_id, fact_2_id), (fact_1_id, fact_3_id)) -order by fact_1_id, fact_2_id, fact_3_id \ No newline at end of file +order by fact_1_id, fact_2_id, fact_3_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby14.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby14.sql similarity index 63% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby14.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby14.sql index 10482644..3e61a048 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby14.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby14.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_1_id, fact_2_id, fact_3_id, diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby15.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby15.sql similarity index 63% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby15.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby15.sql index bd3da1c5..6e6f3ed5 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby15.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby15.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_1_id, fact_2_id, fact_3_id, diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby16.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby16.sql similarity index 51% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby16.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby16.sql index d5aeb49b..107804a6 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby16.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby16.sql @@ -1,7 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_1_id, fact_2_id, sum(sales_value) as sales_value, grouping_id(fact_1_id, fact_2_id) as grouping_id from dimension_tab group by grouping sets(fact_1_id, fact_2_id) -order by fact_1_id, fact_2_id \ No newline at end of file +order by fact_1_id, fact_2_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby17.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby17.sql similarity index 51% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby17.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby17.sql index 03166a8d..4a8ff6ea 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby17.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby17.sql @@ -1,7 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_3_id, fact_4_id, sum(sales_value) as sales_value, grouping_id(fact_3_id, fact_4_id) as grouping_id from dimension_tab group by grouping sets(fact_3_id, fact_4_id) -order by fact_3_id, fact_4_id \ No newline at end of file +order by fact_3_id, fact_4_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby18.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby18.sql similarity index 58% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby18.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby18.sql index 92b7ad76..0cc908ea 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby18.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby18.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select fact_1_id, fact_2_id, fact_3_id, @@ -6,4 +15,4 @@ select fact_1_id, grouping_id(fact_1_id, fact_2_id, fact_3_id, fact_4_id) as grouping_id from dimension_tab group by grouping sets(fact_1_id, fact_2_id), grouping sets(fact_3_id, fact_4_id) -order by fact_1_id, fact_2_id, fact_3_id, fact_4_id \ No newline at end of file +order by fact_1_id, fact_2_id, fact_3_id, fact_4_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby19.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby19.sql similarity index 77% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby19.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby19.sql index 4344eb30..e3fb6155 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby19.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby19.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select channels.channel_desc, countries.country_iso_code, to_char(sum(amount_sold), '9,999,999,999') sales$ from sales, customers, times, channels, countries diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby20.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby20.sql similarity index 78% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby20.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby20.sql index afa085fe..562a90c2 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby20.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby20.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select channels.channel_desc, calendar_month_desc, countries.country_iso_code, to_char(sum(amount_sold), '9,999,999,999') sales$ @@ -10,4 +19,4 @@ where sales.time_id=times.time_id and times.calendar_month_desc in ('2000-09', '2000-10') and countries.country_iso_code in ('gb', 'us') group by - rollup(channels.channel_desc, calendar_month_desc, countries.country_iso_code) \ No newline at end of file + rollup(channels.channel_desc, calendar_month_desc, countries.country_iso_code) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby21.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby21.sql similarity index 77% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby21.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby21.sql index a9686aa0..0210886e 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby21.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby21.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select channel_desc, calendar_month_desc, countries.country_iso_code, to_char(sum(amount_sold), '9,999,999,999') sales$ from sales, customers, times, channels, countries @@ -7,4 +16,4 @@ where sales.time_id=times.time_id and sales.cust_id=customers.cust_id and and channels.channel_desc in ('direct sales', 'internet') and times.calendar_month_desc in ('2000-09', '2000-10') and countries.country_iso_code in ('gb', 'us') -group by cube(channel_desc, calendar_month_desc, countries.country_iso_code) \ No newline at end of file +group by cube(channel_desc, calendar_month_desc, countries.country_iso_code) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby22.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby22.sql similarity index 81% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby22.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby22.sql index 5b0c9c69..db5cf6dd 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby22.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby22.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select channel_desc, calendar_month_desc, country_iso_code, to_char(sum(amount_sold), '9,999,999,999') sales$, grouping(channel_desc) as ch, grouping(calendar_month_desc) as mo, grouping(country_iso_code) as co diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby23.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby23.sql similarity index 85% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby23.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby23.sql index 4b16c2ca..a7ead49c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby23.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/groupby23.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select channel_desc, calendar_month_desc, country_iso_code, to_char( sum(amount_sold), '9,999,999,999') sales$, grouping(channel_desc) ch, grouping (calendar_month_desc) mo, grouping(country_iso_code) co diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert01.sql similarity index 59% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert01.sql index fa035f94..d883e294 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- insert when mod( object_id, 2 ) = 1 then into t1 ( x, y ) values ( s.nextval, object_id ) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert02.sql new file mode 100644 index 00000000..be107839 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert02.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +-- insert pl/sql recond +insert into t values trec diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert03.sql similarity index 75% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert03.sql index 6f6d6263..d0e93094 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- -- insert when insert when (deptno=10) then diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert04.sql similarity index 57% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert04.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert04.sql index 001a9ebe..bff7a588 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert04.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert04.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- -- insert all insert all into ap_cust values (customer_id, program_id, delivered_date) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert05.sql similarity index 58% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert05.sql index 2c136e30..abbad97c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- -- insert all insert all into t (pid, fname, lname) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert06.sql similarity index 74% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert06.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert06.sql index e42048f1..5b60e78a 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert06.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert06.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- insert all when (deptno=10) then into emp_10 (empno,ename,job,mgr,sal,deptno) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert07.sql similarity index 70% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert07.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert07.sql index 3b7f5afa..728b9a6c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert07.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert07.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- insert first when customer_id < 'i' then into cust_ah diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert08.sql new file mode 100644 index 00000000..d8214f41 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert08.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +-- without check option +insert into ( +select deptno, dname, loc +from dept +where deptno < 30) +values (98, 'travel', 'seattle') diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert09.sql new file mode 100644 index 00000000..7b39b0f1 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert09.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +insert into ( +select deptno, dname, loc +from dept +where deptno < 30 with check option) +values (99, 'travel', 'seattle') diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert10.sql new file mode 100644 index 00000000..b1c9c715 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert10.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +insert into ( + select empno, ename, job, sal, deptno + from emp) + values + (1, 'morgan', 'dba', '1', 40) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert11.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert11.sql new file mode 100644 index 00000000..d122b323 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert11.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- + insert into emp + (empno, ename) + values + (seq_emp.nextval, 'morgan') + returning empno + into x diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert12.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert12.sql new file mode 100644 index 00000000..716f3d6d --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/insert12.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- + insert into emp + (empno, ename) + values + (seq_emp.nextval, 'morgan') + returning rowid + into r diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval01.sql new file mode 100644 index 00000000..7398a9be --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval01.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select (systimestamp - order_date) day(9) to second from orders +where order_id = 2458 diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval02.sql new file mode 100644 index 00000000..d58baa4c --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval02.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select interval '42' day from dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval03.sql similarity index 74% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval03.sql index 7114766c..7ab4a252 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select interval '4 5:12:10.222' day to second(3) ,interval '4 5:12' day to minute diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval04.sql new file mode 100644 index 00000000..9f65c891 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval04.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select interval '20' day - interval '240' hour from dual diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval05.sql new file mode 100644 index 00000000..6feb8cd2 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/interval05.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +-- see metalink note 1056382.1 +select 'yes' from dual where (sysdate-5,sysdate) overlaps (sysdate-2,sysdate-1) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join01.sql similarity index 57% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/join01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join01.sql index efee6cae..a1ec8ac5 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select d.department_id as d_dept_id, e.department_id as e_dept_id, e.last_name from departments d full outer join employees e on d.department_id = e.department_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join02.sql similarity index 51% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/join02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join02.sql index 33df17c7..582885bc 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select department_id as d_e_dept_id, e.last_name from departments d full outer join employees e using (department_id) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join03.sql similarity index 53% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/join03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join03.sql index 3d779a49..e73a822b 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select d.department_id, e.last_name from m.departments d right outer join n.employees e on d.department_id = e.department_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join04.sql similarity index 50% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/join04.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join04.sql index e7f07cb0..8a260007 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join04.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join04.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select d.department_id, e.last_name from departments d, employees e where d.department_id = e.department_id(+) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join05.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/join05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join05.sql index 24bd7953..dad46d57 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select times.time_id, product, quantity from inventory partition by (product) right outer join times on (times.time_id = inventory.time_id) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join06.sql new file mode 100644 index 00000000..4846a1ef --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join06.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual d1 +join dual d2 on (d1.dummy = d2.dummy) +join dual d3 on(d1.dummy = d3.dummy) +join dual on(d1.dummy = dual.dummy) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join07.sql new file mode 100644 index 00000000..8ace20c1 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join07.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from t1 +join t2 tt2 using(c) +join t3 tt3 using(d) +join t3 using(d) + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join08.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/join08.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join08.sql index cd1dc617..e90cb27a 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join08.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join08.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from dual t1 join (select * from dual) tt2 using(dummy) join (select * from dual) using(dummy) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join09.sql similarity index 68% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/join09.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join09.sql index 07eb7796..f14759a4 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join09.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join09.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from dual t1 left outer join (select * from dual) tt2 using(dummy) left outer join (select * from dual) using(dummy) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join10.sql new file mode 100644 index 00000000..1a424b71 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join10.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual t1, + ( + dual left outer join (select * from dual) tt2 using(dummy) + ) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join11.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join11.sql new file mode 100644 index 00000000..49d4e00d --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join11.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from t1, ( t2 left outer join t3 using(dummy) ) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join12.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join12.sql new file mode 100644 index 00000000..98c35428 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join12.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual,( dual left outer join tt2 using(dummy) ) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join13.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join13.sql new file mode 100644 index 00000000..7a1ae75f --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join13.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from t1, + (((( + t2 left outer join t3 using(dummy) + )))) + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join14.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join14.sql similarity index 50% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/join14.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join14.sql index 89a995f7..c0dd56c6 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join14.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join14.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from dual t1, ( ( @@ -7,4 +16,4 @@ select * from dual t1, left outer join dual t5 using(dummy) ) - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join15.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join15.sql new file mode 100644 index 00000000..9aaece14 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join15.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual t1, ( dual t2 join dual t3 using(dummy)) left outer join dual t4 using (dummy) + + + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join16.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join16.sql new file mode 100644 index 00000000..50744351 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join16.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual t1, + dual t2 join dual t3 using(dummy) + left outer join dual t4 using(dummy) + left outer join dual t5 using(dummy) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join17.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join17.sql new file mode 100644 index 00000000..e5de76bb --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join17.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * +from hdr a +inner join sh s +inner join ca c +on c.id = s.id +on a.va = s.va + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join18.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join18.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/join18.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join18.sql index 01aa0b4c..b68c1cbd 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join18.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join18.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select department_id as d_e_dept_id, e.last_name from departments full outer join employees on (a=b) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join19.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join19.sql new file mode 100644 index 00000000..41b59111 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join19.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select d1.*, d2.* from dual d1 cross join dual d2 diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join20.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join20.sql new file mode 100644 index 00000000..7b4fe87c --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join20.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select d1.*, d2.* from dual cross join dual diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join21.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join21.sql new file mode 100644 index 00000000..d3c438bc --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/join21.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from sys.dual natural join sys.dual + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier01.sql new file mode 100644 index 00000000..7e1bbb37 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier01.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select timestamp, avg, cume_dist from nulls diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier02.sql new file mode 100644 index 00000000..b05550e0 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier02.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select m.model from model diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier03.sql similarity index 91% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier03.sql index c05b2564..58b1a1e3 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select ind.index_owner,ind.index_name,ind.uniqueness , ind.status,ind.index_type,ind.temporary, ind.partitioned,ind.funcidx_status , ind.join_index,ind.columns,ie.column_expression diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier04.sql new file mode 100644 index 00000000..de336157 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier04.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +(select bs.keep keep, bs.keep_until keep_until +from v$backup_set bs) +union all +(select null keep, null keep_until +from v$backup_piece bp) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier05.sql new file mode 100644 index 00000000..fb50b7da --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/keywordasidentifier05.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select exception from exception diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer01.sql new file mode 100644 index 00000000..1bc17527 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer01.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual where 1 < > 2 and 1 ! = 2 and 1 ^ /*aaa */ = 2 + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer02.sql new file mode 100644 index 00000000..c7722b8e --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer02.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select 'A' | | 'B' from dual + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer03.sql new file mode 100644 index 00000000..13b7a7c6 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer03.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select :1, :X, :1 + 1, 1 + :2 from A where A=:3 and b= :4 and c= :5 and :A = :b + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer04.sql new file mode 100644 index 00000000..a7ff5e9b --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer04.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select tbl$or$idx$part$num("sys"."wrh$_seg_stat",0,4,0,"rowid") as c1 from t1 diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer05.sql new file mode 100644 index 00000000..33dfd3bd --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/lexer05.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select tbl$or$idx$part$num("sys"."wrh:_seg_stat",0,4,0,"rowid") as c1 from t1 diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/like01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/like01.sql new file mode 100644 index 00000000..18fe4a40 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/like01.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select last_name +from employees +where last_name +like '%a\_b%' escape '\' +order by last_name diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/loop01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/loop01.sql similarity index 58% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/loop01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/loop01.sql index 05c25327..65677be0 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/loop01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/loop01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- begin forall i in indices of :jobs update emp diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/loop02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/loop02.sql similarity index 67% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/loop02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/loop02.sql index bcaf9247..198e1369 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/loop02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/loop02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- BEGIN <> FOR i IN 1..3 LOOP @@ -10,4 +19,4 @@ BEGIN END IF; END LOOP inner_loop; END LOOP outer_loop; -END; \ No newline at end of file +END; diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge01.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge01.sql index 464bbcd6..d709618e 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- merge into bonuses d using (select employee_id.* from employees) s on (employee_id = a) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge02.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge02.sql index 28baf2f4..ba00db86 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- merge into bonuses d using (select employee_id.* from employees) s on (employee_id = a) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge03.sql similarity index 87% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge03.sql index c8756c53..9e16d501 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- merge /*+ dynamic_sampling(mm 4) dynamic_sampling_est_cdn(mm) dynamic_sampling(m 4) dynamic_sampling_est_cdn(m) */ diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge04.sql similarity index 87% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge04.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge04.sql index 53e3ccd3..5fe26e21 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/merge04.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/merge04.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- merge /*+ dynamic_sampling(mm 4) dynamic_sampling_est_cdn(mm) dynamic_sampling(m 4) dynamic_sampling_est_cdn(m) */ diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause01.sql similarity index 72% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause01.sql index 300b0f6c..6eb6ee2f 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select country,prod,year,s from sales_view_ref model diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause02.sql similarity index 74% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause02.sql index 7559ebb5..397e2d6d 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select country, year, sale, csum from (select country, year, sum(sale) sale diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause03.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause03.sql index 1459be94..67ed7d54 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select country,prod,year,s from sales_view_ref model diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause04.sql similarity index 66% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause04.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause04.sql index cc40f383..f2e9c525 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause04.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause04.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select country, year, sale, csum from (select country, year, salex sale @@ -12,4 +21,4 @@ select country, year, sale, csum ) order by country, year - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause05.sql similarity index 67% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause05.sql index bb3b96ab..77e3f2cd 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select country, year, sale, csum from (select country, year, salex sale diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause06.sql new file mode 100644 index 00000000..fff30fac --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause06.sql @@ -0,0 +1,20 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select + key , + dummy +from + t +where + key = 1 +model + dimension by ( key ) + measures ( ( select dummy from dual ) as dummy ) + rules ( ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause07.sql similarity index 55% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause07.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause07.sql index 36225b0e..cc9c01cb 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause07.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause07.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select group_2 , num_val , diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause08.sql similarity index 52% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause08.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause08.sql index 9cb5a45f..be4da4d3 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause08.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause08.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select key , num_val , diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause09.sql similarity index 65% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause09.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause09.sql index 202994b5..1008093f 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause09.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause09.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select key , num_val , diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause10.sql similarity index 65% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause10.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause10.sql index 131bc16b..aea6951a 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause10.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause10.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select key , num_val , diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause11.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause11.sql similarity index 67% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause11.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause11.sql index d1aa6dcb..1e132673 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause11.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause11.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select bio, rtrim (str_new, ';') new_str from db_temp model diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause12.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause12.sql similarity index 81% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause12.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause12.sql index 544d5002..e19022a9 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause12.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause12.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select organisation, level1, level2, level3, level4 from ( select 'org_name' as organisation, level as org_level, ename diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause13.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause13.sql similarity index 88% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause13.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause13.sql index 08d155c9..6c05d0ca 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause13.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause13.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- -- http://oracle101.blogspot.de/2008/08/oracle-model-clause.html select organisation, level1, nvl(level2,level1) as level2, nvl(level3,nvl(level2,level1)) as level3, diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause14.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause14.sql similarity index 61% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause14.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause14.sql index 523c8a6f..56f4b120 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause14.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause14.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- -- http://www.adp-gmbh.ch/ora/sql/model_clause/ex_generate_dates.html select dt from (select trunc(sysdate) dt from dual) model diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause15.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause15.sql similarity index 80% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause15.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause15.sql index 7357a877..27d21f9b 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause15.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause15.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- -- http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:8912311513313 select name, to_char(dt,'DD-MM-YYYY') dt, amt, cum_amt diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause16.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause16.sql similarity index 86% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause16.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause16.sql index 01b5dd14..d83fa7ae 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause16.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/model_clause16.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select a, b, d, c, dt, p, pp, tech_pp, tech_p from ( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/numbers01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/numbers01.sql similarity index 69% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/numbers01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/numbers01.sql index 3987650a..78896edb 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/numbers01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/numbers01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select 25 , +6.34 , 0.5 diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/object_access01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/object_access01.sql similarity index 78% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/object_access01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/object_access01.sql index 236c23bb..fd5e5e43 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/object_access01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/object_access01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select extractvalue(value(t), '/select_list_item/pos') + 1 pos, extractvalue(value(t), '/select_list_item/value') res, diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/only-parse-test/comment01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/only-parse-test/comment01.sql new file mode 100644 index 00000000..fe3c4bb5 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/only-parse-test/comment01.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +-- com1 +select * /* +com2 */ +from dual -- com3 + + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/only-parse-test/comment02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/only-parse-test/comment02.sql similarity index 89% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/only-parse-test/comment02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/only-parse-test/comment02.sql index da9654be..c74c8b49 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/only-parse-test/comment02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/only-parse-test/comment02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- WITH REFS AS ( diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/only-parse-test/numbers02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/only-parse-test/numbers02.sql new file mode 100644 index 00000000..edf80bca --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/only-parse-test/numbers02.sql @@ -0,0 +1,20 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select 25 +, 1.-+.5 +, 1.+.5 +, 1.+.5D +, 1.+.5DM +, 1.D +, 1.M +, .5M +, .5DM +from dual + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by01.sql new file mode 100644 index 00000000..9e0d9908 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by01.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual order by 1 diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by02.sql new file mode 100644 index 00000000..aa06c9ac --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by02.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual order by 1 asc diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by03.sql new file mode 100644 index 00000000..58cb61e6 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by03.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual order by m.year, m.title, f(a) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by04.sql new file mode 100644 index 00000000..78d6c22a --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by04.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual order by a nulls first, b nulls last diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by05.sql new file mode 100644 index 00000000..bb78fb27 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by05.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual order siblings by a nulls first, b nulls last, c nulls last, d nulls last, e nulls last diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by06.sql new file mode 100644 index 00000000..f99478ec --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/order_by06.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +with a as (select * from dual order by 1) select * from a diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot01.sql new file mode 100644 index 00000000..d2bf8660 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot01.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from pivot_table + unpivot (yearly_total for order_mode in (store as 'direct', + internet as 'online')) + order by year, order_mode + + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot02.sql similarity index 56% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot02.sql index a29895ae..ae476cbc 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from ( select times_purchased as "puchase frequency", state_code from customers t @@ -9,4 +18,4 @@ select * from ( ) order by 1 - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot03.sql similarity index 51% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot03.sql index 27c91214..40941486 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from ( select times_purchased as "purchase frequency", state_code from customers t @@ -9,4 +18,4 @@ select * from ( ) order by 1 - \ No newline at end of file + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot04.sql new file mode 100644 index 00000000..9747e709 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot04.sql @@ -0,0 +1,29 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select value +from +( + ( + select + 'a' v1, + 'e' v2, + 'i' v3, + 'o' v4, + 'u' v5 + from dual + ) + unpivot + ( + value + for value_type in + (v1,v2,v3,v4,v5) + ) + ) + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot05.sql similarity index 62% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot05.sql index 2b65d13b..bbca7256 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from (select customer_id, product_code, quantity from pivot_test) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot06.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot06.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot06.sql index 224aaa08..5b6b1c6c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot06.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot06.sql @@ -1,6 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from (select product_code, quantity from pivot_test) pivot xml (sum(quantity) as sum_quantity for product_code in (select distinct product_code from pivot_test - where id < 10)) \ No newline at end of file + where id < 10)) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot07.sql similarity index 56% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot07.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot07.sql index bc7f8bfe..3edb744f 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot07.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot07.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from (select customer_id, product_code, quantity from pivot_test) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot08.sql new file mode 100644 index 00000000..108e708b --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot08.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * +from (select product_code, quantity + from pivot_test) +pivot (sum(quantity) as sum_quantity for product_code in ('a' as a, 'b' as b, 'c' as c)) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot09.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot09.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot09.sql index b1ebd96a..e30d9492 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot09.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot09.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from (s join d using(c)) pivot diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot10.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot10.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot10.sql index 82bf6359..bced374f 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot10.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot10.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from s join d using(c) pivot diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot11.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot11.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot11.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot11.sql index dd9dff6a..a7f12098 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot11.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot11.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from s pivot diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot12.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot12.sql similarity index 65% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot12.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot12.sql index 79387a43..91d32a79 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot12.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/pivot12.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select value from ( ( @@ -15,4 +24,4 @@ for value_type in (v1, v2,v3,v4,v5) -- Also can give ANY here. ) - ) \ No newline at end of file + ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring01.sql similarity index 74% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring01.sql index 79df737a..be8ec691 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with reports_to_101 (eid, emp_last, mgr_id, reportlevel) as ( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring02.sql similarity index 78% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring02.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring02.sql index bff7e8b8..ad699b74 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring02.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring02.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with reports_to_101 (eid, emp_last, mgr_id, reportlevel, mgr_list) as diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring03.sql similarity index 74% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring03.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring03.sql index 0db9ed13..84fef75c 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring03.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring03.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with reports_to_101 (eid, emp_last, mgr_id, reportlevel) as ( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring04.sql similarity index 78% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring04.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring04.sql index 1229d664..23efa668 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring04.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring04.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with org_chart (eid, emp_last, mgr_id, reportlevel, salary, job_id) as ( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring05.sql similarity index 76% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring05.sql index 099548ca..9bb17638 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with x1 as (select max(y1) from klm1), x2 as (select max(y2) from klm2), diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring06.sql similarity index 72% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring06.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring06.sql index 7858876f..26c1fcd4 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring06.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring06.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with dept_costs as ( select department_name, sum(salary) dept_total diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring07.sql similarity index 96% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring07.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring07.sql index 7c568a3f..6eeac782 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring07.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring07.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with timegrouped_rawdata as ( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring08.sql similarity index 51% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring08.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring08.sql index 498a8af6..7d314470 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring08.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring08.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with x1 as ( select * from t1 ), x2 as ( select * from t2 join t3 on (t2.a2 = t3.a3)) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring09.sql new file mode 100644 index 00000000..ac0fed06 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring09.sql @@ -0,0 +1,17 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +with rn as ( + select rownum rn + from dual + connect by level <= (select max(cases) from t1)) +select pname +from t1, rn +where rn <= cases +order by pname diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring10.sql similarity index 82% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring10.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring10.sql index c20131da..091a3358 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring10.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring10.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with o(obj,link) as ( select 'a', 'b' from dual union all diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring11.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring11.sql similarity index 65% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring11.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring11.sql index 36b47aa7..2bbb0bf3 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring11.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring11.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with col_generator as ( select t1.batch_id, decode(t1.action, 'sent', t1.actdate) sent, decode(t2.action,'recv', t2.actdate) received diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring12.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring12.sql new file mode 100644 index 00000000..d88bcb98 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring12.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +with days as (select (select trunc(sysdate, 'MONTH') from dual) + rownum -1 as d from dual connect by rownum < 31) +select d from days where (trunc(d) - trunc(d,'IW') +1 ) not in (6,7) and d <= last_day(sysdate) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring13.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring13.sql similarity index 79% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring13.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring13.sql index 068f9f69..e2150e22 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring13.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring13.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with dup_hiredate (eid, emp_last, mgr_id, reportlevel, hire_date, job_id) as ( select employee_id, last_name, manager_id, 0 reportlevel, hire_date, job_id from employees diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring14.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring14.sql similarity index 79% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring14.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring14.sql index ca646e15..25da69e8 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring14.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/query_factoring14.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- with emp_count (eid, emp_last, mgr_id, mgrlevel, salary, cnt_employees) as ( select employee_id, last_name, manager_id, 0 mgrlevel, salary, 0 cnt_employees from employees diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/returning01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/returning01.sql new file mode 100644 index 00000000..a69a66c3 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/returning01.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +update emp +set ename = lower(ename) +where job = :jobs(i) +returning empno +bulk collect into :empnos diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/sample01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/sample01.sql new file mode 100644 index 00000000..80f5031f --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/sample01.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from +( +select 1 as c1 from "sys"."obj$" sample block (14.285714 , 1) seed (1) "o" +) samplesub diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/set01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/set01.sql new file mode 100644 index 00000000..99682a13 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/set01.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select nt + , set(nt) as nt_set + from ( + select varchar2_ntt('a','b','c','c') as nt + from dual + ) diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/set02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/set02.sql new file mode 100644 index 00000000..117126b1 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/set02.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select nt.column_value as distinct_element + from table(set(varchar2_ntt('a','b','c','c'))) nt diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple02.sql new file mode 100644 index 00000000..091b0702 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple02.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select employee_id from (select employee_id+1 as employee_id from employees) + for update + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple03.sql new file mode 100644 index 00000000..2329ce06 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple03.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select employee_id from (select employee_id+1 as employee_id from employees) + for update of employee_id + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple04.sql new file mode 100644 index 00000000..091e2fe1 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple04.sql @@ -0,0 +1,20 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from +( + ( + select * from dual + ) + unpivot + ( + value for value_type in (dummy) + ) +) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple05.sql new file mode 100644 index 00000000..e7089d5c --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple05.sql @@ -0,0 +1,18 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from +( +select * from a + unpivot + ( + value for value_type in (dummy) + ) +) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple06.sql new file mode 100644 index 00000000..b8a9ea6e --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple06.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from (( select * from dual)) a + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple07.sql new file mode 100644 index 00000000..44b26624 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple07.sql @@ -0,0 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual for update +of dual + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple08.sql new file mode 100644 index 00000000..de56d034 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple08.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select a, b, c, d, e, 1, 2, f(a,b,c,1+1) from dual + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple09.sql new file mode 100644 index 00000000..8d73ff96 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple09.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select a||last_name, + employee_id + from employees + start with job_id = 'ad_vp' + connect by prior employee_id = manager_id + + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple10.sql new file mode 100644 index 00000000..625c07d1 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple10.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select a as over from over diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple11.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple11.sql new file mode 100644 index 00000000..19559154 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple11.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select a.* from dual diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple12.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple12.sql new file mode 100644 index 00000000..bb239ac7 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple12.sql @@ -0,0 +1,16 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select + +1, + t2.division_name as aaaa, + a.*, + sum(t3.amount) +from dual + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple13.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple13.sql new file mode 100644 index 00000000..e45d215e --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/simple13.sql @@ -0,0 +1,10 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from (dual), (dual d), (dual) d diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/string01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/string01.sql similarity index 62% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/string01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/string01.sql index 12c46c20..704fbf30 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/string01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/string01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select 'hello' , 'oracle.dbs' diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union01.sql similarity index 63% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/union01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union01.sql index 69ad2845..1d340bff 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- (select 'a' obj, 'b' link from dual) union all (select 'a', 'c' from dual) union all (select 'c', 'd' from dual) union all diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union02.sql new file mode 100644 index 00000000..1168c0e6 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union02.sql @@ -0,0 +1,13 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +(select distinct job_id from hr.jobs) +union all +(select distinct job_id from hr.job_history) + diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union03.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union03.sql new file mode 100644 index 00000000..63ac88f7 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union03.sql @@ -0,0 +1,15 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +(select distinct job_id from hr.jobs) +union all +( + select distinct job_id from hr.job_history +) + diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union04.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union04.sql similarity index 84% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/union04.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union04.sql index 911f952b..46adc54f 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union04.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union04.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- ( select distinct job_id from hr.jobs ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union05.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union05.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/union05.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union05.sql index 87a46aa3..3faf460d 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union05.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union05.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- (select * from dual) union all ( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union06.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union06.sql similarity index 80% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/union06.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union06.sql index 2ca57872..ee1246d2 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union06.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union06.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- (( select "x"."r_no", "x"."i_id", "x"."ind", diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union07.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union07.sql similarity index 96% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/union07.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union07.sql index e169acd9..7d45ccad 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union07.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union07.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from ( select row_.*, rownum rownum_ from ( diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union08.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union08.sql new file mode 100644 index 00000000..127f3049 --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union08.sql @@ -0,0 +1,14 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select * from dual where exists ( + (select * from dual) + union all + (select * from dual) +) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union09.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union09.sql similarity index 87% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/union09.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union09.sql index a63f4993..5bb988ed 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union09.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union09.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select * from ( select row_.* from ( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union10.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union10.sql similarity index 93% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/union10.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union10.sql index a697a08a..09584ad2 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union10.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/union10.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select ( ( diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/xmltable01.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/xmltable01.sql similarity index 64% rename from src/test/resources/net/sf/jsqlparser/test/oracle-tests/xmltable01.sql rename to src/test/resources/net/sf/jsqlparser/statement/oracle-tests/xmltable01.sql index 7d0bd591..cc590233 100644 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/xmltable01.sql +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/xmltable01.sql @@ -1,3 +1,12 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- select warehouse_name warehouse, warehouse2."water", warehouse2."rail" from warehouses, xmltable('/warehouse' diff --git a/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/xmltable02.sql b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/xmltable02.sql new file mode 100644 index 00000000..4a266b2a --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/oracle-tests/xmltable02.sql @@ -0,0 +1,11 @@ +--- +-- #%L +-- JSQLParser library +-- %% +-- Copyright (C) 2004 - 2019 JSQLParser +-- %% +-- Dual licensed under GNU LGPL 2.1 or Apache License 2.0 +-- #L% +--- +select xmlelement("other_attrs", xmlelement("parsing_user_id", parsing_user_id)).getClobVal() other +from f diff --git a/src/test/resources/net/sf/jsqlparser/test/select/complex-lateral-select-request.txt b/src/test/resources/net/sf/jsqlparser/statement/select/complex-lateral-select-request.txt similarity index 100% rename from src/test/resources/net/sf/jsqlparser/test/select/complex-lateral-select-request.txt rename to src/test/resources/net/sf/jsqlparser/statement/select/complex-lateral-select-request.txt diff --git a/src/test/resources/net/sf/jsqlparser/test/select/large-sql-issue-235.txt b/src/test/resources/net/sf/jsqlparser/statement/select/large-sql-issue-235.txt similarity index 100% rename from src/test/resources/net/sf/jsqlparser/test/select/large-sql-issue-235.txt rename to src/test/resources/net/sf/jsqlparser/statement/select/large-sql-issue-235.txt diff --git a/src/test/resources/net/sf/jsqlparser/statement/select/large-sql-issue-566.txt b/src/test/resources/net/sf/jsqlparser/statement/select/large-sql-issue-566.txt new file mode 100644 index 00000000..1207fb5e --- /dev/null +++ b/src/test/resources/net/sf/jsqlparser/statement/select/large-sql-issue-566.txt @@ -0,0 +1,50 @@ +SELECT "CAMPAIGNID","TARGET_SOURCE","NON_INDV_TYPE","GROUP_SPONSOR","SEGMNTS","COUNTRY_CD","TARGET_STATE","TARGET_CITY","TARGET_ZIP","SIC_CLASS","NAICS_CLASS","GENDER_CD","OCCUPATION","CREDIT_SCORE","MARITAL_STATUS","IMPORT_ID","BIRTH_DT","STATUS" + FROM ( + SELECT + X.CAMPAIGNID, + X.FIELDNAME, + CASE WHEN Y.VALUE IS NULL THEN 'ALL' + ELSE Y.VALUE END AS VALUE + FROM + --CREATES A CARTESIAN JOIN TO COMBINE ALL CHARACTERISTICS WITH CAMPAIGN + (SELECT + CAMPAIGNID, + FIELDNAME + FROM CAMPAIGN + CROSS JOIN (SELECT DISTINCT FIELDNAME + FROM FIELDCRITERIA)) X + LEFT JOIN + --RETURNS ALL AVAILABLE CAMPAIGN CHARACTERISTS + ( + SELECT + CAMPAIGNID, + FIELDNAME, + (CASE FIELDNAME + WHEN U'BUSINESSTYPE' THEN D.DISPLAYVALUE + WHEN U'LEADTARGETSOURCE' THEN E.DISPLAYVALUE + ELSE VALUE END) AS VALUE + FROM FIELDCRITERIA A, STRINGFIELDCRITERIA_VALUE B + LEFT JOIN (SELECT + B.CODE, + B.DISPLAYVALUE, + LOOKUPNAME + FROM LOOKUPLIST A, LOOKUPVALUE B + WHERE A.ID = B.LOOKUPLIST_ID AND LOOKUPNAME = 'NONINDIVIDUALTYPE') D ON B.VALUE = D.CODE + LEFT JOIN (SELECT + B.CODE, + B.DISPLAYVALUE, + LOOKUPNAME + FROM LOOKUPLIST A, LOOKUPVALUE B + WHERE A.ID = B.LOOKUPLIST_ID AND LOOKUPNAME = 'LEADTARGETSOURCE') E ON B.VALUE = E.CODE + , + CAMPAIGN C + WHERE A.ID = B.FIELD_CRITERIA_ID + AND A.CRITERIA_ID = C.ID + ) Y ON X.CAMPAIGNID = Y.CAMPAIGNID AND X.FIELDNAME = Y.FIELDNAME + ) + PIVOT (MAX(VALUE) + FOR FIELDNAME + IN + ('LEADTARGETSOURCE' AS TARGET_SOURCE, 'BUSINESSTYPE' AS NON_INDV_TYPE, 'GROUPSPONSOR' AS GROUP_SPONSOR, 'SEGMENTS' AS SEGMNTS, 'COUNTRYCD' AS COUNTRY_CD, 'STATEPROVCD' AS TARGET_STATE, + 'CITY' AS TARGET_CITY, 'POSTALCODE' AS TARGET_ZIP, 'SICCLASSIFICATION' AS SIC_CLASS, 'NAICSCLASSIFICATION' AS NAICS_CLASS, 'GENDERCD' AS GENDER_CD, 'OCCUPATION' AS OCCUPATION, 'CREDITSCORE' AS CREDIT_SCORE, + 'MARITALSTATUSCD' AS MARITAL_STATUS, 'IMPORTID' AS IMPORT_ID, 'BIRTHDATE' AS BIRTH_DT, 'STATUS' AS STATUS)) \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/select/large-sql-with-issue-265.txt b/src/test/resources/net/sf/jsqlparser/statement/select/large-sql-with-issue-265.txt similarity index 100% rename from src/test/resources/net/sf/jsqlparser/test/select/large-sql-with-issue-265.txt rename to src/test/resources/net/sf/jsqlparser/statement/select/large-sql-with-issue-265.txt diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query04.sql deleted file mode 100644 index fbe36762..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query04.sql +++ /dev/null @@ -1,5 +0,0 @@ -select deptno - , ename - , hiredate - , listagg(ename, ',') within group (order by hiredate) over (partition by deptno) as employees -from emp \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query06.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query06.sql deleted file mode 100644 index 20285455..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query06.sql +++ /dev/null @@ -1 +0,0 @@ -select trim(both ' ' from ' a ') from dual where trim(:a) is not null diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query08.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query08.sql deleted file mode 100644 index a2700297..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/analytic_query08.sql +++ /dev/null @@ -1,4 +0,0 @@ -select manager_id, last_name, hire_date, - count(*) over (partition by manager_id order by hire_date - range numtodsinterval(100, 'day') preceding) as t_count - from employees \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar01.sql deleted file mode 100644 index 2192adb9..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar01.sql +++ /dev/null @@ -1,14 +0,0 @@ -insert into p -( -a1, -b2, -c3, -d4, -e5, -f6, -g7, -h8 -) -values -( :b1, :b2, :b3, :b4, :5, :6, :7, :8) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar02.sql deleted file mode 100644 index a93392e3..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar02.sql +++ /dev/null @@ -1,6 +0,0 @@ -select * -from a -where a=:3 -and b= :4 -and c= :5 and :a = :b - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar04.sql deleted file mode 100644 index fc0f8256..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/bindvar04.sql +++ /dev/null @@ -1,7 +0,0 @@ -select * -from -( - select * - from "rme" "rm" - where "rm".a-interval:"sys_b_07" day(:"sys_b_08") to second(:"sys_b_09") -) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when01.sql deleted file mode 100644 index 357eb37c..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when01.sql +++ /dev/null @@ -1,9 +0,0 @@ -select -ROOT,LEV,OBJ,LinK,PaTH,cycle, - case - when (LEV - LEaD(LEV) over (order by orD)) < 0 then 0 - else 1 - end is_LEaF -from T - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when03.sql deleted file mode 100644 index 6bb753e1..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when03.sql +++ /dev/null @@ -1,9 +0,0 @@ -select -case (STaTUS) -when 'N' then 1 -when 'B' then 2 -when 'a' then 3 -end as STaTE -from VaLUE -where KID=:B2 and RID=:B1 - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when04.sql deleted file mode 100644 index 92c4761b..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/case_when04.sql +++ /dev/null @@ -1,3 +0,0 @@ -select -case when row_number() over (partition by bo# order by staleness, osize, obj#) = 1 then 32 else 0 end + 64 aflags -from f diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset02.sql deleted file mode 100644 index cb9631cd..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset02.sql +++ /dev/null @@ -1,6 +0,0 @@ - select title - from - table(select courses from department where name = 'history') - where name like '%etruscan%' - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset03.sql deleted file mode 100644 index 412af233..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset03.sql +++ /dev/null @@ -1,7 +0,0 @@ - select - 1 - , cursor(select 1 from dual) c1 - , cursor(select 2, 3 from dual) as c2 - from - table(select 1 from dual) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset04.sql deleted file mode 100644 index 6fa8a9d0..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset04.sql +++ /dev/null @@ -1,3 +0,0 @@ -select e1.last_name from employees e1 - where f( cursor(select e2.hire_date from employees e2 where e1.employee_id = e2.manager_id), e1.hire_date) = 1 -order by last_name \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset05.sql deleted file mode 100644 index 2985d823..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset05.sql +++ /dev/null @@ -1,6 +0,0 @@ -select * -from - table - ( - function_name() - ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset06.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset06.sql deleted file mode 100644 index d2cee883..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset06.sql +++ /dev/null @@ -1,4 +0,0 @@ -select - cast(collect(cattr(aname, op, to_char(val), support, confidence)) as cattrs) cl_attrs -from a - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset08.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset08.sql deleted file mode 100644 index efa17074..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset08.sql +++ /dev/null @@ -1 +0,0 @@ -select * from table (cast (f_int_date_varchar2() as table_int_date_varchar2)) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset09.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset09.sql deleted file mode 100644 index 5e7d49de..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset09.sql +++ /dev/null @@ -1,2 +0,0 @@ -update customers_demo -set cust_address_ntab = cust_address_ntab multiset union cust_address_ntab diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset10.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset10.sql deleted file mode 100644 index 741fb5cc..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset10.sql +++ /dev/null @@ -1,3 +0,0 @@ -select cast(powermultiset(cust_address_ntab) -as cust_address_tab_tab_typ) -from customers_demo diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset11.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset11.sql deleted file mode 100644 index c5dc0a64..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset11.sql +++ /dev/null @@ -1,4 +0,0 @@ -update table_name -set row = array_of_records(i) -where 1=1 - \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset13.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset13.sql deleted file mode 100644 index 83b69c34..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset13.sql +++ /dev/null @@ -1,3 +0,0 @@ -select customer_id, cust_address_ntab -multiset except distinct cust_address2_ntab multiset_except -from customers_demo diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset14.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset14.sql deleted file mode 100644 index a2013a2d..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset14.sql +++ /dev/null @@ -1,4 +0,0 @@ -select customer_id, cust_address_ntab -multiset intersect all cust_address2_ntab multiset_intersect -from customers_demo -order by customer_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset15.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset15.sql deleted file mode 100644 index e34fa931..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset15.sql +++ /dev/null @@ -1,4 +0,0 @@ -select customer_id, cust_address_ntab -multiset union cust_address2_ntab multiset_union -from customers_demo -order by customer_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset16.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset16.sql deleted file mode 100644 index 848cda55..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset16.sql +++ /dev/null @@ -1,6 +0,0 @@ -select deptno - , collect(ename) as emps - from emp - group by - deptno - \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset17.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset17.sql deleted file mode 100644 index 1b1c6d05..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset17.sql +++ /dev/null @@ -1,5 +0,0 @@ -select deptno - , cast(collect(ename) as varchar2_ntt) as emps - from emp - group by - deptno \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset20.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset20.sql deleted file mode 100644 index 40d4ee96..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset20.sql +++ /dev/null @@ -1,5 +0,0 @@ -select deptno - , cast(collect(job) as varchar2_ntt) as jobs - from emp - group by - deptno \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset21.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset21.sql deleted file mode 100644 index 3f4c7a29..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset21.sql +++ /dev/null @@ -1,7 +0,0 @@ -select deptno - , cast( - collect(distinct job) - as varchar2_ntt) as distinct_jobs - from emp - group by - deptno \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset22.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset22.sql deleted file mode 100644 index 9e9712ae..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset22.sql +++ /dev/null @@ -1,7 +0,0 @@ -select deptno - , cast( - collect(unique job) - as varchar2_ntt) as distinct_jobs - from emp - group by - deptno \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset23.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset23.sql deleted file mode 100644 index 48b9d4db..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset23.sql +++ /dev/null @@ -1,7 +0,0 @@ -select deptno - , cast( - collect(all job) - as varchar2_ntt) as distinct_jobs - from emp - group by - deptno \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset29.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset29.sql deleted file mode 100644 index 5a3f19e0..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset29.sql +++ /dev/null @@ -1,5 +0,0 @@ -select cast( - collect( - distinct empsal_ot(ename, sal) - ) as empsal_ntt) as empsals - from emp \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset30.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset30.sql deleted file mode 100644 index 9cc97fa1..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset30.sql +++ /dev/null @@ -1,6 +0,0 @@ -select cast( - collect( - distinct empsal_ot(ename, sal) - ) as empsal_ntt) as empsals - from emp - \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset32.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset32.sql deleted file mode 100644 index 88fe053e..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset32.sql +++ /dev/null @@ -1,8 +0,0 @@ -select deptno - , set( - cast( - collect(job) - as varchar2_ntt)) as distinct_jobs - from emp - group by - deptno \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset33.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset33.sql deleted file mode 100644 index 7df97a90..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset33.sql +++ /dev/null @@ -1,7 +0,0 @@ -select deptno - , cast( - set(collect(job)) - as varchar2_ntt) as distinct_jobs - from emp - group by - deptno \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset38.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset38.sql deleted file mode 100644 index 6f00721f..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset38.sql +++ /dev/null @@ -1,4 +0,0 @@ -select * - from table( varchar2_ntt('a','b','c') - multiset union distinct - varchar2_ntt('b','c','d') ) \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset39.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset39.sql deleted file mode 100644 index d38c1b22..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset39.sql +++ /dev/null @@ -1,4 +0,0 @@ -select varchar2_ntt('a','b','c') - multiset except - varchar2_ntt('b','c','d') as multiset_except - from dual \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset40.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset40.sql deleted file mode 100644 index f3bb0774..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset40.sql +++ /dev/null @@ -1,4 +0,0 @@ -select cast( - powermultiset( - varchar2_ntt('a','b','c')) as varchar2_ntts) as pwrmltset - from dual \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset41.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset41.sql deleted file mode 100644 index 70e247d4..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset41.sql +++ /dev/null @@ -1,4 +0,0 @@ -select * - from table( - powermultiset_by_cardinality( - varchar2_ntt('a','b','c','d','d'), 3)) \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset43.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset43.sql deleted file mode 100644 index df011071..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/cast_multiset43.sql +++ /dev/null @@ -1,9 +0,0 @@ -select deptno -, avg(sal) avg_sal -, cast - ( collect(ename) - as ename_type - ) enames -from emp -group -by deptno diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/columns01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/columns01.sql deleted file mode 100644 index a750245b..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/columns01.sql +++ /dev/null @@ -1,7 +0,0 @@ -select a, b, -a d, -ddd as ddd, -ddd as "dfdf", -x as x -from dual - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition07.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition07.sql deleted file mode 100644 index 769a7724..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition07.sql +++ /dev/null @@ -1,5 +0,0 @@ -select * -from append -where --- note space between '>' and '=' -(length(w.numer) > = 8) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition08.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition08.sql deleted file mode 100644 index 80a0cca3..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition08.sql +++ /dev/null @@ -1,5 +0,0 @@ -select * -from "p" -where --- note there are no parens around 231092 -( ( "p"."id" in 231092 ) ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition10.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition10.sql deleted file mode 100644 index 4b739492..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition10.sql +++ /dev/null @@ -1,15 +0,0 @@ -select department_id, last_name, salary - from employees x - where - 1 = 1 - and - ( - ( - HI - ) - > - ( - .1 * T.ROWCNT - ) - ) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition11.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition11.sql deleted file mode 100644 index d93cfbd5..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition11.sql +++ /dev/null @@ -1,7 +0,0 @@ -select distinct X -from X,Y,Z -where - X.id = Z.id (+) -and nvl(X.cid, '^') = nvl(Y.clientid (+), '^') -and 0 = Lib.SKU(X.sid, nvl(Z.cid, '^')) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition14.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition14.sql deleted file mode 100644 index bff0216d..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition14.sql +++ /dev/null @@ -1,2 +0,0 @@ -select * from dual where trim(sxhnode_key) is not null - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition16.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition16.sql deleted file mode 100644 index dd711ee7..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition16.sql +++ /dev/null @@ -1,3 +0,0 @@ -select * from persons p - where value(p) is of type(only employee_t) - \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition17.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition17.sql deleted file mode 100644 index 6d8b2691..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition17.sql +++ /dev/null @@ -1,2 +0,0 @@ -delete from table_name -where current of cursor_name diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition18.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition18.sql deleted file mode 100644 index e66f6fbc..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition18.sql +++ /dev/null @@ -1,4 +0,0 @@ -update tab1 -set c1 = 'x' -where current of c_cur1 - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition19.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition19.sql deleted file mode 100644 index de23d248..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition19.sql +++ /dev/null @@ -1,5 +0,0 @@ -select * from employees - where (salary, salary) >= - some ( 1400, 3000) - order by employee_id - \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition20.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition20.sql deleted file mode 100644 index 77419b65..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/condition20.sql +++ /dev/null @@ -1,4 +0,0 @@ -select * from employees - where (salary, salary) >= - some ( select 1, 2 from dual ) - order by employee_id diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by07.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by07.sql deleted file mode 100644 index 382ff583..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/connect_by07.sql +++ /dev/null @@ -1,5 +0,0 @@ -select t.*, connect_by_root id -from test t -start with t.id = 1 -connect by prior t.id = t.parent_id -order siblings by t.some_text diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime03.sql deleted file mode 100644 index 1c9ccf5e..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime03.sql +++ /dev/null @@ -1,3 +0,0 @@ -select -timestamp '2009-10-29 01:30:00' at time zone 'us/pacific'from dual - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime04.sql deleted file mode 100644 index aae6733a..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime04.sql +++ /dev/null @@ -1,4 +0,0 @@ -select -timestamp '2009-10-29 01:30:00' -from dual - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime05.sql deleted file mode 100644 index 45295442..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime05.sql +++ /dev/null @@ -1 +0,0 @@ -select date '1900-01-01' from dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime06.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime06.sql deleted file mode 100644 index c157eedb..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/datetime06.sql +++ /dev/null @@ -1 +0,0 @@ -select * from dual where sysdate > date '2013-04-10' diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/dblink01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/dblink01.sql deleted file mode 100644 index 77d3634a..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/dblink01.sql +++ /dev/null @@ -1,5 +0,0 @@ -select last_name, department_name - from employees@remote, departments - where employees.department_id = departments.department_id - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/flashback01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/flashback01.sql deleted file mode 100644 index 52f94599..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/flashback01.sql +++ /dev/null @@ -1 +0,0 @@ -select value(p$) from "XDB"."XDB$SCHEMA" as of snapshot(:2) p$ where SYS_NC_OID$ = :1 diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update01.sql deleted file mode 100644 index ad5980b2..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update01.sql +++ /dev/null @@ -1,4 +0,0 @@ -select employee_id from (select * from employees) - for update of employee_id - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update02.sql deleted file mode 100644 index 6ea9a8d3..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update02.sql +++ /dev/null @@ -1,4 +0,0 @@ -select employee_id from (select employee_id+1 as employee_id from employees) - for update - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update03.sql deleted file mode 100644 index 27a7ae02..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update03.sql +++ /dev/null @@ -1,4 +0,0 @@ -select employee_id from (select employee_id+1 as employee_id from employees) - for update of employee_id - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update04.sql deleted file mode 100644 index d41b2161..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update04.sql +++ /dev/null @@ -1,3 +0,0 @@ -select employee_id from (select employee_id+1 as employee_id from employees) - for update of employee_id nowait - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update05.sql deleted file mode 100644 index 0b83ea8e..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update05.sql +++ /dev/null @@ -1,3 +0,0 @@ -select employee_id from (select employee_id+1 as employee_id from employees) - for update of employee_id wait 10 - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update06.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update06.sql deleted file mode 100644 index 06a8e6fd..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update06.sql +++ /dev/null @@ -1,3 +0,0 @@ -select employee_id from (select employee_id+1 as employee_id from employees) - for update of employee_id skip locked - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update07.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update07.sql deleted file mode 100644 index 7736043c..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update07.sql +++ /dev/null @@ -1,3 +0,0 @@ -select employee_id from (select employee_id+1 as employee_id from employees) - for update of a, b.c, d skip locked - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update08.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update08.sql deleted file mode 100644 index b1b24737..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/for_update08.sql +++ /dev/null @@ -1,5 +0,0 @@ -select su.ttype ,su.cid ,su.s_id ,sessiontimezone -from sku su -where (nvl(su.up,'n')='n' and su.ttype=:b0) -for update of su.up -order by su.d diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function01.sql deleted file mode 100644 index 1a9bb90b..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function01.sql +++ /dev/null @@ -1 +0,0 @@ -select decode(decode(decode( (select count(1) from dual), a, 1, 0), 0, 1), 1, 0) from dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function02.sql deleted file mode 100644 index 492cb9d0..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function02.sql +++ /dev/null @@ -1 +0,0 @@ -select set(x) from dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function03.sql deleted file mode 100644 index e8f8f02d..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function03.sql +++ /dev/null @@ -1,4 +0,0 @@ -select trim(both from con.ke) -from dual - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function04.sql deleted file mode 100644 index c65722f8..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function04.sql +++ /dev/null @@ -1 +0,0 @@ -select lnnvl( 2 > 1) from dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function05.sql deleted file mode 100644 index 105727cf..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function05.sql +++ /dev/null @@ -1,3 +0,0 @@ -select count(*) - from employees - where lnnvl(commission_pct >= .2) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function06.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function06.sql deleted file mode 100644 index ed4e2ebe..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/function06.sql +++ /dev/null @@ -1 +0,0 @@ -call dbms_scheduler.auto_purge ( ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby03.sql deleted file mode 100644 index 64b1783f..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby03.sql +++ /dev/null @@ -1,4 +0,0 @@ -select * from x -group by grouping sets -( a, 1 ) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby04.sql deleted file mode 100644 index 1d37e20d..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby04.sql +++ /dev/null @@ -1,3 +0,0 @@ -select * from x -group by grouping sets -( (a),1 ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby05.sql deleted file mode 100644 index 6a9f76bf..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/groupby05.sql +++ /dev/null @@ -1,4 +0,0 @@ -select * from x -group by grouping sets -( ((a),b), ((a),b) ) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert02.sql deleted file mode 100644 index 7c561e5d..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert02.sql +++ /dev/null @@ -1,2 +0,0 @@ --- insert pl/sql recond -insert into t values trec diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert08.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert08.sql deleted file mode 100644 index 01cc8acc..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert08.sql +++ /dev/null @@ -1,6 +0,0 @@ --- without check option -insert into ( -select deptno, dname, loc -from dept -where deptno < 30) -values (98, 'travel', 'seattle') diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert09.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert09.sql deleted file mode 100644 index c8e2035a..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert09.sql +++ /dev/null @@ -1,5 +0,0 @@ -insert into ( -select deptno, dname, loc -from dept -where deptno < 30 with check option) -values (99, 'travel', 'seattle') diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert10.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert10.sql deleted file mode 100644 index ff5fb5b8..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert10.sql +++ /dev/null @@ -1,5 +0,0 @@ -insert into ( - select empno, ename, job, sal, deptno - from emp) - values - (1, 'morgan', 'dba', '1', 40) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert11.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert11.sql deleted file mode 100644 index 0e3047d2..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert11.sql +++ /dev/null @@ -1,6 +0,0 @@ - insert into emp - (empno, ename) - values - (seq_emp.nextval, 'morgan') - returning empno - into x diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert12.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert12.sql deleted file mode 100644 index afdff6da..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/insert12.sql +++ /dev/null @@ -1,6 +0,0 @@ - insert into emp - (empno, ename) - values - (seq_emp.nextval, 'morgan') - returning rowid - into r diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval01.sql deleted file mode 100644 index e9ac9ec3..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval01.sql +++ /dev/null @@ -1,2 +0,0 @@ -select (systimestamp - order_date) day(9) to second from orders -where order_id = 2458 diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval02.sql deleted file mode 100644 index 1b82cc4f..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval02.sql +++ /dev/null @@ -1 +0,0 @@ -select interval '42' day from dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval04.sql deleted file mode 100644 index 92025168..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval04.sql +++ /dev/null @@ -1 +0,0 @@ -select interval '20' day - interval '240' hour from dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval05.sql deleted file mode 100644 index e379aad3..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/interval05.sql +++ /dev/null @@ -1,2 +0,0 @@ --- see metalink note 1056382.1 -select 'yes' from dual where (sysdate-5,sysdate) overlaps (sysdate-2,sysdate-1) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join06.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join06.sql deleted file mode 100644 index 8a17093a..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join06.sql +++ /dev/null @@ -1,5 +0,0 @@ -select * from dual d1 -join dual d2 on (d1.dummy = d2.dummy) -join dual d3 on(d1.dummy = d3.dummy) -join dual on(d1.dummy = dual.dummy) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join07.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join07.sql deleted file mode 100644 index 5fcb6eef..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join07.sql +++ /dev/null @@ -1,5 +0,0 @@ -select * from t1 -join t2 tt2 using(c) -join t3 tt3 using(d) -join t3 using(d) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join10.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join10.sql deleted file mode 100644 index d0c84979..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join10.sql +++ /dev/null @@ -1,5 +0,0 @@ -select * from dual t1, - ( - dual left outer join (select * from dual) tt2 using(dummy) - ) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join11.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join11.sql deleted file mode 100644 index ca1db605..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join11.sql +++ /dev/null @@ -1 +0,0 @@ -select * from t1, ( t2 left outer join t3 using(dummy) ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join12.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join12.sql deleted file mode 100644 index 88756517..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join12.sql +++ /dev/null @@ -1,2 +0,0 @@ -select * from dual,( dual left outer join tt2 using(dummy) ) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join13.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join13.sql deleted file mode 100644 index 67fc99df..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join13.sql +++ /dev/null @@ -1,5 +0,0 @@ -select * from t1, - (((( - t2 left outer join t3 using(dummy) - )))) - \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join15.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join15.sql deleted file mode 100644 index 7a7f7085..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join15.sql +++ /dev/null @@ -1,4 +0,0 @@ -select * from dual t1, ( dual t2 join dual t3 using(dummy)) left outer join dual t4 using (dummy) - - - \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join16.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join16.sql deleted file mode 100644 index e1ef2228..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join16.sql +++ /dev/null @@ -1,5 +0,0 @@ -select * from dual t1, - dual t2 join dual t3 using(dummy) - left outer join dual t4 using(dummy) - left outer join dual t5 using(dummy) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join17.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join17.sql deleted file mode 100644 index 24cfc6f2..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join17.sql +++ /dev/null @@ -1,7 +0,0 @@ -select * -from hdr a -inner join sh s -inner join ca c -on c.id = s.id -on a.va = s.va - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join19.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join19.sql deleted file mode 100644 index 6ac41ea0..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join19.sql +++ /dev/null @@ -1 +0,0 @@ -select d1.*, d2.* from dual d1 cross join dual d2 diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join20.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join20.sql deleted file mode 100644 index c95dfae0..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join20.sql +++ /dev/null @@ -1 +0,0 @@ -select d1.*, d2.* from dual cross join dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join21.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join21.sql deleted file mode 100644 index 918212b4..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/join21.sql +++ /dev/null @@ -1,2 +0,0 @@ -select * from sys.dual natural join sys.dual - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier01.sql deleted file mode 100644 index 0628c08d..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier01.sql +++ /dev/null @@ -1 +0,0 @@ -select timestamp, avg, cume_dist from nulls diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier02.sql deleted file mode 100644 index a2b6c0ae..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier02.sql +++ /dev/null @@ -1 +0,0 @@ -select m.model from model diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier04.sql deleted file mode 100644 index ce69961e..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier04.sql +++ /dev/null @@ -1,6 +0,0 @@ -(select bs.keep keep, bs.keep_until keep_until -from v$backup_set bs) -union all -(select null keep, null keep_until -from v$backup_piece bp) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier05.sql deleted file mode 100644 index 87e83911..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/keywordasidentifier05.sql +++ /dev/null @@ -1 +0,0 @@ -select exception from exception \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer01.sql deleted file mode 100644 index f9eae8c0..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer01.sql +++ /dev/null @@ -1,2 +0,0 @@ -select * from dual where 1 < > 2 and 1 ! = 2 and 1 ^ /*aaa */ = 2 - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer02.sql deleted file mode 100644 index 15aaf848..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer02.sql +++ /dev/null @@ -1,2 +0,0 @@ -select 'A' | | 'B' from dual - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer03.sql deleted file mode 100644 index 23769197..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer03.sql +++ /dev/null @@ -1,2 +0,0 @@ -select :1, :X, :1 + 1, 1 + :2 from A where A=:3 and b= :4 and c= :5 and :A = :b - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer04.sql deleted file mode 100644 index c3931e03..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer04.sql +++ /dev/null @@ -1 +0,0 @@ -select tbl$or$idx$part$num("sys"."wrh$_seg_stat",0,4,0,"rowid") as c1 from t1 diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer05.sql deleted file mode 100644 index 8dcc674c..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/lexer05.sql +++ /dev/null @@ -1 +0,0 @@ -select tbl$or$idx$part$num("sys"."wrh:_seg_stat",0,4,0,"rowid") as c1 from t1 diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/like01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/like01.sql deleted file mode 100644 index 5b41b6d8..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/like01.sql +++ /dev/null @@ -1,5 +0,0 @@ -select last_name -from employees -where last_name -like '%a\_b%' escape '\' -order by last_name diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause06.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause06.sql deleted file mode 100644 index 37f0d19b..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/model_clause06.sql +++ /dev/null @@ -1,11 +0,0 @@ -select - key , - dummy -from - t -where - key = 1 -model - dimension by ( key ) - measures ( ( select dummy from dual ) as dummy ) - rules ( ) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/only-parse-test/comment01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/only-parse-test/comment01.sql deleted file mode 100644 index e75f3fc7..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/only-parse-test/comment01.sql +++ /dev/null @@ -1,6 +0,0 @@ --- com1 -select * /* -com2 */ -from dual -- com3 - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/only-parse-test/numbers02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/only-parse-test/numbers02.sql deleted file mode 100644 index 06405816..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/only-parse-test/numbers02.sql +++ /dev/null @@ -1,11 +0,0 @@ -select 25 -, 1.-+.5 -, 1.+.5 -, 1.+.5D -, 1.+.5DM -, 1.D -, 1.M -, .5M -, .5DM -from dual - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by01.sql deleted file mode 100644 index ab2a794f..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by01.sql +++ /dev/null @@ -1 +0,0 @@ -select * from dual order by 1 diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by02.sql deleted file mode 100644 index 2abe954f..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by02.sql +++ /dev/null @@ -1 +0,0 @@ -select * from dual order by 1 asc diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by03.sql deleted file mode 100644 index 517b05a5..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by03.sql +++ /dev/null @@ -1 +0,0 @@ -select * from dual order by m.year, m.title, f(a) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by04.sql deleted file mode 100644 index 0c60c340..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by04.sql +++ /dev/null @@ -1 +0,0 @@ -select * from dual order by a nulls first, b nulls last diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by05.sql deleted file mode 100644 index 5ae8f426..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by05.sql +++ /dev/null @@ -1 +0,0 @@ -select * from dual order siblings by a nulls first, b nulls last, c nulls last, d nulls last, e nulls last \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by06.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by06.sql deleted file mode 100644 index 9127e629..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/order_by06.sql +++ /dev/null @@ -1 +0,0 @@ -with a as (select * from dual order by 1) select * from a diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot01.sql deleted file mode 100644 index 98db5746..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot01.sql +++ /dev/null @@ -1,6 +0,0 @@ -select * from pivot_table - unpivot (yearly_total for order_mode in (store as 'direct', - internet as 'online')) - order by year, order_mode - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot04.sql deleted file mode 100644 index 899d2121..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot04.sql +++ /dev/null @@ -1,20 +0,0 @@ -select value -from -( - ( - select - 'a' v1, - 'e' v2, - 'i' v3, - 'o' v4, - 'u' v5 - from dual - ) - unpivot - ( - value - for value_type in - (v1,v2,v3,v4,v5) - ) - ) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot08.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot08.sql deleted file mode 100644 index db7d5676..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/pivot08.sql +++ /dev/null @@ -1,4 +0,0 @@ -select * -from (select product_code, quantity - from pivot_test) -pivot (sum(quantity) as sum_quantity for product_code in ('a' as a, 'b' as b, 'c' as c)) \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring09.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring09.sql deleted file mode 100644 index b7a1f365..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring09.sql +++ /dev/null @@ -1,8 +0,0 @@ -with rn as ( - select rownum rn - from dual - connect by level <= (select max(cases) from t1)) -select pname -from t1, rn -where rn <= cases -order by pname diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring12.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring12.sql deleted file mode 100644 index 00bd06f2..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/query_factoring12.sql +++ /dev/null @@ -1,2 +0,0 @@ -with days as (select (select trunc(sysdate, 'MONTH') from dual) + rownum -1 as d from dual connect by rownum < 31) -select d from days where (trunc(d) - trunc(d,'IW') +1 ) not in (6,7) and d <= last_day(sysdate) \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/returning01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/returning01.sql deleted file mode 100644 index 0aacd037..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/returning01.sql +++ /dev/null @@ -1,5 +0,0 @@ -update emp -set ename = lower(ename) -where job = :jobs(i) -returning empno -bulk collect into :empnos diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/sample01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/sample01.sql deleted file mode 100644 index 605b0338..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/sample01.sql +++ /dev/null @@ -1,4 +0,0 @@ -select * from -( -select 1 as c1 from "sys"."obj$" sample block (14.285714 , 1) seed (1) "o" -) samplesub diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/set01.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/set01.sql deleted file mode 100644 index b370b47c..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/set01.sql +++ /dev/null @@ -1,6 +0,0 @@ -select nt - , set(nt) as nt_set - from ( - select varchar2_ntt('a','b','c','c') as nt - from dual - ) \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/set02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/set02.sql deleted file mode 100644 index fee2c774..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/set02.sql +++ /dev/null @@ -1,2 +0,0 @@ -select nt.column_value as distinct_element - from table(set(varchar2_ntt('a','b','c','c'))) nt \ No newline at end of file diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple02.sql deleted file mode 100644 index 459fb205..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple02.sql +++ /dev/null @@ -1,3 +0,0 @@ -select employee_id from (select employee_id+1 as employee_id from employees) - for update - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple03.sql deleted file mode 100644 index 3ca7d892..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple03.sql +++ /dev/null @@ -1,3 +0,0 @@ -select employee_id from (select employee_id+1 as employee_id from employees) - for update of employee_id - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple04.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple04.sql deleted file mode 100644 index 07aacdcb..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple04.sql +++ /dev/null @@ -1,11 +0,0 @@ -select * from -( - ( - select * from dual - ) - unpivot - ( - value for value_type in (dummy) - ) -) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple05.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple05.sql deleted file mode 100644 index b1d5077a..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple05.sql +++ /dev/null @@ -1,9 +0,0 @@ -select * from -( -select * from a - unpivot - ( - value for value_type in (dummy) - ) -) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple06.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple06.sql deleted file mode 100644 index 3a443804..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple06.sql +++ /dev/null @@ -1,2 +0,0 @@ -select * from (( select * from dual)) a - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple07.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple07.sql deleted file mode 100644 index c5a60362..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple07.sql +++ /dev/null @@ -1,3 +0,0 @@ -select * from dual for update -of dual - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple08.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple08.sql deleted file mode 100644 index d9980f3b..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple08.sql +++ /dev/null @@ -1,2 +0,0 @@ -select a, b, c, d, e, 1, 2, f(a,b,c,1+1) from dual - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple09.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple09.sql deleted file mode 100644 index d2637f4b..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple09.sql +++ /dev/null @@ -1,7 +0,0 @@ -select a||last_name, - employee_id - from employees - start with job_id = 'ad_vp' - connect by prior employee_id = manager_id - - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple10.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple10.sql deleted file mode 100644 index 753ad3ad..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple10.sql +++ /dev/null @@ -1 +0,0 @@ -select a as over from over diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple11.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple11.sql deleted file mode 100644 index ed220533..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple11.sql +++ /dev/null @@ -1 +0,0 @@ -select a.* from dual diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple12.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple12.sql deleted file mode 100644 index 33f65c6b..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple12.sql +++ /dev/null @@ -1,7 +0,0 @@ -select - +1, - t2.division_name as aaaa, - a.*, - sum(t3.amount) -from dual - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple13.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple13.sql deleted file mode 100644 index e09eef0c..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/simple13.sql +++ /dev/null @@ -1 +0,0 @@ -select * from (dual), (dual d), (dual) d diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union02.sql deleted file mode 100644 index a4fad19a..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union02.sql +++ /dev/null @@ -1,4 +0,0 @@ -(select distinct job_id from hr.jobs) -union all -(select distinct job_id from hr.job_history) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union03.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union03.sql deleted file mode 100644 index 19275978..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union03.sql +++ /dev/null @@ -1,6 +0,0 @@ -(select distinct job_id from hr.jobs) -union all -( - select distinct job_id from hr.job_history -) - diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union08.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union08.sql deleted file mode 100644 index 27039011..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/union08.sql +++ /dev/null @@ -1,5 +0,0 @@ -select * from dual where exists ( - (select * from dual) - union all - (select * from dual) -) diff --git a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/xmltable02.sql b/src/test/resources/net/sf/jsqlparser/test/oracle-tests/xmltable02.sql deleted file mode 100644 index c5f54409..00000000 --- a/src/test/resources/net/sf/jsqlparser/test/oracle-tests/xmltable02.sql +++ /dev/null @@ -1,2 +0,0 @@ -select xmlelement("other_attrs", xmlelement("parsing_user_id", parsing_user_id)).getClobVal() other -from f