Skip to content

Commit c9a9535

Browse files
committed
Python: Use ConceptsTests for ClickHouse SQL libs
This did reveal a few places where we do not detect the incoming SQL
1 parent ee3477c commit c9a9535

File tree

10 files changed

+78
-41
lines changed

10 files changed

+78
-41
lines changed

python/ql/test/experimental/semmle/python/frameworks/aioch/ConceptsTest.expected

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
import python
2+
import experimental.meta.ConceptsTest
23
import experimental.semmle.python.frameworks.ClickHouseDriver
3-
import semmle.python.Concepts
4-
5-
from SqlExecution s
6-
select s, s.getSql()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --max-import-depth=1 --lang=3
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import aioch
2+
3+
4+
SQL = "SOME SQL"
5+
6+
7+
async def aioch_test():
8+
client = aioch.Client("localhost")
9+
10+
await client.execute(SQL) # $ getSql=SQL
11+
await client.execute(query=SQL) # $ MISSING: getSql=SQL
12+
13+
await client.execute_with_progress(SQL) # $ getSql=SQL
14+
await client.execute_with_progress(query=SQL) # $ MISSING: getSql=SQL
15+
16+
await client.execute_iter(SQL) # $ getSql=SQL
17+
await client.execute_iter(query=SQL) # $ MISSING: getSql=SQL
18+
19+
20+
# Using custom client (this has been seen done for the blocking version in
21+
# `clickhouse_driver` PyPI package)
22+
23+
24+
class MyClient(aioch.Client):
25+
pass
26+
27+
28+
async def test_custom_client():
29+
client = MyClient("localhost")
30+
await client.execute(SQL) # $ getSql=SQL

python/ql/test/experimental/semmle/python/frameworks/clickhouse-driver/ClickHouseDriver.expected

Lines changed: 0 additions & 5 deletions
This file was deleted.

python/ql/test/experimental/semmle/python/frameworks/clickhouse-driver/ClickHouseDriver.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

python/ql/test/experimental/semmle/python/frameworks/clickhouse_driver/ConceptsTest.expected

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import python
2+
import experimental.meta.ConceptsTest
3+
import experimental.semmle.python.frameworks.ClickHouseDriver
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import clickhouse_driver
2+
3+
4+
SQL = "SOME SQL"
5+
6+
7+
# Normal operation
8+
client = clickhouse_driver.client.Client("localhost")
9+
10+
client.execute(SQL) # $ MISSING: getSql=SQL
11+
client.execute(query=SQL) # $ MISSING: getSql=SQL
12+
13+
client.execute_with_progress(SQL) # $ MISSING: getSql=SQL
14+
client.execute_with_progress(query=SQL) # $ MISSING: getSql=SQL
15+
16+
client.execute_iter(SQL) # $ MISSING: getSql=SQL
17+
client.execute_iter(query=SQL) # $ MISSING: getSql=SQL
18+
19+
20+
# commonly used alias
21+
client = clickhouse_driver.Client("localhost")
22+
client.execute(SQL) # $ getSql=SQL
23+
24+
25+
# Using PEP249 interface
26+
conn = clickhouse_driver.connect('clickhouse://localhost')
27+
cursor = conn.cursor()
28+
cursor.execute(SQL) # $ getSql=SQL
29+
30+
31+
# Using custom client
32+
#
33+
# examples from real world code
34+
# https://github.com/Altinity/clickhouse-mysql-data-reader/blob/3b1b7088751b05e5bbf45890c5949b58208c2343/clickhouse_mysql/dbclient/chclient.py#L10
35+
# https://github.com/Felixoid/clickhouse-plantuml/blob/d8b2ba7d164a836770ec21f5e4035dfb04c41d9c/clickhouse_plantuml/client.py#L9
36+
37+
38+
class MyClient(clickhouse_driver.Client):
39+
pass
40+
41+
42+
MyClient("localhost").execute(SQL) # $ getSql=SQL
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --max-import-depth=1

0 commit comments

Comments
 (0)