QL is a declarative, object-oriented query language that is optimized to enable efficient analysis of hierarchical data structures, in particular, databases representing software artifacts. The basic syntax will look familiar to anyone who has used SQL but is used somewhat differently.
Its result is just the string
More complicated queries typically follow the following structure:
For example, the following query computes the number 42:
QL code can contain C-style comments. An end-of-line comment is introduced by "
//", and a (possibly multiline) delimited comment is introduced by "
/*" and terminated by "
The rules and metrics used by Semmle analysis are written using QL. This ensures that they can be extended or revised easily to keep up with changes in definitions of best coding practice. Every Semmle release includes improvements to existing rules as we work towards the ultimate goal of 100% precision. For details of the standard rules implemented by QL queries supplied by Semmle, see Semmle standard rules.
You can write your own queries to identify code that breaks your team's guidelines for best practice or customize the default rules to accommodate a new framework.
The easiest way to learn more about QL is to use the query console on LGTM. On LGTM.com, you can write QL code to query open source projects directly—without having to download snapshots and libraries. If your organization uses LGTM Enterprise, you can use this to query private projects too. The query console provides autocomplete suggestions, the option to "jump to definition", and many more writing aids. To start learning QL on LGTM, see Introduction to the QL language and Learning QL.
Alternatively, you can install Semmle Studio (a plugin for Eclipse) and obtain a snapshot to test queries against. For more information, see Semmle Studio . Once you have installed Semmle Studio and obtained a snapshot, we recommend you:
- Work through the QL detective tutorials to learn the basic QL syntax.
- Choose the programming language you want to query, and work through some of the tutorials and examples provided:
- Try out some of the QL cookbook examples:
- QL primer describes the elements of QL and discusses important concepts in QL.
- QL Language Specification is a comprehensive reference for terminology, syntax and other technical details about QL.
- QLDoc specification is a reference for terminology and syntax for QLDoc comments.
- Details of the QL libraries for a variety of languages:
For any questions or feedback relating to documentation, please contact firstname.lastname@example.org. For any other support issues, please contact your organization's email@example.com email address. Using your organization's support address ensures that your message will be received as soon as possible by a member of our support team, even when the staff that you normally speak to are out of the office or on holiday.