📄 quickstart.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>SQLite In 5 Minutes Or Less</title><style type="text/css">body { margin: auto; font-family: "Verdana" "sans-serif"; padding: 8px 1%;}a { color: #45735f }a:visited { color: #734559 }.logo { position:absolute; margin:3px; }.tagline { float:right; text-align:right; font-style:italic; width:240px; margin:12px; margin-top:58px;}.toolbar { font-variant: small-caps; text-align: center; line-height: 1.6em; margin: 0; padding:1px 8px;}.toolbar a { color: white; text-decoration: none; padding: 6px 12px; }.toolbar a:visited { color: white; }.toolbar a:hover { color: #80a796; background: white; }.content { margin: 5%; }.content dt { font-weight:bold; }.content dd { margin-bottom: 25px; margin-left:20%; }.content ul { padding:0px; padding-left: 15px; margin:0px; }/* rounded corners */.se { background: url(images/se.png) 100% 100% no-repeat #80a796}.sw { background: url(images/sw.png) 0% 100% no-repeat }.ne { background: url(images/ne.png) 100% 0% no-repeat }.nw { background: url(images/nw.png) 0% 0% no-repeat }</style><meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head><body><div><!-- container div to satisfy validator --><a href="index.html"><img class="logo" src="images/SQLite.gif" alt="SQLite Logo" border="0"></a><div><!-- IE hack to prevent disappearing logo--></div><div class="tagline">Small. Fast. Reliable.<br>Choose any three.</div><table width=100% style="clear:both"><tr><td> <div class="se"><div class="sw"><div class="ne"><div class="nw"> <div class="toolbar"> <a href="about.html">About</a> <a href="sitemap.html">Sitemap</a> <a href="docs.html">Documentation</a> <a href="download.html">Download</a> <a href="copyright.html">License</a> <a href="news.html">News</a> <a href="http://www.sqlite.org/cvstrac/index">Developers</a> <a href="support.html">Support</a> </div></div></div></div></div></td></tr></table> <p>Here is what you do to start experimenting with SQLite without havingto do a lot of tedious reading and configuration:</p><h2>Download The Code</h2><ul><li><p>Get a copy of the prebuilt binaries for your machine, or get a copyof the sources and compile them yourself. Visitthe <a href="download.html">download</a> page for more information.</p></li></ul><h2>Create A New Database</h2><ul><li><p>At a shell or DOS prompt, enter: "<b>sqlite3 test.db</b>". This willcreate a new database named "test.db". (You can use a different name ifyou like.)</p></li><li><p>Enter SQL commands at the prompt to create and populate thenew database.</p></li><li><p>Additional documentation is available <a href="sqlite.html">here</a></li></ul><h2>Write Programs That Use SQLite</h2><ul><li><p>Below is a simple <a href="http://www.tcl.tk">TCL program</a> that demonstrates how to usethe TCL interface to SQLite. The program executes the SQL statementsgiven as the second argument on the database defined by the firstargument. The commands to watch for are the <b>sqlite3</b> commandon line 7 which opens an SQLite database and createsa new TCL command named "<b>db</b>" to access that database, theinvocation of the <b>db</b> command on line 8 to executeSQL commands against the database, and the closing of the database connectionon the last line of the script.</p><blockquote><pre>#!/usr/bin/tclshif {$argc!=2} { puts stderr "Usage: %s DATABASE SQL-STATEMENT" exit 1}load /usr/lib/tclsqlite3.so Sqlite3<b>sqlite3</b> db [lindex $argv 0]<b>db</b> eval [lindex $argv 1] x { foreach v $x(*) { puts "$v = $x($v)" } puts ""}<b>db</b> close</pre></blockquote></li><li><p>Below is a simple C program that demonstrates how to usethe <a href="c3ref/intro.html">C/C++ interface</a> to SQLite. The name of a database is given bythe first argument and the second argument is one or more SQL statementsto execute against the database. The function calls to pay attentionto here are the call to <a href="c3ref/open.html">sqlite3_open()</a> on line 22 which opensthe database, <a href="c3ref/exec.html">sqlite3_exec()</a> on line 27 that executes SQLcommands against the database, and <a href="c3ref/close.html">sqlite3_close()</a> on line 31that closes the database connection.</p><p>See also the <a href="cintro.html">Introduction To The SQLite C/C++ Interface</a> foran introductory overview and roadmap to the dozens of SQLite interfacefunctions.</p><blockquote><pre>#include <stdio.h>#include <sqlite3.h>static int callback(void *NotUsed, int argc, char **argv, char **azColName){ int i; for(i=0; i<argc; i++){ printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); } printf("\n"); return 0;}int main(int argc, char **argv){ <b>sqlite3</b> *db; char *zErrMsg = 0; int rc; if( argc!=3 ){ fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]); exit(1); } rc = <b>sqlite3_open</b>(argv[1], &db); if( rc ){ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); <b>sqlite3_close</b>(db); exit(1); } rc = <b>sqlite3_exec</b>(db, argv[2], callback, 0, &zErrMsg); if( rc!=SQLITE_OK ){ fprintf(stderr, "SQL error: %s\n", zErrMsg); <b>sqlite3_free</b>(zErrMsg); } <b>sqlite3_close</b>(db); return 0;}</pre></blockquote></li></ul><hr><small><i>This page last modified 2008/05/12 13:08:44 UTC</i></small></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -