程序让生活更美好

半亩方塘 天光云影

  C++博客 ::  :: 新随笔 :: 联系 ::  :: 管理 ::
  55 随笔 :: 4 文章 :: 202 评论 :: 0 Trackbacks

Features and Limitations

特性和局限性

In this section we will look at the key features of SQLite and some of its limitations. The nature of SQLite makes it an ideal choice for quite a number of tasks, but it's not suitable for everything.

在本部分我们将要看一下SQLite关键特性和它的一些局限性。SQLite的本质使它成为许多任务的理想选择,但它并不适合所有的方面。

It is important to decide whether SQLite or any other database engine for that matteris the right choice for your application before committing to a particular technology.

在为你的应用确定一个特殊的技术之前,决定选择使用SQLite或者其它的任何数据库引擎作是非常重要的。

Speed

速度

SQLite is extremely efficient, benefiting from a highly optimized internal architecture and a small memory footprint. Because SQLite is not a client/server database, the overheads of running a database daemon and socket communication are eliminated.

SQLite 非常高效,这得益于高度优化的内部结构和很小的内存需求。因为SQLite 不是一个客户端/服务器类型的数据库,运行一个数据库进程和套接字通信的开销被消除了。

The published speed comparison at
http://www.sqlite.org/speed.html compares SQLite to both MySQL and PostgreSQL. It finds that SQLite can perform up to 20 times faster than PostgreSQL and more than twice as fast as MySQL for common operations.

http://www.sqlite.org/speed.html 上的发表了它和MySQL和PostgreSQL速度对比。对比表明,SQLite在执行普通操作的时候速度比PostgreSQL快20倍,是MySQL的两倍。


These tests were performed with default installations of each database, and although it is possible to tune the MySQL and PostgreSQL servers for slightly better performance in a given environment, SQLite does not require any such optimization.

这个是在每个数据库的默认安装情况下测试的,尽管在给定的环境中调整之后,MySQL和 PostgreSQL 的执行情况会略有提高,但是SQLite是不需要任何优化的。


The tests found that SQLite is significantly slower than the other databases only on the operations to create an index and to drop a table. However, slowness in these areas will not affect performance on a production database.

这个测试发现,SQLite仅仅在执行创建索引和删除表的操作时速度要比其他数据库慢得多。然而,这些方面得低速并不会影响到作为一个生产数据库。

Portability

移植性

Because SQLite databases are stored as single files on the filesystem, they are very portable indeed. A database can be copied from one file to another, even across different operating systems. This means that for a cross-platform distribution you just need to concentrate on making your code portable even when a populated database is to be shipped with the application.

因为SQLite数据库在文件系统上是作为单个文件存储的,实际上它们是非常容易移植的。一个数据库可被从一个文件拷贝到另一个文件,甚至是跨越不同的操作系统。这意味着在有一个交叉平台上发布的时候,你只需要关注于使你的代码,使其可以移植,甚至是当一个可移植的数据库是和应用一起发布的。

SQLite has no external dependencies. The SQLite library is self-contained, so the only system requirement to run an application with an embedded SQLite database is the SQLite library itself. Because SQLite can be freely distributed, you can always ensure that this is present.


SQLite没有额外的依赖性。SQLite 库是自持的,因此在运行嵌入式SQLite数据库的时候,仅仅需要的是SQLite的库本身。因为SQLite能够自由的发布,你总是可以确保这是可行的。

Security
安全

SQLite databases are stored to the filesystem and access control is performed by the underlying operating system based on that file's permission settings.
 SQLite 数据库存储在文件系统之上,访问控制是由基于操作系统之下的的文件权限设定来实现的

Though SQLite can be accessed by processes running as different users if the correct file permissions are set, the database engine does not detect which user is performing a particular operation.

如果正确的文件访问权限设定了,尽管SQLite能够通过进程运行作为不同的用户来被访问,但是数据库引擎并不检测哪个用户正在执行一个特别的操作。

The advantage of this is one of administrative simplicitythere is no need to set up a complex user grants scheme. Any user who has access to read the database file is able to access the database tables and records. Likewise, in a shared environment, users are able to create their own SQLite databases to their file space without any involvement from the system administrators.

它的优点之一就是管理简单,不需要设定复杂的用户授权模式。任何拥有访问权利的用户都可以访问数据库表格和记录。同样,在一个共享环境中,用户可以在他们的自己的文件空间上创建他们自己的SQLite数据库而不用涉及系统管理。

The disadvantage comes when you want to control permissions at a more finely grained level. There is no GRANT operation that would allow access to particular tables to one set of users but not others. If users have read access, they are able to read the entire database, and if they have write access, you have to be sure of their competence and trustworthiness with the data!

缺点是,当你需要在更加细致粒度水平的控制权限的时候,它没有GRANT操作,这个操作允许一部分用户可访问特定的表而另一部分用户不行。当用户拥有访问许可,他们能够读整个数据库,如果他们有写许可,你必须要确定他们在数据上的的权限和信赖度

