随着视频技术的迅速发展以及移动互联网的不断普及,越来越多的人开始使用手机、平板等移动设备观看视频,而这样的设备又往往由于存储空间有限,需要一种轻量级的存储方式。在这类需求下,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.npspro.top/17014.html" rel="bookmark" title="SQLite数据库下载安装方法简介 (sqlite数据库 下载安装)">SQLite数据库下载安装方法简介 (sqlite数据库 下载安装)</a> <small>SQLite数据库是一种轻型的、自包容的、高性能的嵌入式关系型数据库管理系统。它的使用非常方便,目前逐渐被广泛使用。本文将介绍SQLite数据库的下载安装方法以及如何在Windows、Linux和Mac上安装SQLite数据库。...</small></li> </ol> </div> <div class="post-end"> <!--<span><a style="color:#F17B8F; border-bottom: 0px solid #999!important;">-------------------------此篇文章到此结束-------------------------</a></span>--> </div> <ul class="post-copyright"> <!--<li class="post-copyright-author"><strong>本文作者:</strong><a title="www.88531.cn资享网" href="https://www.npspro.top/author/admin">www.88531.cn资享网</a></li>--> <li class="post-copyright-link"><strong>本文来源链接地址:</strong> <a rel="bookmark" title="SQLite数据库:轻量级存储视频的首选 (sqlite数据库 视频)" href="https://www.npspro.top/13766.html"> https://www.npspro.top/13766.html</a></li> <!--<li class="post-copyright-license"><strong>转载请注明来自:<a href="./" data-pjax-state="">www.88531.cn资享网</a></li>--> </ul> </div> <div id="pay-single-box"></div> <div class="article-copyright">www.npspro.top互联侠客<br/><a href="https://www.npspro.top">软师傅</a> » <a href="https://www.npspro.top/13766.html">SQLite数据库:轻量级存储视频的首选 (sqlite数据库 视频)</a></div> <div class="ripro_gg_wrap pc"><a href='https://cloud.tencent.com/act/pro/Featured?from=24551&cps_key=e8dd943ef20bc89427528d2acd8b08d8' target="_blank"><img class="alignnone size-full wp-image-38236" src="/wp-content/uploads/txad/2.png" alt="" width="100%" /></a></div><div class="article-footer"> <div class="author-box"> <div class="author-image"> <img alt='' data-src='https://www.npspro.top/wp-content/themes/ripro/assets/images/avatar/1.png' class='lazyload avatar avatar-96 photo ' height='96' width='96' /> </div> <div class="author-info"> <h4 class="author-name"> <a target="_blank" href="javascript:;">Perfect″—完美</a> <span class="label label-warning"><i class="fa fa-diamond"></i> 钻石</span> </h4> </div> </div> <div class="xshare"> <span class="xshare-title">分享到:</span> <a href="javascript:;" title="收藏文章" etap="star" data-postid="13766" class="ripro-star"><i class="fa fa-star-o"></i></a> <a href="" etap="share" data-share="qq" class="share-qq"><i class="fa fa-qq"></i></a> <a href="" etap="share" data-share="weibo" class="share-weibo"><i class="fa fa-weibo"></i></a> </div> </div> </div> </div> </article> <div class="entry-navigation"> <nav class="article-nav"> <span class="article-nav-prev">上一篇<br><a href="https://www.npspro.top/16018.html" rel="prev">高效可靠!手机删除数据库请看这篇指南 (手机怎么彻底删除数据库)</a></span> <span class="article-nav-next">下一篇<br><a href="https://www.npspro.top/11665.html" rel="next">最大排序MSSQL中轻松获取字母最大排序(mssql 获取字母)</a></span> </nav> </div> </main> </div> </div> <div class="sidebar-column col-lg-3"> <aside class="widget-area"> <div id="block-16" class="widget widget_block">AD:【腾讯云服务器大降价】<a href='https://cloud.tencent.com/act/pro/Featured?from=24551&cps_key=e8dd943ef20bc89427528d2acd8b08d8' style='color:red;' target="_blank">2核4G222元/3年1核2G38元/年</a> <br> <div style="color:red;">100T热门网盘资源精选:<a href='https://link3.cc/88531cn' target="_blank"><点击查看></a></div></div> <div id="recent-posts-4" class="widget widget_recent_entries"> <h5 class="widget-title">近期文章</h5> <ul> <li> <a href="https://www.npspro.top/38061.html">安卓易剪媒 1.0.8最新版 AI自动剪辑视频,支持300+平台去水印和批量处理 新手自媒体创作</a> </li> <li> <a href="https://www.npspro.top/38060.html">安卓易剪媒 1.0.8最新版 AI自动剪辑视频,支持300+平台去水印和批量处理</a> </li> <li> <a href="https://www.npspro.top/38057.html">好奇时间386儿童启蒙教育熊出没全集等动画片VIP解锁会员</a> </li> <li> <a href="https://www.npspro.top/38056.html">一键去除图片/视频水印助手 支持全平台 永久无限解锁版</a> </li> <li> <a href="https://www.npspro.top/38055.html">618抢购神器 – 智能购物助手106跨平台抢购自动化脚本 无需注册账号,不用开通会员</a> </li> </ul> </div><div id="archives-7" class="widget widget_archive"><h5 class="widget-title">归档</h5> <label class="screen-reader-text" for="archives-dropdown-7">归档</label> <select id="archives-dropdown-7" name="archive-dropdown"> <option value="">选择月份</option> <option value='https://www.npspro.top/date/2025/05'> 2025 年 5 月  (193)</option> <option value='https://www.npspro.top/date/2025/04'> 2025 年 4 月  (121)</option> <option value='https://www.npspro.top/date/2025/03'> 2025 年 3 月  (128)</option> <option value='https://www.npspro.top/date/2025/02'> 2025 年 2 月  (63)</option> <option value='https://www.npspro.top/date/2025/01'> 2025 年 1 月  (39)</option> <option value='https://www.npspro.top/date/2024/12'> 2024 年 12 月  (36)</option> <option value='https://www.npspro.top/date/2024/11'> 2024 年 11 月  (32)</option> <option value='https://www.npspro.top/date/2024/10'> 2024 年 10 月  (24)</option> <option value='https://www.npspro.top/date/2024/09'> 2024 年 9 月  (48)</option> <option value='https://www.npspro.top/date/2024/08'> 2024 年 8 月  (20)</option> <option value='https://www.npspro.top/date/2024/07'> 2024 年 7 月  (45)</option> <option value='https://www.npspro.top/date/2024/06'> 2024 年 6 月  (54)</option> <option value='https://www.npspro.top/date/2024/05'> 2024 年 5 月  (181)</option> <option value='https://www.npspro.top/date/2024/04'> 2024 年 4 月  (199)</option> <option value='https://www.npspro.top/date/2024/03'> 2024 年 3 月  (201)</option> <option value='https://www.npspro.top/date/2024/02'> 2024 年 2 月  (153)</option> <option value='https://www.npspro.top/date/2024/01'> 2024 年 1 月  (159)</option> <option value='https://www.npspro.top/date/2023/12'> 2023 年 12 月  (159)</option> <option value='https://www.npspro.top/date/2023/11'> 2023 年 11 月  (252)</option> <option value='https://www.npspro.top/date/2023/10'> 2023 年 10 月  (246)</option> <option value='https://www.npspro.top/date/2023/09'> 2023 年 9 月  (8039)</option> <option value='https://www.npspro.top/date/2023/08'> 2023 年 8 月  (4637)</option> <option value='https://www.npspro.top/date/2023/07'> 2023 年 7 月  (40)</option> </select> <script type="text/javascript"> /* <![CDATA[ */ (function() { var dropdown = document.getElementById( "archives-dropdown-7" ); function onSelectChange() { if ( dropdown.options[ dropdown.selectedIndex ].value !== '' ) { document.location.href = this.options[ this.selectedIndex ].value; } } dropdown.onchange = onSelectChange; })(); /* ]]> */ </script> </div></aside> </div> </div> </div> </div><!-- end sitecoent --> <div class="module parallax"> <img class="jarallax-img lazyload" data-srcset="https://www.npspro.top/wp-content/themes/ripro/assets/images/background/bg-1.jpg" data-sizes="auto" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt=""> <div class="container"> <h4 class="entry-title"> 最TOP的Docker,软路由,虚拟机等学习资料 </h4> <a target="_blank" class="button" href="/jpym">立即查看</a> <a target="_blank" class="button transparent" href="/jpym">了解详情</a> </div> </div> <footer class="site-footer"> <div class="container"> <div class="footer-widget"> <div class="row"> <div class="col-xs-12 col-sm-6 col-md-3 widget--about"> <div class="widget--content"> <div class="footer--logo mb-20"> <img class="tap-logo" src="https://www.npspro.top/wp-content/uploads/2025/02/1740583554-a87ff679a2f3e71.png" data-dark="https://www.npspro.top/wp-content/uploads/2025/02/1740583554-a87ff679a2f3e71.png" alt="软师傅"> </div> <p class="mb-10">软师傅,为你提供最TOP的Docker,软路由,虚拟机等学习资料</p> </div> </div> <!-- .col-md-2 end --> <div class="col-xs-12 col-sm-3 col-md-2 col-md-offset-1 widget--links"> <div class="widget--title"> <h5>本站导航</h5> </div> <div class="widget--content"> <ul class="list-unstyled mb-0"> </ul> </div> </div> <!-- .col-md-2 end --> <div class="col-xs-12 col-sm-3 col-md-2 widget--links"> <div class="widget--title"> <h5>友情链接</h5> </div> <div class="widget--content"> <ul class="list-unstyled mb-0"> </ul> </div> </div> <!-- .col-md-2 end --> <div class="col-xs-12 col-sm-12 col-md-4 widget--newsletter"> <div class="widget--title"> <h5>快速搜索</h5> </div> <div class="widget--content"> <form class="newsletter--form mb-30" action="https://www.npspro.top/" method="get"> <input type="text" class="form-control" name="s" placeholder="关键词"> <button type="submit"><i class="fa fa-arrow-right"></i></button> </form> <h6>特别声明:本站所有资源均来源于互联网,如有侵权请联系站长(181050043#qq.com),将第一时间删除,源码仅供参考学习,请勿商用或其它非法用途,否则一切后果用户自负!</h6> </div> </div> </div> </div> <div class="site-info"> © 2025Theme by - 软师傅www.npspro.top <a href="https://beian.miit.gov.cn" target="_blank" class="text" rel="noreferrer nofollow"> 陕ICP备2023008366号-4</a> <br> </div> </div> </footer> <div class="rollbar"> <div class="rollbar-item tap-dark" etap="tap-dark" title="夜间模式"><i class="mdi mdi-brightness-4"></i></div> <div class="rollbar-item tap-click-qiandao"><a class="click-qiandao" title="签到" href="javascript:;"><i class="fa fa-calendar-check-o"></i></a></div> <div class="rollbar-item tap-pencil"><a target="_blank" title="投稿赚钱" href="https://www.npspro.top/wp-admin/post-new.php"><i class="fa fa-pencil"></i></a></div> <div class="rollbar-item tap-qq" etap="tap-qq"><a target="_blank" title="QQ咨询" href="http://wpa.qq.com/msgrd?v=3&uin=181050043&site=qq&menu=yes"><i class="fa fa-qq"></i></a></div> <div class="rollbar-item tap-blog-style" etap="tap-blog-style" data-id="1" title="博客模式"><i class="fa fa-list"></i></div> <div class="rollbar-item" etap="to_full" title="全屏页面"><i class="fa fa-arrows-alt"></i></div> <div class="rollbar-item" etap="to_top" title="返回顶部"><i class="fa fa-angle-up"></i></div> </div> <div class="dimmer"></div> <div id="popup-signup" class="popup-signup fade" style="display: none;"> <div class="register-login-modal" role="document"> <div class="modal-content"> <div class="modal-body"> <img class="popup-logo" src="https://www.npspro.top/wp-content/uploads/2025/02/1740583554-a87ff679a2f3e71.png" data-dark="https://www.npspro.top/wp-content/uploads/2025/02/1740583554-a87ff679a2f3e71.png" alt="软师傅"> <!-- Nav tabs --> <ul class="nav nav-tabs"> <li class="active"><a href="#login" data-toggle="login">登录</a> </li> <li><a href="#signup" data-toggle="signup">注册</a> </li> </ul> <!-- Tab panes --> <div class="tab-content"> <div class="tab-pane fade in active" id="login"> <div class="signup-form-container text-center"> <form class="mb-0"> <div class="form-group"> <input type="text" class="form-control" name="username" placeholder="*用户名或邮箱"> </div> <div class="form-group"> <input type="password" class="form-control" name="password" placeholder="*密码"> </div> <button type="button" class="go-login btn btn--primary btn--block"><i class="fa fa-bullseye"></i> 安全登录</button> <!-- <a href="#" class="forget-password">忘记密码?</a> --> </form> <!-- form end --> </div> <!-- .signup-form end --> </div> <div class="tab-pane fade in" id="signup"> <form class="mb-0"> <div class="form-group"> <input type="text" class="form-control" name="user_name" placeholder="输入英文用户名"> </div> <!-- .form-group end --> <div class="form-group"> <input type="email" class="form-control" name="user_email" placeholder="绑定邮箱"> </div> <!-- .form-group end --> <div class="form-group"> <input type="password" class="form-control" name="user_pass" placeholder="密码最小长度为6"> </div> <div class="form-group"> <input type="password" class="form-control" name="user_pass2" placeholder="再次输入密码"> </div> <div class="form-group"> <div class="input-group"> <input type="text" class="form-control" name="captcha" placeholder="邮箱验证码"> <span class="input-group-btn"> <button class="go-captcha_email btn btn--secondary" type="button">发送验证码</button> </span> </div> </div> <button type="button" class="go-register btn btn--primary btn--block"><i class="fa fa-bullseye"></i> 立即注册</button> </form> <!-- form end --> </div> </div> <a target="_blank" href="https://www.npspro.top/wp-login.php?action=lostpassword" class="rest-password">忘记密码?</a> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> <!-- /.modal --> </div> <div class="off-canvas"> <div class="canvas-close"><i class="mdi mdi-close"></i></div> <div class="logo-wrapper"> <a href="https://www.npspro.top/"> <img class="logo regular" src="https://www.npspro.top/wp-content/uploads/2025/02/1740583554-a87ff679a2f3e71.png" alt="软师傅"> </a> </div> <div class="mobile-menu hidden-lg hidden-xl"></div> <aside class="widget-area"> <div id="recent-posts-3" class="widget widget_recent_entries"> <h5 class="widget-title">最近文章</h5> <ul> <li> <a href="https://www.npspro.top/38061.html">安卓易剪媒 1.0.8最新版 AI自动剪辑视频,支持300+平台去水印和批量处理 新手自媒体创作</a> <span class="post-date">2025年5月30日</span> </li> <li> <a href="https://www.npspro.top/38060.html">安卓易剪媒 1.0.8最新版 AI自动剪辑视频,支持300+平台去水印和批量处理</a> <span class="post-date">2025年5月30日</span> </li> <li> <a href="https://www.npspro.top/38057.html">好奇时间386儿童启蒙教育熊出没全集等动画片VIP解锁会员</a> <span class="post-date">2025年5月30日</span> </li> <li> <a href="https://www.npspro.top/38056.html">一键去除图片/视频水印助手 支持全平台 永久无限解锁版</a> <span class="post-date">2025年5月30日</span> </li> <li> <a href="https://www.npspro.top/38055.html">618抢购神器 – 智能购物助手106跨平台抢购自动化脚本 无需注册账号,不用开通会员</a> <span class="post-date">2025年5月30日</span> </li> </ul> </div><div id="calendar-3" class="widget widget_calendar"><h5 class="widget-title">日历</h5><div id="calendar_wrap" class="calendar_wrap"><table id="wp-calendar" class="wp-calendar-table"> <caption>2025 年 6 月</caption> <thead> <tr> <th scope="col" title="星期一">一</th> <th scope="col" title="星期二">二</th> <th scope="col" title="星期三">三</th> <th scope="col" title="星期四">四</th> <th scope="col" title="星期五">五</th> <th scope="col" title="星期六">六</th> <th scope="col" title="星期日">日</th> </tr> </thead> <tbody> <tr> <td colspan="5" class="pad"> </td><td id="today">1</td><td>2</td> </tr> <tr> <td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td><td>9</td> </tr> <tr> <td>10</td><td>11</td><td>12</td><td>13</td><td>14</td><td>15</td><td>16</td> </tr> <tr> <td>17</td><td>18</td><td>19</td><td>20</td><td>21</td><td>22</td><td>23</td> </tr> <tr> <td>24</td><td>25</td><td>26</td><td>27</td><td>28</td><td>29</td><td>30</td> </tr> <tr> <td>31</td> <td class="pad" colspan="6"> </td> </tr> </tbody> </table><nav aria-label="上个月及下个月" class="wp-calendar-nav"> <span class="wp-calendar-nav-prev"><a href="https://www.npspro.top/date/2025/05">« 5 月</a></span> <span class="pad"> </span> <span class="wp-calendar-nav-next"> </span> </nav></div></div> </aside> </div> <script> console.log("SQL 请求数:62"); console.log("页面生成耗时: 0.29801"); </script> <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> <link rel='stylesheet' id='yarppRelatedCss-css' href='https://www.npspro.top/wp-content/plugins/yet-another-related-posts-plugin/style/related.css?ver=5.30.10' type='text/css' media='all' /> <script type="text/javascript" id="toc-front-js-extra"> /* <![CDATA[ */ var tocplus = {"visibility_show":"show","visibility_hide":"hide","width":"Auto"}; /* ]]> */ </script> <script type="text/javascript" src="https://www.npspro.top/wp-content/plugins/table-of-contents-plus/front.min.js?ver=2411.1" id="toc-front-js"></script> <script type="text/javascript" src="https://www.npspro.top/wp-content/themes/ripro/assets/js/plugins.js?ver=9.0(8.9新版修复解密增强版)" id="plugins-js"></script> <script type="text/javascript" id="app-js-extra"> /* <![CDATA[ */ var caozhuti = {"site_name":"\u8f6f\u5e08\u5085","home_url":"https:\/\/www.npspro.top","ajaxurl":"https:\/\/www.npspro.top\/wp-admin\/admin-ajax.php","is_singular":"1","tencent_captcha":{"is":"","appid":""},"infinite_load":"\u52a0\u8f7d\u66f4\u591a","infinite_loading":"<i class=\"fa fa-spinner fa-spin\"><\/i> \u52a0\u8f7d\u4e2d...","site_notice":{"is":"0","color":"rgb(33, 150, 243)","html":"<div class=\"notify-content\"><h3>\u6b22\u8fce\u6765\u5230\u8d44\u4eab\u7f51<\/h3><div>\u6211\u4eec\u4e3a\u4f60\u5206\u4eab\u6280\u672f\u548c\u8d44\u6e90<\/div><\/div>"},"pay_type_html":{"html":"<div class=\"pay-button-box\"><div class=\"pay-item\" id=\"alipay\" data-type=\"1\"><i class=\"alipay\"><\/i><span>\u652f\u4ed8\u5b9d<\/span><\/div><div class=\"pay-item\" id=\"weixinpay\" data-type=\"2\"><i class=\"weixinpay\"><\/i><span>\u5fae\u4fe1\u652f\u4ed8<\/span><\/div><\/div><p style=\"font-size: 13px; padding: 0; margin: 0;\">\u5f53\u524d\u4e3a\u6e38\u5ba2\u8d2d\u4e70\u6a21\u5f0f<\/p>","alipay":1,"weixinpay":2}}; /* ]]> */ </script> <script type="text/javascript" src="https://www.npspro.top/wp-content/themes/ripro/assets/js/app.js?ver=9.0(8.9新版修复解密增强版)" id="app-js"></script> <script type="text/javascript" src="https://www.npspro.top/wp-content/themes/ripro/assets/js/plugins/jquery.fancybox.min.js?ver=9.0(8.9新版修复解密增强版)" id="fancybox-js"></script> </body> </html>