File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
python/ql/test/library-tests/frameworks/psycopg2 Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ import python
2
+ import experimental.meta.ConceptsTest
Original file line number Diff line number Diff line change
1
+ # Examples using psycopg2 connection pools.
2
+
3
+ import psycopg2
4
+ from psycopg2 .pool import SimpleConnectionPool , AbstractConnectionPool
5
+
6
+
7
+ DSN = "dbname=test user=test password=test host=localhost port=5432"
8
+
9
+
10
+ def run_simple_pool_query ():
11
+ pool = SimpleConnectionPool (1 , 4 , dsn = DSN )
12
+ try :
13
+ conn = pool .getconn ()
14
+ try :
15
+ cur = conn .cursor ()
16
+ try :
17
+ # Simple, parameterless query
18
+ cur .execute ("SELECT 1" ) # $ getSql="SELECT 1"
19
+ _ = cur .fetchall () if hasattr (cur , "fetchall" ) else None # $ threatModelSource[database]=cur.fetchall()
20
+ finally :
21
+ cur .close ()
22
+ finally :
23
+ pool .putconn (conn )
24
+ finally :
25
+ pool .closeall ()
26
+
27
+
28
+ class LocalPool (AbstractConnectionPool ):
29
+ pass
30
+
31
+
32
+ def run_custom_pool_query ():
33
+ pool = LocalPool (1 , 3 , dsn = DSN )
34
+ try :
35
+ conn = pool .getconn ()
36
+ try :
37
+ cur = conn .cursor ()
38
+ try :
39
+ cur .execute ("SELECT 2" ) # $ getSql="SELECT 2"
40
+ _ = cur .fetchone () if hasattr (cur , "fetchone" ) else None # $ threatModelSource[database]=cur.fetchone()
41
+ finally :
42
+ cur .close ()
43
+ finally :
44
+ pool .putconn (conn )
45
+ finally :
46
+ pool .closeall ()
You can’t perform that action at this time.
0 commit comments