SQL Implementation

SQL工具

SQLite supports a large subset of the ANSI SQL-92 standard. Some features have a limited implementation and a few features are not supported at all.

SQLite支持ANSI SQL-92标准的大的子集。某些特性有一个有限的工具,其他一些特性并不都被支持。
For example, atomic transactions are available but cannot be nested; simple subqueries are possible but correlated subqueries are not; triggers can fire for each row but not for each statement; views are available but are read-only.

例如,原子事务是可用的,但不能嵌套;简单的子查询是可以的,但相互关联的子查询是不行的;触发器可以在每一行触发,但不能在每个语句上触发;视图是可见但是只读的。
The list of current limitations is maintained at
http://www.sqlite.org/omitted.html with the items at the top of the list indicating which items are most likely to be added to SQLite first.

目前被维护的局限性列表在 http://www.sqlite.org/omitted.html 上,列表的上部的选项指示了哪些选项最有可能被先加入到SQLite
In the vast majority of cases, none of the limitations of SQLite will cause problems when developing your application. For those that you need to work around, the benefits of using a fast, portable embedded database will almost certainly outweigh the cost of the workaround.

在大部分的情况下,SQLite的局限性不会给你的应用开发造成任何问题。因此,你需要变通的方法,使用一个快速的,可移植的嵌入式数据库的好处将比变通方法的费用好的多。

Customization

定制

The SQLite library includes a very powerful mechanism for adding user-defined functions to the SQL command set. Custom functions can even be written in many of the supported language APIs, not just C/C++.

 

Additionally, as the SQLite source code is public domain, you are free to examine and modify it as you see fit. If SQLite is missing a feature that you absolutely must have, why not add it yourself and give something back to the community?

此外,因为SQLite的源代码是开放的,你可以自由的检查和修改只要你认为合适。如果SQLite现在缺少一个你很需要但却还没有的特性,为什么不自己添加然后给社区回赠一些呢?

Supported APIs

SQLite now has extensive support for other programming languages through APIs that use the underlying C/C++ interface to communicate with SQLite database files.

C/C++

The core interface is implemented as a single library called libsqlite.so on Linux/Unix systems and sqlite.dll on Windows.

Only the SQLite library is required to allow all users to create their own databases, so very little administration is required to add SQL database capability to a shared system.

PHP

Support for SQLite in PHP has been available for a while, but since the release of PHP 5, it has been shipped with the standard distribution.

Traditionally, PHP and MySQL have gone hand in hand as the interface and back end for dynamic web sites, but it is expected that many more web hosting providers will offer SQLite as PHP 5 gains popularity. From the host's point of view, it is much simpler to administer than a client/server database as there are no complex permissions to manage and database files will be already counted in the disk quota.

Note

SQLite has proved itself to work very well with low- to medium-traffic web sites. As a very rough guideline, if you are expecting over 100,000 hits per dayand in practice, only a small number of web sites will have this level of trafficyou should consider how much database work is done by the web scripts and think about doing some kind of stress testing before committing to SQLite as your back end.


Perl

Perl allows access to SQLite through the Database Interface (DBI) module. This makes it very easy for existing Perl developers to use SQLite within their scripts. The DBI provides an abstraction layer to the Database Driver (DBD), so the same command set is used to access many different types of underlying databases.

The DBD::SQLite driver further allows access to the capabilities of SQLite that the Perl DBI does not allow. Although this does not create a Perl application that can be easily ported to another database back end, it does allow access to the powerful user-defined functions feature.

Tcl

The Tcl interface for SQLite is shipped as part of the SQLite distribution as a library that is imported into Tcl to activate the extensions.

Using Tcl and Tk together with SQLite, you have a platform that is ideal for rapid development of portable graphical user applications.

Other Programming Languages

SQLite has APIs for many other programming languages, including Java, .NET, Smalltalk, and Ruby. As more languages become supported, they are added to the list at http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers .

Scalability

The downside of using a single file to store databases is that SQLite is not as scalable as many client/server database systems.

The SQLite engine can address database files of up to 2TB in size; however, the restriction on the size of a database is more likely to be enforced by your operating system. In many cases, the size limit on a single file is 2GB.

File locking in SQLite is very coarse-grained. When a write operation takes place, the entire file is locked so that no other process can open it for reading or writing. Larger RDBMSs implement locking at the table or row level so that other processes are able to carry on working unless they are trying to access a specific piece of locked data.

Therefore, if you have a database that is likely to involve massive database files or a high frequency of slow write operations, SQLite may not be suitable and you should consider an RDBMS that is designed and tuned for multiple-user access.

 
                     摘自《SQLite》Chris Newman
posted on 2006-05-31 22:25 北风之神007 阅读(776) 评论(0)  编辑 收藏 引用 所属分类: SQLite

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理