TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How to Corrupt an SQLite Database File

152 点作者 naftaliharris超过 11 年前

11 条评论

maxdeliso超过 11 年前
The amount of engineering rigor that has gone into sqlite over the years boggles the mind. It&#x27;s a project that has been held up as a sterling example of successful software development many times, rightfully so. I especially like this part of their license, from the top of sqlite3.h<p><i></i>&quot;The author disclaims copyright to this source code. In place of <i></i> a legal notice, here is a blessing: <i></i> <i></i> May you do good and not evil. <i></i> May you find forgiveness for yourself and forgive others. <i></i> May you share freely, never taking more than you give.&quot;
评论 #6502575 未加载
评论 #6503217 未加载
评论 #6502697 未加载
CraigJPerry超过 11 年前
I know SQLite &quot;does testing right&quot; and they rightly get credit for this.<p>They also &quot;do documentation right&quot; and this is another accessible, clear example of that.<p>It&#x27;s also all public domain. I&#x27;ve used their documentation as an example in the past when driving through documentation improvements and i&#x27;ll no doubt point to them again!
评论 #6502478 未加载
评论 #6502672 未加载
seiji超过 11 年前
That&#x27;s why the D in ACID confused me for a long time. There&#x27;s no way to guarantee durability. They say &quot;durable&quot; but they mean &quot;durable, kinda, we think, we hope, if nothing is lying to us, if your storage array doesn&#x27;t lose power without a battery to flush the cache, if your system doesn&#x27;t power down while your drives are lying about their committed write status, or if your write succeeded then an elf ran away with your platters.&quot;
评论 #6502835 未加载
评论 #6502512 未加载
评论 #6502479 未加载
j_s超过 11 年前
If you do happen to corrupt any SQLite database file, it can usually be repaired... unless it is on an Android phone and the app tries to re-open it before you can make a copy:<p>Android automatically deletes corrupt SQLite files!<p><a href="http://stackoverflow.com/questions/7764943" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;7764943</a>
评论 #6504131 未加载
joe_the_user超过 11 年前
Great stuff and all but can I ask why SQL folks make it hard for an application to get simple <i>read</i> access to a SQLite database? Especially, I have an application which wants to use the Firefox places-bookmarks-etc db file. I can copy the file to a different directory and then run a query on it but can&#x27;t open it in place for reading, for <i>just</i> reading. WTF is the problem with that? Is reading a file a way to corrupt it?
评论 #6502671 未加载
评论 #6502638 未加载
tomcam超过 11 年前
This also serves as a clear illustration of SQLite internals and DBMS internals in general without thick clots of rubbish jargon. Nice. If you&#x27;re interested in database implementation this neatly covers a multitude of topics.
eksith超过 11 年前
I can tell you one of the easiest ways to corrupt an SQLite db file is to not let a library specifically designed for file operations, handle file operations. And of course, not using provided libraries for db access (E.G. PDO if you&#x27;re using PHP).<p>I ran a forum on SQLite a while back, and things worked extremely well as long as I didn&#x27;t pretend I knew better than the library.<p>There&#x27;s no good excuse to not use PDO and there hasn&#x27;t been one for years now. Before that, I&#x27;ve implemented a write queue, which seems redundant in retrospect, in case the file lock issue came about, but it never did even though I did hit the write queue a few times.<p>As for crashes, periodic snapshots of the db <i>and journals</i> (that&#x27;s very important) is usually the best way to avoid recovery issues.
zackmorris超过 11 年前
I stumbled onto this article a couple of days ago when I was trying to find a library to integrate sqlite with a cloud service like dropbox. Does anyone know of one that has:<p>* Read<p>* Write<p>* Callback (to sort out paradoxes when two or more devices update the store independently offline and need to merge)<p>It&#x27;s possible to do this with CoreData, but poorly, with a high burden on the developer to learn the entirety of Apple&#x27;s APIs and no way to alert the user as to what it is doing under the hood, which causes the app to hang for minutes or even forever until the managed object context says it&#x27;s ready.
评论 #6505394 未加载
bch超过 11 年前
Tcl (the test harness) at work.
Daniel_Newby超过 11 年前
The message I got was that POSIX advisory locking needs to be ripped out.
Glyptodon超过 11 年前
On seeing this first thought was &quot;oh, another Ess Kyoo El person&quot; because reading a &quot;An See Kwul&quot; instead of &quot;A See Kwul&quot; just grated. Pardon my attempt at phonetic spelling.
评论 #6502694 未加载