operational requirements and preliminary thinking
Employee Information Form procedures, to achieve additions and deletions to check the operation:
① can be used for fuzzy query , the syntax supports at least the following 3 kinds :
Select Name,age from staff_table where > 22select * from staff_table where dept = ' IT ' select * from Staff_table whe Re enroll_date like "2013" ②
- solution : A python parsing problem with SQL statements that will convert the SQL statements entered by the user into actions that our code can perform correctly. For keywords where, values, limit, set, and like, create a new dictionary as the key value. After parsing the SQL statement, assign the appropriate information to value. For the table field name and age, use the For loop to print the dictionary to get the value of key for name and ages.
② find the information, after printing , the last side to show the number of found
- Solution : read the JSON file into the dictionary, satisfy the conditional query to add new_dict, and use Len () to calculate the key value.
③ can create a new employee record , with the phone to do a unique key, staff_id need to increase
- solution : Use phone number as the unique key, that is, the format in which the main dictionary is created in JSON is: {1390000000: {' name ': ' May Lol ', ' age ': All, ' staff_id ': xxxxxx, ' Enroll_date ': xxxxxxxx}}
- staff_id self-increment, need to build in an ordered dictionary, import collection module, collections. Ordereddict
④ can delete specified employee information record, enter employee ID, delete
- Delete the dictionary key and value
⑤ can modify employee information, the syntax is as follows:
UPDATE staff_table SET dept= "Market" where dept = "IT"
⑥ above requirements, to fully use the function, please do your utmost to reduce duplication of code
The approximately designed functions are:
- Loaded_from_file: Reading JSON file
- Write_into_file: Writing JSON files
- Sql_parse:sql Statement Parsing
- Add, delete, update, search: Add to search
- Main: Inbound function
Knowledge points
1. Python parsing the execution of the SQL language: This is a very troubling question, this article is written in brief. The code is as follows:
Example
Sample 1
Sample 2
Sample 3
Detailed description Reference http://www.cnblogs.com/alex3714/articles/5740985.html
Python Basics-Day 4 assignment-employee Information Sheet Program