mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +01:00
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
# taken from https://dev.mysql.com/doc/connector-python/en/connector-python-example-cursor-transaction.html
|
|
from __future__ import print_function
|
|
from datetime import date, datetime, timedelta
|
|
import mysql.connector
|
|
|
|
cnx = mysql.connector.connect(user='scott', database='employees')
|
|
cursor = cnx.cursor()
|
|
|
|
tomorrow = datetime.now().date() + timedelta(days=1)
|
|
|
|
add_employee = ("INSERT INTO employees "
|
|
"(first_name, last_name, hire_date, gender, birth_date) "
|
|
"VALUES (%s, %s, %s, %s, %s)")
|
|
add_salary = ("INSERT INTO salaries "
|
|
"(emp_no, salary, from_date, to_date) "
|
|
"VALUES (%(emp_no)s, %(salary)s, %(from_date)s, %(to_date)s)")
|
|
|
|
data_employee = ('Geert', 'Vanderkelen', tomorrow, 'M', date(1977, 6, 14))
|
|
|
|
# Insert new employee
|
|
cursor.execute(add_employee, data_employee) # $getSql=add_employee
|
|
emp_no = cursor.lastrowid
|
|
|
|
# Insert salary information
|
|
data_salary = {
|
|
'emp_no': emp_no,
|
|
'salary': 50000,
|
|
'from_date': tomorrow,
|
|
'to_date': date(9999, 1, 1),
|
|
}
|
|
cursor.execute(add_salary, data_salary) # $getSql=add_salary
|
|
|
|
# Make sure data is committed to the database
|
|
cnx.commit()
|
|
|
|
cursor.close()
|
|
cnx.close() |