[±à¼±¾¶Î
]
SQLite¼ò½é
SQLite
µÚÒ»¸öAlpha°æ±¾µ®ÉúÓÚ2000Äê5ÔÂ. ÖÁ½ñÒѾÓÐ10¸öÄêÍ·ÁË. SQLiteÒ²ÓÀ´ÁËÒ»¸ö°æ±¾ SQLite 3ÒѾ·¢²¼.
¡¡¡¡SQLiteÊÇÒ»¿îÇáÐ͵ÄÊý¾Ý¿â£¬ÊÇ×ñÊØACIDµÄ¹ØÁªÊ½Êý¾Ý¿â¹ÜÀíϵͳ£¬ËüµÄÉè¼ÆÄ¿±êÊÇǶÈë
ʽµÄ£¬¶øÇÒÄ¿Ç°ÒѾÔںܶàǶÈëʽ²úÆ·ÖÐʹÓÃÁËËü£¬ËüÕ¼ÓÃ×ÊÔ´·Ç³£µÄµÍ£¬ÔÚǶÈëʽÉ豸ÖУ¬¿ÉÄÜÖ»ÐèÒª¼¸°ÙKµÄÄÚ´æ¾Í¹»ÁË¡£ËüÄܹ»Ö§³Ö
Windows/Linux/UnixµÈµÈÖ÷Á÷µÄ²Ù×÷ϵͳ£¬Í¬Ê±Äܹ»¸úºÜ¶à³ÌÐòÓïÑÔÏà½áºÏ£¬±ÈÈçTcl¡¢PHP¡¢JavaµÈ£¬»¹ÓÐODBC½Ó¿Ú£¬Í¬Ñù±ÈÆð
Mysql¡¢PostgreSQLÕâÁ½¿î¿ªÔ´ÊÀ½çÖøÃûµÄÊý¾Ý¿â¹ÜÀíϵͳÀ´½²£¬ËüµÄ´¦ÀíËٶȱÈËûÃǶ¼¿ì¡£
[±à¼±¾¶Î
]
SQLite¹¦ÄÜ
¡¡¡¡SQLiteËäÈ»ºÜСÇÉ£¬µ«ÊÇÖ§³ÖµÄSQLÓï¾ä²»»áÑ·É«ÓÚÆäËû¿ªÔ´Êý¾Ý¿â£¬ËüÖ§³ÖµÄSQL°ü
À¨£º
¡¡¡¡ATTACH DATABASE
¡¡¡¡BEGIN TRANSACTION
¡¡¡¡comment
¡¡¡¡COMMIT TRANSACTION
¡¡¡¡COPY
¡¡¡¡CREATE INDEX
¡¡¡¡CREATE TABLE
¡¡¡¡CREATE TRIGGER
¡¡¡¡CREATE VIEW
¡¡¡¡DELETE
¡¡¡¡DETACH DATABASE
¡¡¡¡DROP INDEX
¡¡¡¡DROP TABLE
¡¡¡¡DROP TRIGGER
¡¡¡¡DROP VIEW
¡¡¡¡END TRANSACTION
¡¡¡¡EXPLAIN
¡¡¡¡expression
¡¡¡¡INSERT
¡¡¡¡ON ......
android µÄsqlite Ö÷¼üÓësimpleCursorAdapter
×î½üÔÚÔÚ×öÒ»¸öСÀý×Óʱ£¬³öÏÖÒ»¸öСÎÊÌ⣬¾ÍÊDz»ÄÜÏÔʾ´ÓÊý¾Ý¿âÖвé³öµÄÊý¾Ý£¬ºóÀ´ÔÚÍøÉϲéÁËÒ»²é£¬²ÅÖªµÀÔÀ´ÊÇÕâ¸öÎÊÌâ¡£
ÔÚʹÓÃsimpleCursorAdapterÏÔʾsqliteÊý¾Ýʱ£¬±ØÐë×¢ÒâsqliteµÄÖ÷¼üÃüÃû¡£ÓÉÓÚsimpleCursorAdapterµÄ·½·¨Ö»Ê¶±ð_id£¬ËùÒÔ£¬µ±ÄãÓõ½sqliteµÄsimpleCursorAdapterʱ£¬±ØÐë°ÑÊý¾Ý±íµÄÖ÷¼üÃüÃûΪ_id¡£·ñÔò¾Í»á³öÏÖ java.lang.IllegalArgumentException: column ‘_id’ does not exist ´íÎó¡£
ÏÂÃæÊÇActivityMainÀà ¹©´ó¼Ò²Î¿¼ һϡ£
public class ActivityMain extends Activity {
private static int count =0;
//´´½¨Êý¾Ý¿â¶ÔÏó
private SQLiteDatabase mSqliteDatabase=null;
//Êý¾Ý¿âÃû
private static final String DATABASE_NAME="gege.db";
//±íÃû
private static final String TABLE_NAME="jiao";
//±íÖÐ×Ö¶Î
private static final String TABLE_ID="_id";
private static final String TABLE_NUM="num";
private static final String TABLE_DATA="data";
//´´½ ......
package com.jiao.sqlite;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class DbDemo extends Activity {
/**
* SQLite Demo
*
* ¹©Activity˽ÓзÃÎʵÄÊý¾Ý¿â ûÓÐʹÓÃContentProvider ·½Ê½ Ôö¼Ó ²éѯÊý¾Ý
*
* @author daguangspecial@gmail.com
*
*/
EditText inputTxt;
Button btnAdd;
Button btnViewAll;
TextView viewAll;
DBHelper db;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
&n ......
ÔÚ .NET ÀïÃæʹÓà SQLite£¬ ÎÒÕâÀïʹÓõÄwrapperÊÇ System.Data.SQLite£¬ËüÖ»ÐèÒªÒ»¸ödll,½Ó¿Ú·ûºÏADO.Net 2.0µÄ¶¨Òå,ÐÔÄÜÒ²²»´í,NHibernateÓõÄÒ²ÊÇËü£¬Ä¿Ç°Ö§³ÖADO.NET 3.5ÁË£¬Ö§³Ö¼¯³ÉÔÚ VS2005 ºÍ VS2008ÀïÃ棬¶øÇÒÖ§³Öwince£¬ÊǸöÁÁµã
ÒòΪ·ûºÏADO.NETµÄ¹æ·¶£¬ËùÒÔʹÓ÷½Ê½£¬»ù±¾ºÍ SqlClient, OleDbµÈÔÉúµÄÒ»ÖÂ
using System.Data;
using System.Data.SQLite;
//...
using (SQLiteConnection cn = new SQLiteConnection(
"Data Source=Test.db3;Pooling=true;FailIfMissing=false")
)
//PoolingÉèÖÃΪtrueʱ£¬SQLÁ¬½Ó½«´ÓÁ¬½Ó³Ø»ñµÃ£¬Èç¹ûûÓÐÔòн¨²¢Ìí¼Óµ½Á¬½Ó³ØÖÐ,ĬÈÏÊÇtrue¡£
//FailIfMissingĬÈÏΪfalse£¬Èç¹ûÊý¾Ý¿âÎļþ²»´æÔÚ£¬»á×Ô¶¯´´½¨Ò»¸öеģ¬ÈôÉèÖÃΪtrue£¬½«²»»á´´½¨£¬¶øÊÇÅ׳öÒì³£ÐÅÏ¢¡£
{
//ÔÚ´ò¿ªÊý¾Ý¿âʱ£¬»áÅжÏÊý¾Ý¿âÊÇ·ñ´æÔÚ£¬Èç¹û²»´æÔÚ£¬ÔòÔÚµ±Ç°Ä¿Â¼Ï´´½¨Ò»¸ö
cn.Open();
using (SQLiteCommand cmd = new SQLiteCommand())
{
cmd.Connection = cn; ......
ÔÚ .NET ÀïÃæʹÓà SQLite£¬ ÎÒÕâÀïʹÓõÄwrapperÊÇ System.Data.SQLite£¬ËüÖ»ÐèÒªÒ»¸ödll,½Ó¿Ú·ûºÏADO.Net 2.0µÄ¶¨Òå,ÐÔÄÜÒ²²»´í,NHibernateÓõÄÒ²ÊÇËü£¬Ä¿Ç°Ö§³ÖADO.NET 3.5ÁË£¬Ö§³Ö¼¯³ÉÔÚ VS2005 ºÍ VS2008ÀïÃ棬¶øÇÒÖ§³Öwince£¬ÊǸöÁÁµã
ÒòΪ·ûºÏADO.NETµÄ¹æ·¶£¬ËùÒÔʹÓ÷½Ê½£¬»ù±¾ºÍ SqlClient, OleDbµÈÔÉúµÄÒ»ÖÂ
using System.Data;
using System.Data.SQLite;
//...
using (SQLiteConnection cn = new SQLiteConnection(
"Data Source=Test.db3;Pooling=true;FailIfMissing=false")
)
//PoolingÉèÖÃΪtrueʱ£¬SQLÁ¬½Ó½«´ÓÁ¬½Ó³Ø»ñµÃ£¬Èç¹ûûÓÐÔòн¨²¢Ìí¼Óµ½Á¬½Ó³ØÖÐ,ĬÈÏÊÇtrue¡£
//FailIfMissingĬÈÏΪfalse£¬Èç¹ûÊý¾Ý¿âÎļþ²»´æÔÚ£¬»á×Ô¶¯´´½¨Ò»¸öеģ¬ÈôÉèÖÃΪtrue£¬½«²»»á´´½¨£¬¶øÊÇÅ׳öÒì³£ÐÅÏ¢¡£
{
//ÔÚ´ò¿ªÊý¾Ý¿âʱ£¬»áÅжÏÊý¾Ý¿âÊÇ·ñ´æÔÚ£¬Èç¹û²»´æÔÚ£¬ÔòÔÚµ±Ç°Ä¿Â¼Ï´´½¨Ò»¸ö
cn.Open();
using (SQLiteCommand cmd = new SQLiteCommand())
{
cmd.Connection = cn; ......
´úÂëºÜÂÒ£¬¶øÇÒûÓÐÓõ½Ä£°å£¬°Ñhtml´úÂë¸úPython´úÂë»ìÔÚÒ»ÆðÁË£¬¶øÇÒҲûÓÐÓõ½web.py±¾ÉíÌṩµÄÊý¾Ý¿â²Ù×÷Ä£¿é£¬¾ø¶Ô´Ö³¬µÄ´úÂ룡
ѧϰÁ˺ܶණÎ÷£¬Ê×Ïȵ±È»ÊÇweb.py£¬È»ºóÊÇsqlite£¬½ÓÏÂÀ´ÊÇtimeÄ£¿é——¿´À´Ò²Î¨Óв»¶ÏµÄʵ¼ù£¬²ÅÕæÕýÄܽø²½£¡
˵ʵÔڵģ¬Å¼Ñ§htmlµ½ÏÖÔÚÕâô¾Ã£¬»¹ÊÇ°ëÍ°Ë®£¬±¯¾çÁË£¡
01 #!/usr/bin/env python
02 #coding=utf-8
03
04 import os,web,time
05 import sqlite3 as db
06
07 urls = (
08 '/', 'hello',
09 '/add','add'
10 )
11
12 class hello:
13 def GET(self):
14 #ʵÀý»¯sqldb£¬È»ºó»ñÈ¡ÄÚÈÝ
15 s = ""
16 sdb = sqldb()
......
Ò»¡¢SQLite¼ò½é
SQLite ÊÇÓÃCÓïÑÔ±àдµÄ¿ªÔ´Êý¾Ý¿â£¬Ö÷ÒªÓÃÓÚǶÈëʽ£¬ÄãÒ²¿ÉÒÔ°ÑËü¼¯³ÉÔÚ×Ô¼ºµÄ×ÀÃæ³ÌÐòÖУ¬Ò²ÓÐÈ˽«ÆäÌæ´úAccess£¬ÓÃ×÷ºǫ́Êý¾Ý¿â¡£
SQLite Ö§³Ö¶àÊýSQL92±ê×¼£¬ÀýÈ磺Ë÷Òý¡¢ÏÞÖÆ¡¢´¥·¢ºÍ²é¿´Ö§³Ö¡£
Ö§³Ö NULL¡¢INTEGER¡¢REAL¡¢TEXT ºÍ BLOB Êý¾ÝÀàÐÍ£¬Ö§³ÖÊÂÎñ¡£
¶þ¡¢ÏÂÔØSQLite
SQLite¿ÉÒÔµ½¹Ù·½Õ¾µãÏÂÔØ
http://www.sqlite.org/download.html
°üÀ¨£ºLinux,Mac OS X, WindowsϵÄÒѱàÒëÎļþÒÔ¼°Ô´´úÂë¡¢°ïÖúÎĵµ¡£
Èý¡¢SQLiteµÄ¼òµ¥Ê¹ÓÃ
3.1 ½¨Á¢Êý¾Ý¿â
C:\sqlite-3_6_11> sqlite3.exe dbname.db
sqlite3.exeºóÃæ¸úÊý¾Ý¿âÎļþÃû
3.2 ´´½¨Êý¾Ý±í
sqlite> create table users(userid varchar(20) PRIMARY KEY,
...> age int,
...> birthday datetime);
3.3 Ìí¼Ó¼Ç¼
insert into users values('wang',20,'1989-5-4');
insert into users values('li',22,'1987-11-16');
3.4 ²éѯ¼Ç¼
select * from users order by birthday;
3.5 ɾ³ý¼Ç¼
delete from users where userid='wang';
3.6 Í˳ösqlite
sqlite> .exit
SQLiteÊý¾Ý¿âµÄÊý¾Ý½á¹¹ÊÇ´æÖüÔÚ "sqlite_master" ±íÖÐ
¾ßÌåÃüÁî¿ÉÒÔÊä ......
×ܼǼÊý:155; ×ÜÒ³Êý:26; ÿҳ6 Ìõ;
Ê×Ò³ ÉÏÒ»Ò³ [1] [2] 3
[4] [5] [6] [7] [8] [9] [10] ÏÂÒ»Ò³ βҳ