Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The method of reading database data in python operation database

Shulou Source: shulou.com Published: 2022-06-02 19:12:45 10月22日 Update

Automated tests often write data to the database and then read it from the database.

Here's how to read data from a database.

Prerequisite: mysql.connector module is installed

The established database is (under the tet table of the test database):

Use fetchone () to get the next row of the result set

The values read after running are:

If you add a statement C = fetchone () directly after D, C will be the next value in the list:

The value of C obtained is:

And so on, continuing with fetchone will continue to read the next row of data in the result set.

Use fetchall () to get all the remaining rows in the result set

The values read after running are:

Third, use fetchmany () to get the lower line of the result set (specify how many rows of data are printed)

The running result will get 2 rows of data results:

There is a problem QQ × × stream 610845268

Tags: Data results database run one line method and so on premises frequent meetings modules statements problems tests analogies automation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Redmi Linux MySQL macOS