Python / Sqlite3 – Make a DB with Python

Some time ago, I have built something like a primitive SQL language for C# here. Today, I have worked on a similar task, checking the powers of Sqlite3 with Python. This time it was not that primitive and the results were better 🙂

This is how the task looked like:

After creating the sqlite database, implement a script, called that can take command input and do the following things:

  • On command list_employees – Prints out all employees, in the following format – “name – position”
  • On command monthly_spending – Prints out the total sum for monthly spending that the company is doing for salaries
  • On command yearly_spending – Prints out the total sum for one year of operation (Again, salaries)
  • On command add_employee, the program starts to prompt for data, to create a new employee.
  • On command delete_employee <employee_id>, the program should delete the given employee from the database
  • On command update_employee <employee_id>, the program should prompt the user to change each of the fields for the given employee…

What I did? I imported sqlite3 and I generated a function for each command. The commands were called by the console, using the eval() function and adding parenthesis at the end. After each change at the database, the function list_employees() is called to show the results. 

So here comes the code, enjoy it!



Tagged with: , , ,