|
 |
栏目导栏 |
|
| |
|
|
|
|
 |
资料搜索 |
|
| |
|
|
|
|
 |
热门文章 |
|
| |
|
|
|
|
 |
最新文章 |
|
| |
|
|
|
| |
| |
|
|
|
|
SQLite是一款轻型的数据库,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如Tcl、PHP、Java等,还有ODBC接口,同样比起Mysql、PostgreSQL这两款开源世界著名的数据库管理系统来讲,它的处理速度比他们都快。 G7dLinux联盟 G7dLinux联盟 SQLite虽然很小巧,但是支持的SQL语句不会逊色于其他开源数据库,它支持的SQL包括: G7dLinux联盟 G7dLinux联盟 ATTACH DATABASE G7dLinux联盟 BEGIN TRANSACTION G7dLinux联盟 comment G7dLinux联盟 COMMIT TRANSACTION G7dLinux联盟 COPY G7dLinux联盟 CREATE INDEX G7dLinux联盟 CREATE TABLE G7dLinux联盟 CREATE TRIGGER G7dLinux联盟 CREATE VIEW G7dLinux联盟 DELETE G7dLinux联盟 DETACH DATABASE G7dLinux联盟 DROP INDEX G7dLinux联盟 DROP TABLE G7dLinux联盟 DROP TRIGGER G7dLinux联盟 DROP VIEW G7dLinux联盟 END TRANSACTION G7dLinux联盟 EXPLAIN G7dLinux联盟 expression G7dLinux联盟 INSERT G7dLinux联盟 ON CONFLICT clause G7dLinux联盟 PRAGMA G7dLinux联盟 REPLACE G7dLinux联盟 ROLLBACK TRANSACTION G7dLinux联盟 SELECT G7dLinux联盟 UPDATE G7dLinux联盟 G7dLinux联盟 同时它还支持事务处理功能等等。也有人说它象Microsoft的Access,有时候真的觉得有点象,但是事实上它们区别很大。比如SQLite支持跨平台,操作简单,能够使用很多语言直接创建数据库,而不象Access一样需要Office的支持。如果你是个很小型的应用,或者你想做嵌入式开发,没有合适的数据库系统,那么现在你可以考虑使用SQLite。目前它的最新版本是 3.2.2,它的官方网站是:http://www.sqlite.org,能在上面获得源代码和文档。同时因为数据库结构简单,系统源代码也不是很多,也适合想研究数据库系统开发的专业人士。 G7dLinux联盟 G7dLinux联盟 现在我们开始简单的介绍,主要我是想讲清楚几个问题,一是如何安装使用,二是如何跟PHP结合开发。 G7dLinux联盟 G7dLinux联盟 一、安装 G7dLinux联盟 G7dLinux联盟 1. Windows平台 G7dLinux联盟 G7dLinux联盟 下载windows下的文件,其实就是一个命令行程序,(下载地址:http://www.sqlite.org/sqlite-3_2_2.zip),这个命令行程序用来包括生成数据库文件、执行SQL查询、备份数据库等等功能。 G7dLinux联盟 下载后比如我们解压缩到 D:\Downloads\sqlite\sqlite-3_2_2 这个目录下,那么我们进入cmd,并且进入该目录: G7dLinux联盟 cd D:\Downloads\sqlite\sqlite-3_2_2 G7dLinux联盟 D:\Downloads\sqlite\sqlite-3_2_2>sqlite3 test.db G7dLinux联盟 # 如果test.db不存在,那么就产生一个数据库文件,如果存在就直接使用该数据库文件,相当于mysql中的use G7dLinux联盟 SQLite version 3.2.2 G7dLinux联盟 Enter ".help" for instructions G7dLinux联盟 sqlite> G7dLinux联盟 # SQLite的提示符,如果想查看命令帮助输入 .help,在sqlite中所有系统命令都是 . 开头的: G7dLinux联盟 sqlite> .help G7dLinux联盟 .databases List names and files of attached databases G7dLinux联盟 .dump ?TABLE? ... Dump the database in an SQL text format G7dLinux联盟 .echo ON|OFF Turn command echo on or off G7dLinux联盟 .exit Exit this program G7dLinux联盟 .explain ON|OFF Turn output mode suitable for EXPLAIN on or off. G7dLinux联盟 .header(s) ON|OFF Turn display of headers on or off G7dLinux联盟 .help Show this message G7dLinux联盟 .import FILE TABLE Import data from FILE into TABLE G7dLinux联盟 .indices TABLE Show names of all indices on TABLE G7dLinux联盟 .mode MODE ?TABLE? Set output mode where MODE is one of: G7dLinux联盟 csv Comma-separated values G7dLinux联盟 column Left-aligned columns. (See .width) G7dLinux联盟 html HTML <table> code G7dLinux联盟 insert SQL insert statements for TABLE G7dLinux联盟 line One value per line G7dLinux联盟 list Values delimited by .separator string G7dLinux联盟 tabs Tab-separated values G7dLinux联盟 tcl TCL list elements G7dLinux联盟 .nullvalue STRING Print STRING in place of NULL values G7dLinux联盟 .output FILENAME Send output to FILENAME G7dLinux联盟 .output stdout Send output to the screen G7dLinux联盟 .prompt MAIN CONTINUE Replace the standard prompts G7dLinux联盟 .quit Exit this program G7dLinux联盟 .read FILENAME Execute SQL in FILENAME G7dLinux联盟 .schema ?TABLE? Show the CREATE statements G7dLinux联盟 .separator STRING Change separator used by output mode and .import G7dLinux联盟 .show Show the current values for various settings G7dLinux联盟 .tables ?PATTERN? List names of tables matching a LIKE pattern G7dLinux联盟 .timeout MS Try opening locked tables for MS milliseconds G7dLinux联盟 .width NUM NUM ... Set column widths for "column" mode G7dLinux联盟 sqlite> G7dLinux联盟 www.knowsky.com G7dLinux联盟 # 我们创建一个数据库catlog G7dLinux联盟 sqlite> create table catalog( G7dLinux联盟 ...> id integer primarykey, G7dLinux联盟 ...> pid integer, G7dLinux联盟 ...> name varchar(10) UNIQUE G7dLinux联盟 ...> ); G7dLinux联盟 sqlite> G7dLinux联盟 # 如果表存在就会提示: G7dLinux联盟 SQL error: table catalog already exists G7dLinux联盟 # 我们创建索引信息 G7dLinux联盟 create index catalog_idx on catalog (id asc); G7dLinux联盟 # 我们查看表的信息,看有多少个表 G7dLinux联盟 sqlite> .table G7dLinux联盟 aa catalog G7dLinux联盟 # 查看表的结构: G7dLinux联盟 sqlite> .schema catalog G7dLinux联盟 CREATE TABLE catalog( G7dLinux联盟 id integer primary key, G7dLinux联盟 pid integer, G7dLinux联盟 name varchar(10) UNIQUE G7dLinux联盟 ); G7dLinux联盟 CREATE INDEX catalog_idx on catalog(id asc); G7dLinux联盟 # 给数据表插入一条记录 G7dLinux联盟 sqlite> insert into catalog (ppid,name) values ('001','heiyeluren'); G7dLinux联盟 # 成功无任何提示,如果表达式错误提示错误信息: G7dLinux联盟 SQL error: near "set": syntax error G7dLinux联盟 # 检索有多少条记录 G7dLinux联盟 sqlite> select count(*) from catalog; G7dLinux联盟 1 G7dLinux联盟 # 检索搜索记录 G7dLinux联盟 sqlite> select * from catalog; G7dLinux联盟 1|1|heiyeluren G7dLinux联盟 G7dLinux联盟 反正使用标准的SQL来操作就没有问题,不清楚可以去官方网站上查看帮助信息。另外还要说明的是SQLite不支持修改表结构,如果要修改表结构,只有删除表重新再建立,所以建立表的时候一定要考虑扩展性。估计以后这方面的功能会加强。 G7dLinux联盟 G7dLinux联盟 G7dLinux联盟 2. Linux/Unix 平台 G7dLinux联盟 G7dLinux联盟 error: 目前还没装过,呵呵,不过估计跟Windows差不多,改天把这部分内容补上 G7dLinux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论 |
|
|
|
|
|