Get the App
SLTechnology News&Howtos  ›  Development  › 

How Python operates the SQLite database

Shulou Source: shulou.com Published: 2022-06-02 15:55:55 11月10日 Update

Python how to operate SQLite database, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Foreword:

SQLite is a lightweight database that complies with ACID's relational database management system, which is contained in a relatively small C library. It is used in many embedded products, it takes up very low resources, python default inherited the operation of this database engine sqlite3 is better than the packaged version of the database, the development of their own use of Mini Program, the use of it is really awesome.

1. Simple operation of SQLite database

Simple operation of SQLite database: create sqlite database is a lightweight database server, the module is integrated in python by default, the development of small applications is very good.

Creation of import sqlite3# data table conn = sqlite3.connect ("data.db") cursor = conn.cursor () create = "create table persion ("\ "id int auto_increment primary key,"\ "name char (20) not null,"\ "age int not null "\" msg text default null "\") "cursor.execute (create) # performs table creation operation 1, the use of simple insert statements insert =" insert into persion (id,name,age,msg) values "cursor.execute (insert) insert =" insert into persion (id,name,age,msg) values; "cursor.execute (insert) insert =" insert into persion (id,name,age,msg) values; "cursor.execute (insert) insert =" insert into persion (id,name,age,msg) values) "cursor.execute (insert) insert =" insert into persion (id,name,age,msg) values; "cursor.execute (insert) data = [(6, 'king dance', 8pyrone'), (7, 'cookie', 8pyrton'), (9meme'C language', 9pyrthon')] insert =" insert into persion (id,name,age,msg) values (?) "cursor.executemany (insert,data) 2. Use of simple query statements select =" select * from persion; "cursor.execute (select) # print (cursor.fetchall ()) # pull out all data select =" select * from persion where name='lyshark'; "cursor.execute (select) print (cursor.fetchall ()) # pull out all data select =" select * from persion where id > = 1 and id= 1 and id= {} and time = {} and time

Tags: Data database user password input time user name statement error problem authentication aging function name field engine more help development retrieval Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Huawei Xiaomi NVidia vpn