Skip to content

Commit ea74c7f

Browse files
committed
Python: add tests
1 parent cb47b57 commit ea74c7f

File tree

7 files changed

+54
-2
lines changed

7 files changed

+54
-2
lines changed

python/ql/src/experimental/semmle/python/frameworks/MysqlConnectorPython.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* Provides classes modeling security-relevant aspects of the `mysql-connector-python` package.
3-
* See https://dev.mysql.com/doc/dev/connector-python/.
3+
* See
4+
* - https://dev.mysql.com/doc/connector-python/en/
5+
* - https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html
46
*/
57

68
private import python
@@ -11,7 +13,9 @@ private import PEP249
1113

1214
/**
1315
* Provides models for the `mysql-connector-python` package.
14-
* See https://dev.mysql.com/doc/dev/connector-python/.
16+
* See
17+
* - https://dev.mysql.com/doc/connector-python/en/
18+
* - https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html
1519
*/
1620
module MysqlConnectorPython {
1721
// ---------------------------------------------------------------------------

python/ql/test/experimental/library-tests/frameworks/mysql-connector-python/ConceptsTest.expected

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import python
2+
import experimental.meta.ConceptsTest
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# taken from https://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-transaction.html
2+
from __future__ import print_function
3+
from datetime import date, datetime, timedelta
4+
import mysql.connector
5+
6+
cnx = mysql.connector.connect(user='scott', database='employees')
7+
cursor = cnx.cursor()
8+
9+
tomorrow = datetime.now().date() + timedelta(days=1)
10+
11+
add_employee = ("INSERT INTO employees "
12+
"(first_name, last_name, hire_date, gender, birth_date) "
13+
"VALUES (%s, %s, %s, %s, %s)")
14+
add_salary = ("INSERT INTO salaries "
15+
"(emp_no, salary, from_date, to_date) "
16+
"VALUES (%(emp_no)s, %(salary)s, %(from_date)s, %(to_date)s)")
17+
18+
data_employee = ('Geert', 'Vanderkelen', tomorrow, 'M', date(1977, 6, 14))
19+
20+
# Insert new employee
21+
cursor.execute(add_employee, data_employee) # $getSql=add_employee
22+
emp_no = cursor.lastrowid
23+
24+
# Insert salary information
25+
data_salary = {
26+
'emp_no': emp_no,
27+
'salary': 50000,
28+
'from_date': tomorrow,
29+
'to_date': date(9999, 1, 1),
30+
}
31+
cursor.execute(add_salary, data_salary) # $getSql=add_salary
32+
33+
# Make sure data is committed to the database
34+
cnx.commit()
35+
36+
cursor.close()
37+
cnx.close()

python/ql/test/experimental/library-tests/frameworks/mysqldb/ConceptsTest.expected

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import python
2+
import experimental.meta.ConceptsTest
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# taken from https://mysqlclient.readthedocs.io/user_guide.html#some-examples
2+
import MySQLdb
3+
db=MySQLdb.connect(passwd="moonpie",db="thangs")
4+
5+
c=db.cursor()
6+
max_price=5
7+
c.execute("some sql", (max_price,)) # $getSql="some sql"

0 commit comments

Comments
 (0)