随着视频技术的迅速发展以及移动互联网的不断普及,越来越多的人开始使用手机、平板等移动设备观看视频,而这样的设备又往往由于存储空间有限,需要一种轻量级的存储方式。在这类需求下,SQLite数据库成为了存储视频的首选。

1. SQLite数据库的简介

在介绍SQLite数据库在存储视频中的应用之前,我们需要先了解一下SQLite数据库的基本概念。SQLite是一种轻量级的关系型数据库,其数据库引擎实现在一个相对小的C库中,不需要与独立的服务器进行交互,可直接嵌入到应用程序中使用。因此,SQLite具有占用空间小、性能高、易于维护等诸多优点,特别适用于嵌入式系统或移动设备等有限空间的环境下。

2. SQLite数据库在存储视频中的应用

在移动设备中,存储空间通常比较有限,而且视频文件体积较大,因此传统的视频存储方式(如本地存储、储存在云端)不仅占用存储空间,同时还会影响用户观看视频的体验。相比之下,SQLlite数据库具有较小的占用空间,可以在存储大量视频的同时,减少占用存储空间的负担,提高存储效率。

另外,SQLite数据库支持多种数据类型(如BLOB、TEXT、INTEGER等),可实现对视频、图片、音频等多种格式的存储和操作。同时,SQLite也支持事务处理和数据备份等功能,保证数据的安全性和完整性,给用户提供更好的保障。

3. SQLite数据库在视频应用中的实践

实践证明,SQLite数据库已经被广泛应用于视频应用中。例如,在一些流媒体应用中,采用SQLite数据库存储视频信息和用户数据,便于实现多平台共享,同时可减少服务器成本和网络流量。又如,一些观看视频的应用,在使用SQLite数据库储存视频时,结合缓存、网络传输技术等技术手段,提高了用户观看视频的体验,降低了卡顿等问题。

SQLite数据库是一种轻量级的存储视频的首选。在实际的应用中,SQLite数据库不仅能够提高存储效率,保证数据完整性,还能够实现多种格式的存储和操作。对于移动设备和服务器开发人员,选择SQLite数据库作为视频存储方式,是一种明智而可行的选择。

相关问题拓展阅读:

后端编程Python3-数据库编程

对大多数软件开发者而言,术语数据库通常是指RDBMS(关系数据库管理系统), 这些系统使用表格(类似于电子表格的网格),其中行表示记录,列表示记录的字段。表格及其中存放的数据是使用SQL (结构化査询语言)编写的语句来创建并操纵的。Python提供了用于操纵SQL数据库的API(应用程序接口),通常与作为标准的SQLite 3数据库一起发布。

另一种数据库是DBM (数据库管理器),其中存放任意数量的键-值项。Python 的标准库提供了几种DBM的接口,包括某些特定于UNIX平台的。DBM的工作方式 与Python中的字典类似,区别在于DBM通常存放于磁盘上而不是内存中,并且其键与值总是bytes对象,并可能受到长度限制。本章之一节中讲解的shelve模块提供了方便的DBM接口,允许我们使用字符串作为键,使用任意(picklable)对象作为值。

如果可用的 DBM 与 SQLite 数据库不够充分,Python Package Index, pypi.python.org/pypi中提供了大量数据库相关的包,包括bsddb DBM (“Berkeley DB”),对象-关系映射器,比如SQLAlchemy (www.sqlalchemy.org),以及流行的客户端/服务器数据的接口,比如 DB2、Informix、Ingres、MySQL、ODBC 以及 PostgreSQL。

本章中,我们将实现某程序的两个版本,该程序用于维护一个DVD列表,并追踪每个DVD的标题、发行年份、时间长度以及发行者。该程序的之一版使用DBM (通过shelve模块)存放其数据,第二版则使用SQLite数据库。两个程序都可以加载与保存简单的XML格式,这使得从某个程序导出DVD数据并将其导入到其他程序成为可能。与DBM版相比,基于SQL的程序提供了更多一些的功能,并且其数据设计也稍干净一些。

12.1 DBM数据库

shelve模块为DBM提供了一个wrapper,借助于此,我们在与DBM交互时,可以将其看做一个字典,这里是假定我们只使用字符串键与picklable值,实际处理时, shelve模块会将键与值转换为bytes对象(或者反过来)。

由于shelve模块使用的是底层的DBM,因此,如果其他计算机上没有同样的DBM,那么在某台计算机上保存的DBM文件在其他机器上无法读取是可能的。为解决这一问题,常见的解决方案是对那些必须在机器之间可传输的文件提供XML导入与导出功能,这也是我们在本节的DVD程序dvds-dbm.py中所做的。

对键,我们使用DVD的标题;对值,则使用元组,其中存放发行者、发行年份以及时间。借助于shelve模块,我们不需要进行任何数据转换,并可以把DBM对象当做一个字典进行处理。

程序在结构上类似于我们前面看到的那种菜单驱动型的程序,因此,这里主要展示的是与DBM程序设计相关的那部分。下面给出的是程序main()函数中的一部分, 忽略了其中菜单处理的部分代码。

db = None

try:

db = shelve.open(filename, protocol=pickle.HIGHEST_PROTOCOL)

finally:

if db is not None:

db.dose()

这里我们已打开(如果不存在就创建)指定的DBM文件,以便于对其进行读写操作。每一项的值使用指定的pickle协议保存为一个pickle,现有的项可以被读取, 即便是使用更底层的协议保存的,因为Python可以计算出用于读取pickle的正确协议。最后,DBM被关闭——其作用是清除DBM的内部缓存,并确保磁盘文件可以反映出已作的任何改变,此外,文件也需要关闭。

该程序提供了用于添加、编辑、列出、移除、导入、导出DVD数据的相应选项。除添加外,我们将忽略大部分用户接口代码,同样是因为已经在其他上下文中进行了展示。

def add_dvd(db):

title = Console.get_string(“Title”, “title”)

