We have prepared the pre-development environment, we need to do a little bit of preparation, your account information is there, of course, there is a database, we are going to pay, deduct money, must be operating from the database, to update the data in the Account table, so we have to prepare the database, set up the Account table , initialize several account information in order to complete the mock interface.
Let's learn how Python operates a database, how to execute SQL, and a database using Sqlite,sqlite is a lightweight relational database that is open-source across platforms without the need for configuration and installation to be used directly, SQL statements and MySQL, server, Databases such as Oracle are the same.
First create a database, and then create the Account table, insert a few initialization data, here to use navicat this tool, or other SQLite visualizer can also, Navicat installation package connected to Http://pan.baidu.com/s/1eRArvAM , open navicat After the connection select SQLite, and then choose a new SQLite3 database, select a path, enter the database name to create a database, and then select the newly created database, new query, execute SQL can, see below.
Create a database
Execute SQL
The initialization of the database is ready, the following is to build a table and insert some initial data, or write interface when there is no data test, payment is definitely the operation of the Account table, so to create the Account table, there must be an account ID, user ID and the balance of the user three fields, the table structure is also designed, and then access a little data , to facilitate the use of the later self-test, SQL is as follows:
Table structure is also created, the data also has, the following will use Python to manipulate the database, very simple, is to execute SQL, code as follows, each line is annotated
Test Development Series Python Development Mock Interface (II)