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
For information about installing the CodeQL extension for Visual Studio code, see ":ref:`Setting up CodeQL in Visual Studio Code <setting-up-codeql-in-visual-studio-code>`."
Copy file name to clipboardExpand all lines: docs/codeql/writing-codeql-queries/catch-the-fire-starter.rst
+64-2Lines changed: 64 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,7 +105,7 @@ Now try applying ``isAllowedIn(string region)`` to a person ``p``. If ``p`` is n
105
105
106
106
You know that the fire starters live in the south *and* that they must have been able to travel to the north. Write a query to find the possible suspects. You could also extend the ``select`` clause to list the age of the suspects. That way you can clearly see that all the children have been excluded from the list.
107
107
108
-
➤ `See the answer in the query console on LGTM.com <https://lgtm.com/query/2551838470440192723/>`__
108
+
➤ `Check your answer <#exercise-1>`__
109
109
110
110
You can now continue to gather more clues and find out which of your suspects started the fire...
111
111
@@ -142,11 +142,73 @@ The predicate ``isBald`` is defined to take a ``Person``, so it can also take a
142
142
143
143
You can now write a query to select the bald southerners who are allowed into the north.
144
144
145
-
➤ `See the answer in the query console on LGTM.com <https://lgtm.com/query/2572701606358725253/>`__
145
+
➤ `Check your answer <#exercise-2>`__
146
146
147
147
You have found the two fire starters! They are arrested and the villagers are once again impressed with your work.
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*.
Copy file name to clipboardExpand all lines: docs/codeql/writing-codeql-queries/crown-the-rightful-heir.rst
+46-2Lines changed: 46 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,7 +129,7 @@ Here is one way to define ``relativeOf()``:
129
129
130
130
Don't forget to use the predicate ``isDeceased()`` to find relatives that are still alive.
131
131
132
-
➤ `See the answer in the query console on LGTM.com <https://lgtm.com/query/6710025057257064639/>`__
132
+
➤ `Check your answer <#exercise-1>`__
133
133
134
134
Select the true heir
135
135
--------------------
@@ -142,7 +142,7 @@ To decide who should inherit the king's fortune, the villagers carefully read th
142
142
143
143
As your final challenge, define a predicate ``hasCriminalRecord`` so that ``hasCriminalRecord(p)`` holds if ``p`` is any of the criminals you unmasked earlier (in the ":doc:`Find the thief <find-the-thief>`" and ":doc:`Catch the fire starter <catch-the-fire-starter>`" tutorials).
144
144
145
-
➤ `See the answer in the query console on LGTM.com <https://lgtm.com/query/1820692755164273290/>`__
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*.
174
+
175
+
Exercise 1
176
+
~~~~~~~~~~
177
+
178
+
.. code-block:: ql
179
+
180
+
import tutorial
181
+
182
+
Person relativeOf(Person p) { parentOf*(result) = parentOf*(p) }
183
+
184
+
from Person p
185
+
where
186
+
not p.isDeceased() and
187
+
p = relativeOf("King Basil")
188
+
select p
189
+
190
+
Exercise 2
191
+
~~~~~~~~~~
192
+
193
+
.. code-block:: ql
194
+
195
+
import tutorial
196
+
197
+
Person relativeOf(Person p) { parentOf*(result) = parentOf*(p) }
Once you have finished, you will have a list of possible suspects. One of those people must be the thief!
211
209
212
-
➤ `See the answer in the query console on LGTM.com <https://lgtm.com/query/1505743955992/>`__
213
-
214
-
.. pull-quote::
215
-
216
-
Note
217
-
218
-
In the answer, we used ``/*`` 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 just a *comment*.
210
+
➤ `Check your answer <#exercise-1>`__
219
211
220
212
You are getting closer to solving the mystery! Unfortunately, you still have quite a long list of suspects... To find out which of your suspects is the thief, you must gather more information and refine your query in the next step.
221
213
@@ -291,9 +283,59 @@ You can now translate the remaining questions into QL:
291
283
292
284
Have you found the thief?
293
285
294
-
➤ `See the answer in the query console on LGTM.com <https://lgtm.com/query/1505744186085/>`__
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*.
300
+
301
+
Exercise 1
302
+
^^^^^^^^^^
303
+
304
+
.. code-block:: ql
305
+
306
+
import tutorial
307
+
308
+
from Person t
309
+
where
310
+
/* 1 */ t.getHeight() > 150 and
311
+
/* 2 */ not t.getHairColor() = "blond" and
312
+
/* 3 */ exists (string c | t.getHairColor() = c) and
313
+
/* 4 */ not t.getAge() < 30 and
314
+
/* 5 */ t.getLocation() = "east" and
315
+
/* 6 */ (t.getHairColor() = "black" or t.getHairColor() = "brown") and
316
+
/* 7 */ not (t.getHeight() > 180 and t.getHeight() < 190) and
317
+
/* 8 */ exists(Person p | p.getAge() > t.getAge())
318
+
select t
319
+
320
+
Exercise 2
321
+
^^^^^^^^^^
322
+
323
+
.. code-block:: ql
324
+
325
+
import tutorial
326
+
327
+
from Person t
328
+
where
329
+
/* 1 */ t.getHeight() > 150 and
330
+
/* 2 */ not t.getHairColor() = "blond" and
331
+
/* 3 */ exists (string c | t.getHairColor() = c) and
332
+
/* 4 */ not t.getAge() < 30 and
333
+
/* 5 */ t.getLocation() = "east" and
334
+
/* 6 */ (t.getHairColor() = "black" or t.getHairColor() = "brown") and
335
+
/* 7 */ not (t.getHeight() > 180 and t.getHeight() < 190) and
336
+
/* 8 */ exists(Person p | p.getAge() > t.getAge()) and
337
+
/* 9 */ not t = max(Person p | | p order by p.getHeight()) and
338
+
/* 10 */ t.getHeight() < avg(float i | exists(Person p | p.getHeight() = i) | i) and
339
+
/* 11 */ t = max(Person p | p.getLocation() = "east" | p order by p.getAge())
0 commit comments