Showing preview only (288K chars total). Download the full file or copy to clipboard to get everything.
Repository: mtxr/SQLTools
Branch: master
Commit: 1af1303dff8f
Files: 66
Total size: 270.1 KB
Directory structure:
gitextract_blnxvnte/
├── .bumpversion.cfg
├── .gitignore
├── .mention-bot
├── .no-sublime-package
├── Default (Linux).sublime-keymap
├── Default (OSX).sublime-keymap
├── Default (Windows).sublime-keymap
├── Default.sublime-commands
├── ISSUE_TEMPLATE.md
├── LICENSE.md
├── Main.sublime-menu
├── README.md
├── SQLTools.py
├── SQLTools.sublime-settings
├── SQLToolsAPI/
│ ├── Command.py
│ ├── Completion.py
│ ├── Connection.py
│ ├── History.py
│ ├── ParseUtils.py
│ ├── README.md
│ ├── Storage.py
│ ├── Utils.py
│ ├── __init__.py
│ └── lib/
│ └── sqlparse/
│ ├── __init__.py
│ ├── __main__.py
│ ├── cli.py
│ ├── compat.py
│ ├── engine/
│ │ ├── __init__.py
│ │ ├── filter_stack.py
│ │ ├── grouping.py
│ │ └── statement_splitter.py
│ ├── exceptions.py
│ ├── filters/
│ │ ├── __init__.py
│ │ ├── aligned_indent.py
│ │ ├── others.py
│ │ ├── output.py
│ │ ├── reindent.py
│ │ ├── right_margin.py
│ │ └── tokens.py
│ ├── formatter.py
│ ├── keywords.py
│ ├── lexer.py
│ ├── sql.py
│ ├── tokens.py
│ └── utils.py
├── SQLToolsConnections.sublime-settings
├── SQLToolsSavedQueries.sublime-settings
├── messages/
│ ├── install.md
│ ├── v0.1.6.md
│ ├── v0.2.0.md
│ ├── v0.3.0.md
│ ├── v0.8.2.md
│ ├── v0.9.0.md
│ ├── v0.9.1.md
│ ├── v0.9.10.md
│ ├── v0.9.11.md
│ ├── v0.9.12.md
│ ├── v0.9.2.md
│ ├── v0.9.3.md
│ ├── v0.9.4.md
│ ├── v0.9.5.md
│ ├── v0.9.6.md
│ ├── v0.9.7.md
│ ├── v0.9.8.md
│ └── v0.9.9.md
└── messages.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .bumpversion.cfg
================================================
[bumpversion]
current_version = 0.9.12
files = SQLTools.py
tag = True
commit = True
================================================
FILE: .gitignore
================================================
.DS_Store
*.pyc
*.py~
*.sublime-workspace
.idea/
================================================
FILE: .mention-bot
================================================
{
"maxReviewers": 2,
"skipCollaboratorPR": true
}
================================================
FILE: .no-sublime-package
================================================
================================================
FILE: Default (Linux).sublime-keymap
================================================
[
{ "keys": ["ctrl+alt+e"], "command": "st_select_connection" },
{ "keys": ["ctrl+e", "ctrl+e"], "command": "st_execute" },
{ "keys": ["ctrl+e", "ctrl+a"], "command": "st_execute_all" },
{ "keys": ["ctrl+e", "ctrl+x"], "command": "st_explain_plan" },
{ "keys": ["ctrl+e", "ctrl+h"], "command": "st_history" },
{ "keys": ["ctrl+e", "ctrl+s"], "command": "st_show_records" },
{ "keys": ["ctrl+e", "ctrl+d"], "command": "st_desc_table" },
{ "keys": ["ctrl+e", "ctrl+f"], "command": "st_desc_function" },
{ "keys": ["ctrl+e", "ctrl+b"], "command": "st_format" },
{ "keys": ["ctrl+e", "ctrl+q"], "command": "st_save_query" },
{ "keys": ["ctrl+e", "ctrl+r"], "command": "st_remove_saved_query" },
{ "keys": ["ctrl+e", "ctrl+l"], "command": "st_list_queries", "args": {"mode" : "run"}},
{ "keys": ["ctrl+e", "ctrl+o"], "command": "st_list_queries", "args": {"mode" : "open"}},
{ "keys": ["ctrl+e", "ctrl+i"], "command": "st_list_queries", "args": {"mode" : "insert"}}
]
================================================
FILE: Default (OSX).sublime-keymap
================================================
[
{ "keys": ["ctrl+super+e"], "command": "st_select_connection" },
{ "keys": ["ctrl+e", "ctrl+e"], "command": "st_execute" },
{ "keys": ["ctrl+e", "ctrl+a"], "command": "st_execute_all" },
{ "keys": ["ctrl+e", "ctrl+x"], "command": "st_explain_plan" },
{ "keys": ["ctrl+e", "ctrl+h"], "command": "st_history" },
{ "keys": ["ctrl+e", "ctrl+s"], "command": "st_show_records" },
{ "keys": ["ctrl+e", "ctrl+d"], "command": "st_desc_table" },
{ "keys": ["ctrl+e", "ctrl+f"], "command": "st_desc_function" },
{ "keys": ["ctrl+e", "ctrl+b"], "command": "st_format" },
{ "keys": ["ctrl+e", "ctrl+q"], "command": "st_save_query" },
{ "keys": ["ctrl+e", "ctrl+r"], "command": "st_remove_saved_query" },
{ "keys": ["ctrl+e", "ctrl+l"], "command": "st_list_queries", "args": {"mode" : "run"}},
{ "keys": ["ctrl+e", "ctrl+o"], "command": "st_list_queries", "args": {"mode" : "open"}},
{ "keys": ["ctrl+e", "ctrl+i"], "command": "st_list_queries", "args": {"mode" : "insert"}}
]
================================================
FILE: Default (Windows).sublime-keymap
================================================
[
{ "keys": ["ctrl+alt+e"], "command": "st_select_connection" },
{ "keys": ["ctrl+e", "ctrl+e"], "command": "st_execute" },
{ "keys": ["ctrl+e", "ctrl+a"], "command": "st_execute_all" },
{ "keys": ["ctrl+e", "ctrl+x"], "command": "st_explain_plan" },
{ "keys": ["ctrl+e", "ctrl+h"], "command": "st_history" },
{ "keys": ["ctrl+e", "ctrl+s"], "command": "st_show_records" },
{ "keys": ["ctrl+e", "ctrl+d"], "command": "st_desc_table" },
{ "keys": ["ctrl+e", "ctrl+f"], "command": "st_desc_function" },
{ "keys": ["ctrl+e", "ctrl+b"], "command": "st_format" },
{ "keys": ["ctrl+e", "ctrl+q"], "command": "st_save_query" },
{ "keys": ["ctrl+e", "ctrl+r"], "command": "st_remove_saved_query" },
{ "keys": ["ctrl+e", "ctrl+l"], "command": "st_list_queries", "args": {"mode" : "run"}},
{ "keys": ["ctrl+e", "ctrl+o"], "command": "st_list_queries", "args": {"mode" : "open"}},
{ "keys": ["ctrl+e", "ctrl+i"], "command": "st_list_queries", "args": {"mode" : "insert"}}
]
================================================
FILE: Default.sublime-commands
================================================
[
{
"caption": "ST: Select Connection",
"command": "st_select_connection"
},
{
"caption": "ST: Execute",
"command": "st_execute"
},
{
"caption": "ST: Execute All File",
"command": "st_execute_all"
},
{
"caption": "ST: Explain Plan",
"command": "st_explain_plan"
},
{
"caption": "ST: History",
"command": "st_history"
},
{
"caption": "ST: Show Table Records",
"command": "st_show_records"
},
{
"caption": "ST: Table Description",
"command": "st_desc_table"
},
{
"caption": "ST: Function Description",
"command": "st_desc_function"
},
{
"caption": "ST: Refresh Connection Data",
"command": "st_refresh_connection_data"
},
{
"caption": "ST: Save Query",
"command": "st_save_query"
},
{
"caption": "ST: Remove Saved Query",
"command": "st_remove_saved_query"
},
{
"caption": "ST: List and Run Saved Queries",
"command": "st_list_queries",
"args" : {"mode": "run"}
},
{
"caption": "ST: List and Open Saved Queries",
"command": "st_list_queries",
"args" : {"mode": "open"}
},
{
"caption": "ST: List and Insert Saved Queries",
"command": "st_list_queries",
"args" : {"mode": "insert"}
},
{
"caption": "ST: Format SQL",
"command": "st_format"
},
{
"caption": "ST: Format SQL All File",
"command": "st_format_all"
},
{
"caption": "ST: About",
"command": "st_version"
},
{
"caption": "ST: Setup Connections",
"command": "edit_settings", "args":
{
"base_file": "${packages}/SQLTools/SQLToolsConnections.sublime-settings",
"default": "// List all your connections to DBs here\n{\n\t\"connections\": {\n\t\t$0\n\t},\n\t\"default\": null\n}"
}
},
{
"caption": "ST: Settings",
"command": "edit_settings", "args":
{
"base_file": "${packages}/SQLTools/SQLTools.sublime-settings",
"default": "// Settings in here override those in \"SQLTools/SQLTools.sublime-settings\"\n{\n\t$0\n}\n"
}
}
]
================================================
FILE: ISSUE_TEMPLATE.md
================================================
> This issue template helps us understand your SQLTools issues better.
>
> You don't need to stick to this template, but please try to guide us to reproduce the errors or understand your feature requests.
>
> Before submitting an issue, please consider these things first:
> * Are you running the latest version? If not, try to upgrade.
> * Did you check the [Setup Guide](https://code.mteixeira.dev/SublimeText-SQLTools/)?
> * Did you check the logs in console (``Ctrl+` `` or select *View → Show Console*)?
### Issue Type
Feature Request |
Bug/Error |
Question |
Other
### Description
[Description of the bug / feature / question]
### Version
- *SQLTools Version*: vX.Y.Z
- *OS*: (Windows, Mac, Linux)
- *RDBMS*: (MySQL, PostgreSQL, Oracle, MSSQL, SQLite, Vertica, ...)
> You can get this information by executing `ST: About` from Sublime `Command Palette`.
### Steps to Reproduce (For bugfixes)
1. [First Step]
2. [Second Step]
3. [and so on...]
**Expected behavior:** [What you expected to happen]
**Actual behavior:** [What actually happened]
================================================
FILE: LICENSE.md
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, 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
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If 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 convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU 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
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 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 Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
================================================
FILE: Main.sublime-menu
================================================
[
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children":
[
{
"caption": "Package Settings",
"mnemonic": "P",
"id": "package-settings",
"children":
[
{
"caption": "SQLTools",
"children":
[
{
"caption": "Connections",
"command": "edit_settings", "args":
{
"base_file": "${packages}/SQLTools/SQLToolsConnections.sublime-settings",
"default": "// List all your connections to DBs here\n{\n\t\"connections\": {\n\t\t$0\n\t},\n\t\"default\": null\n}"
}
},
{
"caption": "Settings",
"command": "edit_settings", "args":
{
"base_file": "${packages}/SQLTools/SQLTools.sublime-settings",
"default": "// Settings in here override those in \"SQLTools/SQLTools.sublime-settings\"\n{\n\t$0\n}\n"
}
},
{
"caption": "Key Bindings",
"command": "edit_settings", "args":
{
"base_file": "${packages}/SQLTools/Default ($platform).sublime-keymap",
"default": "[\n\t$0\n]\n"
}
}
]
}
]
}
]
}
]
================================================
FILE: README.md
================================================
 SQLTools
===============
> Looking for maintainers! I'm currently using VSCode as my editor, so I'm not actively maintaining this project anymore.
>
> If you are interested in maintaining this project, contact me.
>
> If you are interested in checking VSCode version, see [https://github.com/mtxr/vscode-sqltools](https://github.com/mtxr/vscode-sqltools).
[](https://gitter.im/SQLTools/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Your swiss knife SQL for Sublime Text.
Write your SQL with smart completions and handy table and function definitions, execute SQL and explain queries, format your queries and save them in history.
Project website: [https://code.mteixeira.dev/SublimeText-SQLTools/](https://code.mteixeira.dev/SublimeText-SQLTools/)
> If you are looking for VSCode version go to [https://github.com/mtxr/vscode-sqltools](https://github.com/mtxr/vscode-sqltools).
## Donate
SQLTools was developed with ♥ to save us time during our programming journey. But It also takes me time and efforts to develop SQLTools.
SQLTools will save you (for sure) a lot of time and help you to increase your productivity so, I hope you can donate and help SQLTools to become more awesome than ever.
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RSMB6DGK238V8" title="Donate to this project using Paypal"><img src="https://img.shields.io/badge/paypal-donate-yellow.svg" alt="PayPal donate button" /></a>
## Features
* Works with PostgreSQL, MySQL, Oracle, MSSQL, SQLite, Vertica, Firebird and Snowflake
* Smart completions (except SQLite)
* Run SQL Queries <kbd>CTRL+e</kbd>, <kbd>CTRL+e</kbd>

* View table description <kbd>CTRL+e</kbd>, <kbd>CTRL+d</kbd>

* Show table records <kbd>CTRL+e</kbd>, <kbd>CTRL+s</kbd>

* Show explain plan for queries <kbd>CTRL+e</kbd>, <kbd>CTRL+x</kbd>
* Formatting SQL Queries <kbd>CTRL+e</kbd>, <kbd>CTRL+b</kbd>

* View Queries history <kbd>CTRL+e</kbd>, <kbd>CTRL+h</kbd>
* Save queries <kbd>CTRL+e</kbd>, <kbd>CTRL+q</kbd>
* List and Run saved queries <kbd>CTRL+e</kbd>, <kbd>CTRL+l</kbd>
* Remove saved queries <kbd>CTRL+e</kbd>, <kbd>CTRL+r</kbd>
* Threading support to prevent lockups
* Query timeout (kill thread if query takes too long)
## Installing
### Using Sublime Package Control
If you are using [Sublime Package Control](https://packagecontrol.io/packages/SQLTools), you can easily install SQLTools via the `Package Control: Install Package` menu item.
1. Press <kbd>CTRL+SHIFT+p</kbd>
2. Type *`Install Package`*
3. Find *`SQLTools`*
4. Wait & Done!
### Download Manually
I strongly recommend you to use Package Control. It helps you to keep the package updated with the last version.
1. Download the latest released zip file [here](https://github.com/mtxr/SublimeText-SQLTools/releases/latest)
2. Unzip the files and rename the folder to `SQLTools`
3. Find your `Packages` directory using the menu item `Preferences -> Browse Packages...`
4. Copy the folder into your Sublime Text `Packages` directory
### Using SQLTools with Mac OS X
Sublime Text has it's environment variable `PATH` set from launchctl, not by your shell. Binaries installed by packages such as homebrew, for instance `psql` DB CLI for `PostgreSQL`, cannot be found by Sublime Text and results in error in Sublime Text console by `SQLTools`. Installing the package `Fix Mac Path` or setting the full path to your DB CLI binary in `SQLTools.sublime-settings` resolves this issue. Package can be downloaded via [PackageControl](https://packagecontrol.io/packages/Fix%20Mac%20Path) or [github](https://github.com/int3h/SublimeFixMacPath).
## Contributors
This project exists thanks to all the people who [contribute](https://github.com/mtxr/SublimeText-SQLTools/graphs/contributors).
## Configuration
Documentation: [https://code.mteixeira.dev/SublimeText-SQLTools/](https://code.mteixeira.dev/SublimeText-SQLTools/)
================================================
FILE: SQLTools.py
================================================
__version__ = "v0.9.12"
import sys
import os
import re
import logging
from collections import OrderedDict
import sublime
from sublime_plugin import WindowCommand, EventListener, TextCommand
from Default.paragraph import expand_to_paragraph
from .SQLToolsAPI import Utils
from .SQLToolsAPI.Storage import Storage, Settings
from .SQLToolsAPI.Connection import Connection
from .SQLToolsAPI.History import History
from .SQLToolsAPI.Completion import Completion
MESSAGE_RUNNING_CMD = 'Executing SQL command...'
SYNTAX_PLAIN_TEXT = 'Packages/Text/Plain text.tmLanguage'
SYNTAX_SQL = 'Packages/SQL/SQL.tmLanguage'
SQLTOOLS_SETTINGS_FILE = 'SQLTools.sublime-settings'
SQLTOOLS_CONNECTIONS_FILE = 'SQLToolsConnections.sublime-settings'
SQLTOOLS_QUERIES_FILE = 'SQLToolsSavedQueries.sublime-settings'
USER_FOLDER = None
DEFAULT_FOLDER = None
SETTINGS_FILENAME = None
SETTINGS_FILENAME_DEFAULT = None
CONNECTIONS_FILENAME = None
CONNECTIONS_FILENAME_DEFAULT = None
QUERIES_FILENAME = None
QUERIES_FILENAME_DEFAULT = None
settingsStore = None
queriesStore = None
connectionsStore = None
historyStore = None
# create pluggin logger
DEFAULT_LOG_LEVEL = logging.WARNING
plugin_logger = logging.getLogger(__package__)
# some plugins are not playing by the rules and configure the root loger
plugin_logger.propagate = False
if not plugin_logger.handlers:
plugin_logger_handler = logging.StreamHandler()
plugin_logger_formatter = logging.Formatter("[{name}] {levelname}: {message}", style='{')
plugin_logger_handler.setFormatter(plugin_logger_formatter)
plugin_logger.addHandler(plugin_logger_handler)
plugin_logger.setLevel(DEFAULT_LOG_LEVEL)
logger = logging.getLogger(__name__)
def getSublimeUserFolder():
return os.path.join(sublime.packages_path(), 'User')
def startPlugin():
global USER_FOLDER, DEFAULT_FOLDER
global SETTINGS_FILENAME, SETTINGS_FILENAME_DEFAULT
global CONNECTIONS_FILENAME, CONNECTIONS_FILENAME_DEFAULT
global QUERIES_FILENAME, QUERIES_FILENAME_DEFAULT
global settingsStore, queriesStore, connectionsStore, historyStore
USER_FOLDER = getSublimeUserFolder()
DEFAULT_FOLDER = os.path.dirname(__file__)
SETTINGS_FILENAME = os.path.join(USER_FOLDER, SQLTOOLS_SETTINGS_FILE)
SETTINGS_FILENAME_DEFAULT = os.path.join(DEFAULT_FOLDER, SQLTOOLS_SETTINGS_FILE)
CONNECTIONS_FILENAME = os.path.join(USER_FOLDER, SQLTOOLS_CONNECTIONS_FILE)
CONNECTIONS_FILENAME_DEFAULT = os.path.join(DEFAULT_FOLDER, SQLTOOLS_CONNECTIONS_FILE)
QUERIES_FILENAME = os.path.join(USER_FOLDER, SQLTOOLS_QUERIES_FILE)
QUERIES_FILENAME_DEFAULT = os.path.join(DEFAULT_FOLDER, SQLTOOLS_QUERIES_FILE)
try:
settingsStore = Settings(SETTINGS_FILENAME, default=SETTINGS_FILENAME_DEFAULT)
except Exception as e:
msg = '{0}: Failed to parse {1} file'.format(__package__, SQLTOOLS_SETTINGS_FILE)
logging.exception(msg)
Window().status_message(msg)
try:
connectionsStore = Settings(CONNECTIONS_FILENAME, default=CONNECTIONS_FILENAME_DEFAULT)
except Exception as e:
msg = '{0}: Failed to parse {1} file'.format(__package__, SQLTOOLS_CONNECTIONS_FILE)
logging.exception(msg)
Window().status_message(msg)
queriesStore = Storage(QUERIES_FILENAME, default=QUERIES_FILENAME_DEFAULT)
historyStore = History(settingsStore.get('history_size', 100))
if settingsStore.get('debug', False):
plugin_logger.setLevel(logging.DEBUG)
else:
plugin_logger.setLevel(DEFAULT_LOG_LEVEL)
Connection.setTimeout(settingsStore.get('thread_timeout', 15))
Connection.setHistoryManager(historyStore)
logger.info('plugin (re)loaded')
logger.info('version %s', __version__)
def readConnections():
mergedConnections = {}
# fixes #39 and #45
if not connectionsStore:
startPlugin()
# global connections
globalConnectionsDict = connectionsStore.get('connections', {})
# project-specific connections
projectConnectionsDict = {}
projectData = Window().project_data()
if projectData:
projectConnectionsDict = projectData.get('connections', {})
# merge connections
mergedConnections = globalConnectionsDict.copy()
mergedConnections.update(projectConnectionsDict)
ordered = OrderedDict(sorted(mergedConnections.items()))
return ordered
def getDefaultConnectionName():
default = connectionsStore.get('default', False)
if not default:
return
return default
def createOutput(panel=None, syntax=None, prependText=None):
onInitialOutput = None
if not panel:
panel, onInitialOutput = getOutputPlace(syntax)
if prependText:
panel.run_command('append', {'characters': str(prependText)})
initial = True
def append(outputContent):
nonlocal initial
if initial:
initial = False
if onInitialOutput:
onInitialOutput()
# append content
panel.set_read_only(False)
panel.run_command('append', {'characters': outputContent})
panel.set_read_only(True)
return append
def toNewTab(content, name="", suffix="SQLTools Saved Query"):
resultContainer = Window().new_file()
resultContainer.set_name(
((name + " - ") if name != "" else "") + suffix)
resultContainer.set_syntax_file(SYNTAX_SQL)
resultContainer.run_command('append', {'characters': content})
def insertContent(content):
view = View()
# getting the settings local to this view/tab
viewSettings = view.settings()
# saving the original settings for "auto_indent", or True if none set
autoIndent = viewSettings.get('auto_indent', True)
# turn off automatic indenting otherwise the tabbing of the original
# string is not respected after a newline is encountered
viewSettings.set('auto_indent', False)
view.run_command('insert', {'characters': content})
# restore "auto_indent" setting
viewSettings.set('auto_indent', autoIndent)
def getOutputPlace(syntax=None, name="SQLTools Result"):
showResultOnWindow = settingsStore.get('show_result_on_window', False)
if not showResultOnWindow:
resultContainer = Window().find_output_panel(name)
if resultContainer is None:
resultContainer = Window().create_output_panel(name)
else:
resultContainer = None
views = Window().views()
for view in views:
if view.name() == name:
resultContainer = view
break
if not resultContainer:
resultContainer = Window().new_file()
resultContainer.set_name(name)
resultContainer.set_scratch(True) # avoids prompting to save
resultContainer.set_read_only(True)
resultContainer.settings().set("word_wrap", "false")
def onInitialOutputCallback():
if settingsStore.get('clear_output', False):
resultContainer.set_read_only(False)
resultContainer.run_command('select_all')
resultContainer.run_command('left_delete')
resultContainer.set_read_only(True)
# set custom syntax highlight, only if one was passed explicitly,
# otherwise use Plain Text syntax
if syntax:
# if custom and SQL related, use that, otherwise defaults to SQL
if 'sql' in syntax.lower():
resultContainer.set_syntax_file(syntax)
else:
resultContainer.set_syntax_file(SYNTAX_SQL)
else:
resultContainer.set_syntax_file(SYNTAX_PLAIN_TEXT)
# hide previously set command running message (if any)
Window().status_message('')
if not showResultOnWindow:
# if case this is an output pannel, show it
Window().run_command("show_panel", {"panel": "output." + name})
if settingsStore.get('focus_on_result', False):
Window().focus_view(resultContainer)
return resultContainer, onInitialOutputCallback
def getSelectionText():
text = []
selectionRegions = getSelectionRegions()
if not selectionRegions:
return text
for region in selectionRegions:
text.append(View().substr(region))
return text
def getSelectionRegions():
expandedRegions = []
if not View().sel():
return None
# If we would need to expand the empty selection, then which type:
# 'file', 'view' = use text of current view
# 'paragraph' = paragraph(s) (text between newlines)
# 'line' = current line(s)
expandTo = settingsStore.get('expand_to', 'file')
if not expandTo:
expandTo = 'file'
# keep compatibility with previous settings
expandToParagraph = settingsStore.get('expand_to_paragraph')
if expandToParagraph is True:
expandTo = 'paragraph'
expandTo = str(expandTo).strip()
if expandTo not in ['file', 'view', 'paragraph', 'line']:
expandTo = 'file'
for region in View().sel():
# if user did not select anything - expand selection,
# otherwise use the currently selected region
if region.empty():
if expandTo in ['file', 'view']:
region = sublime.Region(0, View().size())
# no point in further iterating over selections, just use entire file
return [region]
elif expandTo == 'paragraph':
region = expand_to_paragraph(View(), region.b)
else:
# expand to line
region = View().line(region)
# even if we could not expand, avoid adding empty regions
if not region.empty():
expandedRegions.append(region)
return expandedRegions
def getCurrentSyntax():
view = View()
currentSyntax = None
if view:
currentSyntax = view.settings().get('syntax')
return currentSyntax
class ST(EventListener):
connectionDict = None
conn = None
tables = []
columns = []
functions = []
completion = None
@staticmethod
def bootstrap():
ST.connectionDict = readConnections()
ST.setDefaultConnection()
@staticmethod
def setDefaultConnection():
default = getDefaultConnectionName()
if not default:
return
if default not in ST.connectionDict:
logger.error('connection "%s" set as default, but it does not exists', default)
return
logger.info('default connection is set to "%s"', default)
ST.setConnection(default)
@staticmethod
def setConnection(connectionName, callback=None):
if not connectionName:
return
if connectionName not in ST.connectionDict:
return
settings = settingsStore.all()
config = ST.connectionDict.get(connectionName)
promptKeys = [key for key, value in config.items() if value is None]
promptDict = {}
logger.info('[setConnection] prompt keys {}'.format(promptKeys))
def mergeConfig(config, promptedKeys=None):
merged = config.copy()
if promptedKeys:
merged.update(promptedKeys)
return merged
def createConnection(connectionName, config, settings, callback=None):
# if DB cli binary could not be found in path a FileNotFoundError is thrown
try:
ST.conn = Connection(connectionName, config, settings=settings)
except FileNotFoundError as e:
# use only first line of the Exception in status message
Window().status_message(__package__ + ": " + str(e).splitlines()[0])
raise e
ST.loadConnectionData(callback)
if not promptKeys:
createConnection(connectionName, config, settings, callback)
return
def setMissingKey(key, value):
nonlocal promptDict
if value is None:
return
promptDict[key] = value
if promptKeys:
promptNext()
else:
merged = mergeConfig(config, promptDict)
createConnection(connectionName, merged, settings, callback)
def promptNext():
nonlocal promptKeys
if not promptKeys:
merged = mergeConfig(config, promptDict)
createConnection(connectionName, merged, settings, callback)
key = promptKeys.pop();
Window().show_input_panel(
'Connection ' + key,
'',
lambda userInput: setMissingKey(key, userInput),
None,
None)
promptNext()
@staticmethod
def loadConnectionData(callback=None):
# clear the list of identifiers (in case connection is changed)
ST.tables = []
ST.columns = []
ST.functions = []
ST.completion = None
objectsLoaded = 0
if not ST.conn:
return
def afterAllDataHasLoaded():
ST.completion = Completion(ST.tables, ST.columns, ST.functions, settings=settingsStore)
logger.info('completions loaded')
if (callback):
callback()
def tablesCallback(tables):
ST.tables = tables
nonlocal objectsLoaded
objectsLoaded += 1
logger.info('loaded tables : "{0}"'.format(tables))
if objectsLoaded == 3:
afterAllDataHasLoaded()
def columnsCallback(columns):
ST.columns = columns
nonlocal objectsLoaded
objectsLoaded += 1
logger.info('loaded columns : "{0}"'.format(columns))
if objectsLoaded == 3:
afterAllDataHasLoaded()
def functionsCallback(functions):
ST.functions = functions
nonlocal objectsLoaded
objectsLoaded += 1
logger.info('loaded functions: "{0}"'.format(functions))
if objectsLoaded == 3:
logger.info('all objects loaded')
afterAllDataHasLoaded()
ST.conn.getTables(tablesCallback)
ST.conn.getColumns(columnsCallback)
ST.conn.getFunctions(functionsCallback)
@staticmethod
def selectConnectionQuickPanel(callback=None):
ST.connectionDict = readConnections()
if len(ST.connectionDict) == 0:
sublime.message_dialog('You need to setup your connections first.')
return
def connectionMenuList(connDictionary):
menuItemsList = []
template = '{dbtype}://{user}{host}{port}{db}'
for name, config in ST.connectionDict.items():
dbtype = config.get('type', '')
user = '{}@'.format(config.get('username', '')) if 'username' in config else ''
# user = config.get('username', '')
host=config.get('host', '')
port = ':{}'.format(config.get('port', '')) if 'port' in config else ''
db = '/{}'.format(config.get('database', '')) if 'database' in config else ''
connectionInfo = template.format(
dbtype=dbtype,
user=user,
host=host,
port=port,
db=db)
menuItemsList.append([name, connectionInfo])
menuItemsList.sort()
return menuItemsList
def onConnectionSelected(index, callback):
menuItemsList = connectionMenuList(ST.connectionDict)
if index < 0 or index >= len(menuItemsList):
return
connectionName = menuItemsList[index][0]
ST.setConnection(connectionName, callback)
logger.info('Connection "{0}" selected'.format(connectionName))
menu = connectionMenuList(ST.connectionDict)
# show pannel with callback above
Window().show_quick_panel(menu, lambda index: onConnectionSelected(index, callback))
@staticmethod
def showTablesQuickPanel(callback):
if len(ST.tables) == 0:
sublime.message_dialog('Your database has no tables.')
return
ST.showQuickPanelWithSelection(ST.tables, callback)
@staticmethod
def showFunctionsQuickPanel(callback):
if len(ST.functions) == 0:
sublime.message_dialog('Your database has no functions.')
return
ST.showQuickPanelWithSelection(ST.functions, callback)
@staticmethod
def showQuickPanelWithSelection(arrayOfValues, callback):
w = Window();
view = w.active_view()
selection = view.sel()[0]
initialText = ''
# ignore obvious non-identifier selections
if selection.size() <= 128:
(row_begin,_) = view.rowcol(selection.begin())
(row_end,_) = view.rowcol(selection.end())
# only consider selections within same line
if row_begin == row_end:
initialText = view.substr(selection)
w.show_quick_panel(arrayOfValues, callback)
w.run_command('insert', {'characters': initialText})
w.run_command("select_all")
@staticmethod
def on_query_completions(view, prefix, locations):
# skip completions, if no connection
if ST.conn is None:
return None
if ST.completion is None:
return None
if ST.completion.isDisabled():
return None
if not len(locations):
return None
ignoreSelectors = ST.completion.getIgnoreSelectors()
if ignoreSelectors:
for selector in ignoreSelectors:
if view.match_selector(locations[0], selector):
return None
activeSelectors = ST.completion.getActiveSelectors()
if activeSelectors:
for selector in activeSelectors:
if view.match_selector(locations[0], selector):
break
else:
return None
# sublimePrefix = prefix
# sublimeCompletions = view.extract_completions(sublimePrefix, locations[0])
# preferably get prefix ourselves instead of using default sublime "prefix".
# Sublime will return only last portion of this preceding text. Given:
# SELECT table.col|
# sublime will return: "col", and we need: "table.col"
# to know more precisely which completions are more appropriate
# get a Region that starts at the beginning of current line
# and ends at current cursor position
currentPoint = locations[0]
lineStartPoint = view.line(currentPoint).begin()
lineStartToLocation = sublime.Region(lineStartPoint, currentPoint)
try:
lineStr = view.substr(lineStartToLocation)
prefix = re.split('[^`\"\w.\$]+', lineStr).pop()
except Exception as e:
logger.debug(e)
# use current paragraph as sql text to parse
sqlRegion = expand_to_paragraph(view, currentPoint)
sql = view.substr(sqlRegion)
sqlToCursorRegion = sublime.Region(sqlRegion.begin(), currentPoint)
sqlToCursor = view.substr(sqlToCursorRegion)
# get completions
autoCompleteList, inhibit = ST.completion.getAutoCompleteList(prefix, sql, sqlToCursor)
# safe check here, so even if we return empty completions and inhibit is true
# we return empty completions to show default sublime completions
if autoCompleteList is None or len(autoCompleteList) == 0:
return None
if inhibit:
return (autoCompleteList, sublime.INHIBIT_WORD_COMPLETIONS)
return autoCompleteList
# #
# # Commands
# #
# Usage for old keybindings defined by users
class StShowConnectionMenu(WindowCommand):
@staticmethod
def run():
Window().run_command('st_select_connection')
class StSelectConnection(WindowCommand):
@staticmethod
def run():
ST.selectConnectionQuickPanel()
class StShowRecords(WindowCommand):
@staticmethod
def run():
if not ST.conn:
ST.selectConnectionQuickPanel(callback=lambda: Window().run_command('st_show_records'))
return
def onTableSelected(index):
if index < 0:
return None
Window().status_message(MESSAGE_RUNNING_CMD)
tableName = ST.tables[index]
prependText = 'Table "{tableName}"\n'.format(tableName=tableName)
return ST.conn.getTableRecords(
tableName,
createOutput(prependText=prependText))
ST.showTablesQuickPanel(callback=onTableSelected)
class StDescTable(WindowCommand):
@staticmethod
def run():
currentSyntax = getCurrentSyntax()
if not ST.conn:
ST.selectConnectionQuickPanel(callback=lambda: Window().run_command('st_desc_table'))
return
def onTableSelected(index):
if index < 0:
return None
Window().status_message(MESSAGE_RUNNING_CMD)
return ST.conn.getTableDescription(ST.tables[index], createOutput(syntax=currentSyntax))
ST.showTablesQuickPanel(callback=onTableSelected)
class StDescFunction(WindowCommand):
@staticmethod
def run():
currentSyntax = getCurrentSyntax()
if not ST.conn:
ST.selectConnectionQuickPanel(callback=lambda: Window().run_command('st_desc_function'))
return
def onFunctionSelected(index):
if index < 0:
return None
Window().status_message(MESSAGE_RUNNING_CMD)
functionName = ST.functions[index].split('(', 1)[0]
return ST.conn.getFunctionDescription(functionName, createOutput(syntax=currentSyntax))
# get everything until first occurrence of "(", e.g. get "function_name"
# from "function_name(int)"
ST.showFunctionsQuickPanel(callback=onFunctionSelected)
class StRefreshConnectionData(WindowCommand):
@staticmethod
def run():
if not ST.conn:
return
ST.loadConnectionData()
class StExplainPlan(WindowCommand):
@staticmethod
def run():
if not ST.conn:
ST.selectConnectionQuickPanel(callback=lambda: Window().run_command('st_explain_plan'))
return
Window().status_message(MESSAGE_RUNNING_CMD)
ST.conn.explainPlan(getSelectionText(), createOutput())
class StExecute(WindowCommand):
@staticmethod
def run():
if not ST.conn:
ST.selectConnectionQuickPanel(callback=lambda: Window().run_command('st_execute'))
return
Window().status_message(MESSAGE_RUNNING_CMD)
ST.conn.execute(getSelectionText(), createOutput())
class StExecuteAll(WindowCommand):
@staticmethod
def run():
if not ST.conn:
ST.selectConnectionQuickPanel(callback=lambda: Window().run_command('st_execute_all'))
return
Window().status_message(MESSAGE_RUNNING_CMD)
allText = View().substr(sublime.Region(0, View().size()))
ST.conn.execute(allText, createOutput())
class StFormat(TextCommand):
@staticmethod
def run(edit):
selectionRegions = getSelectionRegions()
if not selectionRegions:
return
for region in selectionRegions:
textToFormat = View().substr(region)
View().replace(edit, region, Utils.formatSql(textToFormat, settingsStore.get('format', {})))
class StFormatAll(TextCommand):
@staticmethod
def run(edit):
region = sublime.Region(0, View().size())
textToFormat = View().substr(region)
View().replace(edit, region, Utils.formatSql(textToFormat, settingsStore.get('format', {})))
class StVersion(WindowCommand):
@staticmethod
def run():
sublime.message_dialog('Using {0} {1}'.format(__package__, __version__))
class StHistory(WindowCommand):
@staticmethod
def run():
if not ST.conn:
ST.selectConnectionQuickPanel(callback=lambda: Window().run_command('st_history'))
return
if len(historyStore.all()) == 0:
sublime.message_dialog('History is empty.')
return
def cb(index):
if index < 0:
return None
return ST.conn.execute(historyStore.get(index), createOutput())
Window().show_quick_panel(historyStore.all(), cb)
class StSaveQuery(WindowCommand):
@staticmethod
def run():
query = getSelectionText()
def cb(alias):
queriesStore.add(alias, query)
Window().show_input_panel('Query alias', '', cb, None, None)
class StListQueries(WindowCommand):
@staticmethod
def run(mode="run"):
if mode == "run" and not ST.conn:
ST.selectConnectionQuickPanel(callback=lambda: Window().run_command('st_list_queries',
{'mode': mode}))
return
queriesList = queriesStore.all()
if len(queriesList) == 0:
sublime.message_dialog('No saved queries.')
return
options = []
for alias, query in queriesList.items():
options.append([str(alias), str(query)])
options.sort()
def cb(index):
if index < 0:
return None
alias, query = options[index]
if mode == "run":
ST.conn.execute(query, createOutput())
elif mode == "insert":
insertContent(query)
else:
toNewTab(query, alias)
return
try:
Window().show_quick_panel(options, cb)
except Exception:
pass
class StRemoveSavedQuery(WindowCommand):
@staticmethod
def run():
if not ST.conn:
ST.selectConnectionQuickPanel(callback=lambda: Window().run_command('st_remove_saved_query'))
return
queriesList = queriesStore.all()
if len(queriesList) == 0:
sublime.message_dialog('No saved queries.')
return
options = []
for alias, query in queriesList.items():
options.append([str(alias), str(query)])
options.sort()
def cb(index):
if index < 0:
return None
return queriesStore.delete(options[index][0])
try:
Window().show_quick_panel(options, cb)
except Exception:
pass
def Window():
return sublime.active_window()
def View():
return Window().active_view()
def reload():
try:
# python 3.0 to 3.3
import imp
imp.reload(sys.modules[__package__ + ".SQLToolsAPI"])
imp.reload(sys.modules[__package__ + ".SQLToolsAPI.Utils"])
imp.reload(sys.modules[__package__ + ".SQLToolsAPI.Completion"])
imp.reload(sys.modules[__package__ + ".SQLToolsAPI.Storage"])
imp.reload(sys.modules[__package__ + ".SQLToolsAPI.History"])
imp.reload(sys.modules[__package__ + ".SQLToolsAPI.Command"])
imp.reload(sys.modules[__package__ + ".SQLToolsAPI.Connection"])
except Exception as e:
raise (e)
try:
ST.bootstrap()
except Exception:
pass
def plugin_loaded():
try:
from package_control import events
if events.install(__name__):
logger.info('Installed %s!' % events.install(__name__))
elif events.post_upgrade(__name__):
logger.info('Upgraded to %s!' % events.post_upgrade(__name__))
sublime.message_dialog(('{0} was upgraded.' +
'If you have any problem,' +
'just restart your Sublime Text.'
).format(__name__)
)
except Exception:
pass
startPlugin()
reload()
def plugin_unloaded():
if plugin_logger.handlers:
plugin_logger.handlers.pop()
================================================
FILE: SQLTools.sublime-settings
================================================
// NOTE: it is strongly advised to override ONLY those settings
// that you wish to change in your Users/SQLTools.sublime-settings.
// Don't copy-paste the entire config.
{
/**
* If DB cli binary is not in PATH, set the full path in "cli" section.
* Note: forward slashes ("/") should be used in path. Example:
* "mysql" : "c:/Program Files/MySQL/MySQL Server 5.7/bin/mysql.exe"
*/
"cli": {
"mysql" : "mysql",
"pgsql" : "psql",
"mssql" : "sqlcmd",
"oracle" : "sqlplus",
"sqlite" : "sqlite3",
"vertica" : "vsql",
"firebird": "isql",
"sqsh" : "sqsh",
"snowsql" : "snowsql"
},
// If there is no SQL selected, use "expanded" region.
// Possible options:
// "file" - entire file contents
// "paragraph" - text between newlines relative to cursor(s)
// "line" - current line of cursor(s)
"expand_to": "file",
// puts results either in output panel or new window
"show_result_on_window": false,
// focus on result panel
"focus_on_result": false,
// clears the output of previous query
"clear_output": true,
// query timeout in seconds
"thread_timeout": 15,
// stream the output line by line
"use_streams": false,
// number of queries to save in the history
"history_size": 100,
"show_records": {
"limit": 50
},
// unless false, appends LIMIT clause to SELECT statements (not compatible with all DB's)
"safe_limit": false,
"debug": false,
/**
* Print the queries that were executed to the output.
* Possible values for show_query: "top", "bottom", true ("top"), or false (disable)
* When using regular output, this will determine where query details is displayed.
* In stream output mode, any option that isn't false will print query details at
* the bottom of result.
*/
"show_query": false,
/**
* Possible values for autocompletion: "basic", "smart", true ("smart"),
* or false (disable)
* Completion keywords case is controlled by format.keyword_case (see below)
*/
"autocompletion": "smart",
// Settings used for formatting the queries and autocompletions
//
// "keyword_case" , "upper", "lower", "capitalize" and null (leaves case intact)
// "identifier_case", "upper", "lower", "capitalize" and null (leaves case intact)
// "strip_comments" , formatting removes comments
// "indent_tabs" , use tabs instead of spaces
// "indent_width" , indentation width
// "reindent" , reindent code
"format": {
"keyword_case" : "upper",
"identifier_case" : null,
"strip_comments" : false,
"indent_tabs" : false,
"indent_width" : 4,
"reindent" : true
},
/**
* The list of syntax selectors for which the autocompletion will be active.
* An empty list means autocompletion always active.
*/
"autocomplete_selectors_active": [
"source.sql",
"source.pgsql",
"source.plpgsql.postgres",
"source.plsql.oracle",
"source.tsql"
],
/**
* The list of syntax selectors for which the autocompletion will be disabled.
*/
"autocomplete_selectors_ignore": [
"string.quoted.single.sql",
"string.quoted.single.pgsql",
"string.quoted.single.postgres",
"string.quoted.single.oracle",
"string.group.quote.oracle"
],
/**
* Command line interface options for each RDBMS.
* In this file, the section `cli` above has the names you can use here.
* E.g.: "mysql", "pgsql", "oracle"
*
* Names in the curly brackets (e.g. `{host}`) in sections `args`, `args_optional`,
* `env`, `env_optional` are replaced by the values specified in the connection.
*/
"cli_options": {
"pgsql": {
"options": ["--no-password"],
"before": [],
"after": [],
"args": "-d {database}",
"args_optional": [
"-h {host}",
"-p {port}",
"-U {username}"
],
"env_optional": {
"PGPASSWORD": "{password}"
},
"queries": {
"execute": {
"options": []
},
"show records": {
"query": "select * from {0} limit {1};",
"options": []
},
"desc table": {
"query": "\\d+ {0}",
"options": []
},
"desc function": {
"query": "\\sf {0}",
"options": []
},
"explain plan": {
"query": "explain analyze {0};",
"options": []
},
"desc": {
"query": "select quote_ident(table_schema) || '.' || quote_ident(table_name) as tblname from information_schema.tables where table_schema not in ('pg_catalog', 'information_schema') order by table_schema = current_schema() desc, table_schema, table_name;",
"options": ["--tuples-only", "--no-psqlrc"]
},
"columns": {
"query": "select distinct quote_ident(table_name) || '.' || quote_ident(column_name) from information_schema.columns where table_schema not in ('pg_catalog', 'information_schema');",
"options": ["--tuples-only", "--no-psqlrc"]
},
"functions": {
"query": "select quote_ident(n.nspname) || '.' || quote_ident(f.proname) || '(' || pg_get_function_identity_arguments(f.oid) || ')' as funname from pg_catalog.pg_proc as f inner join pg_catalog.pg_namespace as n on n.oid = f.pronamespace where n.nspname not in ('pg_catalog', 'information_schema');",
"options": ["--tuples-only", "--no-psqlrc"]
}
}
},
"mysql": {
"options": ["--no-auto-rehash", "--compress"],
"before": [],
"after": [],
"args": "-D\"{database}\"",
"args_optional": [
"--login-path=\"{login-path}\"",
"--defaults-extra-file=\"{defaults-extra-file}\"",
"--default-character-set=\"{default-character-set}\"",
"-h\"{host}\"",
"-P{port}",
"-u\"{username}\""
],
"env_optional": {
"MYSQL_PWD": "{password}"
},
"queries": {
"execute": {
"options": ["--table"]
},
"show records": {
"query": "select * from {0} limit {1};",
"options": ["--table"]
},
"desc table": {
"query": "desc {0};",
"options": ["--table"]
},
"desc function": {
"query": "select routine_definition from information_schema.routines where concat(case when routine_schema REGEXP '[^0-9a-zA-Z$_]' then concat('`',routine_schema,'`') else routine_schema end, '.', case when routine_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',routine_name,'`') else routine_name end) = '{0}';",
"options": ["--silent", "--raw"]
},
"explain plan": {
"query": "explain {0};",
"options": ["--table"]
},
"desc" : {
"query": "select concat(case when table_schema REGEXP '[^0-9a-zA-Z$_]' then concat('`',table_schema,'`') else table_schema end, '.', case when table_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',table_name,'`') else table_name end) as obj from information_schema.tables where table_schema = database() order by table_name;",
"options": ["--silent", "--raw", "--skip-column-names"]
},
"columns": {
"query": "select concat(case when table_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',table_name,'`') else table_name end, '.', case when column_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',column_name,'`') else column_name end) as obj from information_schema.columns where table_schema = database() order by table_name, ordinal_position;",
"options": ["--silent", "--raw", "--skip-column-names"]
},
"functions": {
"query": "select concat(case when routine_schema REGEXP '[^0-9a-zA-Z$_]' then concat('`',routine_schema,'`') else routine_schema end, '.', case when routine_name REGEXP '[^0-9a-zA-Z$_]' then concat('`',routine_name,'`') else routine_name end, '()') as obj from information_schema.routines where routine_schema = database();",
"options": ["--silent", "--raw", "--skip-column-names"]
}
}
},
"mssql": {
"options": [],
"before": [],
"after": ["go", "quit"],
"args": "-d \"{database}\"",
"args_optional": ["-S \"{host},{port}\"", "-S \"{host}\\{instance}\"", "-U \"{username}\"", "-P \"{password}\""],
"queries": {
"execute": {
"options": ["-k"]
},
"show records": {
"query": "select top {1} * from {0};",
"options": []
},
"desc table": {
"query": "exec sp_help N'{0}';",
"options": ["-y30", "-Y30"]
},
"desc function": {
"query": "exec sp_helptext N'{0}';",
"options": ["-h-1"]
},
"explain plan": {
"query": "{0};",
"options": ["-k"],
"before": [
"SET STATISTICS PROFILE ON",
"SET STATISTICS IO ON",
"SET STATISTICS TIME ON"
]
},
"desc": {
"query": "set nocount on; select concat(table_schema, '.', table_name) as obj from information_schema.tables order by table_schema, table_name;",
"options": ["-h-1", "-r1"]
},
"columns": {
"query": "set nocount on; select distinct concat(table_name, '.', column_name) as obj from information_schema.columns;",
"options": ["-h-1", "-r1"]
},
"functions": {
"query": "set nocount on; select concat(routine_schema, '.', routine_name) as obj from information_schema.routines order by routine_schema, routine_name;",
"options": ["-h-1", "-r1"]
}
}
},
"oracle": {
"options": ["-S"],
"before": [
"SET LINESIZE 32767",
"SET WRAP OFF",
"SET PAGESIZE 0",
"SET EMBEDDED ON",
"SET TRIMOUT ON",
"SET TRIMSPOOL ON",
"SET TAB OFF",
"SET SERVEROUT ON",
"SET NULL '@'",
"SET COLSEP '|'",
"SET SQLBLANKLINES ON"
],
"after": [],
"env_optional": {
"NLS_LANG": "{nls_lang}"
},
"args": "{username}/{password}@\"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={host})(PORT={port})))(CONNECT_DATA=(SERVICE_NAME={service})))\"",
"queries": {
"execute": {
"options": [],
"before": [
// "SET TIMING ON",
"SET FEEDBACK ON"
]
},
"show records": {
"query": "select * from {0} where rownum <= {1};",
"options": [],
"before": [
"SET FEEDBACK ON"
]
},
"desc table": {
"query": "desc {0};",
"options": [],
"before": [
"SET LINESIZE 80", // override for readability
"SET WRAP ON", // override for readability
"SET FEEDBACK ON"
]
},
"desc function": {
"query": "select text from all_source where type in ('FUNCTION', 'PROCEDURE', 'PACKAGE', 'PACKAGE BODY') and name = nvl(substr(ltrim('{0}', sys_context('USERENV', 'CURRENT_SCHEMA') || '.' ), 0, instr(ltrim('{0}', sys_context('USERENV', 'CURRENT_SCHEMA') || '.' ), '.')-1), ltrim('{0}', sys_context('USERENV', 'CURRENT_SCHEMA') || '.' )) and owner = sys_context('USERENV', 'CURRENT_SCHEMA') order by type, line;",
"options": [],
"before": [
"SET SERVEROUT OFF", // override
"SET NULL ''", // override
"SET HEADING OFF",
"SET FEEDBACK OFF"
]
},
"explain plan": {
"query": "explain plan for {0};\nselect plan_table_output from table(dbms_xplan.display());",
"options": [],
"before": [
"SET FEEDBACK ON"
]
},
"desc" : {
"query": "select owner || '.' || case when upper(name) = name then name else chr(34) || name || chr(34) end as obj from (select owner, table_name as name from all_tables union all select owner, view_name as name from all_views) o where owner not in ('ANONYMOUS','APPQOSSYS','CTXSYS','DBSNMP','EXFSYS', 'LBACSYS', 'MDSYS','MGMT_VIEW','OLAPSYS','OWBSYS','ORDPLUGINS', 'ORDSYS','OUTLN', 'SI_INFORMTN_SCHEMA','SYS','SYSMAN','SYSTEM', 'TSMSYS','WK_TEST','WKSYS', 'WKPROXY','WMSYS','XDB','APEX_040000', 'APEX_PUBLIC_USER','DIP', 'FLOWS_30000','FLOWS_FILES','MDDATA', 'ORACLE_OCM','SPATIAL_CSW_ADMIN_USR', 'SPATIAL_WFS_ADMIN_USR', 'XS$NULL','PUBLIC');",
"options": [],
"before": [
"SET SERVEROUT OFF", // override
"SET NULL ''", // override
"SET HEADING OFF",
"SET FEEDBACK OFF"
]
},
"columns": {
"query": "select case when upper(table_name) = table_name then table_name else chr(34) || table_name || chr(34) end || '.' || case when upper(column_name) = column_name then column_name else chr(34) || column_name || chr(34) end as obj from (select c.table_name, c.column_name, t.owner from all_tab_columns c inner join all_tables t on c.owner = t.owner and c.table_name = t.table_name union all select c.table_name, c.column_name, t.owner from all_tab_columns c inner join all_views t on c.owner = t.owner and c.table_name = t.view_name) o where owner not in ('ANONYMOUS','APPQOSSYS','CTXSYS','DBSNMP','EXFSYS', 'LBACSYS', 'MDSYS','MGMT_VIEW','OLAPSYS','OWBSYS','ORDPLUGINS', 'ORDSYS','OUTLN', 'SI_INFORMTN_SCHEMA','SYS','SYSMAN','SYSTEM', 'TSMSYS','WK_TEST','WKSYS', 'WKPROXY','WMSYS','XDB','APEX_040000', 'APEX_PUBLIC_USER','DIP', 'FLOWS_30000','FLOWS_FILES','MDDATA', 'ORACLE_OCM','SPATIAL_CSW_ADMIN_USR', 'SPATIAL_WFS_ADMIN_USR', 'XS$NULL','PUBLIC');",
"options": [],
"before": [
"SET SERVEROUT OFF", // override
"SET NULL ''", // override
"SET HEADING OFF",
"SET FEEDBACK OFF"
]
},
"functions": {
"query": "select case when object_type = 'PACKAGE' then object_name||'.'||procedure_name else owner || '.' || object_name end || '()' as obj from all_procedures where object_type in ('FUNCTION','PROCEDURE','PACKAGE') and not (object_type = 'PACKAGE' and procedure_name is null) and owner = sys_context('USERENV', 'CURRENT_SCHEMA');",
"options": [],
"before": [
"SET SERVEROUT OFF", // override
"SET NULL ''", // override
"SET HEADING OFF",
"SET FEEDBACK OFF"
]
}
}
},
"sqlite": {
"options": [],
"before": [],
"after": [],
"args": "\"{database}\"",
"queries": {
"execute": {
"options": ["-column", "-header", "-bail"]
},
"show records": {
"query": "select * from \"{0}\" limit {1};",
"options": ["-column", "-header"]
},
"explain plan": {
"query": "EXPLAIN QUERY PLAN {0};",
"options": ["-column", "-header", "-bail"]
},
"desc table": {
"query": ".schema \"{0}\"",
"options": ["-column", "-header"]
},
"desc" : {
"query": "SELECT name FROM sqlite_master WHERE type='table';",
"options": ["-noheader"],
"before": [
".headers off"
]
}
}
},
"vertica": {
"options": [],
"before" : [],
"after": [],
"args": "-h \"{host}\" -p {port} -U \"{username}\" -w \"{password}\" -d \"{database}\"",
"queries": {
"execute": {
"options": []
},
"show records": {
"query": "select * from {0} limit {1};",
"options": []
},
"desc table": {
"query": "\\d {0}",
"options": []
},
"explain plan": {
"query": "explain {0};",
"options": []
},
"desc" : {
"query": "select quote_ident(table_schema) || '.' || quote_ident(table_name) as obj from v_catalog.tables where is_system_table = false;",
"options": ["--tuples-only", "--no-vsqlrc"]
},
"columns": {
"query": "select quote_ident(table_name) || '.' || quote_ident(column_name) as obj from v_catalog.columns where is_system_table = false order by table_name, ordinal_position;",
"options": ["--tuples-only", "--no-vsqlrc"]
}
}
},
"firebird": {
"options": [],
"before": [],
"after": [],
"args": "-pagelength 10000 -u \"{username}\" -p \"{password}\" \"{host}/{port}:{database}\"",
"queries": {
"execute": {
"options": [],
"before": [
"set bail on;",
"set count on;"
]
},
"show records": {
"query": "select first {1} * from {0};",
"options": [],
"before": [
"set bail off;",
"set count on;"
]
},
"desc table": {
"query": "show table {0}; \n show view {0};",
"before": [
"set bail off;"
]
},
"desc function": {
"query": "show procedure {0};",
"before": [
"set bail off;"
]
},
"explain plan": {
"query": "{0};",
"before": [
"set bail on;",
"set count on;",
"set plan on;",
"set stats on;"
]
},
"desc" : {
"query": "select case when upper(rdb$relation_name) = rdb$relation_name then trim(rdb$relation_name) else '\"' || trim(rdb$relation_name) || '\"' end as obj from rdb$relations where (rdb$system_flag is null or rdb$system_flag = 0);",
"before": [
"set bail off;",
"set heading off;",
"set count off;",
"set stats off;"
]
},
"columns": {
"query": "select case when upper(f.rdb$relation_name) = f.rdb$relation_name then trim(f.rdb$relation_name) else '\"' || trim(f.rdb$relation_name) || '\"' end || '.' || case when upper(f.rdb$field_name) = f.rdb$field_name then trim(f.rdb$field_name) else '\"' || trim(f.rdb$field_name) || '\"' end as obj from rdb$relation_fields f join rdb$relations r on f.rdb$relation_name = r.rdb$relation_name where (r.rdb$system_flag is null or r.rdb$system_flag = 0) order by f.rdb$relation_name, f.rdb$field_position;",
"before": [
"set bail off;",
"set heading off;",
"set count off;",
"set stats off;"
]
},
"functions": {
"query": "select case when upper(rdb$procedure_name) = rdb$procedure_name then trim(rdb$procedure_name) else '\"' || trim(rdb$procedure_name) || '\"' end || '()' as obj from rdb$procedures where (rdb$system_flag is null or rdb$system_flag = 0);",
"before": [
"set bail off;",
"set heading off;",
"set count off;",
"set stats off;"
]
}
}
},
"sqsh": {
"options": [],
"before": [],
"after": [],
"args": "-S {host}:{port} -U\"{username}\" -P\"{password}\" -D{database}",
"queries": {
"execute": {
"options": [],
"before": ["\\set semicolon_cmd=\"\\go -mpretty -l\""]
},
"desc": {
"query": "select concat(table_schema, '.', table_name) from information_schema.tables order by table_name;",
"options": [],
"before" :["\\set semicolon_cmd=\"\\go -mpretty -l -h -f\""]
},
"columns": {
"query": "select concat(table_name, '.', column_name) from information_schema.columns order by table_name, ordinal_position;",
"options": [],
"before" :["\\set semicolon_cmd=\"\\go -mpretty -l -h -f\""]
},
"desc table": {
"query": "exec sp_columns \"{0}\";",
"options": [],
"before": ["\\set semicolon_cmd=\"\\go -mpretty -l -h -f\""]
},
"show records": {
"query": "select top {1} * from \"{0}\";",
"options": [],
"before": ["\\set semicolon_cmd=\"\\go -mpretty -l\""]
}
}
},
"snowsql": {
"options": [],
"env_optional": {
"SNOWSQL_PWD": "{password}"
},
"args": "-u {user} -a {account} -d {database} --authenticator {auth} -K",
"queries": {
"execute": {
"options": [],
},
"show records": {
"query": "SELECT * FROM {0} LIMIT {1};"
},
"desc table": {
"query": "DESC TABLE {0};",
"options": ["-o", "output_format=plain",
"-o", "timing=False"]
},
"desc": {
"query": "SELECT TABLE_SCHEMA || '.' || TABLE_NAME AS tbl FROM INFORMATION_SCHEMA.TABLES ORDER BY tbl;",
"options": ["-o", "output_format=plain",
"-o", "header=False",
"-o", "timing=False"]
},
"columns": {
"query": "SELECT TABLE_NAME || '.' || COLUMN_NAME AS col FROM INFORMATION_SCHEMA.COLUMNS ORDER BY col;",
"options": ["-o", "output_format=plain",
"-o", "header=False",
"-o", "timing=False"]
}
}
}
}
}
================================================
FILE: SQLToolsAPI/Command.py
================================================
import os
import signal
import subprocess
import time
import logging
from threading import Thread, Timer
logger = logging.getLogger(__name__)
class Command(object):
timeout = 15
def __init__(self, args, env, callback, query=None, encoding='utf-8',
options=None, timeout=15, silenceErrors=False, stream=False):
if options is None:
options = {}
self.args = args
self.env = env
self.callback = callback
self.query = query
self.encoding = encoding
self.options = options
self.timeout = timeout
self.silenceErrors = silenceErrors
self.stream = stream
self.process = None
if 'show_query' not in self.options:
self.options['show_query'] = False
elif self.options['show_query'] not in ['top', 'bottom']:
self.options['show_query'] = 'top' if (isinstance(self.options['show_query'], bool) and
self.options['show_query']) else False
def run(self):
if not self.query:
return
self.args = map(str, self.args)
si = None
if os.name == 'nt':
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
# select appropriate file handle for stderr
# usually we want to redirect stderr to stdout, so erros are shown
# in the output in the right place (where they actually occurred)
# only if silenceErrors=True, we separate stderr from stdout and discard it
stderrHandle = subprocess.STDOUT
if self.silenceErrors:
stderrHandle = subprocess.PIPE
# set the environment
modifiedEnvironment = os.environ.copy()
if (self.env):
modifiedEnvironment.update(self.env)
queryTimerStart = time.time()
self.process = subprocess.Popen(self.args,
stdout=subprocess.PIPE,
stderr=stderrHandle,
stdin=subprocess.PIPE,
env=modifiedEnvironment,
startupinfo=si)
if self.stream:
self.process.stdin.write(self.query.encode(self.encoding))
self.process.stdin.close()
hasWritten = False
for line in self.process.stdout:
self.callback(line.decode(self.encoding, 'replace').replace('\r', ''))
hasWritten = True
queryTimerEnd = time.time()
# we are done with the output, terminate the process
if self.process:
self.process.terminate()
else:
if hasWritten:
self.callback('\n')
if self.options['show_query']:
formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd)
self.callback(formattedQueryInfo + '\n')
return
# regular mode is handled with more reliable Popen.communicate
# which also terminates the process afterwards
results, errors = self.process.communicate(input=self.query.encode(self.encoding))
queryTimerEnd = time.time()
resultString = ''
if results:
resultString += results.decode(self.encoding,
'replace').replace('\r', '')
if errors and not self.silenceErrors:
resultString += errors.decode(self.encoding,
'replace').replace('\r', '')
if self.process is None and resultString != '':
resultString += '\n'
if self.options['show_query']:
formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd)
queryPlacement = self.options['show_query']
if queryPlacement == 'top':
resultString = "{0}\n{1}".format(formattedQueryInfo, resultString)
elif queryPlacement == 'bottom':
resultString = "{0}{1}\n".format(resultString, formattedQueryInfo)
self.callback(resultString)
@staticmethod
def _formatShowQuery(query, queryTimeStart, queryTimeEnd):
resultInfo = "/*\n-- Executed querie(s) at {0} took {1:.3f} s --".format(
str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(queryTimeStart))),
(queryTimeEnd - queryTimeStart))
resultLine = "-" * (len(resultInfo) - 3)
resultString = "{0}\n{1}\n{2}\n{3}\n*/".format(
resultInfo, resultLine, query, resultLine)
return resultString
@staticmethod
def createAndRun(args, env, callback, query=None, encoding='utf-8',
options=None, timeout=15, silenceErrors=False, stream=False):
if options is None:
options = {}
command = Command(args=args,
env=env,
callback=callback,
query=query,
encoding=encoding,
options=options,
timeout=timeout,
silenceErrors=silenceErrors,
stream=stream)
command.run()
class ThreadCommand(Command, Thread):
def __init__(self, args, env, callback, query=None, encoding='utf-8',
options=None, timeout=Command.timeout, silenceErrors=False, stream=False):
if options is None:
options = {}
Command.__init__(self,
args=args,
env=env,
callback=callback,
query=query,
encoding=encoding,
options=options,
timeout=timeout,
silenceErrors=silenceErrors,
stream=stream)
Thread.__init__(self)
def stop(self):
if not self.process:
return
# if poll returns None - proc still running, otherwise returns process return code
if self.process.poll() is not None:
return
try:
# Windows does not provide SIGKILL, go with SIGTERM
sig = getattr(signal, 'SIGKILL', signal.SIGTERM)
os.kill(self.process.pid, sig)
self.process = None
logger.info("command execution exceeded timeout (%s s), process killed", self.timeout)
self.callback(("Command execution time exceeded 'thread_timeout' ({0} s).\n"
"Process killed!\n\n"
).format(self.timeout))
except Exception:
logger.info("command execution exceeded timeout (%s s), process could not be killed", self.timeout)
self.callback(("Command execution time exceeded 'thread_timeout' ({0} s).\n"
"Process could not be killed!\n\n"
).format(self.timeout))
pass
@staticmethod
def createAndRun(args, env, callback, query=None, encoding='utf-8',
options=None, timeout=Command.timeout, silenceErrors=False, stream=False):
# Don't allow empty dicts or lists as defaults in method signature,
# cfr http://nedbatchelder.com/blog/200806/pylint.html
if options is None:
options = {}
command = ThreadCommand(args=args,
env=env,
callback=callback,
query=query,
encoding=encoding,
options=options,
timeout=timeout,
silenceErrors=silenceErrors,
stream=stream)
command.start()
killTimeout = Timer(command.timeout, command.stop)
killTimeout.start()
================================================
FILE: SQLToolsAPI/Completion.py
================================================
import re
import logging
from collections import namedtuple
from .ParseUtils import extractTables
JOIN_COND_PATTERN = r"\s+?JOIN\s+?[\w\.`\"]+\s+?(?:AS\s+)?(\w+)\s+?ON\s+?(?:[\w\.]+)?$"
JOIN_COND_REGEX = re.compile(JOIN_COND_PATTERN, re.IGNORECASE)
keywords_list = [
'SELECT', 'UPDATE', 'DELETE', 'INSERT', 'INTO', 'FROM',
'WHERE', 'GROUP BY', 'ORDER BY', 'HAVING', 'JOIN',
'INNER JOIN', 'LEFT JOIN', 'RIGHT JOIN', 'USING',
'LIMIT', 'DISTINCT', 'SET'
]
logger = logging.getLogger(__name__)
# this function is generously used in completions code to get rid
# of all sorts of leading and trailing quotes in RDBMS identifiers
def _stripQuotes(ident):
return ident.strip('"\'`')
# used for formatting output
def _stripQuotesOnDemand(ident, doStrip=True):
if doStrip:
return _stripQuotes(ident)
return ident
def _startsWithQuote(ident):
# ident is matched against any of the possible ident quotes
quotes = ('`', '"')
return ident.startswith(quotes)
def _stripPrefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text
# escape $ sign when formatting output
def _escapeDollarSign(ident):
return ident.replace("$", "\$")
class CompletionItem(namedtuple('CompletionItem', ['type', 'ident'])):
"""Represents a potential or actual completion item.
* type - type of item (Table, Function, Column)
* ident - identifier (table.column, schema.table, alias)
"""
__slots__ = ()
@property
def parent(self):
"""Parent of identifier, e.g. "table" from "table.column" """
if self.ident.count('.') == 0:
return None
else:
return self.ident.partition('.')[0]
@property
def name(self):
"""Name of identifier, e.g. "column" from "table.column" """
return self.ident.split('.').pop()
# for functions - strip open bracket "(" and everything after that
# e.g: mydb.myAdd(int, int) --> mydb.myadd
def _matchIdent(self):
if self.type == 'Function':
return self.ident.partition('(')[0].lower()
return self.ident.lower()
# Helper method for string matching
# When exactly is true:
# matches search string to target exactly, but empty search string matches anything
# When exactly is false:
# if only one char given in search string match this single char with start
# of target string, otherwise match search string anywhere in target string
@staticmethod
def _stringMatched(target, search, exactly):
if exactly:
return target == search or search == ''
else:
if (len(search) == 1):
return target.startswith(search)
return search in target
# Method to match completion item against search string (prefix).
# Lower score means a better match.
# If completion item matches prefix with parent identifier, e.g.:
# table_name.column ~ table_name.co, then score = 1
# If completion item matches prefix without parent identifier, e.g.:
# table_name.column ~ co, then score = 2
# If completion item matches, but prefix has no parent, e.g.:
# table ~ tab, then score = 3
def prefixMatchScore(self, search, exactly=False):
target = self._matchIdent()
search = search.lower()
# match parent exactly and partially match name
if '.' in target and '.' in search:
searchList = search.split('.')
searchObject = _stripQuotes(searchList.pop())
searchParent = _stripQuotes(searchList.pop())
targetList = target.split('.')
targetObject = _stripQuotes(targetList.pop())
targetParent = _stripQuotes(targetList.pop())
if (searchParent == targetParent):
if self._stringMatched(targetObject, searchObject, exactly):
return 1 # highest score
return 0
# second part matches ?
if '.' in target:
targetObjectNoQuote = _stripQuotes(target.split('.').pop())
searchNoQuote = _stripQuotes(search)
if self._stringMatched(targetObjectNoQuote, searchNoQuote, exactly):
return 2
else:
targetNoQuote = _stripQuotes(target)
searchNoQuote = _stripQuotes(search)
if self._stringMatched(targetNoQuote, searchNoQuote, exactly):
return 3
else:
return 0
return 0
def prefixMatchListScore(self, searchList, exactly=False):
for item in searchList:
score = self.prefixMatchScore(item, exactly)
if score:
return score
return 0
# format completion item according to sublime text completions format
def format(self, stripQuotes=False):
typeDisplay = ''
if self.type == 'Table':
typeDisplay = self.type
elif self.type == 'Keyword':
typeDisplay = self.type
elif self.type == 'Alias':
typeDisplay = self.type
elif self.type == 'Function':
typeDisplay = 'Func'
elif self.type == 'Column':
typeDisplay = 'Col'
if not typeDisplay:
return (self.ident, _stripQuotesOnDemand(self.ident, stripQuotes))
part = self.ident.split('.')
if len(part) > 1:
return ("{0}\t({1} {2})".format(part[1], part[0], typeDisplay),
_stripQuotesOnDemand(_escapeDollarSign(part[1]), stripQuotes))
return ("{0}\t({1})".format(self.ident, typeDisplay),
_stripQuotesOnDemand(_escapeDollarSign(self.ident), stripQuotes))
class Completion:
def __init__(self, allTables, allColumns, allFunctions, settings=None):
self.allTables = [CompletionItem('Table', table) for table in allTables]
self.allColumns = [CompletionItem('Column', column) for column in allColumns]
self.allFunctions = [CompletionItem('Function', func) for func in allFunctions]
# we don't save the settings (we don't need them after init)
if settings is None:
settings = {}
# check old setting name ('selectors') first for compatibility
activeSelectors = settings.get('selectors', None)
if not activeSelectors:
activeSelectors = settings.get(
'autocomplete_selectors_active',
['source.sql'])
self.activeSelectors = activeSelectors
self.ignoreSelectors = settings.get(
'autocomplete_selectors_ignore',
['string.quoted.single.sql'])
# determine type of completions
self.completionType = settings.get('autocompletion', 'smart')
if not self.completionType:
self.completionType = None # autocompletion disabled
else:
self.completionType = str(self.completionType).strip()
if self.completionType not in ['basic', 'smart']:
self.completionType = 'smart'
# determine desired keywords case from settings
formatSettings = settings.get('format', {})
keywordCase = formatSettings.get('keyword_case', 'upper')
uppercaseKeywords = keywordCase.lower().startswith('upper')
self.allKeywords = []
for keyword in keywords_list:
if uppercaseKeywords:
keyword = keyword.upper()
else:
keyword = keyword.lower()
self.allKeywords.append(CompletionItem('Keyword', keyword))
def getActiveSelectors(self):
return self.activeSelectors
def getIgnoreSelectors(self):
return self.ignoreSelectors
def isDisabled(self):
return self.completionType is None
def getAutoCompleteList(self, prefix, sql, sqlToCursor):
if self.isDisabled():
return None
autocompleteList = []
inhibit = False
if self.completionType == 'smart':
autocompleteList, inhibit = self._getAutoCompleteListSmart(prefix, sql, sqlToCursor)
else:
autocompleteList = self._getAutoCompleteListBasic(prefix)
if not autocompleteList:
return None, False
# return completions with or without quotes?
# determined based on ident after last dot
startsWithQuote = _startsWithQuote(prefix.split(".").pop())
autocompleteList = [item.format(startsWithQuote) for item in autocompleteList]
return autocompleteList, inhibit
def _getAutoCompleteListBasic(self, prefix):
prefix = prefix.lower()
autocompleteList = []
# columns, tables and functions that match the prefix
for item in self.allColumns:
score = item.prefixMatchScore(prefix)
if score:
autocompleteList.append(item)
for item in self.allTables:
score = item.prefixMatchScore(prefix)
if score:
autocompleteList.append(item)
for item in self.allFunctions:
score = item.prefixMatchScore(prefix)
if score:
autocompleteList.append(item)
if len(autocompleteList) == 0:
return None
return autocompleteList
def _getAutoCompleteListSmart(self, prefix, sql, sqlToCursor):
"""
Generally, we recognize 3 different variations in prefix:
* ident| // no dots (.) in prefix
In this case we show completions for all available identifiers (tables, columns,
functions) that have "ident" text in them. Identifiers relevant to current
statement shown first.
* parent.ident| // single dot in prefix
In this case, if "parent" matches on of parsed table aliases we show column
completions for them, as well as we do prefix search for all other identifiers.
If something is matched, we return results as well as set a flag to suppress
Sublime completions.
If we don't find any objects using prefix search or we know that "parent" is
a query alias, we don't return anything and allow Sublime to do it's job by
showing most relevant completions.
* database.table.col| // multiple dots in prefix
In this case we only show columns for "table" column, as there is nothing else
that could be referenced that way.
Since it's too complicated to handle the specifics of identifiers case sensitivity
as well as all nuances of quoting of those identifiers for each RDBMS, we always
match against lower-cased and stripped quotes of both prefix and our internal saved
identifiers (tables, columns, functions). E.g. "MyTable"."myCol" --> mytable.mycol
"""
# TODO: add completions of function out fields
prefix = prefix.lower()
prefixDots = prefix.count('.')
# continue with empty identifiers list, even if we failed to parse identifiers
identifiers = []
try:
identifiers = extractTables(sql)
except Exception as e:
logger.debug('Failed to extact the list identifiers from SQL:\n {}'.format(sql),
exc_info=True)
# joinAlias is set only if user is editing join condition with alias. E.g.
# SELECT a.* from tbl_a a inner join tbl_b b ON |
joinAlias = None
if prefixDots <= 1:
try:
joinCondMatch = JOIN_COND_REGEX.search(sqlToCursor, re.IGNORECASE)
if joinCondMatch:
joinAlias = joinCondMatch.group(1)
except Exception as e:
logger.debug('Failed search of join condition, SQL:\n {}'.format(sqlToCursor),
exc_info=True)
autocompleteList = []
inhibit = False
if prefixDots == 0:
autocompleteList, inhibit = self._noDotsCompletions(prefix, identifiers, joinAlias)
elif prefixDots == 1:
autocompleteList, inhibit = self._singleDotCompletions(prefix, identifiers, joinAlias)
else:
autocompleteList, inhibit = self._multiDotCompletions(prefix, identifiers)
if not autocompleteList:
return None, False
return autocompleteList, inhibit
def _noDotsCompletions(self, prefix, identifiers, joinAlias=None):
"""
Method handles most generic completions when prefix does not contain any dots.
In this case completions can be anything: cols, tables, functions that have this name.
Still we try to predict users needs and output aliases, tables, columns and function
that are used in currently parsed statement first, then show everything else that
could be related.
Order: statement aliases -> statement cols -> statement tables -> statement functions,
then: other cols -> other tables -> other functions that match the prefix in their names
"""
# use set, as we are interested only in unique identifiers
sqlAliases = set()
sqlTables = []
sqlColumns = []
sqlFunctions = []
otherTables = []
otherColumns = []
otherFunctions = []
otherKeywords = []
otherJoinConditions = []
# utilitary temp lists
identTables = set()
identColumns = set()
identFunctions = set()
for ident in identifiers:
if ident.has_alias():
aliasItem = CompletionItem('Alias', ident.alias)
score = aliasItem.prefixMatchScore(prefix)
if score and aliasItem.ident != prefix:
sqlAliases.add(aliasItem)
if ident.is_function:
identFunctions.add(ident.full_name)
elif ident.is_table_alias:
identTables.add(ident.full_name)
identColumns.add(ident.name + '.' + prefix)
for table in self.allTables:
score = table.prefixMatchScore(prefix, exactly=False)
if score:
if table.prefixMatchListScore(identTables, exactly=True) > 0:
sqlTables.append(table)
else:
otherTables.append(table)
for col in self.allColumns:
score = col.prefixMatchScore(prefix, exactly=False)
if score:
if col.prefixMatchListScore(identColumns, exactly=False) > 0:
sqlColumns.append(col)
else:
otherColumns.append(col)
for fun in self.allFunctions:
score = fun.prefixMatchScore(prefix, exactly=False)
if score:
if fun.prefixMatchListScore(identFunctions, exactly=True) > 0:
sqlColumns.append(fun)
else:
otherColumns.append(fun)
# keywords
for item in self.allKeywords:
score = item.prefixMatchScore(prefix)
if score:
otherKeywords.append(item)
# join conditions
if joinAlias:
joinConditions = self._joinConditionCompletions(identifiers, joinAlias)
for condition in joinConditions:
if condition.ident.lower().startswith(prefix):
otherJoinConditions.append(condition)
# collect the results in prefered order
autocompleteList = []
# first of all list join conditions (if applicable)
autocompleteList.extend(otherJoinConditions)
# then aliases and identifiers related to currently parsed statement
autocompleteList.extend(sqlAliases)
# then cols, tables, functions related to current statement
autocompleteList.extend(sqlColumns)
autocompleteList.extend(sqlTables)
autocompleteList.extend(sqlFunctions)
# then other matching cols, tables, functions
autocompleteList.extend(otherKeywords)
autocompleteList.extend(otherColumns)
autocompleteList.extend(otherTables)
autocompleteList.extend(otherFunctions)
return autocompleteList, False
def _singleDotCompletions(self, prefix, identifiers, joinAlias=None):
"""
More intelligent completions can be shown if we have single dot in prefix in certain cases.
"""
prefixList = prefix.split(".")
prefixObject = prefixList.pop()
prefixParent = prefixList.pop()
# get join conditions
joinConditions = []
if joinAlias:
joinConditions = self._joinConditionCompletions(identifiers, joinAlias)
sqlTableAliases = set() # set of CompletionItem
sqlQueryAliases = set() # set of strings
# we use set, as we are interested only in unique identifiers
for ident in identifiers:
if ident.has_alias() and ident.alias.lower() == prefixParent:
if ident.is_query_alias:
sqlQueryAliases.add(ident.alias)
if ident.is_table_alias:
tables = [
table
for table in self.allTables
if table.prefixMatchScore(ident.full_name, exactly=True) > 0
]
sqlTableAliases.update(tables)
autocompleteList = []
for condition in joinConditions:
aliasPrefix = prefixParent + '.'
if condition.ident.lower().startswith(aliasPrefix):
autocompleteList.append(CompletionItem(condition.type,
_stripPrefix(condition.ident, aliasPrefix)))
# first of all expand table aliases to real table names and try
# to match their columns with prefix of these expanded identifiers
# e.g. select x.co| from tab x // "x.co" will expland to "tab.co"
for table_item in sqlTableAliases:
prefix_to_match = table_item.name + '.' + prefixObject
for item in self.allColumns:
score = item.prefixMatchScore(prefix_to_match)
if score:
autocompleteList.append(item)
# try to match all our other objects (tables, columns, functions) with prefix
for item in self.allColumns:
score = item.prefixMatchScore(prefix)
if score:
autocompleteList.append(item)
for item in self.allTables:
score = item.prefixMatchScore(prefix)
if score:
autocompleteList.append(item)
for item in self.allFunctions:
score = item.prefixMatchScore(prefix)
if score:
autocompleteList.append(item)
inhibit = len(autocompleteList) > 0
# in case prefix parent is a query alias we simply don't know what those
# columns might be so, set inhibit = False to allow sublime default completions
if prefixParent in sqlQueryAliases:
inhibit = False
return autocompleteList, inhibit
# match only columns if prefix contains multiple dots (db.table.col)
def _multiDotCompletions(self, prefix, identifiers):
autocompleteList = []
for item in self.allColumns:
score = item.prefixMatchScore(prefix)
if score:
autocompleteList.append(item)
if len(autocompleteList) > 0:
return autocompleteList, True
return None, False
def _joinConditionCompletions(self, identifiers, joinAlias=None):
if not joinAlias:
return None
# use set, as we are interested only in unique identifiers
sqlTableAliases = set()
joinAliasColumns = set()
sqlOtherColumns = set()
for ident in identifiers:
if ident.has_alias() and not ident.is_function:
sqlTableAliases.add(CompletionItem('Alias', ident.alias))
prefixForColumnMatch = ident.name + '.'
columns = [
(ident.alias, col)
for col in self.allColumns
if (col.prefixMatchScore(prefixForColumnMatch, exactly=True) > 0 and
_stripQuotes(col.name).lower().endswith('id'))
]
if ident.alias == joinAlias:
joinAliasColumns.update(columns)
else:
sqlOtherColumns.update(columns)
joinCandidatesCompletions = []
for joinAlias, joinColumn in joinAliasColumns:
# str.endswith can be matched against a tuple
columnsToMatch = None
if _stripQuotes(joinColumn.name).lower() == 'id':
columnsToMatch = (
_stripQuotes(joinColumn.parent).lower() + _stripQuotes(joinColumn.name).lower(),
_stripQuotes(joinColumn.parent).lower() + '_' + _stripQuotes(joinColumn.name).lower()
)
else:
columnsToMatch = (
_stripQuotes(joinColumn.name).lower(),
_stripQuotes(joinColumn.parent).lower() + _stripQuotes(joinColumn.name).lower(),
_stripQuotes(joinColumn.parent).lower() + '_' + _stripQuotes(joinColumn.name).lower()
)
for otherAlias, otherColumn in sqlOtherColumns:
if _stripQuotes(otherColumn.name).lower().endswith(columnsToMatch):
sideA = joinAlias + '.' + joinColumn.name
sideB = otherAlias + '.' + otherColumn.name
joinCandidatesCompletions.append(CompletionItem('Condition', sideA + ' = ' + sideB))
joinCandidatesCompletions.append(CompletionItem('Condition', sideB + ' = ' + sideA))
return joinCandidatesCompletions
================================================
FILE: SQLToolsAPI/Connection.py
================================================
import shutil
import shlex
import codecs
import logging
import sqlparse
from . import Utils as U
from . import Command as C
logger = logging.getLogger(__name__)
def _encoding_exists(enc):
try:
codecs.lookup(enc)
except LookupError:
return False
return True
class Connection(object):
DB_CLI_NOT_FOUND_MESSAGE = """DB CLI '{0}' could not be found.
Please set the path to DB CLI '{0}' binary in your SQLTools settings before continuing.
Example of "cli" section in SQLTools.sublime-settings:
/* ... (note the use of forward slashes) */
"cli" : {{
"mysql" : "c:/Program Files/MySQL/MySQL Server 5.7/bin/mysql.exe",
"pgsql" : "c:/Program Files/PostgreSQL/9.6/bin/psql.exe"
}}
You might need to restart the editor for settings to be refreshed."""
name = None
options = None
settings = None
type = None
host = None
port = None
database = None
username = None
password = None
encoding = None
safe_limit = None
show_query = None
rowsLimit = None
history = None
timeout = None
def __init__(self, name, options, settings=None, commandClass='ThreadCommand'):
self.Command = getattr(C, commandClass)
self.name = name
self.options = {k: v for k, v in options.items() if v is not None}
if settings is None:
settings = {}
self.settings = settings
self.type = self.options.get('type', None)
self.host = self.options.get('host', None)
self.port = self.options.get('port', None)
self.database = self.options.get('database', None)
self.username = self.options.get('username', None)
self.password = self.options.get('password', None)
self.encoding = self.options.get('encoding', 'utf-8')
self.encoding = self.encoding or 'utf-8' # defaults to utf-8
if not _encoding_exists(self.encoding):
self.encoding = 'utf-8'
self.safe_limit = settings.get('safe_limit', None)
self.show_query = settings.get('show_query', False)
self.rowsLimit = settings.get('show_records', {}).get('limit', 50)
self.useStreams = settings.get('use_streams', False)
self.cli = settings.get('cli')[self.options['type']]
cli_path = shutil.which(self.cli)
if cli_path is None:
logger.info(self.DB_CLI_NOT_FOUND_MESSAGE.format(self.cli))
raise FileNotFoundError(self.DB_CLI_NOT_FOUND_MESSAGE.format(self.cli))
def __str__(self):
return self.name
def info(self):
return 'DB: {0}, Connection: {1}@{2}:{3}'.format(
self.database, self.username, self.host, self.port)
def runInternalNamedQueryCommand(self, queryName, callback):
query = self.getNamedQuery(queryName)
if not query:
emptyList = []
callback(emptyList)
return
queryToRun = self.buildNamedQuery(queryName, query)
args = self.buildArgs(queryName)
env = self.buildEnv()
def cb(result):
callback(U.getResultAsList(result))
self.Command.createAndRun(args=args,
env=env,
callback=cb,
query=queryToRun,
encoding=self.encoding,
timeout=60,
silenceErrors=True,
stream=False)
def getTables(self, callback):
self.runInternalNamedQueryCommand('desc', callback)
def getColumns(self, callback):
self.runInternalNamedQueryCommand('columns', callback)
def getFunctions(self, callback):
self.runInternalNamedQueryCommand('functions', callback)
def runFormattedNamedQueryCommand(self, queryName, formatValues, callback):
query = self.getNamedQuery(queryName)
if not query:
return
# added for compatibility with older format string
query = query.replace("%s", "{0}", 1)
query = query.replace("%s", "{1}", 1)
if isinstance(formatValues, tuple):
query = query.format(*formatValues) # unpack the tuple
else:
query = query.format(formatValues)
queryToRun = self.buildNamedQuery(queryName, query)
args = self.buildArgs(queryName)
env = self.buildEnv()
self.Command.createAndRun(args=args,
env=env,
callback=callback,
query=queryToRun,
encoding=self.encoding,
timeout=self.timeout,
silenceErrors=False,
stream=False)
def getTableRecords(self, tableName, callback):
# in case we expect multiple values pack them into tuple
formatValues = (tableName, self.rowsLimit)
self.runFormattedNamedQueryCommand('show records', formatValues, callback)
def getTableDescription(self, tableName, callback):
self.runFormattedNamedQueryCommand('desc table', tableName, callback)
def getFunctionDescription(self, functionName, callback):
self.runFormattedNamedQueryCommand('desc function', functionName, callback)
def explainPlan(self, queries, callback):
queryName = 'explain plan'
explainQuery = self.getNamedQuery(queryName)
if not explainQuery:
return
strippedQueries = [
explainQuery.format(query.strip().strip(";"))
for rawQuery in queries
for query in filter(None, sqlparse.split(rawQuery))
]
queryToRun = self.buildNamedQuery(queryName, strippedQueries)
args = self.buildArgs(queryName)
env = self.buildEnv()
self.Command.createAndRun(args=args,
env=env,
callback=callback,
query=queryToRun,
encoding=self.encoding,
timeout=self.timeout,
silenceErrors=False,
stream=self.useStreams)
def execute(self, queries, callback, stream=None):
queryName = 'execute'
# if not explicitly overriden, use the value from settings
if stream is None:
stream = self.useStreams
if isinstance(queries, str):
queries = [queries]
# add original (umodified) queries to the history
if self.history:
self.history.add('\n'.join(queries))
processedQueriesList = []
for rawQuery in queries:
for query in sqlparse.split(rawQuery):
if self.safe_limit:
parsedTokens = sqlparse.parse(query.strip().replace("'", "\""))
if ((parsedTokens[0][0].ttype in sqlparse.tokens.Keyword and
parsedTokens[0][0].value == 'select')):
applySafeLimit = True
for parse in parsedTokens:
for token in parse.tokens:
if token.ttype in sqlparse.tokens.Keyword and token.value == 'limit':
applySafeLimit = False
if applySafeLimit:
if (query.strip()[-1:] == ';'):
query = query.strip()[:-1]
query += " LIMIT {0};".format(self.safe_limit)
processedQueriesList.append(query)
queryToRun = self.buildNamedQuery(queryName, processedQueriesList)
args = self.buildArgs(queryName)
env = self.buildEnv()
logger.debug("Query: %s", str(queryToRun))
self.Command.createAndRun(args=args,
env=env,
callback=callback,
query=queryToRun,
encoding=self.encoding,
options={'show_query': self.show_query},
timeout=self.timeout,
silenceErrors=False,
stream=stream)
def getNamedQuery(self, queryName):
if not queryName:
return None
cliOptions = self.getOptionsForSgdbCli()
return cliOptions.get('queries', {}).get(queryName, {}).get('query')
def buildNamedQuery(self, queryName, queries):
if not queryName:
return None
if not queries:
return None
cliOptions = self.getOptionsForSgdbCli()
beforeCli = cliOptions.get('before')
afterCli = cliOptions.get('after')
beforeQuery = cliOptions.get('queries', {}).get(queryName, {}).get('before')
afterQuery = cliOptions.get('queries', {}).get(queryName, {}).get('after')
# sometimes we preprocess the raw queries from user, in that case we already have a list
if type(queries) is not list:
queries = [queries]
builtQueries = []
if beforeCli is not None:
builtQueries.extend(beforeCli)
if beforeQuery is not None:
builtQueries.extend(beforeQuery)
if queries is not None:
builtQueries.extend(queries)
if afterQuery is not None:
builtQueries.extend(afterQuery)
if afterCli is not None:
builtQueries.extend(afterCli)
# remove empty list items
builtQueries = list(filter(None, builtQueries))
return '\n'.join(builtQueries)
def buildArgs(self, queryName=None):
cliOptions = self.getOptionsForSgdbCli()
args = [self.cli]
# append otional args (if any) - could be a single value or a list
optionalArgs = cliOptions.get('args_optional')
if optionalArgs: # only if we have optional args
if isinstance(optionalArgs, list):
for item in optionalArgs:
formattedItem = self.formatOptionalArgument(item, self.options)
if formattedItem:
args = args + shlex.split(formattedItem)
else:
formattedItem = self.formatOptionalArgument(optionalArgs, self.options)
if formattedItem:
args = args + shlex.split(formattedItem)
# append generic options
options = cliOptions.get('options', None)
if options:
args = args + options
# append query specific options (if present)
if queryName:
queryOptions = cliOptions.get('queries', {}).get(queryName, {}).get('options')
if queryOptions:
if len(queryOptions) > 0:
args = args + queryOptions
# append main args - could be a single value or a list
mainArgs = cliOptions['args']
if isinstance(mainArgs, list):
mainArgs = ' '.join(mainArgs)
mainArgs = mainArgs.format(**self.options)
args = args + shlex.split(mainArgs)
logger.debug('CLI args (%s): %s', str(queryName), ' '.join(args))
return args
def buildEnv(self):
cliOptions = self.getOptionsForSgdbCli()
env = dict()
# append **optional** environment variables dict (if any)
optionalEnv = cliOptions.get('env_optional')
if optionalEnv: # only if we have optional args
if isinstance(optionalEnv, dict):
for var, value in optionalEnv.items():
formattedValue = self.formatOptionalArgument(value, self.options)
if formattedValue:
env.update({var: formattedValue})
# append environment variables dict (if any)
staticEnv = cliOptions.get('env')
if staticEnv: # only if we have optional args
if isinstance(staticEnv, dict):
for var, value in staticEnv.items():
formattedValue = value.format(**self.options)
if formattedValue:
env.update({var: formattedValue})
logger.debug('CLI environment: %s', str(env))
return env
def getOptionsForSgdbCli(self):
return self.settings.get('cli_options', {}).get(self.type)
@staticmethod
def formatOptionalArgument(argument, formatOptions):
try:
formattedArg = argument.format(**formatOptions)
except (KeyError, IndexError):
return None
if argument == formattedArg: # string not changed after format
return None
return formattedArg
@staticmethod
def setTimeout(timeout):
Connection.timeout = timeout
logger.info('Connection timeout set to {0} seconds'.format(timeout))
@staticmethod
def setHistoryManager(manager):
Connection.history = manager
size = manager.getMaxSize()
logger.info('Connection history size is {0}'.format(size))
================================================
FILE: SQLToolsAPI/History.py
================================================
__version__ = "v0.1.0"
class SizeException(Exception):
pass
class NotFoundException(Exception):
pass
class History:
def __init__(self, maxSize=100):
self.items = []
self.maxSize = maxSize
def add(self, query):
if self.getSize() >= self.getMaxSize():
self.items.pop(0)
self.items.insert(0, query)
def get(self, index):
if index < 0 or index > (len(self.items) - 1):
raise NotFoundException("No query selected")
return self.items[index]
def setMaxSize(self, size=100):
if size < 1:
raise SizeException("Size can't be lower than 1")
self.maxSize = size
return self.maxSize
def getMaxSize(self):
return self.maxSize
def getSize(self):
return len(self.items)
def all(self):
return self.items
def clear(self):
self.items = []
return self.items
================================================
FILE: SQLToolsAPI/ParseUtils.py
================================================
import os
import sys
import itertools
from collections import namedtuple
dirpath = os.path.join(os.path.dirname(__file__), 'lib')
if dirpath not in sys.path:
sys.path.append(dirpath)
import sqlparse
from sqlparse.sql import IdentifierList, Identifier, Function
from sqlparse.tokens import Keyword, DML
class Reference(namedtuple('Reference', ['schema', 'name', 'alias', 'is_function'])):
__slots__ = ()
def has_alias(self):
return self.alias is not None
@property
def is_query_alias(self):
return self.name is None and self.alias is not None
@property
def is_table_alias(self):
return self.name is not None and self.alias is not None and not self.is_function
@property
def full_name(self):
if self.schema is None:
return self.name
else:
return self.schema + '.' + self.name
def _is_subselect(parsed):
if not parsed.is_group:
return False
for item in parsed.tokens:
if item.ttype is DML and item.value.upper() in ('SELECT', 'INSERT',
'UPDATE', 'CREATE', 'DELETE'):
return True
return False
def _identifier_is_function(identifier):
return any(isinstance(t, Function) for t in identifier.tokens)
def _extract_from_part(parsed):
tbl_prefix_seen = False
for item in parsed.tokens:
if item.is_group:
for x in _extract_from_part(item):
yield x
if tbl_prefix_seen:
if _is_subselect(item):
for x in _extract_from_part(item):
yield x
# An incomplete nested select won't be recognized correctly as a
# sub-select. eg: 'SELECT * FROM (SELECT id FROM user'. This causes
# the second FROM to trigger this elif condition resulting in a
# StopIteration. So we need to ignore the keyword if the keyword
# FROM.
# Also 'SELECT * FROM abc JOIN def' will trigger this elif
# condition. So we need to ignore the keyword JOIN and its variants
# INNER JOIN, FULL OUTER JOIN, etc.
elif item.ttype is Keyword and (
not item.value.upper() == 'FROM') and (
not item.value.upper().endswith('JOIN')):
tbl_prefix_seen = False
else:
yield item
elif item.ttype is Keyword or item.ttype is Keyword.DML:
item_val = item.value.upper()
if (item_val in ('COPY', 'FROM', 'INTO', 'UPDATE', 'TABLE') or
item_val.endswith('JOIN')):
tbl_prefix_seen = True
# 'SELECT a, FROM abc' will detect FROM as part of the column list.
# So this check here is necessary.
elif isinstance(item, IdentifierList):
for identifier in item.get_identifiers():
if (identifier.ttype is Keyword and
identifier.value.upper() == 'FROM'):
tbl_prefix_seen = True
break
def _extract_table_identifiers(token_stream):
for item in token_stream:
if isinstance(item, IdentifierList):
for ident in item.get_identifiers():
try:
alias = ident.get_alias()
schema_name = ident.get_parent_name()
real_name = ident.get_real_name()
except AttributeError:
continue
if real_name:
yield Reference(schema_name, real_name,
alias, _identifier_is_function(ident))
elif isinstance(item, Identifier):
yield Reference(item.get_parent_name(), item.get_real_name(),
item.get_alias(), _identifier_is_function(item))
elif isinstance(item, Function):
yield Reference(item.get_parent_name(), item.get_real_name(),
item.get_alias(), _identifier_is_function(item))
def extractTables(sql):
# let's handle multiple statements in one sql string
extracted_tables = []
statements = list(sqlparse.parse(sql))
for statement in statements:
stream = _extract_from_part(statement)
extracted_tables.append(list(_extract_table_identifiers(stream)))
return list(itertools.chain(*extracted_tables))
================================================
FILE: SQLToolsAPI/README.md
================================================
## SQLTools API for plugins - v0.2.5
Docs will be ready soon
================================================
FILE: SQLToolsAPI/Storage.py
================================================
import os
import shutil
from . import Utils as U
__version__ = "v0.1.0"
class Storage:
def __init__(self, filename, default=None):
self.storageFile = filename
self.defaultFile = default
self.items = {}
# copy entire file, to keep comments
# if not os.path.isfile(filename) and default and os.path.isfile(default):
# shutil.copyfile(default, filename)
self.all()
def all(self):
userFile = self.getFilename()
if os.path.exists(userFile):
self.items = U.parseJson(self.getFilename())
else:
self.items = {}
return U.merge(self.items, self.defaults())
def write(self):
return U.saveJson(self.items if isinstance(self.items, dict) else {}, self.getFilename())
def add(self, key, value):
if len(key) <= 0:
return
self.all()
if isinstance(value, str):
value = [value]
self.items[key] = '\n'.join(value)
self.write()
def delete(self, key):
if len(key) <= 0:
return
self.all()
self.items.pop(key)
self.write()
def get(self, key, default=None):
if len(key) <= 0:
return
items = self.all()
return items[key] if key in items else default
def getFilename(self):
return self.storageFile
def defaults(self):
if self.defaultFile and os.path.isfile(self.defaultFile):
return U.parseJson(self.defaultFile)
return {}
class Settings(Storage):
pass
================================================
FILE: SQLToolsAPI/Utils.py
================================================
__version__ = "v0.2.0"
import json
import os
import re
import sys
dirpath = os.path.join(os.path.dirname(__file__), 'lib')
if dirpath not in sys.path:
sys.path.append(dirpath)
import sqlparse
# Regular expression for comments
comment_re = re.compile(
'(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
re.DOTALL | re.MULTILINE
)
def parseJson(filename):
""" Parse a JSON file
First remove comments and then use the json module package
Comments look like :
// ...
or
/*
...
*/
"""
with open(filename, mode='r', encoding='utf-8') as f:
content = ''.join(f.readlines())
# Looking for comments
match = comment_re.search(content)
while match:
# single line comment
content = content[:match.start()] + content[match.end():]
match = comment_re.search(content)
# remove trailing commas
content = re.sub(r',([ \t\r\n]+)}', r'\1}', content)
content = re.sub(r',([ \t\r\n]+)\]', r'\1]', content)
# Return json file
return json.loads(content, encoding='utf-8')
def saveJson(content, filename):
with open(filename, mode='w', encoding='utf-8') as outfile:
json.dump(content, outfile,
sort_keys=True, indent=2, separators=(',', ': '))
def getResultAsList(results):
resultList = []
for result in results.splitlines():
lineResult = ''
for element in result.strip('|').split('|'):
lineResult += element.strip()
if lineResult:
resultList.append(lineResult)
return resultList
def formatSql(raw, settings):
try:
result = sqlparse.format(raw, **settings)
return result
except Exception:
return None
def merge(source, destination):
"""
run me with nosetests --with-doctest file.py
>>> a = { 'first' : { 'all_rows' : { 'pass' : 'dog', 'number' : '1' } } }
>>> b = { 'first' : { 'all_rows' : { 'fail' : 'cat', 'number' : '5' } } }
>>> merge(b, a) == { 'first' : { 'all_rows' : { 'pass' : 'dog', 'fail' : 'cat', 'number' : '5' } } }
True
"""
for key, value in source.items():
if isinstance(value, dict):
# get node or create one
node = destination.setdefault(key, {})
merge(value, node)
else:
destination[key] = value
return destination
================================================
FILE: SQLToolsAPI/__init__.py
================================================
__version__ = "v0.3.0"
__all__ = [
'Utils',
'Completion',
'Command',
'Connection',
'History',
'Storage',
'Settings'
]
================================================
FILE: SQLToolsAPI/lib/sqlparse/__init__.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
"""Parse SQL statements."""
# Setup namespace
from sqlparse import sql
from sqlparse import cli
from sqlparse import engine
from sqlparse import tokens
from sqlparse import filters
from sqlparse import formatter
from sqlparse.compat import text_type
__version__ = '0.2.3'
__all__ = ['engine', 'filters', 'formatter', 'sql', 'tokens', 'cli']
def parse(sql, encoding=None):
"""Parse sql and return a list of statements.
:param sql: A string containing one or more SQL statements.
:param encoding: The encoding of the statement (optional).
:returns: A tuple of :class:`~sqlparse.sql.Statement` instances.
"""
return tuple(parsestream(sql, encoding))
def parsestream(stream, encoding=None):
"""Parses sql statements from file-like object.
:param stream: A file-like object.
:param encoding: The encoding of the stream contents (optional).
:returns: A generator of :class:`~sqlparse.sql.Statement` instances.
"""
stack = engine.FilterStack()
stack.enable_grouping()
return stack.run(stream, encoding)
def format(sql, encoding=None, **options):
"""Format *sql* according to *options*.
Available options are documented in :ref:`formatting`.
In addition to the formatting options this function accepts the
keyword "encoding" which determines the encoding of the statement.
:returns: The formatted SQL statement as string.
"""
stack = engine.FilterStack()
options = formatter.validate_options(options)
stack = formatter.build_filter_stack(stack, options)
stack.postprocess.append(filters.SerializerUnicode())
return u''.join(stack.run(sql, encoding))
def split(sql, encoding=None):
"""Split *sql* into single statements.
:param sql: A string containing one or more SQL statements.
:param encoding: The encoding of the statement (optional).
:returns: A list of strings.
"""
stack = engine.FilterStack()
return [text_type(stmt).strip() for stmt in stack.run(sql, encoding)]
================================================
FILE: SQLToolsAPI/lib/sqlparse/__main__.py
================================================
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
"""Entrypoint module for `python -m sqlparse`.
Why does this file exist, and why __main__? For more info, read:
- https://www.python.org/dev/peps/pep-0338/
- https://docs.python.org/2/using/cmdline.html#cmdoption-m
- https://docs.python.org/3/using/cmdline.html#cmdoption-m
"""
import sys
from sqlparse.cli import main
if __name__ == '__main__':
sys.exit(main())
================================================
FILE: SQLToolsAPI/lib/sqlparse/cli.py
================================================
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
"""Module that contains the command line app.
Why does this file exist, and why not put this in __main__?
You might be tempted to import things from __main__ later, but that will
cause problems: the code will get executed twice:
- When you run `python -m sqlparse` python will execute
``__main__.py`` as a script. That means there won't be any
``sqlparse.__main__`` in ``sys.modules``.
- When you import __main__ it will get executed again (as a module) because
there's no ``sqlparse.__main__`` in ``sys.modules``.
Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
"""
import argparse
import sys
from io import TextIOWrapper
from codecs import open, getreader
import sqlparse
from sqlparse.compat import PY2
from sqlparse.exceptions import SQLParseError
# TODO: Add CLI Tests
# TODO: Simplify formatter by using argparse `type` arguments
def create_parser():
_CASE_CHOICES = ['upper', 'lower', 'capitalize']
parser = argparse.ArgumentParser(
prog='sqlformat',
description='Format FILE according to OPTIONS. Use "-" as FILE '
'to read from stdin.',
usage='%(prog)s [OPTIONS] FILE, ...',
)
parser.add_argument('filename')
parser.add_argument(
'-o', '--outfile',
dest='outfile',
metavar='FILE',
help='write output to FILE (defaults to stdout)')
parser.add_argument(
'--version',
action='version',
version=sqlparse.__version__)
group = parser.add_argument_group('Formatting Options')
group.add_argument(
'-k', '--keywords',
metavar='CHOICE',
dest='keyword_case',
choices=_CASE_CHOICES,
help='change case of keywords, CHOICE is one of {0}'.format(
', '.join('"{0}"'.format(x) for x in _CASE_CHOICES)))
group.add_argument(
'-i', '--identifiers',
metavar='CHOICE',
dest='identifier_case',
choices=_CASE_CHOICES,
help='change case of identifiers, CHOICE is one of {0}'.format(
', '.join('"{0}"'.format(x) for x in _CASE_CHOICES)))
group.add_argument(
'-l', '--language',
metavar='LANG',
dest='output_format',
choices=['python', 'php'],
help='output a snippet in programming language LANG, '
'choices are "python", "php"')
group.add_argument(
'--strip-comments',
dest='strip_comments',
action='store_true',
default=False,
help='remove comments')
group.add_argument(
'-r', '--reindent',
dest='reindent',
action='store_true',
default=False,
help='reindent statements')
group.add_argument(
'--indent_width',
dest='indent_width',
default=2,
type=int,
help='indentation width (defaults to 2 spaces)')
group.add_argument(
'-a', '--reindent_aligned',
action='store_true',
default=False,
help='reindent statements to aligned format')
group.add_argument(
'-s', '--use_space_around_operators',
action='store_true',
default=False,
help='place spaces around mathematical operators')
group.add_argument(
'--wrap_after',
dest='wrap_after',
default=0,
type=int,
help='Column after which lists should be wrapped')
group.add_argument(
'--comma_first',
dest='comma_first',
default=False,
type=bool,
help='Insert linebreak before comma (default False)')
group.add_argument(
'--encoding',
dest='encoding',
default='utf-8',
help='Specify the input encoding (default utf-8)')
return parser
def _error(msg):
"""Print msg and optionally exit with return code exit_."""
sys.stderr.write(u'[ERROR] {0}\n'.format(msg))
return 1
def main(args=None):
parser = create_parser()
args = parser.parse_args(args)
if args.filename == '-': # read from stdin
if PY2:
data = getreader(args.encoding)(sys.stdin).read()
else:
data = TextIOWrapper(
sys.stdin.buffer, encoding=args.encoding).read()
else:
try:
data = ''.join(open(args.filename, 'r', args.encoding).readlines())
except IOError as e:
return _error(
u'Failed to read {0}: {1}'.format(args.filename, e))
if args.outfile:
try:
stream = open(args.outfile, 'w', args.encoding)
except IOError as e:
return _error(u'Failed to open {0}: {1}'.format(args.outfile, e))
else:
stream = sys.stdout
formatter_opts = vars(args)
try:
formatter_opts = sqlparse.formatter.validate_options(formatter_opts)
except SQLParseError as e:
return _error(u'Invalid options: {0}'.format(e))
s = sqlparse.format(data, **formatter_opts)
stream.write(s)
stream.flush()
return 0
================================================
FILE: SQLToolsAPI/lib/sqlparse/compat.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
"""Python 2/3 compatibility.
This module only exists to avoid a dependency on six
for very trivial stuff. We only need to take care of
string types, buffers and metaclasses.
Parts of the code is copied directly from six:
https://bitbucket.org/gutworth/six
"""
import sys
from io import TextIOBase
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if PY3:
def unicode_compatible(cls):
return cls
bytes_type = bytes
text_type = str
string_types = (str,)
from io import StringIO
file_types = (StringIO, TextIOBase)
elif PY2:
def unicode_compatible(cls):
cls.__unicode__ = cls.__str__
cls.__str__ = lambda x: x.__unicode__().encode('utf-8')
return cls
bytes_type = str
text_type = unicode
string_types = (str, unicode,)
from StringIO import StringIO
file_types = (file, StringIO, TextIOBase)
from StringIO import StringIO
================================================
FILE: SQLToolsAPI/lib/sqlparse/engine/__init__.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
from sqlparse.engine import grouping
from sqlparse.engine.filter_stack import FilterStack
from sqlparse.engine.statement_splitter import StatementSplitter
__all__ = [
'grouping',
'FilterStack',
'StatementSplitter',
]
================================================
FILE: SQLToolsAPI/lib/sqlparse/engine/filter_stack.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
"""filter"""
from sqlparse import lexer
from sqlparse.engine import grouping
from sqlparse.engine.statement_splitter import StatementSplitter
class FilterStack(object):
def __init__(self):
self.preprocess = []
self.stmtprocess = []
self.postprocess = []
self._grouping = False
def enable_grouping(self):
self._grouping = True
def run(self, sql, encoding=None):
stream = lexer.tokenize(sql, encoding)
# Process token stream
for filter_ in self.preprocess:
stream = filter_.process(stream)
stream = StatementSplitter().process(stream)
# Output: Stream processed Statements
for stmt in stream:
if self._grouping:
stmt = grouping.group(stmt)
for filter_ in self.stmtprocess:
filter_.process(stmt)
for filter_ in self.postprocess:
stmt = filter_.process(stmt)
yield stmt
================================================
FILE: SQLToolsAPI/lib/sqlparse/engine/grouping.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
from sqlparse import sql
from sqlparse import tokens as T
from sqlparse.utils import recurse, imt
T_NUMERICAL = (T.Number, T.Number.Integer, T.Number.Float)
T_STRING = (T.String, T.String.Single, T.String.Symbol)
T_NAME = (T.Name, T.Name.Placeholder)
def _group_matching(tlist, cls):
"""Groups Tokens that have beginning and end."""
opens = []
tidx_offset = 0
for idx, token in enumerate(list(tlist)):
tidx = idx - tidx_offset
if token.is_whitespace:
# ~50% of tokens will be whitespace. Will checking early
# for them avoid 3 comparisons, but then add 1 more comparison
# for the other ~50% of tokens...
continue
if token.is_group and not isinstance(token, cls):
# Check inside previously grouped (ie. parenthesis) if group
# of differnt type is inside (ie, case). though ideally should
# should check for all open/close tokens at once to avoid recursion
_group_matching(token, cls)
continue
if token.match(*cls.M_OPEN):
opens.append(tidx)
elif token.match(*cls.M_CLOSE):
try:
open_idx = opens.pop()
except IndexError:
# this indicates invalid sql and unbalanced tokens.
# instead of break, continue in case other "valid" groups exist
continue
close_idx = tidx
tlist.group_tokens(cls, open_idx, close_idx)
tidx_offset += close_idx - open_idx
def group_brackets(tlist):
_group_matching(tlist, sql.SquareBrackets)
def group_parenthesis(tlist):
_group_matching(tlist, sql.Parenthesis)
def group_case(tlist):
_group_matching(tlist, sql.Case)
def group_if(tlist):
_group_matching(tlist, sql.If)
def group_for(tlist):
_group_matching(tlist, sql.For)
def group_begin(tlist):
_group_matching(tlist, sql.Begin)
def group_typecasts(tlist):
def match(token):
return token.match(T.Punctuation, '::')
def valid(token):
return token is not None
def post(tlist, pidx, tidx, nidx):
return pidx, nidx
valid_prev = valid_next = valid
_group(tlist, sql.Identifier, match, valid_prev, valid_next, post)
def group_period(tlist):
def match(token):
return token.match(T.Punctuation, '.')
def valid_prev(token):
sqlcls = sql.SquareBrackets, sql.Identifier
ttypes = T.Name, T.String.Symbol
return imt(token, i=sqlcls, t=ttypes)
def valid_next(token):
# issue261, allow invalid next token
return True
def post(tlist, pidx, tidx, nidx):
# next_ validation is being performed here. issue261
sqlcls = sql.SquareBrackets, sql.Function
ttypes = T.Name, T.String.Symbol, T.Wildcard
next_ = tlist[nidx] if nidx is not None else None
valid_next = imt(next_, i=sqlcls, t=ttypes)
return (pidx, nidx) if valid_next else (pidx, tidx)
_group(tlist, sql.Identifier, match, valid_prev, valid_next, post)
def group_as(tlist):
def match(token):
return token.is_keyword and token.normalized == 'AS'
def valid_prev(token):
return token.normalized == 'NULL' or not token.is_keyword
def valid_next(token):
ttypes = T.DML, T.DDL
return not imt(token, t=ttypes) and token is not None
def post(tlist, pidx, tidx, nidx):
return pidx, nidx
_group(tlist, sql.Identifier, match, valid_prev, valid_next, post)
def group_assignment(tlist):
def match(token):
return token.match(T.Assignment, ':=')
def valid(token):
return token is not None
def post(tlist, pidx, tidx, nidx):
m_semicolon = T.Punctuation, ';'
snidx, _ = tlist.token_next_by(m=m_semicolon, idx=nidx)
nidx = snidx or nidx
return pidx, nidx
valid_prev = valid_next = valid
_group(tlist, sql.Assignment, match, valid_prev, valid_next, post)
def group_comparison(tlist):
sqlcls = (sql.Parenthesis, sql.Function, sql.Identifier,
sql.Operation)
ttypes = T_NUMERICAL + T_STRING + T_NAME
def match(token):
return token.ttype == T.Operator.Comparison
def valid(token):
if imt(token, t=ttypes, i=sqlcls):
return True
elif token and token.is_keyword and token.normalized == 'NULL':
return True
else:
return False
def post(tlist, pidx, tidx, nidx):
return pidx, nidx
valid_prev = valid_next = valid
_group(tlist, sql.Comparison, match,
valid_prev, valid_next, post, extend=False)
@recurse(sql.Identifier)
def group_identifier(tlist):
ttypes = (T.String.Symbol, T.Name)
tidx, token = tlist.token_next_by(t=ttypes)
while token:
tlist.group_tokens(sql.Identifier, tidx, tidx)
tidx, token = tlist.token_next_by(t=ttypes, idx=tidx)
def group_arrays(tlist):
sqlcls = sql.SquareBrackets, sql.Identifier, sql.Function
ttypes = T.Name, T.String.Symbol
def match(token):
return isinstance(token, sql.SquareBrackets)
def valid_prev(token):
return imt(token, i=sqlcls, t=ttypes)
def valid_next(token):
return True
def post(tlist, pidx, tidx, nidx):
return pidx, tidx
_group(tlist, sql.Identifier, match,
valid_prev, valid_next, post, extend=True, recurse=False)
def group_operator(tlist):
ttypes = T_NUMERICAL + T_STRING + T_NAME
sqlcls = (sql.SquareBrackets, sql.Parenthesis, sql.Function,
sql.Identifier, sql.Operation)
def match(token):
return imt(token, t=(T.Operator, T.Wildcard))
def valid(token):
return imt(token, i=sqlcls, t=ttypes)
def post(tlist, pidx, tidx, nidx):
tlist[tidx].ttype = T.Operator
return pidx, nidx
valid_prev = valid_next = valid
_group(tlist, sql.Operation, match,
valid_prev, valid_next, post, extend=False)
def group_identifier_list(tlist):
m_role = T.Keyword, ('null', 'role')
sqlcls = (sql.Function, sql.Case, sql.Identifier, sql.Comparison,
sql.IdentifierList, sql.Operation)
ttypes = (T_NUMERICAL + T_STRING + T_NAME +
(T.Keyword, T.Comment, T.Wildcard))
def match(token):
return token.match(T.Punctuation, ',')
def valid(token):
return imt(token, i=sqlcls, m=m_role, t=ttypes)
def post(tlist, pidx, tidx, nidx):
return pidx, nidx
valid_prev = valid_next = valid
_group(tlist, sql.IdentifierList, match,
valid_prev, valid_next, post, extend=True)
@recurse(sql.Comment)
def group_comments(tlist):
tidx, token = tlist.token_next_by(t=T.Comment)
while token:
eidx, end = tlist.token_not_matching(
lambda tk: imt(tk, t=T.Comment) or tk.is_whitespace, idx=tidx)
if end is not None:
eidx, end = tlist.token_prev(eidx, skip_ws=False)
tlist.group_tokens(sql.Comment, tidx, eidx)
tidx, token = tlist.token_next_by(t=T.Comment, idx=tidx)
@recurse(sql.Where)
def group_where(tlist):
tidx, token = tlist.token_next_by(m=sql.Where.M_OPEN)
while token:
eidx, end = tlist.token_next_by(m=sql.Where.M_CLOSE, idx=tidx)
if end is None:
end = tlist._groupable_tokens[-1]
else:
end = tlist.tokens[eidx - 1]
# TODO: convert this to eidx instead of end token.
# i think above values are len(tlist) and eidx-1
eidx = tlist.token_index(end)
tlist.group_tokens(sql.Where, tidx, eidx)
tidx, token = tlist.token_next_by(m=sql.Where.M_OPEN, idx=tidx)
@recurse()
def group_aliased(tlist):
I_ALIAS = (sql.Parenthesis, sql.Function, sql.Case, sql.Identifier,
sql.Operation)
tidx, token = tlist.token_next_by(i=I_ALIAS, t=T.Number)
while token:
nidx, next_ = tlist.token_next(tidx)
if isinstance(next_, sql.Identifier):
tlist.group_tokens(sql.Identifier, tidx, nidx, extend=True)
tidx, token = tlist.token_next_by(i=I_ALIAS, t=T.Number, idx=tidx)
@recurse(sql.Function)
def group_functions(tlist):
has_create = False
has_table = False
for tmp_token in tlist.tokens:
if tmp_token.value == 'CREATE':
has_create = True
if tmp_token.value == 'TABLE':
has_table = True
if has_create and has_table:
return
tidx, token = tlist.token_next_by(t=T.Name)
while token:
nidx, next_ = tlist.token_next(tidx)
if isinstance(next_, sql.Parenthesis):
tlist.group_tokens(sql.Function, tidx, nidx)
tidx, token = tlist.token_next_by(t=T.Name, idx=tidx)
def group_order(tlist):
"""Group together Identifier and Asc/Desc token"""
tidx, token = tlist.token_next_by(t=T.Keyword.Order)
while token:
pidx, prev_ = tlist.token_prev(tidx)
if imt(prev_, i=sql.Identifier, t=T.Number):
tlist.group_tokens(sql.Identifier, pidx, tidx)
tidx = pidx
tidx, token = tlist.token_next_by(t=T.Keyword.Order, idx=tidx)
@recurse()
def align_comments(tlist):
tidx, token = tlist.token_next_by(i=sql.Comment)
while token:
pidx, prev_ = tlist.token_prev(tidx)
if isinstance(prev_, sql.TokenList):
tlist.group_tokens(sql.TokenList, pidx, tidx, extend=True)
tidx = pidx
tidx, token = tlist.token_next_by(i=sql.Comment, idx=tidx)
def group(stmt):
for func in [
group_comments,
# _group_matching
group_brackets,
group_parenthesis,
group_case,
group_if,
group_for,
group_begin,
group_functions,
group_where,
group_period,
group_arrays,
group_identifier,
group_order,
group_typecasts,
group_operator,
group_as,
group_aliased,
group_assignment,
group_comparison,
align_comments,
group_identifier_list,
]:
func(stmt)
return stmt
def _group(tlist, cls, match,
valid_prev=lambda t: True,
valid_next=lambda t: True,
post=None,
extend=True,
recurse=True
):
"""Groups together tokens that are joined by a middle token. ie. x < y"""
tidx_offset = 0
pidx, prev_ = None, None
for idx, token in enumerate(list(tlist)):
tidx = idx - tidx_offset
if token.is_whitespace:
continue
if recurse and token.is_group and not isinstance(token, cls):
_group(token, cls, match, valid_prev, valid_next, post, extend)
if match(token):
nidx, next_ = tlist.token_next(tidx)
if prev_ and valid_prev(prev_) and valid_next(next_):
from_idx, to_idx = post(tlist, pidx, tidx, nidx)
grp = tlist.group_tokens(cls, from_idx, to_idx, extend=extend)
tidx_offset += to_idx - from_idx
pidx, prev_ = from_idx, grp
continue
pidx, prev_ = tidx, token
================================================
FILE: SQLToolsAPI/lib/sqlparse/engine/statement_splitter.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
from sqlparse import sql, tokens as T
class StatementSplitter(object):
"""Filter that split stream at individual statements"""
def __init__(self):
self._reset()
def _reset(self):
"""Set the filter attributes to its default values"""
self._in_declare = False
self._is_create = False
self._begin_depth = 0
self.consume_ws = False
self.tokens = []
self.level = 0
def _change_splitlevel(self, ttype, value):
"""Get the new split level (increase, decrease or remain equal)"""
# ANSI
# if normal token return
# wouldn't parenthesis increase/decrease a level?
# no, inside a paranthesis can't start new statement
if ttype not in T.Keyword:
return 0
# Everything after here is ttype = T.Keyword
# Also to note, once entered an If statement you are done and basically
# returning
unified = value.upper()
# three keywords begin with CREATE, but only one of them is DDL
# DDL Create though can contain more words such as "or replace"
if ttype is T.Keyword.DDL and unified.startswith('CREATE'):
self._is_create = True
return 0
# can have nested declare inside of being...
if unified == 'DECLARE' and self._is_create and self._begin_depth == 0:
self._in_declare = True
return 1
if unified == 'BEGIN':
self._begin_depth += 1
if self._is_create:
# FIXME(andi): This makes no sense.
return 1
return 0
# Should this respect a preceeding BEGIN?
# In CASE ... WHEN ... END this results in a split level -1.
# Would having multiple CASE WHEN END and a Assigment Operator
# cause the statement to cut off prematurely?
if unified == 'END':
self._begin_depth = max(0, self._begin_depth - 1)
return -1
if (unified in ('IF', 'FOR', 'WHILE') and
self._is_create and self._begin_depth > 0):
return 1
if unified in ('END IF', 'END FOR', 'END WHILE'):
return -1
# Default
return 0
def process(self, stream):
"""Process the stream"""
EOS_TTYPE = T.Whitespace, T.Comment.Single
# Run over all stream tokens
for ttype, value in stream:
# Yield token if we finished a statement and there's no whitespaces
# It will count newline token as a non whitespace. In this context
# whitespace ignores newlines.
# why don't multi line comments also count?
if self.consume_ws and ttype not in EOS_TTYPE:
yield sql.Statement(self.tokens)
# Reset filter and prepare to process next statement
self._reset()
# Change current split level (increase, decrease or remain equal)
self.level += self._change_splitlevel(ttype, value)
# Append the token to the current statement
self.tokens.append(sql.Token(ttype, value))
# Check if we get the end of a statement
if self.level <= 0 and ttype is T.Punctuation and value == ';':
self.consume_ws = True
# Yield pending statement (if any)
if self.tokens:
yield sql.Statement(self.tokens)
================================================
FILE: SQLToolsAPI/lib/sqlparse/exceptions.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
"""Exceptions used in this package."""
class SQLParseError(Exception):
"""Base class for exceptions in this module."""
================================================
FILE: SQLToolsAPI/lib/sqlparse/filters/__init__.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
from sqlparse.filters.others import SerializerUnicode
from sqlparse.filters.others import StripCommentsFilter
from sqlparse.filters.others import StripWhitespaceFilter
from sqlparse.filters.others import SpacesAroundOperatorsFilter
from sqlparse.filters.output import OutputPHPFilter
from sqlparse.filters.output import OutputPythonFilter
from sqlparse.filters.tokens import KeywordCaseFilter
from sqlparse.filters.tokens import IdentifierCaseFilter
from sqlparse.filters.tokens import TruncateStringFilter
from sqlparse.filters.reindent import ReindentFilter
from sqlparse.filters.right_margin import RightMarginFilter
from sqlparse.filters.aligned_indent import AlignedIndentFilter
__all__ = [
'SerializerUnicode',
'StripCommentsFilter',
'StripWhitespaceFilter',
'SpacesAroundOperatorsFilter',
'OutputPHPFilter',
'OutputPythonFilter',
'KeywordCaseFilter',
'IdentifierCaseFilter',
'TruncateStringFilter',
'ReindentFilter',
'RightMarginFilter',
'AlignedIndentFilter',
]
================================================
FILE: SQLToolsAPI/lib/sqlparse/filters/aligned_indent.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
from sqlparse import sql, tokens as T
from sqlparse.compat import text_type
from sqlparse.utils import offset, indent
class AlignedIndentFilter(object):
join_words = (r'((LEFT\s+|RIGHT\s+|FULL\s+)?'
r'(INNER\s+|OUTER\s+|STRAIGHT\s+)?|'
r'(CROSS\s+|NATURAL\s+)?)?JOIN\b')
split_words = ('FROM',
join_words, 'ON',
'WHERE', 'AND', 'OR',
'GROUP', 'HAVING', 'LIMIT',
'ORDER', 'UNION', 'VALUES',
'SET', 'BETWEEN', 'EXCEPT')
def __init__(self, char=' ', n='\n'):
self.n = n
self.offset = 0
self.indent = 0
self.char = char
self._max_kwd_len = len('select')
def nl(self, offset=1):
# offset = 1 represent a single space after SELECT
offset = -len(offset) if not isinstance(offset, int) else offset
# add two for the space and parens
indent = self.indent * (2 + self._max_kwd_len)
return sql.Token(T.Whitespace, self.n + self.char * (
self._max_kwd_len + offset + indent + self.offset))
def _process_statement(self, tlist):
if tlist.tokens[0].is_whitespace and self.indent == 0:
tlist.tokens.pop(0)
# process the main query body
self._process(sql.TokenList(tlist.tokens))
def _process_parenthesis(self, tlist):
# if this isn't a subquery, don't re-indent
_, token = tlist.token_next_by(m=(T.DML, 'SELECT'))
if token is not None:
with indent(self):
tlist.insert_after(tlist[0], self.nl('SELECT'))
# process the inside of the parantheses
self._process_default(tlist)
# de-indent last parenthesis
tlist.insert_before(tlist[-1], self.nl())
def _process_identifierlist(self, tlist):
# columns being selected
identifiers = list(tlist.get_identifiers())
identifiers.pop(0)
[tlist.insert_before(token, self.nl()) for token in identifiers]
self._process_default(tlist)
def _process_case(self, tlist):
offset_ = len('case ') + len('when ')
cases = tlist.get_cases(skip_ws=True)
# align the end as well
end_token = tlist.token_next_by(m=(T.Keyword, 'END'))[1]
cases.append((None, [end_token]))
condition_width = [len(' '.join(map(text_type, cond))) if cond else 0
for cond, _ in cases]
max_cond_width = max(condition_width)
for i, (cond, value) in enumerate(cases):
# cond is None when 'else or end'
stmt = cond[0] if cond else value[0]
if i > 0:
tlist.insert_before(stmt, self.nl(
offset_ - len(text_type(stmt))))
if cond:
ws = sql.Token(T.Whitespace, self.char * (
max_cond_width - condition_width[i]))
tlist.insert_after(cond[-1], ws)
def _next_token(self, tlist, idx=-1):
split_words = T.Keyword, self.split_words, True
tidx, token = tlist.token_next_by(m=split_words, idx=idx)
# treat "BETWEEN x and y" as a single statement
if token and token.normalized == 'BETWEEN':
tidx, token = self._next_token(tlist, tidx)
if token and token.normalized == 'AND':
tidx, token = self._next_token(tlist, tidx)
return tidx, token
def _split_kwds(self, tlist):
tidx, token = self._next_token(tlist)
while token:
# joins are special case. only consider the first word as aligner
if token.match(T.Keyword, self.join_words, regex=True):
token_indent = token.value.split()[0]
else:
token_indent = text_type(token)
tlist.insert_before(token, self.nl(token_indent))
tidx += 1
tidx, token = self._next_token(tlist, tidx)
def _process_default(self, tlist):
self._split_kwds(tlist)
# process any sub-sub statements
for sgroup in tlist.get_sublists():
idx = tlist.token_index(sgroup)
pidx, prev_ = tlist.token_prev(idx)
# HACK: make "group/order by" work. Longer than max_len.
offset_ = 3 if (prev_ and prev_.match(T.Keyword, 'BY')) else 0
with offset(self, offset_):
self._process(sgroup)
def _process(self, tlist):
func_name = '_process_{cls}'.format(cls=type(tlist).__name__)
func = getattr(self, func_name.lower(), self._process_default)
func(tlist)
def process(self, stmt):
self._process(stmt)
return stmt
================================================
FILE: SQLToolsAPI/lib/sqlparse/filters/others.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
from sqlparse import sql, tokens as T
from sqlparse.utils import split_unquoted_newlines
class StripCommentsFilter(object):
@staticmethod
def _process(tlist):
def get_next_comment():
# TODO(andi) Comment types should be unified, see related issue38
return tlist.token_next_by(i=sql.Comment, t=T.Comment)
tidx, token = get_next_comment()
while token:
pidx, prev_ = tlist.token_prev(tidx, skip_ws=False)
nidx, next_ = tlist.token_next(tidx, skip_ws=False)
# Replace by whitespace if prev and next exist and if they're not
# whitespaces. This doesn't apply if prev or next is a paranthesis.
if (prev_ is None or next_ is None or
prev_.is_whitespace or prev_.match(T.Punctuation, '(') or
next_.is_whitespace or next_.match(T.Punctuation, ')')):
tlist.tokens.remove(token)
else:
tlist.tokens[tidx] = sql.Token(T.Whitespace, ' ')
tidx, token = get_next_comment()
def process(self, stmt):
[self.process(sgroup) for sgroup in stmt.get_sublists()]
StripCommentsFilter._process(stmt)
return stmt
class StripWhitespaceFilter(object):
def _stripws(self, tlist):
func_name = '_stripws_{cls}'.format(cls=type(tlist).__name__)
func = getattr(self, func_name.lower(), self._stripws_default)
func(tlist)
@staticmethod
def _stripws_default(tlist):
last_was_ws = False
is_first_char = True
for token in tlist.tokens:
if token.is_whitespace:
token.value = '' if last_was_ws or is_first_char else ' '
last_was_ws = token.is_whitespace
is_first_char = False
def _stripws_identifierlist(self, tlist):
# Removes newlines before commas, see issue140
last_nl = None
for token in list(tlist.tokens):
if last_nl and token.ttype is T.Punctuation and token.value == ',':
tlist.tokens.remove(last_nl)
last_nl = token if token.is_whitespace else None
# next_ = tlist.token_next(token, skip_ws=False)
# if (next_ and not next_.is_whitespace and
# token.ttype is T.Punctuation and token.value == ','):
# tlist.insert_after(token, sql.Token(T.Whitespace, ' '))
return self._stripws_default(tlist)
def _stripws_parenthesis(self, tlist):
if tlist.tokens[1].is_whitespace:
tlist.tokens.pop(1)
if tlist.tokens[-2].is_whitespace:
tlist.tokens.pop(-2)
self._stripws_default(tlist)
def process(self, stmt, depth=0):
[self.process(sgroup, depth + 1) for sgroup in stmt.get_sublists()]
self._stripws(stmt)
if depth == 0 and stmt.tokens and stmt.tokens[-1].is_whitespace:
stmt.tokens.pop(-1)
return stmt
class SpacesAroundOperatorsFilter(object):
@staticmethod
def _process(tlist):
ttypes = (T.Operator, T.Comparison)
tidx, token = tlist.token_next_by(t=ttypes)
while token:
nidx, next_ = tlist.token_next(tidx, skip_ws=False)
if next_ and next_.ttype != T.Whitespace:
tlist.insert_after(tidx, sql.Token(T.Whitespace, ' '))
pidx, prev_ = tlist.token_prev(tidx, skip_ws=False)
if prev_ and prev_.ttype != T.Whitespace:
tlist.insert_before(tidx, sql.Token(T.Whitespace, ' '))
tidx += 1 # has to shift since token inserted before it
# assert tlist.token_index(token) == tidx
tidx, token = tlist.token_next_by(t=ttypes, idx=tidx)
def process(self, stmt):
[self.process(sgroup) for sgroup in stmt.get_sublists()]
SpacesAroundOperatorsFilter._process(stmt)
return stmt
# ---------------------------
# postprocess
class SerializerUnicode(object):
@staticmethod
def process(stmt):
lines = split_unquoted_newlines(stmt)
return '\n'.join(line.rstrip() for line in lines)
================================================
FILE: SQLToolsAPI/lib/sqlparse/filters/output.py
================================================
# -*- coding: utf-8 -*-
#
# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: https://opensource.org/licenses/BSD-3-Clause
from sqlparse import sql, tokens as T
from sqlparse.compat import text_type
class OutputFilter(object):
varname_prefix = ''
def __init__(self, varname='sql'):
self.varname = self.varname_prefix + varname
self.count = 0
def _process(self, stream, varname, has_nl):
raise NotImplementedError
def process(self, stmt):
self.count += 1
if self.count > 1:
varname = u'{f.varname}{f.count}'.format(f=self)
else:
varname = self.varname
has_nl = len(text_type(stmt).strip().splitlines()) > 1
stmt.tokens = self._process(stmt.tokens, varname, has_nl)
return stmt
class OutputPythonFilter(OutputFilter):
def _process(self, stream, varname, has_nl):
# SQL query asignation to varname
if self.count > 1:
yield sql.Token(T.Whitespace, '\n')
yield sql.Token(T.Name, varname)
yield sql.Token(T.Whitespace, ' ')
yield sql.Token(T.Operator, '=')
yield sql.Token(T.Whitespace, ' ')
if has_nl:
yield sql.Token(T.Operator, '(')
yield sql.Token(T.Text, "'")
# Print the tokens on the quote
for token in stream:
# Token is a new line separator
if token.is_whitespace and '\n' in token.value:
# Close quote and add a new line
yield sql.Token(T.Text, " '")
yield sql.Token(T.Whitespace, '\n')
# Quote header on secondary lines
yield sql.Token(T.Whitespace, ' ' * (len(varname) + 4))
yield sql.Token(T.Text, "'")
# Indentation
after_lb = token.value.split('\n', 1)[1]
if after_lb:
yield sql.Token(T.Whitespace, after_lb)
continue
# Token has escape chars
elif "'" in token.value:
token.value = token.value.replace("'", "\\'")
# Put the token
yield sql.Token(T.Text, token.value)
# Close quote
yield sql.Token(T.Text, "'")
if has_nl:
yield sql.Token(T.Operator, ')')
class OutputPHPFilter(OutputFilter):
varname_prefix = '$'
def _process(self, stream, varname, has_nl):
# SQL query asignation to varname (quote header)
if self.count > 1:
yield sql.Token(T.Whitespace, '\n')
yield sql.Token(T.Name, varname)
yield sql.Token(T.Whitespace, ' ')
if has_nl:
yield sql.Token(T.Whitespace, ' ')
yield sql.Token(T.Operator, '=')
yield sql.Token(T.Whitespace, ' ')
yield sql.Token(T.Text, '"')
# Print the tokens on the quote
for token in stream:
# Token is a new line separator
if token.is_whitespace and '\n' in token.value:
# Close quote and add a new line
yield sql.Token(T.Text, ' ";')
yield sql.Token(T.Whitespace, '\n')
# Quote header on secondary lines
yield sql.Token(T.Name, varname)
yield sql.Token(T.Whitespace, ' ')
yield sql.Token(T.Operator, '.=')
yield sql.Token(T.Whitespace, ' ')
yield sq
gitextract_blnxvnte/ ├── .bumpversion.cfg ├── .gitignore ├── .mention-bot ├── .no-sublime-package ├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap ├── Default (Windows).sublime-keymap ├── Default.sublime-commands ├── ISSUE_TEMPLATE.md ├── LICENSE.md ├── Main.sublime-menu ├── README.md ├── SQLTools.py ├── SQLTools.sublime-settings ├── SQLToolsAPI/ │ ├── Command.py │ ├── Completion.py │ ├── Connection.py │ ├── History.py │ ├── ParseUtils.py │ ├── README.md │ ├── Storage.py │ ├── Utils.py │ ├── __init__.py │ └── lib/ │ └── sqlparse/ │ ├── __init__.py │ ├── __main__.py │ ├── cli.py │ ├── compat.py │ ├── engine/ │ │ ├── __init__.py │ │ ├── filter_stack.py │ │ ├── grouping.py │ │ └── statement_splitter.py │ ├── exceptions.py │ ├── filters/ │ │ ├── __init__.py │ │ ├── aligned_indent.py │ │ ├── others.py │ │ ├── output.py │ │ ├── reindent.py │ │ ├── right_margin.py │ │ └── tokens.py │ ├── formatter.py │ ├── keywords.py │ ├── lexer.py │ ├── sql.py │ ├── tokens.py │ └── utils.py ├── SQLToolsConnections.sublime-settings ├── SQLToolsSavedQueries.sublime-settings ├── messages/ │ ├── install.md │ ├── v0.1.6.md │ ├── v0.2.0.md │ ├── v0.3.0.md │ ├── v0.8.2.md │ ├── v0.9.0.md │ ├── v0.9.1.md │ ├── v0.9.10.md │ ├── v0.9.11.md │ ├── v0.9.12.md │ ├── v0.9.2.md │ ├── v0.9.3.md │ ├── v0.9.4.md │ ├── v0.9.5.md │ ├── v0.9.6.md │ ├── v0.9.7.md │ ├── v0.9.8.md │ └── v0.9.9.md └── messages.json
SYMBOL INDEX (341 symbols across 27 files)
FILE: SQLTools.py
function getSublimeUserFolder (line 53) | def getSublimeUserFolder():
function startPlugin (line 57) | def startPlugin():
function readConnections (line 103) | def readConnections():
function getDefaultConnectionName (line 127) | def getDefaultConnectionName():
function createOutput (line 134) | def createOutput(panel=None, syntax=None, prependText=None):
function toNewTab (line 158) | def toNewTab(content, name="", suffix="SQLTools Saved Query"):
function insertContent (line 166) | def insertContent(content):
function getOutputPlace (line 180) | def getOutputPlace(syntax=None, name="SQLTools Result"):
function getSelectionText (line 232) | def getSelectionText():
function getSelectionRegions (line 246) | def getSelectionRegions():
function getCurrentSyntax (line 290) | def getCurrentSyntax():
class ST (line 298) | class ST(EventListener):
method bootstrap (line 307) | def bootstrap():
method setDefaultConnection (line 312) | def setDefaultConnection():
method setConnection (line 323) | def setConnection(connectionName, callback=None):
method loadConnectionData (line 385) | def loadConnectionData(callback=None):
method selectConnectionQuickPanel (line 432) | def selectConnectionQuickPanel(callback=None):
method showTablesQuickPanel (line 471) | def showTablesQuickPanel(callback):
method showFunctionsQuickPanel (line 479) | def showFunctionsQuickPanel(callback):
method showQuickPanelWithSelection (line 487) | def showQuickPanelWithSelection(arrayOfValues, callback):
method on_query_completions (line 506) | def on_query_completions(view, prefix, locations):
class StShowConnectionMenu (line 580) | class StShowConnectionMenu(WindowCommand):
method run (line 582) | def run():
class StSelectConnection (line 586) | class StSelectConnection(WindowCommand):
method run (line 588) | def run():
class StShowRecords (line 592) | class StShowRecords(WindowCommand):
method run (line 594) | def run():
class StDescTable (line 612) | class StDescTable(WindowCommand):
method run (line 614) | def run():
class StDescFunction (line 630) | class StDescFunction(WindowCommand):
method run (line 632) | def run():
class StRefreshConnectionData (line 651) | class StRefreshConnectionData(WindowCommand):
method run (line 653) | def run():
class StExplainPlan (line 659) | class StExplainPlan(WindowCommand):
method run (line 661) | def run():
class StExecute (line 670) | class StExecute(WindowCommand):
method run (line 672) | def run():
class StExecuteAll (line 681) | class StExecuteAll(WindowCommand):
method run (line 683) | def run():
class StFormat (line 693) | class StFormat(TextCommand):
method run (line 695) | def run(edit):
class StFormatAll (line 706) | class StFormatAll(TextCommand):
method run (line 708) | def run(edit):
class StVersion (line 714) | class StVersion(WindowCommand):
method run (line 716) | def run():
class StHistory (line 720) | class StHistory(WindowCommand):
method run (line 722) | def run():
class StSaveQuery (line 739) | class StSaveQuery(WindowCommand):
method run (line 741) | def run():
class StListQueries (line 749) | class StListQueries(WindowCommand):
method run (line 751) | def run(mode="run"):
class StRemoveSavedQuery (line 787) | class StRemoveSavedQuery(WindowCommand):
method run (line 789) | def run():
function Window (line 815) | def Window():
function View (line 819) | def View():
function reload (line 823) | def reload():
function plugin_loaded (line 843) | def plugin_loaded():
function plugin_unloaded (line 865) | def plugin_unloaded():
FILE: SQLToolsAPI/Command.py
class Command (line 11) | class Command(object):
method __init__ (line 14) | def __init__(self, args, env, callback, query=None, encoding='utf-8',
method run (line 36) | def run(self):
method _formatShowQuery (line 121) | def _formatShowQuery(query, queryTimeStart, queryTimeEnd):
method createAndRun (line 131) | def createAndRun(args, env, callback, query=None, encoding='utf-8',
class ThreadCommand (line 147) | class ThreadCommand(Command, Thread):
method __init__ (line 148) | def __init__(self, args, env, callback, query=None, encoding='utf-8',
method stop (line 165) | def stop(self):
method createAndRun (line 191) | def createAndRun(args, env, callback, query=None, encoding='utf-8',
FILE: SQLToolsAPI/Completion.py
function _stripQuotes (line 22) | def _stripQuotes(ident):
function _stripQuotesOnDemand (line 27) | def _stripQuotesOnDemand(ident, doStrip=True):
function _startsWithQuote (line 33) | def _startsWithQuote(ident):
function _stripPrefix (line 39) | def _stripPrefix(text, prefix):
function _escapeDollarSign (line 46) | def _escapeDollarSign(ident):
class CompletionItem (line 50) | class CompletionItem(namedtuple('CompletionItem', ['type', 'ident'])):
method parent (line 58) | def parent(self):
method name (line 66) | def name(self):
method _matchIdent (line 72) | def _matchIdent(self):
method _stringMatched (line 84) | def _stringMatched(target, search, exactly):
method prefixMatchScore (line 100) | def prefixMatchScore(self, search, exactly=False):
method prefixMatchListScore (line 132) | def prefixMatchListScore(self, searchList, exactly=False):
method format (line 140) | def format(self, stripQuotes=False):
class Completion (line 165) | class Completion:
method __init__ (line 166) | def __init__(self, allTables, allColumns, allFunctions, settings=None):
method getActiveSelectors (line 210) | def getActiveSelectors(self):
method getIgnoreSelectors (line 213) | def getIgnoreSelectors(self):
method isDisabled (line 216) | def isDisabled(self):
method getAutoCompleteList (line 219) | def getAutoCompleteList(self, prefix, sql, sqlToCursor):
method _getAutoCompleteListBasic (line 240) | def _getAutoCompleteListBasic(self, prefix):
method _getAutoCompleteListSmart (line 265) | def _getAutoCompleteListSmart(self, prefix, sql, sqlToCursor):
method _noDotsCompletions (line 327) | def _noDotsCompletions(self, prefix, identifiers, joinAlias=None):
method _singleDotCompletions (line 427) | def _singleDotCompletions(self, prefix, identifiers, joinAlias=None):
method _multiDotCompletions (line 500) | def _multiDotCompletions(self, prefix, identifiers):
method _joinConditionCompletions (line 512) | def _joinConditionCompletions(self, identifiers, joinAlias=None):
FILE: SQLToolsAPI/Connection.py
function _encoding_exists (line 13) | def _encoding_exists(enc):
class Connection (line 21) | class Connection(object):
method __init__ (line 48) | def __init__(self, name, options, settings=None, commandClass='ThreadC...
method __str__ (line 80) | def __str__(self):
method info (line 83) | def info(self):
method runInternalNamedQueryCommand (line 87) | def runInternalNamedQueryCommand(self, queryName, callback):
method getTables (line 110) | def getTables(self, callback):
method getColumns (line 113) | def getColumns(self, callback):
method getFunctions (line 116) | def getFunctions(self, callback):
method runFormattedNamedQueryCommand (line 119) | def runFormattedNamedQueryCommand(self, queryName, formatValues, callb...
method getTableRecords (line 145) | def getTableRecords(self, tableName, callback):
method getTableDescription (line 150) | def getTableDescription(self, tableName, callback):
method getFunctionDescription (line 153) | def getFunctionDescription(self, functionName, callback):
method explainPlan (line 156) | def explainPlan(self, queries, callback):
method execute (line 179) | def execute(self, queries, callback, stream=None):
method getNamedQuery (line 227) | def getNamedQuery(self, queryName):
method buildNamedQuery (line 234) | def buildNamedQuery(self, queryName, queries):
method buildArgs (line 268) | def buildArgs(self, queryName=None):
method buildEnv (line 308) | def buildEnv(self):
method getOptionsForSgdbCli (line 333) | def getOptionsForSgdbCli(self):
method formatOptionalArgument (line 337) | def formatOptionalArgument(argument, formatOptions):
method setTimeout (line 348) | def setTimeout(timeout):
method setHistoryManager (line 353) | def setHistoryManager(manager):
FILE: SQLToolsAPI/History.py
class SizeException (line 4) | class SizeException(Exception):
class NotFoundException (line 8) | class NotFoundException(Exception):
class History (line 12) | class History:
method __init__ (line 14) | def __init__(self, maxSize=100):
method add (line 18) | def add(self, query):
method get (line 23) | def get(self, index):
method setMaxSize (line 29) | def setMaxSize(self, size=100):
method getMaxSize (line 36) | def getMaxSize(self):
method getSize (line 39) | def getSize(self):
method all (line 42) | def all(self):
method clear (line 45) | def clear(self):
FILE: SQLToolsAPI/ParseUtils.py
class Reference (line 16) | class Reference(namedtuple('Reference', ['schema', 'name', 'alias', 'is_...
method has_alias (line 19) | def has_alias(self):
method is_query_alias (line 23) | def is_query_alias(self):
method is_table_alias (line 27) | def is_table_alias(self):
method full_name (line 31) | def full_name(self):
function _is_subselect (line 38) | def _is_subselect(parsed):
function _identifier_is_function (line 48) | def _identifier_is_function(identifier):
function _extract_from_part (line 52) | def _extract_from_part(parsed):
function _extract_table_identifiers (line 91) | def _extract_table_identifiers(token_stream):
function extractTables (line 112) | def extractTables(sql):
FILE: SQLToolsAPI/Storage.py
class Storage (line 8) | class Storage:
method __init__ (line 9) | def __init__(self, filename, default=None):
method all (line 20) | def all(self):
method write (line 30) | def write(self):
method add (line 33) | def add(self, key, value):
method delete (line 45) | def delete(self, key):
method get (line 53) | def get(self, key, default=None):
method getFilename (line 60) | def getFilename(self):
method defaults (line 63) | def defaults(self):
class Settings (line 69) | class Settings(Storage):
FILE: SQLToolsAPI/Utils.py
function parseJson (line 21) | def parseJson(filename):
function saveJson (line 50) | def saveJson(content, filename):
function getResultAsList (line 56) | def getResultAsList(results):
function formatSql (line 67) | def formatSql(raw, settings):
function merge (line 76) | def merge(source, destination):
FILE: SQLToolsAPI/lib/sqlparse/__init__.py
function parse (line 24) | def parse(sql, encoding=None):
function parsestream (line 34) | def parsestream(stream, encoding=None):
function format (line 46) | def format(sql, encoding=None, **options):
function split (line 63) | def split(sql, encoding=None):
FILE: SQLToolsAPI/lib/sqlparse/cli.py
function create_parser (line 34) | def create_parser():
function _error (line 139) | def _error(msg):
function main (line 145) | def main(args=None):
FILE: SQLToolsAPI/lib/sqlparse/compat.py
function unicode_compatible (line 26) | def unicode_compatible(cls):
function unicode_compatible (line 37) | def unicode_compatible(cls):
FILE: SQLToolsAPI/lib/sqlparse/engine/filter_stack.py
class FilterStack (line 15) | class FilterStack(object):
method __init__ (line 16) | def __init__(self):
method enable_grouping (line 22) | def enable_grouping(self):
method run (line 25) | def run(self, sql, encoding=None):
FILE: SQLToolsAPI/lib/sqlparse/engine/grouping.py
function _group_matching (line 17) | def _group_matching(tlist, cls):
function group_brackets (line 52) | def group_brackets(tlist):
function group_parenthesis (line 56) | def group_parenthesis(tlist):
function group_case (line 60) | def group_case(tlist):
function group_if (line 64) | def group_if(tlist):
function group_for (line 68) | def group_for(tlist):
function group_begin (line 72) | def group_begin(tlist):
function group_typecasts (line 76) | def group_typecasts(tlist):
function group_period (line 90) | def group_period(tlist):
function group_as (line 115) | def group_as(tlist):
function group_assignment (line 132) | def group_assignment(tlist):
function group_comparison (line 149) | def group_comparison(tlist):
function group_identifier (line 174) | def group_identifier(tlist):
function group_arrays (line 183) | def group_arrays(tlist):
function group_operator (line 203) | def group_operator(tlist):
function group_identifier_list (line 223) | def group_identifier_list(tlist):
function group_comments (line 245) | def group_comments(tlist):
function group_where (line 258) | def group_where(tlist):
function group_aliased (line 275) | def group_aliased(tlist):
function group_functions (line 288) | def group_functions(tlist):
function group_order (line 307) | def group_order(tlist):
function align_comments (line 319) | def align_comments(tlist):
function group (line 329) | def group(stmt):
function _group (line 361) | def _group(tlist, cls, match,
FILE: SQLToolsAPI/lib/sqlparse/engine/statement_splitter.py
class StatementSplitter (line 11) | class StatementSplitter(object):
method __init__ (line 14) | def __init__(self):
method _reset (line 17) | def _reset(self):
method _change_splitlevel (line 27) | def _change_splitlevel(self, ttype, value):
method process (line 77) | def process(self, stream):
FILE: SQLToolsAPI/lib/sqlparse/exceptions.py
class SQLParseError (line 11) | class SQLParseError(Exception):
FILE: SQLToolsAPI/lib/sqlparse/filters/aligned_indent.py
class AlignedIndentFilter (line 13) | class AlignedIndentFilter(object):
method __init__ (line 24) | def __init__(self, char=' ', n='\n'):
method nl (line 31) | def nl(self, offset=1):
method _process_statement (line 40) | def _process_statement(self, tlist):
method _process_parenthesis (line 47) | def _process_parenthesis(self, tlist):
method _process_identifierlist (line 59) | def _process_identifierlist(self, tlist):
method _process_case (line 66) | def _process_case(self, tlist):
method _next_token (line 89) | def _next_token(self, tlist, idx=-1):
method _split_kwds (line 99) | def _split_kwds(self, tlist):
method _process_default (line 111) | def _process_default(self, tlist):
method _process (line 122) | def _process(self, tlist):
method process (line 127) | def process(self, stmt):
FILE: SQLToolsAPI/lib/sqlparse/filters/others.py
class StripCommentsFilter (line 12) | class StripCommentsFilter(object):
method _process (line 14) | def _process(tlist):
method process (line 34) | def process(self, stmt):
class StripWhitespaceFilter (line 40) | class StripWhitespaceFilter(object):
method _stripws (line 41) | def _stripws(self, tlist):
method _stripws_default (line 47) | def _stripws_default(tlist):
method _stripws_identifierlist (line 56) | def _stripws_identifierlist(self, tlist):
method _stripws_parenthesis (line 70) | def _stripws_parenthesis(self, tlist):
method process (line 77) | def process(self, stmt, depth=0):
class SpacesAroundOperatorsFilter (line 85) | class SpacesAroundOperatorsFilter(object):
method _process (line 87) | def _process(tlist):
method process (line 104) | def process(self, stmt):
class SerializerUnicode (line 113) | class SerializerUnicode(object):
method process (line 115) | def process(stmt):
FILE: SQLToolsAPI/lib/sqlparse/filters/output.py
class OutputFilter (line 12) | class OutputFilter(object):
method __init__ (line 15) | def __init__(self, varname='sql'):
method _process (line 19) | def _process(self, stream, varname, has_nl):
method process (line 22) | def process(self, stmt):
class OutputPythonFilter (line 34) | class OutputPythonFilter(OutputFilter):
method _process (line 35) | def _process(self, stream, varname, has_nl):
class OutputPHPFilter (line 78) | class OutputPHPFilter(OutputFilter):
method _process (line 81) | def _process(self, stream, varname, has_nl):
FILE: SQLToolsAPI/lib/sqlparse/filters/reindent.py
class ReindentFilter (line 13) | class ReindentFilter(object):
method __init__ (line 14) | def __init__(self, width=2, char=' ', wrap_after=0, n='\n',
method _flatten_up_to_token (line 26) | def _flatten_up_to_token(self, token):
method leading_ws (line 37) | def leading_ws(self):
method _get_offset (line 40) | def _get_offset(self, token):
method nl (line 46) | def nl(self, offset=0):
method _next_token (line 51) | def _next_token(self, tlist, idx=-1):
method _split_kwds (line 66) | def _split_kwds(self, tlist):
method _split_statements (line 82) | def _split_statements(self, tlist):
method _process (line 96) | def _process(self, tlist):
method _process_where (line 101) | def _process_where(self, tlist):
method _process_parenthesis (line 109) | def _process_parenthesis(self, tlist):
method _process_identifierlist (line 119) | def _process_identifierlist(self, tlist):
method _process_case (line 149) | def _process_case(self, tlist):
method _process_default (line 168) | def _process_default(self, tlist, stmts=True):
method process (line 174) | def process(self, stmt):
FILE: SQLToolsAPI/lib/sqlparse/filters/right_margin.py
class RightMarginFilter (line 15) | class RightMarginFilter(object):
method __init__ (line 20) | def __init__(self, width=79):
method _process (line 24) | def _process(self, group, stream):
method process (line 46) | def process(self, group):
FILE: SQLToolsAPI/lib/sqlparse/filters/tokens.py
class _CaseFilter (line 12) | class _CaseFilter(object):
method __init__ (line 15) | def __init__(self, case=None):
method process (line 19) | def process(self, stream):
class KeywordCaseFilter (line 26) | class KeywordCaseFilter(_CaseFilter):
class IdentifierCaseFilter (line 30) | class IdentifierCaseFilter(_CaseFilter):
method process (line 33) | def process(self, stream):
class TruncateStringFilter (line 40) | class TruncateStringFilter(object):
method __init__ (line 41) | def __init__(self, width, char):
method process (line 45) | def process(self, stream):
FILE: SQLToolsAPI/lib/sqlparse/formatter.py
function validate_options (line 14) | def validate_options(options):
function build_filter_stack (line 118) | def build_filter_stack(stack, options):
FILE: SQLToolsAPI/lib/sqlparse/keywords.py
function is_keyword (line 13) | def is_keyword(value):
FILE: SQLToolsAPI/lib/sqlparse/lexer.py
class Lexer (line 21) | class Lexer(object):
method get_tokens (line 27) | def get_tokens(text, encoding=None):
function tokenize (line 75) | def tokenize(sql, encoding=None):
FILE: SQLToolsAPI/lib/sqlparse/sql.py
class Token (line 19) | class Token(object):
method __init__ (line 30) | def __init__(self, ttype, value):
method __str__ (line 40) | def __str__(self):
method __repr__ (line 47) | def __repr__(self):
method _get_repr_name (line 55) | def _get_repr_name(self):
method _get_repr_value (line 58) | def _get_repr_value(self):
method flatten (line 64) | def flatten(self):
method match (line 68) | def match(self, ttype, values, regex=False):
method within (line 102) | def within(self, group_cls):
method is_child_of (line 115) | def is_child_of(self, other):
method has_ancestor (line 119) | def has_ancestor(self, other):
class TokenList (line 130) | class TokenList(Token):
method __init__ (line 139) | def __init__(self, tokens=None):
method __str__ (line 145) | def __str__(self):
method __iter__ (line 152) | def __iter__(self):
method __getitem__ (line 155) | def __getitem__(self, item):
method _get_repr_name (line 158) | def _get_repr_name(self):
method _pprint_tree (line 161) | def _pprint_tree(self, max_depth=None, depth=0, f=None):
method get_token_at_offset (line 175) | def get_token_at_offset(self, offset):
method flatten (line 184) | def flatten(self):
method get_sublists (line 196) | def get_sublists(self):
method _groupable_tokens (line 202) | def _groupable_tokens(self):
method _token_matching (line 205) | def _token_matching(self, funcs, start=0, end=None, reverse=False):
method token_first (line 227) | def token_first(self, skip_ws=True, skip_cm=False):
method token_next_by (line 241) | def token_next_by(self, i=None, m=None, t=None, idx=-1, end=None):
method token_not_matching (line 246) | def token_not_matching(self, funcs, idx):
method token_matching (line 251) | def token_matching(self, funcs, idx):
method token_prev (line 254) | def token_prev(self, idx, skip_ws=True, skip_cm=False):
method token_next (line 264) | def token_next(self, idx, skip_ws=True, skip_cm=False, _reverse=False):
method token_index (line 278) | def token_index(self, token, start=0):
method group_tokens (line 283) | def group_tokens(self, grp_cls, start, end, include_end=True,
method insert_before (line 313) | def insert_before(self, where, token):
method insert_after (line 320) | def insert_after(self, where, token, skip_ws=True):
method has_alias (line 331) | def has_alias(self):
method get_alias (line 335) | def get_alias(self):
method get_name (line 348) | def get_name(self):
method get_real_name (line 357) | def get_real_name(self):
method get_parent_name (line 363) | def get_parent_name(self):
method _get_first_name (line 372) | def _get_first_name(self, idx=None, reverse=False, keywords=False):
class Statement (line 389) | class Statement(TokenList):
method get_type (line 392) | def get_type(self):
class Identifier (line 427) | class Identifier(TokenList):
method is_wildcard (line 433) | def is_wildcard(self):
method get_typecast (line 438) | def get_typecast(self):
method get_ordering (line 444) | def get_ordering(self):
method get_array_indices (line 449) | def get_array_indices(self):
class IdentifierList (line 458) | class IdentifierList(TokenList):
method get_identifiers (line 461) | def get_identifiers(self):
class Parenthesis (line 471) | class Parenthesis(TokenList):
method _groupable_tokens (line 477) | def _groupable_tokens(self):
class SquareBrackets (line 481) | class SquareBrackets(TokenList):
method _groupable_tokens (line 487) | def _groupable_tokens(self):
class Assignment (line 491) | class Assignment(TokenList):
class If (line 495) | class If(TokenList):
class For (line 501) | class For(TokenList):
class Comparison (line 507) | class Comparison(TokenList):
method left (line 511) | def left(self):
method right (line 515) | def right(self):
class Comment (line 519) | class Comment(TokenList):
method is_multiline (line 522) | def is_multiline(self):
class Where (line 526) | class Where(TokenList):
class Case (line 533) | class Case(TokenList):
method get_cases (line 538) | def get_cases(self, skip_ws=False):
class Function (line 586) | class Function(TokenList):
method get_parameters (line 589) | def get_parameters(self):
class Begin (line 600) | class Begin(TokenList):
class Operation (line 606) | class Operation(TokenList):
FILE: SQLToolsAPI/lib/sqlparse/tokens.py
class _TokenType (line 15) | class _TokenType(tuple):
method __contains__ (line 18) | def __contains__(self, item):
method __getattr__ (line 21) | def __getattr__(self, name):
method __repr__ (line 27) | def __repr__(self):
FILE: SQLToolsAPI/lib/sqlparse/utils.py
function split_unquoted_newlines (line 37) | def split_unquoted_newlines(stmt):
function remove_quotes (line 55) | def remove_quotes(val):
function recurse (line 64) | def recurse(*cls):
function imt (line 82) | def imt(token, i=None, m=None, t=None):
function consume (line 106) | def consume(iterator, n):
function offset (line 112) | def offset(filter_, n=0):
function indent (line 119) | def indent(filter_, n=1):
Condensed preview — 66 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (292K chars).
[
{
"path": ".bumpversion.cfg",
"chars": 85,
"preview": "[bumpversion]\ncurrent_version = 0.9.12\nfiles = SQLTools.py\ntag = True\ncommit = True\n\n"
},
{
"path": ".gitignore",
"chars": 49,
"preview": ".DS_Store\n*.pyc\n*.py~\n*.sublime-workspace\n.idea/\n"
},
{
"path": ".mention-bot",
"chars": 54,
"preview": "{\n \"maxReviewers\": 2,\n \"skipCollaboratorPR\": true\n}\n"
},
{
"path": ".no-sublime-package",
"chars": 0,
"preview": ""
},
{
"path": "Default (Linux).sublime-keymap",
"chars": 1019,
"preview": "[\n { \"keys\": [\"ctrl+alt+e\"], \"command\": \"st_select_connection\" },\n { \"keys\": [\"ctrl+e\", \"ctrl+e\"], \"command\": \"st_"
},
{
"path": "Default (OSX).sublime-keymap",
"chars": 1021,
"preview": "[\n { \"keys\": [\"ctrl+super+e\"], \"command\": \"st_select_connection\" },\n { \"keys\": [\"ctrl+e\", \"ctrl+e\"], \"command\": \"s"
},
{
"path": "Default (Windows).sublime-keymap",
"chars": 1019,
"preview": "[\n { \"keys\": [\"ctrl+alt+e\"], \"command\": \"st_select_connection\" },\n { \"keys\": [\"ctrl+e\", \"ctrl+e\"], \"command\": \"st_"
},
{
"path": "Default.sublime-commands",
"chars": 2061,
"preview": "[\n {\n \"caption\": \"ST: Select Connection\",\n \"command\": \"st_select_connection\"\n },\n {\n \"caption\": \"ST: Execute"
},
{
"path": "ISSUE_TEMPLATE.md",
"chars": 1063,
"preview": "> This issue template helps us understand your SQLTools issues better. \n>\n> You don't need to stick to this template, bu"
},
{
"path": "LICENSE.md",
"chars": 35147,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
},
{
"path": "Main.sublime-menu",
"chars": 1971,
"preview": "[\n {\n \"caption\": \"Preferences\",\n \"mnemonic\": \"n\",\n \"id\": \"preferences\",\n \"children\":\n "
},
{
"path": "README.md",
"chars": 4563,
"preview": " SQLTools\n===============\n\n> Looking for maint"
},
{
"path": "SQLTools.py",
"chars": 28446,
"preview": "__version__ = \"v0.9.12\"\n\nimport sys\nimport os\nimport re\nimport logging\nfrom collections import OrderedDict\n\nimport subli"
},
{
"path": "SQLTools.sublime-settings",
"chars": 25473,
"preview": "// NOTE: it is strongly advised to override ONLY those settings\n// that you wish to change in your Users/SQLTools.sublim"
},
{
"path": "SQLToolsAPI/Command.py",
"chars": 8071,
"preview": "import os\nimport signal\nimport subprocess\nimport time\nimport logging\n\nfrom threading import Thread, Timer\n\nlogger = logg"
},
{
"path": "SQLToolsAPI/Completion.py",
"chars": 21956,
"preview": "import re\nimport logging\nfrom collections import namedtuple\n\nfrom .ParseUtils import extractTables\n\nJOIN_COND_PATTERN = "
},
{
"path": "SQLToolsAPI/Connection.py",
"chars": 13265,
"preview": "import shutil\nimport shlex\nimport codecs\nimport logging\nimport sqlparse\n\nfrom . import Utils as U\nfrom . import Command "
},
{
"path": "SQLToolsAPI/History.py",
"chars": 942,
"preview": "__version__ = \"v0.1.0\"\n\n\nclass SizeException(Exception):\n pass\n\n\nclass NotFoundException(Exception):\n pass\n\n\nclass"
},
{
"path": "SQLToolsAPI/ParseUtils.py",
"chars": 4419,
"preview": "import os\nimport sys\nimport itertools\nfrom collections import namedtuple\n\ndirpath = os.path.join(os.path.dirname(__file_"
},
{
"path": "SQLToolsAPI/README.md",
"chars": 62,
"preview": "## SQLTools API for plugins - v0.2.5\n\nDocs will be ready soon\n"
},
{
"path": "SQLToolsAPI/Storage.py",
"chars": 1588,
"preview": "import os\nimport shutil\nfrom . import Utils as U\n\n__version__ = \"v0.1.0\"\n\n\nclass Storage:\n def __init__(self, filenam"
},
{
"path": "SQLToolsAPI/Utils.py",
"chars": 2458,
"preview": "__version__ = \"v0.2.0\"\n\nimport json\nimport os\nimport re\nimport sys\n\ndirpath = os.path.join(os.path.dirname(__file__), 'l"
},
{
"path": "SQLToolsAPI/__init__.py",
"chars": 148,
"preview": "__version__ = \"v0.3.0\"\n\n\n__all__ = [\n 'Utils',\n 'Completion',\n 'Command',\n 'Connection',\n 'History',\n "
},
{
"path": "SQLToolsAPI/lib/sqlparse/__init__.py",
"chars": 2224,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/__main__.py",
"chars": 609,
"preview": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This mod"
},
{
"path": "SQLToolsAPI/lib/sqlparse/cli.py",
"chars": 5249,
"preview": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This mod"
},
{
"path": "SQLToolsAPI/lib/sqlparse/compat.py",
"chars": 1140,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/engine/__init__.py",
"chars": 446,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/engine/filter_stack.py",
"chars": 1200,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/engine/grouping.py",
"chars": 11377,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/engine/statement_splitter.py",
"chars": 3648,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/exceptions.py",
"chars": 341,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/filters/__init__.py",
"chars": 1241,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/filters/aligned_indent.py",
"chars": 4932,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/filters/others.py",
"chars": 4350,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/filters/output.py",
"chars": 4051,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/filters/reindent.py",
"chars": 6985,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/filters/right_margin.py",
"chars": 1595,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/filters/tokens.py",
"chars": 1612,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/formatter.py",
"chars": 6836,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/keywords.py",
"chars": 24233,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/lexer.py",
"chars": 2506,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/sql.py",
"chars": 19488,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/tokens.py",
"chars": 1657,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsAPI/lib/sqlparse/utils.py",
"chars": 3488,
"preview": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) 2016 Andi Albrecht, albrecht.andi@gmail.com\n#\n# This module is part of python-"
},
{
"path": "SQLToolsConnections.sublime-settings",
"chars": 3734,
"preview": "{\n \"connections\": {\n /*\n \"Generic Template\": { // Connection name, used in menu (Display name)\n // connec"
},
{
"path": "SQLToolsSavedQueries.sublime-settings",
"chars": 4,
"preview": "{\n}\n"
},
{
"path": "messages/install.md",
"chars": 981,
"preview": "# SQLTools\n===============\n\nYour swiss knife SQL for Sublime Text.\n\nWrite your SQL with smart completions and handy tabl"
},
{
"path": "messages/v0.1.6.md",
"chars": 280,
"preview": "# SQLTools\n===============\n\nYour swiss knife SQL for Sublime Text.\n\n\n## v0.1.6 Changelog\n\n### Improvements\n* History sor"
},
{
"path": "messages/v0.2.0.md",
"chars": 349,
"preview": "## v0.2.0 Changelog\n\nNow you can open your saved queries using `CTRL+E CTRL+O`!\n\n### Improvements\n* Added opening suppor"
},
{
"path": "messages/v0.3.0.md",
"chars": 210,
"preview": "## v0.3.0 Changelog\n\n### Features\n\n* Describe user functions `CTRL+E CTRL+F` for PostgreSQL!\n* PostgreSQL user functions"
},
{
"path": "messages/v0.8.2.md",
"chars": 756,
"preview": "## v0.8.2 Notes\n\n### Features\n\n* New smarter completions that will suggest tables, columns,\n aliases, columns for table"
},
{
"path": "messages/v0.9.0.md",
"chars": 124,
"preview": "## v0.9.0 Notes\n\n### Features\n\n* Added support for query result streaming [#19](https://github.com/mtxr/SQLTools/issues/"
},
{
"path": "messages/v0.9.1.md",
"chars": 394,
"preview": "## v0.9.1 Notes\n\n### Improvements\n\n* Display errors inline instead of appending them at the bottom [#92](https://github."
},
{
"path": "messages/v0.9.10.md",
"chars": 81,
"preview": "## v0.9.10 Notes\n\n### Fixes\n\n* Added `focus_result` setting closing issue [#183]\n"
},
{
"path": "messages/v0.9.11.md",
"chars": 134,
"preview": "## v0.9.11 Notes\n\n### Fixes\n\n* New command `ST: Format SQL All File` (internal name `st_format_all`) to format the entir"
},
{
"path": "messages/v0.9.12.md",
"chars": 775,
"preview": "## v0.9.12 Notes\n\n### Improvements\n\n* Snowflake (`snowsql`) support\n* Added support for prompting of the connection para"
},
{
"path": "messages/v0.9.2.md",
"chars": 493,
"preview": "## v0.9.2 Notes\n\n### Improvements\n\n* Support PostgreSQL \"password\" setting in Connections file [#106](https://github.com"
},
{
"path": "messages/v0.9.3.md",
"chars": 208,
"preview": "## v0.9.3 Notes\n\n### Improvements\n\n* [Oracle] Get identifiers (tables, columns) in all schemas [#112](https://github.co"
},
{
"path": "messages/v0.9.4.md",
"chars": 343,
"preview": "## v0.9.4 Notes\n\n### Improvements\n\n* Execute All File [#114]\n https://github.com/mtxr/SQLTools/issues/114\n* Configurabl"
},
{
"path": "messages/v0.9.5.md",
"chars": 386,
"preview": "## v0.9.5 Notes\n\n### Improvements\n\n* New Feature: List and Insert Saved Queries (ctrl+e ctrl+i) [#126]\n* Better error me"
},
{
"path": "messages/v0.9.6.md",
"chars": 90,
"preview": "## v0.9.6 Notes\n\n### Fixes\n\n* [MySQL] Added basic backtick escaping of identifiers [#147]\n"
},
{
"path": "messages/v0.9.7.md",
"chars": 98,
"preview": "## v0.9.7 Notes\n\n### Fixes\n\n* Completions not working with identifiers containing $ symbol [#152]\n"
},
{
"path": "messages/v0.9.8.md",
"chars": 2145,
"preview": "## v0.9.8 Notes\n\n### Improvements\n\n* Add MSSQL support via native `sqlcmd` CLI\n* Add more options for expanding the empt"
},
{
"path": "messages/v0.9.9.md",
"chars": 188,
"preview": "## v0.9.9 Notes\n\n### Improvements\n\n* Use `utf-8` encoding if Connection `encoding` is not a valid python encoding\n\n\n### "
},
{
"path": "messages.json",
"chars": 677,
"preview": "{\n \"install\": \"messages/install.md\",\n \"0.1.6\": \"messages/v0.1.6.md\",\n \"0.2.0\": \"messages/v0.2.0.md\",\n \"0.3.0"
}
]
About this extraction
This page contains the full source code of the mtxr/SQLTools GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 66 files (270.1 KB), approximately 64.5k tokens, and a symbol index with 341 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.