LGTM Enterprise 1.25

About the query console

You can use the query console to run existing queries, such as the built-in queries, to see how they work and how they are structured. However, the main use of the query console is undoubtedly for developing new queries. You can experiment with a new query, run it on multiple projects, view the results, and further refine it so it suits your needs.

You can also write and run queries locally using the CodeQL for Visual Studio Code extension. Go to the Integrations tab for a project and install the extension. Then you can import and query any project database downloaded from LGTM. For more information, see Running queries in your IDE.

The query console always runs your query against the most recently analyzed snapshots of the selected projects, for the chosen language. Each snapshot generated by LGTM represents a snapshot of the whole codebase of the project for a single language. For more information, see About CodeQL databases

For information on how to run existing queries, write and run queries in the query console, and explore results, see Using the query console.

Getting to the query console

There are several ways to get to the query console:

  • In the menu bar at the top of LGTM, click Query console.
  • On any project page, click Query this project to go to the console, with the current project selected for querying.
  • On the default view of the Alerts tabs of a project page (where the alerts are ordered by significance), click an alert name then Open in query console to load the query that finds that alert. If Group by query is selected, first select a group of alerts to view, then click an individual alert, and Open in query console.

    For more information see Exploring queries.

  • Similarly, on a Query help page (for example, for the Comparison of identical values query), click Open in query console to load the console with the query that finds code that breaks this rule of best coding practice.
  • LGTM.com users can navigate to https://lgtm.com/query. For LGTM Enterprise, just replace https://lgtm.com with the URL of your LGTM Enterprise server.

What does the query console look like?

The screenshot below shows the Query console page once Java has been selected in the language selector:

The different areas of the query console

Language selector—Used to select the language to query when writing a new query. This selector will be populated with the language the query is for, when you're viewing an existing query.

Project selector—Used to select one or more projects or project lists to query. There won't be any projects or project lists selected when you open an existing query, or when you start writing a new query (Project:none).

Query tab—Contains the name of the opened query for an existing query, or simply Query for a new one.

Code box—Where you write the code for a new query or where code is displayed for existing queries. For more information about developing your own queries to use on LGTM, see Writing custom queries to include in LGTM analysis.

Button—This button will have a caption depending on the type of query opened in the console and whether it's ready to be run. Possible captions are self-explanatory and are as follows: Select projects to query, Compiling, Invalid query, Run and View results.

View some example queries—A drop down list containing some example queries for the currently selected language. Click an example to load in it the code box.

For information on how to write and run queries in the query console, see Writing custom queries to include in LGTM analysis and Using the query console.

For details about the results displayed in the query console, and about the information that's provided in those results, see Viewing results in the query console

Related topicsRelated topics