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/language/learn-ql/introduction-to-ql.rst
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
Introduction to QL
2
2
==================
3
3
4
-
Work through some simple exercises to learn about the basics of QL and CodeQL.
4
+
Work through some simple exercises and examples to learn about the basics of QL and CodeQL.
5
5
6
6
Basic syntax
7
7
------------
@@ -12,6 +12,9 @@ QL is a logic programming language, so it is built up of logical formulas. QL us
12
12
13
13
QL also supports recursion and aggregates. This allows you to write complex recursive queries using simple QL syntax and directly use aggregates such as ``count``, ``sum``, and ``average``.
14
14
15
+
Running a query
16
+
---------------
17
+
15
18
You can try out the following examples and exercises using `CodeQL for VS Code <https://help.semmle.com/codeql/codeql-for-vscode.html>`__, or you can run them in the `query console on LGTM.com <https://lgtm.com/query>`__. Before you can run a query on LGTM.com, you need to select a language and project to query (for these logic examples, any language and project will do).
16
19
17
20
Once you have selected a language, the query console is populated with the query:
@@ -45,7 +48,7 @@ Note that ``int`` specifies that the **type** of ``x`` and ``y`` is 'integer'. T
45
48
Simple exercises
46
49
----------------
47
50
48
-
You can try to write simple queries using the some of the basic functions that are available for the ``int``, ``date``, ``float``, ``boolean`` and ``string`` types. To apply a function, append it to the argument. For example, ``1.toString()`` converts the value ``1`` to a string. Notice that as you start typing a function, a pop-up is displayed making it easy to select the function that you want. Also note that you can apply multiple functions in succession. For example, ``100.log().sqrt()`` first takes the natural logarithm of 100 and then computes the square root of the result.
51
+
You can write simple queries using the some of the basic functions that are available for the ``int``, ``date``, ``float``, ``boolean`` and ``string`` types. To apply a function, append it to the argument. For example, ``1.toString()`` converts the value ``1`` to a string. Notice that as you start typing a function, a pop-up is displayed making it easy to select the function that you want. Also note that you can apply multiple functions in succession. For example, ``100.log().sqrt()`` first takes the natural logarithm of 100 and then computes the square root of the result.
49
52
50
53
Exercise 1
51
54
~~~~~~~~~~
@@ -113,7 +116,8 @@ To simplify the query, we can introduce a class ``SmallInt`` representing the in
113
116
Example CodeQL queries
114
117
----------------------
115
118
116
-
The previous examples used the primitive types built in to QL. Although we chose a project to query, they did not use the project-specific database. The following example queries *do* use these databases and give you an idea of how CodeQL is used to analyze projects.
119
+
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.
120
+
The following example queries *do* use these databases and give you an idea of how to use CodeQL to analyze projects.
117
121
118
122
Queries using the CodeQL libraries can find errors and uncover variants of important security vulnerabilities in codebases.
119
123
Visit `GitHub Security Lab <https://securitylab.github.com/>`__ to read about examples of vulnerabilities that we have recently found in open source projects.
0 commit comments