You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/writing-codeql-queries/introduction-to-ql.rst
+13-16Lines changed: 13 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,20 +17,19 @@ QL also supports recursion and aggregates. This allows you to write complex recu
17
17
Running a query
18
18
---------------
19
19
20
-
You can try out the following examples and exercises using :ref:`CodeQL for VS Code <codeql-for-visual-studio-code>`, or you can run them in GitHub Codespaces using the `CodeQL template <https://github.com/codespaces/new?template_repository=github/codeql-codespaces-template>`__. To access the template, click on the link then click **Use this template**. This will open a GitHub Codespaces environment that is preconfigured to run CodeQL queries.
20
+
You can try out the following examples and exercises using :ref:`CodeQL for VS Code <codeql-for-visual-studio-code>`, or you can run them in GitHub Codespaces using the `CodeQL template <https://github.com/codespaces/new?template_repository=github/codeql-codespaces-template>`__. This will open a GitHub Codespaces environment preconfigured to run CodeQL queries.
21
21
22
-
Once you open the GitHub Codespaces template, follow the instructions in the ReadMe to take a code tour and learn how to run queries in the workspace.
22
+
Once you open the GitHub Codespaces template, follow the instructions in the README to take a code tour and learn how to run queries in the workspace.
23
23
24
-
The first query in the `tutorial.ql` file is populated with the query:
24
+
Here is an example of a basic query:
25
25
26
26
.. code-block:: ql
27
27
28
28
import tutorial
29
29
30
-
from Person p
31
-
select p
30
+
select "hello world"
32
31
33
-
This query returns a list of people in the tutorial's database.
32
+
This query returns the string `"hello world"`.
34
33
35
34
More complicated queries typically look like this:
36
35
@@ -60,7 +59,7 @@ Exercise 1
60
59
61
60
Write a query which returns the length of the string ``"lgtm"``. (Hint: `here <https://codeql.github.com/docs/ql-language-reference/ql-language-specification/#built-ins-for-string>`__ is the list of the functions that can be applied to strings.)
62
61
63
-
➤ `Check your answer <#exercise-1>`__
62
+
➤ `Check your answer <#answer:-exercise-1>`__
64
63
65
64
There is often more than one way to define a query. For example, we can also write the above query in the shorter form:
66
65
@@ -73,21 +72,21 @@ Exercise 2
73
72
74
73
Write a query which returns the sine of the minimum of ``3^5`` (``3`` raised to the power ``5``) and ``245.6``.
75
74
76
-
➤ `Check your answer <#exercise-2>`__
75
+
➤ `Check your answer <#answer:-exercise-2>`__
77
76
78
77
Exercise 3
79
78
~~~~~~~~~~
80
79
81
80
Write a query which returns the opposite of the boolean ``false``.
82
81
83
-
➤ `Check your answer <#exercise-3>`__
82
+
➤ `Check your answer <#answer:-exercise-3>`__
84
83
85
84
Exercise 4
86
85
~~~~~~~~~~
87
86
88
87
Write a query which computes the number of days between June 10 and September 28, 2017.
89
88
90
-
➤ `Check your answer <#exercise-4>`__
89
+
➤ `Check your answer <#answer:-exercise-4>`__
91
90
92
91
Example query with multiple results
93
92
-----------------------------------
@@ -175,9 +174,7 @@ Further reading
175
174
Answers
176
175
-------
177
176
178
-
In these answers, we use ``/*`` and ``*/`` to label the different parts of the query. Any text surrounded by ``/*`` and ``*/`` is not evaluated as part of the QL code, but is treated as a *comment*.
0 commit comments