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
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,13 +19,13 @@ QL also supports recursion and aggregates. This allows you to write complex recu
19
19
Running a query
20
20
---------------
21
21
22
-
You can try out the following examples and exercises using :ref:`CodeQL for VS Code <codeql-for-visual-studio-code>` or the `CodeQL template <https://github.com/codespaces/new?template_repository=github/codeql-codespaces-template>'.
22
+
You can try out the following examples and exercises using :ref:`CodeQL for VS Code <codeql-for-visual-studio-code>` or the `CodeQL template <https://github.com/codespaces/new?template_repository=github/codeql-codespaces-template>' on GitHub Codespaces.
23
23
24
24
Here is an example of a basic query:
25
25
26
26
.. code-block:: ql
27
27
28
-
import <language>
28
+
import tutorial
29
29
30
30
select "hello world"
31
31
@@ -111,11 +111,13 @@ Example CodeQL queries
111
111
----------------------
112
112
113
113
The previous examples used the primitive types built in to QL. Although we chose a project to query, we didn't use the information in that project's database.
114
-
The following example queries *do* use these databases and give you an idea of how to use CodeQL to analyze projects.
114
+
The following example queries *do* use these databases and give you an idea of how to use CodeQL to analyze projects.
115
115
116
116
Queries using the CodeQL libraries can find errors and uncover variants of important security vulnerabilities in codebases.
117
117
Visit `GitHub Security Lab <https://securitylab.github.com/>`__ to read about examples of vulnerabilities that we have recently found in open source projects.
118
118
119
+
Before you can run the following examples, you will need to install the CodeQL extension for Visual Studio Code. For more information, see :ref:`Setting up CodeQL in Visual Studio Code <setting-up-codeql-in-visual-studio-code>`. You will also need to import and select a database in the corresponding programming language. For more information about obtaining CodeQL databases, see `Analyzing your projects <https://codeql.github.com/docs/codeql-for-visual-studio-code/analyzing-your-projects/#choosing-a-database>`__ in the CodeQL for VS Code documentation.
120
+
119
121
To import the CodeQL library for a specific programming language, type ``import <language>`` at the start of the query.
120
122
121
123
.. code-block:: ql
@@ -163,6 +165,8 @@ Exercise 1
163
165
164
166
.. code-block:: ql
165
167
168
+
import tutorial
169
+
166
170
from string s
167
171
where s = "lgtm"
168
172
select s.length()
@@ -171,13 +175,17 @@ There is often more than one way to define a query. For example, we can also wri
171
175
172
176
.. code-block:: ql
173
177
178
+
import tutorial
179
+
174
180
select "lgtm".length()
175
181
176
182
Exercise 2
177
183
~~~~~~~~~~
178
184
179
185
.. code-block:: ql
180
186
187
+
import tutorial
188
+
181
189
from float x, float y
182
190
where x = 3.pow(5) and y = 245.6
183
191
select x.minimum(y).sin()
@@ -187,6 +195,8 @@ Exercise 3
187
195
188
196
.. code-block:: ql
189
197
198
+
import tutorial
199
+
190
200
from boolean b
191
201
where b = false
192
202
select b.booleanNot()
@@ -196,6 +206,8 @@ Exercise 4
196
206
197
207
.. code-block:: ql
198
208
209
+
import tutorial
210
+
199
211
from date start, date end
200
212
where start = "10/06/2017".toDate() and end = "28/09/2017".toDate()
0 commit comments