Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Python operates the SQLite database

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report