使用SQLite的感想
使用SQLite的感想 最近都在使用SQLite数据库,老实说这才是我使用的第三款数据库而已。使用它原因就应为它够轻量,而且性能挺不错。但使用久了也发现了一些问题。偶尔也会有怨言,但也不会骂SQLite是个破东西之类的,原因又几个:对SQLite的了解不过透彻,使
使用SQLite的感想
最近都在使用SQLite数据库,老实说这才是我使用的第三款数据库而已。使用它原因就应为它够轻量,而且性能挺不错。但使用久了也发现了一些问题。偶尔也会有怨言,但也不会骂SQLite是个破东西之类的,原因又几个:对SQLite的了解不过透彻,使用方式上总有些不妥;自己的资历尚浅,解决问题的能力有限;自己也没本事写出比SQLite更好的数据库。
在网上看了一下SQLite的适用场景。100000次/天访问量的网站,嵌入式设备和应用软件,应用程序文件格式等。但是读数据可时也会抛锁表的异常,SQLite的锁是粗粒度,这个对异常的处理不知如何是好;还有的就是数据库的损坏。Database disk image is malformed。网上说数据库造成数据库损坏的原因有三个
sqlite数据库在写入时断电等,导致数据库里的结果被破坏。
sqlite数据库所存的磁盘空间不够。
磁盘有坏磁道等
之前数据库的损坏估计是第一种原因。而当时又没有对数据进行什么备份。只能人工用.dump命令从损坏的数据库中把数据导出来。这个顺带也讲一下吧
在SQLite的命令模式中打开数据库,依次输入一下命令
sqlite> .mode insert
sqlite> .output test.sql
sqlite> .dump
sqlite> .exit
当然不一定要”.exit”命令,按“Ctrl+C”或直接关掉都行,导出的文件名“test.sql”随个人喜好。
或者用这个命令更好
sqlite3.exe dbname.db .dump>fileName.sql
这个命令导出的SQL会比上面那个要工整。
无论哪一种导出的SQL,如果数据库有问题的,导出的SQL里面会有这行
/**** ERROR: (11) database disk image is malformed *****/
最后也只能回滚事务RollBack。
要是想用回这些数据的话,把回滚事务改掉,把那句ERROR的删掉。
然后就是导入数据
sqlite3.exe newDBName.db
sqlite> .read test.sql
sqlite> .exit
今后就打算对SQLite定期进行备份,备份的方式也只是单纯的文件IO操作——Copy一份呗。在读写数据库时万一抛出Database disk image is malformed异常时就认为数据库已经损坏了,马上换上备份的数据库。
还有在写数据库的时候,在对数据库里多条记录进行操作的时候,对多个表的数据操作的时候用事务包起来,那么在写入数据库的时候,在数据库文件相同的目录下会产生一个文件名格式为: 数据库文件名 + "-journal"的文件。该文件在事物提交或回滚后将被立刻删除,不过听说在Android下,这个文件没被删除,只是以一个0B大小的文件存在。在事物运行期间,如果当前主机因电源故障而宕机,而此时由于回滚日志文件已经保存在磁盘上,那么当下一次程序启动时,SQLite在打开数据库文件的过程中将会发现该临时文件的存在,SQLite会在成功打开数据库之前先基于该文件完成数据库的恢复工作,以保证数据库的数据回复到上一个事物开始之前的状态。这样虽然不能避免数据库的损坏,但是能保证数据状态的一致性。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Magnet link is a link method for downloading resources, which is more convenient and efficient than traditional download methods. Magnet links allow you to download resources in a peer-to-peer manner without relying on an intermediary server. This article will introduce how to use magnet links and what to pay attention to. 1. What is a magnet link? A magnet link is a download method based on the P2P (Peer-to-Peer) protocol. Through magnet links, users can directly connect to the publisher of the resource to complete resource sharing and downloading. Compared with traditional downloading methods, magnetic

How to use mdf files and mds files With the continuous advancement of computer technology, we can store and share data in a variety of ways. In the field of digital media, we often encounter some special file formats. In this article, we will discuss a common file format - mdf and mds files, and introduce how to use them. First, we need to understand the meaning of mdf files and mds files. mdf is the extension of the CD/DVD image file, and the mds file is the metadata file of the mdf file.

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

After long pressing the play button of the speaker, connect to wifi in the software and you can use it. Tutorial Applicable Model: Xiaomi 12 System: EMUI11.0 Version: Xiaoai Classmate 2.4.21 Analysis 1 First find the play button of the speaker, and press and hold to enter the network distribution mode. 2 Log in to your Xiaomi account in the Xiaoai Speaker software on your phone and click to add a new Xiaoai Speaker. 3. After entering the name and password of the wifi, you can call Xiao Ai to use it. Supplement: What functions does Xiaoai Speaker have? 1 Xiaoai Speaker has system functions, social functions, entertainment functions, knowledge functions, life functions, smart home, and training plans. Summary/Notes: The Xiao Ai App must be installed on your mobile phone in advance for easy connection and use.

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension
