Test Development Series Python Development Mock Interface (II)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.