而且目前已经在很多嵌入式产品中使用了它,其他平台可以下载对应的shell命令行
分类:热门新闻

SQLite是一款轻型的数据库,它的安插性目的是嵌入式的,并且近些日子以前在好多嵌入式产物中选取了它,它占用财富十分低,在嵌入式设备中,大概只要求几百K的内部存款和储蓄器就够了。它亦可支持Windows/Linux/Unix等等主流的操作系统,同有的时候候能够跟相当多程序语言相结合,比方Tcl、PHP、Java等,还应该有ODBC接口,相符比起Mysql、PostgreSQL那五款开源世界盛名的数据库治理体系来说,它的管理速度比她们都快。SQLite纵然很精妙,可是辅助的SQL语句不会未有于其它开源数据库,它援救的SQL包含:ATTACH DATABASEBEGIN TRANSACTIONcommentCOMMIT TRANSACTIONCOPYCREATE INDEXCREATE TABLECREATE T卡宴IGGERCREATE VIEWDELETEDETACH DATABASEDROP INDEXDROP TABLEDROP T途乐IGGE奥迪Q3DROP VIEWEND TRANSACTIONEXPLAINexpressionINSERTON CONFLICT clausePRA红霉素AREPLACEROLLBACK TRANSACTIONSELECTUPDATE同一时候它还帮忙事务管理效能等等。也可以有一些人会说它象Microsoft的Access,有的时候候真的以为有一些象,可是其实它们分别非常大。譬如SQLite支持跨平台,操作简便,能够接收过多言语直接开立数据库,而不象Access相近需求Office的支撑。倘令你是个很Mini的利用,或许您想做嵌入式开荒,未有合适的数据库系统,那么今后您能够思量动用SQLite。这段日子它的洋气版本是 3.2.2,它的官网是:,能在上边取得源代码和文书档案。同有时候因为数据库结构轻松,系统源代码亦非众多,也相符想商量数据库系统开拓的专门的学问职员。以后大家早先轻松的牵线,首要本身是想讲明白多少个难点,一是怎么设置使用,二是怎么着跟PHP结合开拓。一、安装1. Windows平台下载windows下的文本,其实正是八个指令路程序,,那些命令路程序用来总结生成数据库文件、施行SQL查询、备份数据库等等效能。下载后譬如大家解压缩到 D:Downloadssqlitesqlite-3_2_2 这几个目录下,那么大家进来cmd,并且步向该目录:cd D:Downloadssqlitesqlite-3_2_2D:Downloadssqlitesqlite-3_2_2sqlite3 test.db# 假设test.db不设有,那么就时有产生二个数据库文件,倘使存在就径直选取该数据库文件,相当于mysql中的useSQLite version 3.2.2Enter .help for instructionssqlite# SQLite的唤起符,要是想查看命令扶助输入 .help,在sqlite中有所系统命令都是. 带头的:sqlite .help.databases List names and files of attached databases.dump ?TABLE? ... Dump the database in an SQL text format.echo ON|OFF Turn command echo on or off.exit Exit this program.explain ON|OFF Turn output mode suitable for EXPLAIN on or off..header(s卡塔尔(قطر‎ ON|OFF Turn display of headers on or off.help Show this message.import FILE TABLE Import data from FILE into TABLE.indices TABLE Show names of all indices on TABLE.mode MODE ?TABLE? Set output mode where MODE is one of:csv Comma-separated valuescolumn Left-aligned columns. (See .width卡塔尔html HTML table codeinsert SQL insert statements for TABLEline One value per linelist Values delimited by .separator stringtabs Tab-separated valuestcl TCL list elements.nullvalue ST奥迪Q5ING Print STRubiconING in place of NULL values.output FILENAME Send output to FILENAME.output stdout Send output to the screen

一 sqlite

简轻便单地说SQLite数据库对应的便是一个文件(日常命名称叫xxx.db)。能够透过sqlite shell命令行来操作sqlite数据库,也足以在其余的语言中经过api来操作sqlite数据库。sqlite数据库的探问依然无需客户名和密码。

 

在windows上得以下载:sqlite-shell-win32-x86-3071300.zip , 其余平台能够下载对应的shell命令行。

 

帮助:

 

d:sqlite_test>sqlite3.exe test.db

SQLite version 3.7.13 2012-06-11 02:05:22

Enter ".help" for instructions

Enter SQL statements terminated with a ";"

sqlite> .help

.backup ?DB? FILE      Backup DB (default "main") to FILE

.bail ON|OFF           Stop after hitting an error.  Default OFF

.databases             List names and files of attached databases

.dump ?TABLE? ...      Dump the database in an SQL text format

                         If TABLE specified, only dump tables matching

                         LIKE pattern TABLE.

.echo ON|OFF           Turn command echo on or off

.exit                  Exit this program

.explain ?ON|OFF?      Turn output mode suitable for EXPLAIN on or off.

                         With no args, it turns EXPLAIN on.

.header(s) ON|OFF      Turn display of headers on or off

.help                  Show this message

.import FILE TABLE     Import data from FILE into TABLE

.indices ?TABLE?       Show names of all indices

                         If TABLE specified, only show indices for tables

                         matching LIKE pattern TABLE.

.load FILE ?ENTRY?     Load an extension library

.log FILE|off          Turn logging on or off.  FILE can be stderr/stdout

.mode MODE ?TABLE?     Set output mode where MODE is one of:

                         csv      Comma-separated values

                         column   Left-aligned columns.  (See .width)

                         html     HTML <table> code

                         insert   SQL insert statements for TABLE

                         line     One value per line

                         list     Values delimited by .separator string

                         tabs     Tab-separated values

                         tcl      TCL list elements

.nullvalue STRING      Print STRING in place of NULL values

.output FILENAME       Send output to FILENAME

.output stdout         Send output to the screen

.prompt MAIN CONTINUE  Replace the standard prompts

.quit                  Exit this program

.read FILENAME         Execute SQL in FILENAME

.restore ?DB? FILE     Restore content of DB (default "main") from FILE

.schema ?TABLE?        Show the CREATE statements

                         If TABLE specified, only show tables matching

                         LIKE pattern TABLE.

.separator STRING      Change separator used by output mode and .import

.show                  Show the current values for various settings

.stats ON|OFF          Turn stats on or off

.tables ?TABLE?        List names of tables

                         If TABLE specified, only list tables matching

                         LIKE pattern TABLE.

.timeout MS            Try opening locked tables for MS milliseconds

.trace FILE|off        Output each SQL statement as it is run

.vfsname ?AUX?         Print the name of the VFS stack

.width NUM1 NUM2 ...   Set column widths for "column" mode

.timer ON|OFF          Turn the CPU timer measurement on or off

 

 

二 使用sqlite

1)展开或创办sqlite数据库

 

d:sqlite_test>sqlite3.exe test.db

SQLite version 3.7.13 2012-06-11 02:05:22

Enter ".help" for instructions

Enter SQL statements terminated with a ";"

sqlite> 

 

 

2) 创设表及插入数据

sqlite> create table mytable(name varchar(10), age smallint);

sqlite> insert into mytable values("itech", 5);

sqlite> insert into mytable values("jason", 10);

sqlite> select * from mytable;

itech|5

jason|10

sqlite> 

 

3)查看表及表的schema

sqlite> .tables

mytable

sqlite> .schema mytable

CREATE TABLE mytable(name varchar(10), age smallint);

sqlite> 

 

4)数据库导出为ascii的sql文件 + 重新导入到新的数据库

d:sqlite_test>echo .dump | sqlite3 test.db > test.db.dump 

d:sqlite_test>type test.db.dump

PRAGMA foreign_keys=OFF;

BEGIN TRANSACTION;

CREATE TABLE mytable(name varchar(10), age smallint);

INSERT INTO "mytable" VALUES('itech',5);

INSERT INTO "mytable" VALUES('jason',10);

COMMIT;

 

 

d:sqlite_test>type test.db.dump | sqlite3 test2.db

d:sqlite_test>sqlite3 test2.db

SQLite version 3.7.13 2012-06-11 02:05:22

Enter ".help" for instructions

Enter SQL statements terminated with a ";"

sqlite> .tables

mytable

sqlite>

 

 

5)格式化输出

sqlite> .mode column

sqlite> .header on

sqlite> select * from mytable;

name        age

----------  ----------

itech       5

jason       10

sqlite> 

 

完! 

本文由威尼斯在线注册平台发布于热门新闻,转载请注明出处:而且目前已经在很多嵌入式产品中使用了它,其他平台可以下载对应的shell命令行

上一篇:没有了 下一篇:php超级功能,汉字转拼音
猜你喜欢
热门排行
精彩图文