if not title:

return

director = Console.get_string(“Director”, “director”)

if not director:

return

year = Console.get_integer(“Year”, “year”,minimum=1896,

maximum=datetime,date.today().year)

duration = Console.get_integer(“Duration (minutes)”, “minutes“, minimum=0, maximum=60*48)

db = (director, year, duration) </p> <p><p> db.sync() </p> <p> 像程序菜单调用的所有函数一样,这一函数也以DBM对象(db)作为其唯一参数。该函数的大部分工作都是获取DVD的详细资料,在倒数第二行,我们将键-值项存储在DBM文件中,DVD的标题作为键,发行者、年份以及时间(由shelve模块pickled在一起)作为值。 </p> <p> 为与Python通常的一致性同步,DBM提供了与字典一样的API,因此,除了 shelve.open() 函数(前面已展示)与shelve.Shelf.sync()方法(该方法用于清除shelve的内部缓存,并对磁盘上文件的数据与所做的改变进行同步——这里就是添加一个新项),我们不需要学习任何新语法。 </p> <p> def edit_dvd(db): </p> <p> old_title = find_dvd(db, “edit”) </p> <p> if old_title is None: </p> <p> return </p> <p> title = Console.get.string(“Title”, “title”, old_title) </p> <p> if not title: </p> <p> return </p> <p> director, year, duration = db </p> <p><p> … </p> <p> db<title>= (director, year, duration) </p> <p><p> if title != old_title: </p> <p> del db </p> <p><p> db.sync() </p> <p> 为对某个DVD进行编辑,用户必须首先选择要操作的DVD,也就是获取DVD 的标题,因为标题用作键,值则用于存放其他相关数据。由于必要的功能在其他场合 (比如移除DVD)也需要使用,因此我们将其实现在一个单独的find_dvd()函数中,稍后将査看该函数。如果找到了该DVD,我们就获取用户所做的改变,并使用现有值作为默认值,以便提高交互的速度。(对于这一函数,我们忽略了大部分用户接口代码, 因为其与添加DVD时几乎是相同的。)最后,我们保存数据,就像添加时所做的一样。如果标题未作改变,就重写相关联的值;如果标题已改变,就创建一个新的键-值对, 并且需要删除原始项。 </p> <p> def find_dvd(db, message): </p> <p> message = “(Start of) title to ” + message </p> <p> while True: </p> <p> matches = </p> <p> start = Console.get_string(message, “title”) </p> <p> if not start: </p> <p> return None </p> <p> for title in db: </p> <p> if title.lower().startswith(start.lower()): </p> <p> matches.append(title) </p> <p> if len(matches) == 0: </p> <p> print(“There are no dvds starting with”, start) </p> <p> continue </p> <p> elif len(matches) == 1: </p> <p> return matches </p> <p><p> elif len(matches) > DISPLAY_LIMIT: </p> <p> print(“Too many dvds start with {0}; try entering more of the title”.format(start) </p> <p> continue </p> <p> else: </p> <p> matches = sorted(matches, key=str.lower) </p> <p> for i, match in enumerate(matches): </p> <p> print(“{0}: {1}”.format(i+1, match)) </p> <p> which = Console.get_integer(“Number (or 0 to cancel)”, </p> <p> “number”, minimum=1, maximum=len(matches)) </p> <p> return matches if which != 0 else None </p> <p><p> 为尽可能快而容易地发现某个DVD,我们需要用户只输入其标题的一个或头几个字符。在具备了标题的起始字符后,我们在DBM中迭代并创建一个匹配列表。如果只有一个匹配项,就返回该项;如果有几个匹配项(但少于DISPLAY_LIMIT, 一个在程序中其他地方设置的整数),就以大小写不敏感的顺序展示所有这些匹配项,并为每一项设置一个编号,以便用户可以只输入编号就可以选择某个标题。(Console.get_integer()函数可以接受0,即便最小值大于0,以便0可以用作一个删除值。通过使用参数allow_zero=False, 可以禁止这种行为。我们不能使用Enter键,也就是说,没有什么意味着取消,因为什么也不输入意味着接受默认值。) </p> <p> def list_dvds(db): </p> <p> start =”” </p> <p> if len(db)> DISPLAY.LIMIT: </p> <p> start = Console.get_string(“List those starting with ”, “start”) </p> <p><p> print() </p> <p> for title in sorted(db, key=str.lower): </p> <p> if not start or title.Iower().startswith(start.lower()): </p> <p> director, year, duration = db<title> </p> <p><p> print(“{title} ({year}) {duration} minute{0}, by ” </p> <p> “{director}”.format(Util.s(duration),**locals())) </p> <p> 列出所有DVD (或者那些标题以某个子字符串引导)就是对DBM的所有项进行迭代。 </p> <p> Util.s()函数就是简单的s = lambda x: “” if x == 1 else “s”,因此,如果时间长度不是1分钟,就返回”s”。 </p> <p> def remove_dvd(db): </p> <p> title = find_dvd(db, “remove”) </p> <p> if title is None: </p> <p> return </p> <p> ans = Console.get_bool(“Remove {0}?”.format(title), “no”) </p> <p> if ans: </p> <p> del db<title> </p> <p><p> db.sync() </p> <p> 要移除一个DVD,首先需要找到用户要移除的DVD,并请求确认,获取后从DBM中删除该项即可。 </p> <p> 到这里,我们展示了如何使用shelve模块打开(或创建)一个DBM文件,以及如何向其中添加项、编辑项、对其项进行迭代以及移除某个项。 </p> <p> 遗憾的是,在我们的数据设计中存在一个瑕疵。发行者名称是重复的,这很容易导致不一致性,比如,发行者Danny DeVito可能被输入为”Danny De Vito”,用于 一个电影;也可以输入为“Danny deVito”,用于另一个。为解决这一问题,可以使用两个DBM文件,主DVD文件使用标题键与(年份,时间长度,发行者ID)值; 发行者文件使用发行者ID (整数)键与发行者名称值。下一节展示的SQL数据库 版程序将避免这一瑕疵,这是通过使用两个表格实现的,一个用于DVD,另一个用于发行者。 </p> <p> 12.2 SQL数据库 </p> <p> 大多数流行的SQL数据库的接口在第三方模块中是可用的,Python带有sqlite3 模块(以及SQLite 3数据库),因此,在Python中,可以直接开始数据库程序设计。SQLite是一个轻量级的SQL数据库,缺少很多诸如PostgreSQL这种数据库的功能, 但非常便于构造原型系统,并且在很多情况下也是够用的。 </p> <p> 为使后台数据库之间的切换尽可能容易,PEP 249 (Python Database API Specification v2.0)提供了称为DB-API 2.0的API规范。数据库接口应该遵循这一规范,比如sqlite3模块就遵循这一规范,但不是所有第三方模块都遵循。API规范中指定了两种主要的对象,即连接对象与游标对象。表12-1与表12-2中分别列出了这两种对象必须支持的API。在sqlite3模块中,除DB-API 2.0规范必需的之外,其连接对象与游标对象都提供了很多附加的属性与方法。 </p> <p> DVD程序的SQL版本为dvds.sql.py,该程序将发行者与DVD数据分开存储,以 避免重复,并提供一个新菜单,以供用户列出发行者。该程序使用的两个表格在图12-1 </p> </p> <p> def connect(filename): </p> <p> create= not os.path.exists(filename) </p> <p> db = sqlite3.connect(filename) </p> <p> if create: </p> <p> cursor = db.cursor() </p> <p> cursor.execute(“CREATE TABLE directors (” </p> <p> “id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, ” </p> <p> “name TEXT UNIQUE NOT NULL)”) </p> <p> cursor.execute(“CREATE TABLE dvds (” </p> <p> “id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, ” </p> <p> “title TEXT NOT NULL, ” </p> <p> “year INTEGER NOT NULL,” </p> <p> “duration INTEGER NOT NULL, ” </p> <p> “director_id INTEGER NOT NULL, ” </p> <p> “FOREIGN KEY (director_id) REFERENCES directors)”) </p> <p> db.commit() </p> <p> return db </p> <p> sqlite3.connect()函数会返回一个数据库对象,并打开其指定的数据库文件。如果该文件不存在,就创建一个空的数据库文件。鉴于此,在调用sqlite3.connect()之前,我们要注意数据库是否是准备从头开始创建,如果是,就必须创建该程序要使用的表格。所有査询都是通过一个数据库游标完成的,可以从数据库对象的cursor()方法获取。 </p> <p> 注意,两个表格都是使用一个ID字段创建的,ID字段有一个AUTOINCREMENT 约束——这意味着SQLite会自动为ID字段赋予唯一性的数值,因此,在插入新记录时,我们可以将这些字段留给SQLite处理。 </p> <p> SQLite支持有限的数据类型——实际上就是布尔型、数值型与字符串——但使用数据’‘适配器”可以对其进行扩展,或者是扩展到预定义的数据类型(比如那些用于日期与datetimes的类型),或者是用于表示任意数据类型的自定义类型。DVD程序并不需要这一功能,如果需要,sqlite3模块的文档提供了很多详细解释。我们使用的外部键语法可能与用于其他数据库的语法不同,并且在任何情况下,只是记录我们的意图,因为SQLite不像很多其他数据库那样需要强制关系完整性,sqlite3另一点与众不同的地方在于其默认行为是支持隐式的事务处理,因此,没有提供显式的“开始事务” 方法。 </p> <p> def add_dvd(db): </p> <p> title = Console.get_string(“Title”, “title”) </p> <p> if not title: </p> <p> return </p> <p> director = Console.get_string(“Director”, “director”) </p> <p> if not director: </p> <p> return </p> <p> year = Console.get_integer(“Year”, “year”, minimum=1896, </p> <p> maximum=datetime.date.today().year) </p> <p> duration = Console.get_integer(“Duration (minutes)”, “minutes”, </p> <p> minimum=0,maximum=60*48) </p> <p> director_id = get_and_set_director(db, director) </p> <p> cursor = db.cursor() </p> <p> cursor.execute(“INSERT INTO dvds ” </p> <p> “(title, year, duration, director_id)” </p> <p> “VALUES (?, ?, ?, ?)”, </p> <p> (title, year, duration, director_id)) </p> <p> db.commit() </p> <p> 这一函数的开始代码与dvds-dbm.py程序中的对应函数一样,但在完成数据的收集后,与原来的函数有很大的差别。用户输入的发行者可能在也可能不在directors表格中,因此,我们有一个get_and_set_director()函数,在数据库中尚无某个发行者时, 该函数就将其插入到其中,无论哪种情况都返回就绪的发行者ID,以便在需要的时候插入到dvds表。在所有数据都可用后,我们执行一条SQL INSERT语句。我们不需要指定记录ID,因为SQLite会自动为我们提供。 </p> <p> 在査询中,我们使用问号(?)作为占位符,每个?都由包含SQL语句的字符串后面的序列中的值替代。命名的占位符也可以使用,后面在编辑记录时我们将看到。尽管避免使用占位符(而只是简单地使用嵌入到其中的数据来格式化SQL字符串)也是可能的,我们建议总是使用占位符,并将数据项正确编码与转义的工作留给数据库模块来完成。使用占位符的另一个好处是可以提高安全性,因为这可以防止任意的SQL 被恶意地插入到一个査询中。 </p> <p> def get_and_set_director(db, director): </p> <p> director_id = get_director_id(db, director) </p> <p> if directorjd is not None: </p> <p> return director_id </p> <p> cursor = db.cursor() </p> <p> cursor.execute(“lNSERT INTO directors (name) VALUES (?)”,(director,)) </p> <p> db.commit() </p> <p> return get_director_id(db, director) </p> <p> 这一函数返回给定发行者的ID,并在必要的时候插入新的发行者记录。如果某个记录入,我们首先尝试使用get_director_id()函数取回其ID。 </p> <p> def get_director_id(db, director): </p> <p> cursor = db.cursor() </p> <p> cursor.execute(“SELECT id FROM directors WHERE name=?”,(director,)) </p> <p> fields = cursor.fetchone() </p> <p> return fields if fields is not None else None </p> <p><p> get_director_id()函数返回给定发行者的ID,如果数据库中没有指定的发行者,就返回None。我们使用fetchone()方法,因为或者有一个匹配的记录,或者没有。(我们知道,不会有重复的发行者,因为directors表格的名称字段有一个UNIQUE约束,在任何情况下,在添加一个新的发行者之前,我们总是先检査其是否存在。)这种取回方法总是返回一个字段序列(如果没有更多的记录,就返回None)。即便如此,这里我们只是请求返回一个单独的字段。 </p> <p> def edit_dvd(db): </p> <p> title, identity = find_dvd(db, “edit”) </p> <p> if title is None: </p> <p> return </p> <p> title = Console.get_string(“Title”,”title”, title) </p> <p> if not title: </p> <p> return </p> <p> cursor = db.cursor() </p> <p> cursor.execute(“SELECT dvds.year, dvds.duration, directors.name” </p> <p> “FROM dvds, directors ” </p> <p> “WHERE dvds.director_id = directors.id AND ” </p> <p> “dvds.id=:id”, dict(id=identity)) </p> <p> year, duration, director = cursor.fetchone() </p> <p> director = Console.get_string(“Director”, “director”, director) </p> <p> if not director: </p> <p> return </p> <p> year = Console,get_integer(“Year”,”year”, year, 1896,datetime.date.today().year) </p> <p> duration = Console.get_integer(“Duration (minutes)”, “minutes”, </p> <p> duration, minimum=0, maximum=60*48) </p> <p> director_id = get_and_set_director(db, director) </p> <p> cursor.execute(“UPDATE dvds SET title=:title, year=:year,” </p> <p> “duration=:duration, director_id=:directorjd ” </p> <p> “WHERE id=:identity”, locals()) </p> <p> db.commit() </p> <p> 要编辑DVD记录,我们必须首先找到用户需要操纵的记录。如果找到了某个记录,我们就给用户修改其标题的机会,之后取回该记录的其他字段,以便将现有值作为默认值,将用户的输入工作最小化,用户只需要按Enter键就可以接受默认值。这里,我们使用了命名的占位符(形式为:name),并且必须使用映射来提供相应的值。对SELECT语句,我们使用一个新创建的字典;对UPDATE语句,我们使用的是由 locals()返回的字典。 </p> <p> 我们可以同时为这两个语句都使用新字典,这种情况下,对UPDATE语句,我们可以传递 dict(title=title, year=year, duration=duration, director_id=director_id, id=identity)),而非 locals()。 </p> <p> 在具备所有字段并且用户已经输入了需要做的改变之后,我们取回相应的发行者ID (如果必要就插入新的发行者记录),之后使用新数据对数据库进行更新。我们采用了一种简化的方法,对记录的所有字段进行更新,而不仅仅是那些做了修改的字段。 </p> <p> 在使用DBM文件时,DVD标题被用作键,因此,如果标题进行了修改,我们就需要创建一个新的键-值项,并删除原始项。不过,这里每个DVD记录都有一个唯一性的ID,该ID是记录初次插入时创建的,因此,我们只需要改变任何其他字段的值, 而不需要其他操作。 </p> <p> def find_dvd(db, message): </p> <p> message = “(Start of) title to ” + message </p> <p> cursor = db.cursor() </p> <p> while True: . </p> <p> start = Console.get_stnng(message, “title”) </p> <p> if not start: </p> <p> return (None, None) </p> <p> cursor.execute(“SELECT title, id FROM dvds ” </p> <p> “WHERE title LIKE ? ORDER BY title”, </p> <p> (start +”%”,)) </p> <p> records = cursor.fetchall() </p> <p> if len(records) == 0: </p> <p> print(“There are no dvds starting with”, start) </p> <p> continue </p> <p> elif len(records) == 1: </p> <p> return records </p> <p><p> elif len(records) > DISPLAY_LIMIT: </p> <p> print(“Too many dvds ({0}) start with {1}; try entering ” </p> <p> “more of the title”.format(len(records),start)) </p> <p> continue </p> <p> else: </p> <p> for i, record in enumerate(records): </p> <p> print(“{0}:{1}”.format(i + 1, record)) </p> <p><p> which = Console.get_integer(“Number (or 0 to cancel)”, </p> <p> “number”, minimum=1, maximum=len(records)) </p> <p> return records if which != 0 else (None, None) </p> <p><p> 这一函数的功能与dvdsdbm.py程序中的find_dvd()函数相同,并返回一个二元组 (DVD标题,DVD ID)或(None, None),具体依赖于是否找到了某个记录。这里并不需要在所有数据上进行迭代,而是使用SQL通配符(%),因此只取回相关的记录。 </p> <p> 由于我们希望匹配的记录数较小,因此我们一次性将其都取回到序列的序列中。如果有不止一个匹配的记录,但数量上又少到可以显示,我们就打印记录,并将每条记录附带一个数字编号,以便用户可以选择需要的记录,其方式与在dvds-dbm.py程序中所做的类似: </p> <p> def list_dvds(db): </p> <p> cursor = db.cursor() </p> <p> sql = (“SELECT dvds.title, dvds.year, dvds.duration, ” </p> <p> “directors.name FROM dvds, directors ” </p> <p> “WHERE dvds.director_id = directors.id”) </p> <p> start = None </p> <p> if dvd_count(db) > DISPLAY_LIMIT: </p> <p> start = Console.get_string(“List those starting with “, “start”) </p> <p><p> sql += ” AND dvds.title LIKE ?” </p> <p> sql += ” ORDER BY dvds.title” </p> <p> print() </p> <p> if start is None: </p> <p> cursor.execute(sql) </p> <p> else: </p> <p> cursor.execute(sql, (start +”%”,)) </p> <p> for record in cursor: </p> <p> print(“{0} ({0}) {0} minutes, by {0}”.format(record)) </p> <p><p> 要列出每个DVD的详细资料,我们执行一个SELECT査询。该査询连接两个表,如果记录(由dvd_count()函数返回)数量超过了显示限制值,就将第2个元素添加到WHERE 分支,之后执行该査询,并在结果上进行迭代。每个记录都是一个序列,其字段是与 SELECT査询相匹配的。 </p> <p> def dvd_count(db): </p> <p> cursor = db.cursor() </p> <p> cursor.execute(“SELECT COUNT(*) FROM dvds”) </p> <p> return cursor.fetchone() </p> <p><p> 我们将这几行代码放置在一个单独的函数中,因为我们在几个不同的函数中都需要使用这几行代码。 </p> <p> 我们忽略了 list_directors()函数的代码,因为该函数在结构上与list_dvds()函数非常类似,只不过更简单一些,因为本函数只列出一个字段(name)。 </p> <p> def remove_dvd(db): </p> <p> title, identity = find_dvd(db, “remove”) </p> <p> if title is None: </p> <p> return </p> <p> ans = Console.get_bool(“Remove {0}?”.format(title), “no”) </p> <p> if ans: </p> <p> cursor = db.cursor() </p> <p> cursor.execute(“DELETE FROM dvds WHERE id=?”, (identity,)) </p> <p> db.commit() </p> <p> 在用户需要删除一个记录时,将调用本函数,并且本函数与dvds-dbm.py程序中 相应的函数是非常类似的。 </p> <p> 到此,我们完全查阅了 dvds-sql.py程序,并且了解了如何创建数据库表格、选取 记录、在选定的记录上进行迭代以及插入、更新与删除记录。使用execute()方法,我们可以执行底层数据库所支持的任意SQL语句。 </p> <p> SQLite提供了比我们这里使用的多得多的功能,包括自动提交模式(以及任意其他类型的事务控制),以及创建可以在SQL查询内执行的函数的能力。提供一个工厂函数并用于控制对每个取回的记录返回什么(比如,一个字典或自定义类型,而不是字段序列)也是可能的。此外,通过传递“:memory:”作为文件名,创建内存中的SQLite 数据库也是可能的。 </p> <p>sqlite数据库 视频的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于sqlite数据库 视频,SQLite数据库:轻量级存储视频的首选,后端编程Python3-数据库编程的信息别忘了在本站进行查找喔。</p> <div class='yarpp yarpp-related yarpp-related-website yarpp-template-list'> <!-- YARPP List --> <h3>相关推荐:</h3><ol> <li><a href="https://www.88531.cn/17014.html" rel="bookmark" title="SQLite数据库下载安装方法简介 (sqlite数据库 下载安装)">SQLite数据库下载安装方法简介 (sqlite数据库 下载安装)</a> <small>SQLite数据库是一种轻型的、自包容的、高性能的嵌入式关系型数据库管理系统。它的使用非常方便,目前逐渐被广泛使用。本文将介绍SQLite数据库的下载安装方法以及如何在Windows、Linux和Mac上安装SQLite数据库。...</small></li> </ol> </div> <div class="entry-copyright"> <i class="fas fa-info-circle me-1"></i>声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。</div> </article> <div class="site-addswarp pc bottum"><a href='https://doc.88531.cn/docs/yfwqtj' target="_blank"><img class="alignnone size-medium wp-image-38237" src="/wp-content/uploads/txad/2.png" alt="" /></a></div> <div class="entry-social"> <div class="row mt-2 mt-lg-3"> <div class="col"> <a class="share-author" href="https://www.88531.cn/author/0c8c07f5705b9474"> <div class="avatar me-1"><img class="avatar-img rounded-circle border border-white border-3 shadow" src="//www.88531.cn/wp-content/themes/ripro-v5/assets/img/avatar.png" alt=""> </div>NO.1 </a> </div> <div class="col-auto"> <a class="btn btn-sm btn-success-soft post-fav-btn" href="javascript:void(0);" data-is="1"><i class="far fa-star me-1"></i></i>收藏</a> <a class="btn btn-sm btn-danger-soft post-like-btn" href="javascript:void(0);" data-text="已点赞"><i class="far fa-heart me-1"></i>点赞(<span class="count">0</span>)</a> </div> </div> </div> </div> <div class="tab-pane fade" id="pills-faq" role="tabpanel" aria-labelledby="pills-faq-tab"> <ol class="list-group list-group-numbered"> <li class="list-group-item list-group-item-info d-flex justify-content-between align-items-start"> <div class="ms-2 me-auto"> <div class="fw-bold">免费下载或者VIP会员资源能否直接商用?</div> <div class="text-muted">本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。</div> </div> </li> <li class="list-group-item list-group-item-info d-flex justify-content-between align-items-start"> <div class="ms-2 me-auto"> <div class="fw-bold">提示下载完但解压或打开不了?</div> <div class="text-muted">最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。 若排除这种情况,可在对应资源底部留言,或联络我们。</div> </div> </li> <li class="list-group-item list-group-item-info d-flex justify-content-between align-items-start"> <div class="ms-2 me-auto"> <div class="fw-bold">找不到素材资源介绍文章里的示例图片?</div> <div class="text-muted">对于会员专享、整站源码、程序插件、网站模板、网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。</div> </div> </li> <li class="list-group-item list-group-item-info d-flex justify-content-between align-items-start"> <div class="ms-2 me-auto"> <div class="fw-bold">付款后无法显示下载地址或者无法查看内容?</div> <div class="text-muted">如果您已经成功付款但是网站没有弹出成功提示,请联系站长提供付款信息为您处理</div> </div> </li> <li class="list-group-item list-group-item-info d-flex justify-content-between align-items-start"> <div class="ms-2 me-auto"> <div class="fw-bold">购买该资源后,可以退款吗?</div> <div class="text-muted">源码素材属于虚拟商品,具有可复制性,可传播性,一旦授予,不接受任何形式的退款、换货要求。请您在购买获取之前确认好 是您所需要的资源</div> </div> </li> </ol> </div> </div> </div> <div class="entry-navigation"> <div class="row g-3"> <div class="col-lg-6 col-12"> <a class="entry-page-prev" href="https://www.88531.cn/16018.html" title="高效可靠!手机删除数据库请看这篇指南 (手机怎么彻底删除数据库)"> <div class="entry-page-icon"><i class="fas fa-arrow-left"></i></div> <div class="entry-page-info"> <span class="d-block rnav">上一篇</span> <div class="title">高效可靠!手机删除数据库请看这篇指南 (手机怎么彻底删除数据库)</div> </div> </a> </div> <div class="col-lg-6 col-12"> <a class="entry-page-next" href="https://www.88531.cn/11665.html" title="最大排序MSSQL中轻松获取字母最大排序(mssql 获取字母)"> <div class="entry-page-info"> <span class="d-block rnav">下一篇</span> <div class="title">最大排序MSSQL中轻松获取字母最大排序(mssql 获取字母)</div> </div> <div class="entry-page-icon"><i class="fas fa-arrow-right"></i></div> </a> </div> </div> </div> <div class="related-posts"> <h2 class="related-posts-title"><i class="fab fa-hive me-1"></i>相关文章</h2> <div class="row g-2 g-md-3 row-cols-2 row-cols-md-3 row-cols-lg-4"> <div class="col"> <article class="post-item item-grid"> <div class="tips-badge position-absolute top-0 start-0 z-1 m-2"> </div> <div class="entry-media ratio ratio-3x2"> <a target="_blank" class="media-img lazy bg-cover bg-center" href="https://www.88531.cn/16737.html" title="深入了解数据库:掌握explain使用方法 (数据库explain的用法)" data-bg="https://www.88531.cn/wp-content/themes/ripro-v5/assets/img/thumb.jpg"> <!-- 音视频缩略图 --> </a> </div> <div class="entry-wrapper"> <div class="entry-cat-dot"><a href="https://www.88531.cn/category/jsfx">技术分享</a> <a href="https://www.88531.cn/category/jsfx/shujuku">数据库</a></div> <h2 class="entry-title"> <a target="_blank" href="https://www.88531.cn/16737.html" title="深入了解数据库:掌握explain使用方法 (数据库explain的用法)">深入了解数据库:掌握explain使用方法 (数据库explain的用法)</a> </h2> <div class="entry-desc">在如今的互联网时代,数据的管理和使用相当重要,尤其是在企业或者组织中,数据更是至...</div> <div class="entry-meta"> <span class="meta-date"><i class="far fa-clock me-1"></i><time class="pub-date" datetime="2023-09-06T18:48:26+08:00">2 年前</time></span> <span class="meta-likes d-none d-md-inline-block"><i class="far fa-heart me-1"></i>0</span> <span class="meta-fav d-none d-md-inline-block"><i class="far fa-star me-1"></i>0</span> <span class="meta-views"><i class="far fa-eye me-1"></i>175</span> </div> </div> </article> </div> <div class="col"> <article class="post-item item-grid"> <div class="tips-badge position-absolute top-0 start-0 z-1 m-2"> </div> <div class="entry-media ratio ratio-3x2"> <a target="_blank" class="media-img lazy bg-cover bg-center" href="https://www.88531.cn/14416.html" title="MySQL数据库备份出现数据丢失问题 (mysql 数据库备份数据丢失)" data-bg="https://www.88531.cn/wp-content/themes/ripro-v5/assets/img/thumb.jpg"> <!-- 音视频缩略图 --> </a> </div> <div class="entry-wrapper"> <div class="entry-cat-dot"><a href="https://www.88531.cn/category/jsfx">技术分享</a> <a href="https://www.88531.cn/category/jsfx/shujuku">数据库</a></div> <h2 class="entry-title"> <a target="_blank" href="https://www.88531.cn/14416.html" title="MySQL数据库备份出现数据丢失问题 (mysql 数据库备份数据丢失)">MySQL数据库备份出现数据丢失问题 (mysql 数据库备份数据丢失)</a> </h2> <div class="entry-desc">MySQL数据库备份是保障数据安全的重要手段,但是备份的过程中也可能会出现数据丢...</div> <div class="entry-meta"> <span class="meta-date"><i class="far fa-clock me-1"></i><time class="pub-date" datetime="2023-09-06T08:21:17+08:00">2 年前</time></span> <span class="meta-likes d-none d-md-inline-block"><i class="far fa-heart me-1"></i>0</span> <span class="meta-fav d-none d-md-inline-block"><i class="far fa-star me-1"></i>0</span> <span class="meta-views"><i class="far fa-eye me-1"></i>174</span> </div> </div> </article> </div> <div class="col"> <article class="post-item item-grid"> <div class="tips-badge position-absolute top-0 start-0 z-1 m-2"> </div> <div class="entry-media ratio ratio-3x2"> <a target="_blank" class="media-img lazy bg-cover bg-center" href="https://www.88531.cn/15810.html" title="维护oracle数据库表空间,提升系统性能 (oracle 数据库表空间维护)" data-bg="https://www.88531.cn/wp-content/themes/ripro-v5/assets/img/thumb.jpg"> <!-- 音视频缩略图 --> </a> </div> <div class="entry-wrapper"> <div class="entry-cat-dot"><a href="https://www.88531.cn/category/jsfx">技术分享</a> <a href="https://www.88531.cn/category/jsfx/shujuku">数据库</a></div> <h2 class="entry-title"> <a target="_blank" href="https://www.88531.cn/15810.html" title="维护oracle数据库表空间,提升系统性能 (oracle 数据库表空间维护)">维护oracle数据库表空间,提升系统性能 (oracle 数据库表空间维护)</a> </h2> <div class="entry-desc">维护Oracle数据库表空间,提升系统性能Oracle数据库作为一种大型关系型数...</div> <div class="entry-meta"> <span class="meta-date"><i class="far fa-clock me-1"></i><time class="pub-date" datetime="2023-08-31T17:05:43+08:00">2 年前</time></span> <span class="meta-likes d-none d-md-inline-block"><i class="far fa-heart me-1"></i>0</span> <span class="meta-fav d-none d-md-inline-block"><i class="far fa-star me-1"></i>0</span> <span class="meta-views"><i class="far fa-eye me-1"></i>186</span> </div> </div> </article> </div> <div class="col"> <article class="post-item item-grid"> <div class="tips-badge position-absolute top-0 start-0 z-1 m-2"> </div> <div class="entry-media ratio ratio-3x2"> <a target="_blank" class="media-img lazy bg-cover bg-center" href="https://www.88531.cn/12447.html" title="Android实现全局共享数据库 (android 全局共享数据库)" data-bg="https://www.88531.cn/wp-content/themes/ripro-v5/assets/img/thumb.jpg"> <!-- 音视频缩略图 --> </a> </div> <div class="entry-wrapper"> <div class="entry-cat-dot"><a href="https://www.88531.cn/category/jsfx">技术分享</a> <a href="https://www.88531.cn/category/jsfx/shujuku">数据库</a></div> <h2 class="entry-title"> <a target="_blank" href="https://www.88531.cn/12447.html" title="Android实现全局共享数据库 (android 全局共享数据库)">Android实现全局共享数据库 (android 全局共享数据库)</a> </h2> <div class="entry-desc">随着移动互联网的快速发展,越来越多的应用程序被开发出来。在这些应用程序中,使用数...</div> <div class="entry-meta"> <span class="meta-date"><i class="far fa-clock me-1"></i><time class="pub-date" datetime="2023-09-07T05:45:42+08:00">2 年前</time></span> <span class="meta-likes d-none d-md-inline-block"><i class="far fa-heart me-1"></i>0</span> <span class="meta-fav d-none d-md-inline-block"><i class="far fa-star me-1"></i>0</span> <span class="meta-views"><i class="far fa-eye me-1"></i>177</span> </div> </div> </article> </div> </div> </div> </div> <div class="sidebar-wrapper col-md-12 col-lg-3 h-100" data-sticky> <div class="sidebar"> <div id="recent-posts-2" class="widget widget_recent_entries"> <h5 class="widget-title">近期文章</h5> <ul> <li> <a href="https://www.88531.cn/42805.html">不用开VIP会员,这个开源神器让你实现音乐自由多端支持Spotube</a> </li> <li> <a href="https://www.88531.cn/42800.html">受够音乐平台VIP套路?这个开源神器让你实现音乐自由</a> </li> <li> <a href="https://www.88531.cn/42756.html">强大!支持全网的安卓万能视频下载工具 v3.9.2 去广告会员版</a> </li> <li> <a href="https://www.88531.cn/42759.html">ACR Phone安卓版(安卓电话录音软件) v0.364 修改版</a> </li> <li> <a href="https://www.88531.cn/42769.html">安卓手机哔哩哔哩漫游 v8.43.0 去广告净化</a> </li> </ul> </div> </div> </div> </div> </div> </main> <!-- **************** MAIN CONTENT END **************** --> <!-- ======================= Footer START --> <footer class="site-footer py-md-4 py-2 mt-2 mt-md-4"> <div class="container"> <div class="row d-none d-lg-flex mb-3"> <div class="col-md-4"> <div class="logo-wrapper"> </div> <div class="logo-wrapper"> <a rel="nofollow noopener noreferrer" href="https://www.88531.cn/"><img class="logo regular" data-light="https://www.88531.cn/wp-content/uploads/2024/08/diugai.com171276885347379-1.png" data-dark="https://www.88531.cn/wp-content/uploads/2024/08/diugai.com171276885347379-1.png" src="https://www.88531.cn/wp-content/uploads/2024/08/diugai.com171276885347379-1.png" alt="88531资享网"></a></div> <p class="small mb-0">88531资享网:专为新手菜鸟分享各种最新精品资源和学习技术,精品VIP网站源码等资源,免费网站源码下载!,新手菜鸟的好帮手网站! </p> </div> <div class="col-md-2"> <h4 class="widget-title">快速导航</h4> <ul class="list-unstyled widget-links"> <li><a href="https://www.88531.cn/user">个人中心</a></li><li><a href="https://www.88531.cn/tags">标签云</a></li><li><a href="https://www.88531.cn/links">网址导航</a></li> </ul> </div> <div class="col-md-2"> <h4 class="widget-title">关于本站</h4> <ul class="list-unstyled widget-links"> <li><a href="https://www.88531.cn/vip-prices">VIP介绍</a></li><li><a href="https://www.88531.cn/user/ticket">客服咨询</a></li><li><a href="https://www.88531.cn/user/aff">推广计划</a></li> </ul> </div> <div class="col-md-4"> <h4 class="widget-title">联系我们</h4> <div class="">QQ: 181050043</div> </div> </div> <div class="text-center small w-100"> <div>Copyright © 2025 <a target="_blank" href="https://www.88531.cn">88531资享网</a> - All rights reserved</div> <div class=""><a href="https://beian.miit.gov.cn" target="_blank" rel="noreferrer nofollow">京ICP备0000000号-1</a><a href="#" target="_blank" rel="noreferrer nofollow">京公网安备 00000000</a></div> </div> </div> </footer> <!-- ======================= Footer END --> <!-- Back to top rollbar--> <div class="rollbar"> <ul class="actions"> <li><a target="" href="https://www.88531.cn/" rel="nofollow noopener noreferrer"><i class="fas fa-home"></i><span>首页</span></a></li><li><a target="" href="https://www.88531.cn/user" rel="nofollow noopener noreferrer"><i class="far fa-user"></i><span>用户中心</span></a></li><li><a target="" href="https://www.88531.cn/vip-prices" rel="nofollow noopener noreferrer"><i class="fa fa-diamond"></i><span>会员介绍</span></a></li><li><a target="" href="http://wpa.qq.com/msgrd?v=3&uin=181050043&site=qq&menu=yes" rel="nofollow noopener noreferrer"><i class="fab fa-qq"></i><span>QQ客服</span></a></li><li><a target="_blank" href="https://www.88531.cn/links" rel="nofollow noopener noreferrer"><i class="fab fa-shopware"></i><span>导航</span></a></li> </ul> </div> <div class="back-top"><i class="fas fa-caret-up"></i></div> <!-- m-navbar --> <div class="m-navbar"> <ul> <li><a target="" href="https://www.88531.cn" rel="nofollow noopener noreferrer"><i class="fas fa-home"></i><span>首页</span></a></li><li><a target="" href="https://www.88531.cn/tags" rel="nofollow noopener noreferrer"><i class="fas fa-layer-group"></i><span>分类</span></a></li><li><a target="" href="https://www.88531.cn/vip-prices" rel="nofollow noopener noreferrer"><i class="far fa-gem"></i><span>会员</span></a></li><li><a target="" href="https://www.88531.cn/user" rel="nofollow noopener noreferrer"><i class="fas fa-user"></i><span>我的</span></a></li> </ul> </div> <!-- dimmer--> <div class="dimmer"></div> <div class="off-canvas"> <div class="canvas-close"><i class="fas fa-times"></i></div> <!-- logo --> <div class="logo-wrapper"> <a rel="nofollow noopener noreferrer" href="https://www.88531.cn/"><img class="logo regular" data-light="https://www.88531.cn/wp-content/uploads/2024/08/diugai.com171276885347379-1.png" data-dark="https://www.88531.cn/wp-content/uploads/2024/08/diugai.com171276885347379-1.png" src="https://www.88531.cn/wp-content/uploads/2024/08/diugai.com171276885347379-1.png" alt="88531资享网"></a></div> <div class="mobile-menu d-block d-lg-none"></div> </div> <script type="speculationrules"> {"prefetch":[{"source":"document","where":{"and":[{"href_matches":"\/*"},{"not":{"href_matches":["\/wp-*.php","\/wp-admin\/*","\/wp-content\/uploads\/*","\/wp-content\/*","\/wp-content\/plugins\/*","\/wp-content\/themes\/ripro-v5\/*","\/*\\?(.+)"]}},{"not":{"selector_matches":"a[rel~=\"nofollow\"]"}},{"not":{"selector_matches":".no-prefetch, .no-prefetch a"}}]},"eagerness":"conservative"}]} </script> <link rel='stylesheet' id='yarppRelatedCss-css' href='https://www.88531.cn/wp-content/plugins/yet-another-related-posts-plugin/style/related.css?ver=5.30.11' media='all' /> <script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/highlight.min.js?ver=11.7.0" id="highlight-js"></script> <script src="https://www.88531.cn/wp-content/themes/ripro-v5/assets/js/vendor.min.js?ver=8.0" id="vendor-js"></script> <script id="main-js-extra"> var zb = {"home_url":"https:\/\/www.88531.cn","ajax_url":"https:\/\/www.88531.cn\/wp-admin\/admin-ajax.php","theme_url":"https:\/\/www.88531.cn\/wp-content\/themes\/ripro-v5","singular_id":"13766","post_content_nav":"1","site_popup_login":"1","site_notify_auto":"0","current_user_id":"0","ajax_nonce":"844b14b13c","gettext":{"__copypwd":"\u5bc6\u7801\u5df2\u590d\u5236\u526a\u8d34\u677f","__copybtn":"\u590d\u5236","__copy_succes":"\u590d\u5236\u6210\u529f","__comment_be":"\u63d0\u4ea4\u4e2d...","__comment_succes":"\u8bc4\u8bba\u6210\u529f","__comment_succes_n":"\u8bc4\u8bba\u6210\u529f\uff0c\u5373\u5c06\u5237\u65b0\u9875\u9762","__buy_be_n":"\u8bf7\u6c42\u652f\u4ed8\u4e2d\u00b7\u00b7\u00b7","__buy_no_n":"\u652f\u4ed8\u5df2\u53d6\u6d88","__is_delete_n":"\u786e\u5b9a\u5220\u9664\u6b64\u8bb0\u5f55\uff1f"}}; </script> <script src="https://www.88531.cn/wp-content/themes/ripro-v5/assets/js/main.min.js?ver=8.0" id="main-js"></script> <script id="q2w3_fixed_widget-js-extra"> var q2w3_sidebar_options = [{"sidebar":"sidebar","use_sticky_position":false,"margin_top":0,"margin_bottom":0,"stop_elements_selectors":"","screen_max_width":0,"screen_max_height":0,"widgets":["#block-2"]},{"sidebar":"single-sidebar","use_sticky_position":false,"margin_top":0,"margin_bottom":0,"stop_elements_selectors":"","screen_max_width":0,"screen_max_height":0,"widgets":["#recent-posts-2"]}]; </script> <script src="https://www.88531.cn/wp-content/plugins/q2w3-fixed-widget/js/frontend.min.js?ver=6.2.3" id="q2w3_fixed_widget-js"></script> <!-- 自定义js代码 统计代码 --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?225297bceab00c11f86be5cf7eefe4ca"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script><!-- 自定义js代码 统计代码 END --> </body> </html>