⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 whentouse.tcl

📁 sqlite-3.4.1,嵌入式数据库.是一个功能强大的开源数据库,给学习和研发以及小型公司的发展带来了全所未有的好处.
💻 TCL
字号:
## Run this TCL script to generate HTML for the goals.html file.#set rcsid {$Id: whentouse.tcl,v 1.7 2007/04/14 12:04:39 drh Exp $}source common.tclheader {Appropriate Uses For SQLite}puts {<p>SQLite is different from most other SQL database engines in that itsprimary design goal is to be simple:</p><ul><li>Simple to administer</li><li>Simple to operate</li><li>Simple to embed in a larger program</li><li>Simple to maintain and customize</li></ul><p>Many people like SQLite because it is small and fast.  But thosequalities are just happy accidents.Users also find that SQLite is very reliable.  Reliability isa consequence of simplicity.  With less complication, there isless to go wrong.  So, yes, SQLite is small, fast, and reliable,but first and foremost, SQLite strives to be simple.</p><p>Simplicity in a database engine can be either a strength or aweakness, depending on what you are trying to do.  In order toachieve simplicity, SQLite has had to sacrifice other characteristicsthat some people find useful, such as high concurrency, fine-grainedaccess control, a rich set of built-in functions, stored procedures,esoteric SQL language features, XML and/or Java extensions,tera- or peta-byte scalability, and so forth.  If you need some of thesefeatures and do not mind the added complexity that theybring, then SQLite is probably not the database for you.SQLite is not intended to be an enterprise database engine.  Itnot designed to compete with Oracle or PostgreSQL.</p><p>The basic rule of thumb for when it is appropriate to use SQLite isthis:  Use SQLite in situations where simplicity of administration,implementation, and maintenance are more important than the countlesscomplex features that enterprise database engines provide.As it turns out, situations where simplicity is the better choiceare more common than many people realize.</p><h2>Situations Where SQLite Works Well</h2><ul><li><p><b>Websites</b></p><p>SQLite usually will work great as the database engine for low tomedium traffic websites (which is to say, 99.9% of all websites).The amount of web traffic that SQLite can handle depends, of course,on how heavily the website uses its database.  Generallyspeaking, any site that gets fewer than a 100000 hits/day should workfine with SQLite.The 100000 hits/day figure is a conservative estimate, not ahard upper bound.SQLite has been demonstrated to work with 10 times that amountof traffic.</p></li><li><p><b>Embedded devices and applications</b></p><p>Because an SQLite database requires little or no administration,SQLite is a good choice for devices or services that must workunattended and without human support.  SQLite is a good fit foruse in cellphones, PDAs, set-top boxes, and/or appliances.  It alsoworks well as an embedded database in downloadable consumer applications.</p></li><li><p><b>Application File Format</b></p><p>SQLite has been used with great success as the on-disk file formatfor desktop applications such as financial analysis tools, CADpackages, record keeping programs, and so forth.  The traditionalFile/Open operation does an sqlite3_open() and executes aBEGIN TRANSACTION to get exclusive access to the content.  File/Savedoes a COMMIT followed by another BEGIN TRANSACTION.  The useof transactions guarantees that updates to the application file are atomic,durable, isolated, and consistent.</p><p>Temporary triggers can be added to the database to record allchanges into a (temporary) undo/redo log table.  These changes can thenbe played back when the user presses the Undo and Redo buttons.  Usingthis technique, a unlimited depth undo/redo implementation can be writtenin surprising little code.</p></li><li><p><b>Replacement for <i>ad hoc</i> disk files</b></p><p>Many programs use fopen(), fread(), and fwrite() to create andmanage files of data in home-grown formats.  SQLite works particularly well as areplacement for these <i>ad hoc</i> data files.</p></li><li><p><b>Internal or temporary databases</b></p><p>For programs that have a lot of data that must be sifted and sortedin diverse ways, it is often easier and quicker to load the data intoan in-memory SQLite database and use queries with joins and ORDER BYclauses to extract the data in the form and order needed rather thanto try to code the same operations manually.Using an SQL database internally in this way also gives the programgreater flexibility since new columns and indices can be added withouthaving to recode every query.</p></li><li><p><b>Command-line dataset analysis tool</b></p><p>Experienced SQL users can employthe command-line <b>sqlite</b> program to analyze miscellaneousdatasets. Raw data can be imported from CSV files, then thatdata can be sliced and diced to generate a myriad of summaryreports.  Possible uses include website log analysis, sportsstatistics analysis, compilation of programming metrics, andanalysis of experimental results.</p><p>You can also do the same thing with a enterprise client/serverdatabase, of course.  The advantages to using SQLite in this situationare that SQLite is much easier to set up and the resulting database is a single file that you can store on a floppy disk or flash-memory stickor email to a colleague.</p></li><li><p><b>Stand-in for an enterprise database during demos or testing</b></p><p>If you are writing a client application for an enterprise database engine,it makes sense to use a generic database backend that allows you to connectto many different kinds of SQL database engines.  It makes even bettersense togo ahead and include SQLite in the mix of supported database and to staticallylink the SQLite engine in with the client.  That way the client programcan be used standalone with an SQLite data file for testing or fordemonstrations.</p></li><li><p><b>Database Pedagogy</b></p><p>Because it is simple to setup and use (installation is trivial: justcopy the <b>sqlite</b> or <b>sqlite.exe</b> executable to the target machineand run it) SQLite makes a good database engine for use in teaching SQL.Students can easily create as many databases as they like and canemail databases to the instructor for comments or grading.  For moreadvanced students who are interested in studying how an RDBMS isimplemented, the modular and well-commented and documented SQLite codecan serve as a good basis.  This is not to say that SQLite is an accuratemodel of how other database engines are implemented, but rather a student whounderstands how SQLite works can more quickly comprehend the operationalprinciples of other systems.</p></li><li><p><b>Experimental SQL language extensions</b></p><p>The simple, modular design of SQLite makes it a good platform forprototyping new, experimental database language features or ideas.</p></li></ul><h2>Situations Where Another RDBMS May Work Better</h2><ul><li><p><b>Client/Server Applications</b><p><p>If you have many client programs accessing a common databaseover a network, you should consider using a client/server databaseengine instead of SQLite.  SQLite will work over a network filesystem,but because of the latency associated with most network filesystems,performance will not be great.  Also, the file locking logic ofmany network filesystems implementation contains bugs (on both Unixand windows).  If file locking does not work like it should,it might be possible for two or more client programs to modify thesame part of the same database at the same time, resulting in database corruption.  Because this problem results from bugs inthe underlying filesystem implementation, there is nothing SQLitecan do to prevent it.</p><p>A good rule of thumb is that you should avoid using SQLitein situations where the same database will be accessed simultaneouslyfrom many computers over a network filesystem.</p></li><li><p><b>High-volume Websites</b></p><p>SQLite will normally work fine as the database backend to a website.But if you website is so busy that your are thinking of splitting thedatabase component off onto a separate machine, then you should definitely consider using an enterprise-class client/server databaseengine instead of SQLite.</p></li><li><p><b>Very large datasets</b></p><p>When you start a transaction in SQLite (which happens automaticallybefore any write operation that is not within an explicit BEGIN...COMMIT)the engine has to allocate a bitmap of dirty pages in the disk file tohelp it manage its rollback journal.  SQLite needs 256 bytes of RAM forevery 1MiB of database (assuming a 1024-byte page size: less memory isused with larger page sizes, of course).  For smaller databases, the amount of memoryrequired is not a problem, but when database begin to grow into themulti-gigabyte range, the size of the bitmap can get quite large.  Ifyou need to store and modify more than a few dozen GB of data, you shouldconsider using a different database engine.</p></li><li><p><b>High Concurrency</b></p><p>SQLite uses reader/writer locks on the entire database file.  That meansif any process is reading from any part of the database, all otherprocesses are prevented from writing any other part of the database.Similarly, if any one process is writing to the database,all other processes are prevented from reading any other part of thedatabase.For many situations, this is not a problem.  Each applicationdoes its database work quickly and moves on, and no lock lasts for morethan a few dozen milliseconds.  But there are some applications that requiremore concurrency, and those applications may need to seek a differentsolution.</p></li></ul>}footer $rcsid

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -