SQLite
µÄ×îа汾¿ÉÒÔ´ÓÕâÀïÏÂÔØ
¡£ÏÂÃæÎÒÃÇÒÔWindows°æ±¾sqlite-3_5_1.zip
ΪÀý½éÉÜÆä°²×°·½·¨¡£
£¨´ó¼Ò¿ÉÒÔÑ¡ÔñÏÂÔØ°²×°ÊʺÏ×Ô¼ºµÄ°æ±¾£©
ÏÂÔغ󣬽«sqlite-3_5_1.zip½âѹËõÖÁC:\sqliteĿ¼¼´Íê³É°²×°¡£
C:\sqliteĿ¼¹¹ÔìΪ£º
C:\sqlite
|
+--sqlite3.exe
´ò¿ªÒ»¸öCMDÃüÁî´°¿Ú
C:\>cd sqlite
C:\sqlite>sqlite3.exe mydb.db
SQLite version 3.5.1
Enter ".help" for instructions
sqlite> create table user ( id integer primary key, name varchar(32) );
sqlite> .schema
CREATE TABLE user ( id integer primary key, name varchar(32) );
sqlite>.quit
Í˳öºó£¬²é¿´C:\sqliteĿ¼£¬»á·¢ÏÖ¶à³öÒ»¸ömydb.dbÎļþ£º
C:\sqlite
|
+--sqlite3.exe
+--mydb.db
Java+JDBC ʹÓÃSQLite
SQLite
µÄ×îÐÂJDBCÇý¶¯¿ÉÒÔ´Ó http://www.ch-werner.de/javasqlite/
ÏÂÔØ¡£
Ŀ¼×îеÄbinary°æÊÇjavasqlite-20070915-win32.zip
½âѹËõ¡£²¢½«½âѹËõºóµÃµ½µÄsqlite.jarÎļþ¿½±´µ½%JAVA_HOME%\jre\lib\ext£¬sqlite_jni.dllÎļþ¿½±´µ½%JAVA_HOME%\jre\bin¡£
²âÊÔ£º ......
¡¡Android SQLite Database±¾´òËã·â×°SQLiteµÄ£¬µ«ÊÇ£¬·¢ÏÖʵ¼ÊÉÏAndroidÒѾ·â×°ÁËÒ»²ã£¬ÓÈÆäÊÇÊý¾ÝµÄÔö¡¢É¾¡¢²é¡¢¸ÄÉÏ£¬¸üÊÇÈç´Ë£¬ËùÒÔ£¬ÎÒºóÀ´Ö»·â×°ÁËÒ»¸öÁ¬½Ó²ã£¬¸ºÔð´ò¿ª¡¢½¨Á¢Êý¾Ý¿â£¬²¢·µ»ØÒ»¸öSQLiteµÄʵÀýÓÃÀ´Íê³ÉÔö¡¢É¾¡¢²å¡¢¸ÄµÈ²Ù×÷¡£
//----------- DBHelper -------------
package utility.db;
import java.io.FileNotFoundException;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
public class DBHelper
{
private SQLiteDatabase db = null;
private Context ctx = null;
public DBHelper( Context ctx )
{
this.ctx = ctx;
}
/**
* ÅжÏÊý¾Ý¿âÊÇ·ñ´æÔÚ
*
* @param dbName
* Êý¾Ý¿âÃû³Æ
* @return true´æÔÚ false²»´æÔÚ
*/
public boolean exist( String dbName )
{
Log.log("called fun : exist()");
boolean flag = false;
try
{
db = ctx.openDatabase(dbName, null);
Log.log("database/"+dbName+" exist");
flag = true;
}
catch (FileNotFoundException e)
{
flag = false;
Log.log("database/"+dbName+" not ......
°²×°:
¹Ù·½ÍøÕ¾ÏÂÔØ×îеÄsqlite°æ±¾
¹Ù·½ÍøÕ¾: http://www.sqlite.org/
ÏÂÔصØַΪ: http://www.sqlite.org/download.html
¹Ù·½µÄÏÂÔØÒ³ÃæÌṩÁ˺ܶà°æ±¾µÄÏÂÔØ…ÕâÀï½éÉÜÒ»ÏÂ;
Source Code: Ô´´úÂë°æ±¾µÄÏÂÔØ
Documentation: Ïà¹ØÎĵµ
Precompiled Binaries for Linux / Precompiled Binaries For Mac OS X /
Precompiled Binaries For Windows
Linux/Mac/Win°æ±¾µÄÔ¤±àÒë°æ±¾
Èç¹ûÄãÖ»ÊÇÊý¾Ý¿âµÄÓû§ÄÇôÏÂÔØÒѾ±àÒëºÃµÄ°æ±¾¼´¿É! ÕâÀïÎÒÊÇWinÓû§,ÏÂÔصÄÎļþΪ: sqlite3.exe
½«Õâ¸öÎļþ·Åµ½Ò»¸öĿ¼ÖÐ,ÕâÑù¾ÍÍê³ÉÁËÈ«²¿µÄsqliteÊý¾Ý¿âµÄ°²×°!
н¨:
ÔÚÃüÁîÌáʾ·ûÏÂ($ΪshellÌáʾºÅ), ²âÊÔµÄsqlite3.exe·¾¶Îªe:\sqlite3\sqlite3.exe
ÍøÉÏÒ²ÌṩÁ˺ܶ෽·¨,µ«ºÃÏó¶¼ÓеãÎÊÌâ,¾¹ýÃþË÷½áÂÛΪÒÔϼ¸ÖÖ·½·¨,µ«²»È·¶¨ÊÇ·ñÊܲÙ×÷ϵͳϵͳӰÏì!
Éú³ÉÊý¾Ý¿âÎļþºó¹Ò½Ó
$> sqlite3.exe test.db ;
$> sqlite3.exe test.db
Ö±½Ó¹Ò½ÓÉú³É
$> sqlite3.exe test.db;
Ñ¡ÔñÐÔ¹Ò½Ó ÌôÑ¡ÒѾ´æÔÚµÄÊý¾ÝÎļþ¹Ò½Ó
$> sqlite3.exe test.db »òÕß
$> sqlite3.exe e:\sqlite3\test.db
¹Ò½ÓºÃÊý¾Ý¿âºó,¾Í¿ÉÒÔͨ¹ýÃüÁîÐеÄÐÎʽ¶ÔËù¹Ò½ÓµÄÊý¾ ......
@ǶÈëʽ¹ØϵÐÍÊý¾Ý¿âSQLite
Ìصã
1.Ö§³ÖÎåÖÖÊý¾ÝÀàÐÍ null,INTEGER,REAL(¸¡µãÊý),TEXT(×Ö·û´®Îı¾)ºÍBLOB£¨¶þ½øÖÆÎı¾£©Êý¾ÝÀàÐÍ£¬ËäÈ»
ËüÖ»ÓÐÎåÖÖ£¬µ«Êµ¼ÊÉÏsqlite3Ò²½ÓÊÖvarcher(n),char(n),decimal(p,s)µÈÊý¾ÝÀàÐÍ£¬Ö»²»¹ýÔÚÔËËã»î±£´æʱ»áת³É
ÏàÓ¦µÄÎåÖÖÊý¾ÝÀàÐÍ¡£
2.×î´óµÄÌصã
¿ÉÒÔ±£´æÈκÎÀàÐ͵ÄÊý¾Ýµ½ÈκÎ×Ö¶ÎÖУ¬ÎÞÂÛÕâÁÐÉùÃ÷µÄÊý¾ÝÊÇʲôÀàÐÍ¡£
ÀýÈ磺
¿ÉÒÔÔÚIntegerÀàÐ͵Ä×Ö¶ÎÖдæ·Å×Ö·û´®£¬»òÕßÔÚBoolean Öдæ·Å¸¡µãÊý£¬»òÕßÔÚ×Ö·ûÐÍ×Ö¶ÎÖдæ·ÅÈÕÆÚÐÍÖµµ«ÓÐÒ»ÖÖÇé¿öÀýÍâ
ÀýÍâ:
&n ......
SQLite¹Ù·½ÍøÕ¾Àý×Ó£º
#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){
sqlite3 *db;
char *zErrMsg = 0;
int rc;
if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
exit(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
return 0;
}
ÓÃgcc±àÒë
gcc -lsqlite3 sqlite.c -o sqlite
ÔËÐÐʱ./sqlite ab.db 'SQL Óï¾ä'
......
SQLite¹Ù·½ÍøÕ¾Àý×Ó£º
#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){
sqlite3 *db;
char *zErrMsg = 0;
int rc;
if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
exit(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
return 0;
}
ÓÃgcc±àÒë
gcc -lsqlite3 sqlite.c -o sqlite
ÔËÐÐʱ./sqlite ab.db 'SQL Óï¾ä'
......
ÄÚ´æÊý¾Ý¿âFastDBºÍSQLiteÐÔÄܲâÆÀ
×÷Õߣºtamsyn
À´Ô´£ºwww.sqlite.com.cn
ʱ¼ä£º2009-10-21
Ò»¡¢ÒýÑÔ
ÔںܶàÏîÄ¿ÖУ¬¾³£»áÅöµ½ÕâÑùµÄÐèÇó£¬ÐèÒª¶Ô´óÁ¿Êý¾Ý½øÐпìËÙ´æ´¢¡¢²éѯ¡¢É¾³ýµÈ²Ù×÷£¬ÌرðÊÇÔÚһЩÕë¶ÔÖîÈçÔËÓªÉÌ¡¢ÒøÐеȴóÐÍÆóÒµµÄÓ¦ÓÃÖУ¬ÕâЩ
ÐèÇóÓÈΪ³£¼û¡£±ÈÈçÖÇÄÜÍøÖеĴóÁ¿ÔÚÏß²¢·¢Óû§µÄÊý¾Ý¹ÜÀí¡¢Èí½»»»Æ½Ì¨ÖеÄÔÚÏßÐÅÏ¢½»»¥¡¢¿í´ø/3GµÈÊý¾ÝÍøÖÐÔÚÏßÓû§ÐÐΪ¼Ç¼µÈµÈ¡£
Õë¶ÔÕâЩÇéÐΣ¬ÎÒÃÇͨ³£ÐèҪѡÔñ¸ßÐÔÄܵÄÊý¾Ý¿â²úÆ·£¬¶øÇÒͨ³£ÐèҪʹÓÃÄÚ´æÊý¾Ý¿â£¬¹ËÃû˼Ò壬ÄÚ´æÊý¾Ý¿âÖ¸µÄÊÇËùÓеÄÊý¾Ý·ÃÎÊ¿ØÖƶ¼ÔÚÄÚ´æÖнøÐУ¬
ÕâÊÇÓë´ÅÅÌÊý¾Ý¿âÏà¶Ô¶øÑԵģ¬´ÅÅÌÊý¾Ý¿âËäȻҲÓÐÒ»¶¨µÄ»º´æ»úÖÆ£¬µ«¶¼²»ÄܱÜÃâ´ÓÍâÉèµ½ÄÚ´æµÄ½»»»£¬¶øÕâÖÖ½»»»¹ý³Ì¶ÔÐÔÄܵÄËðºÄÊÇÖÂÃüµÄ£¬Ä¿Ç°Ö÷Á÷Êý¾Ý¿â
ÈçSYBASE¡¢ORACLEµÈ¶¼ÓÐÕâÖÖ»º´æ»úÖÆ£¬È罫Ìض¨±í°ó¶¨Ò»¶¨µÄ»º´æ£¬´Ó¶øÔÚÒ»¶¨³Ì¶ÈÉϸÄÉÆÊý¾ÝÍÌÍÂÐÔÄÜ¡£¶øÄÚ´æÊý¾Ý¿â¼¸ºõ¿ÉÒÔÍêÈ«±ÜÃâÕâÖÖÄÚÍâ
´æÊý¾Ý½»»»µÄ·¢Éú£¬ÌرðÊÇÔÚÎïÀíÄÚ´æ×ã¹»´óµÄÉ豸ÉÏÓÈÆäÈç´Ë£¬Í¨³£ÕâÖÖÊý¾Ý¿âÒ²±»³ÆΪÖ÷´æÊý¾Ý¿â(Main Memory DataBase,
MMDB)¡£
¶þ¡¢Ö÷´æÊý¾Ý¿â±È½Ï
Ä¿Ç°±È½ÏÖª ......