SQLite DatabaseÅжÏÊÇ·ñ´æÔÚ¡¢Ð½¨¡¢É¾³ý.....
¡¡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 exist");
}
finally
{
if (db != null)
db.close();
db = null;
}
return flag;
}
/**
* ´ò¿ªÊý¾Ý¿â
*
* @param dbName
* Êý¾Ý¿âÃû³Æ
* @return true ´ò¿ª³É¹¦ false´ò¿ªÊ§°Ü
*/
public boolean openDatabase( String dbName , boolean created )
{
return openDatabase(dbName, null, created);
}
/**
* ´ò¿ªÊý¾Ý¿â
*
* @param dbName
* Êý¾Ý¿âÃû³Æ
* @param factory
* @return true ´ò¿ª³É¹¦ false´ò¿ªÊ§°Ü
*/
public boolean openDatabase( String dbName , CursorFactory factory ,
boolean created )
{
Log.log("called fun : openDatabase()");
Log.log("called fun : if not exist then created "+dbName+" ? : "+created);
boolean flag = false;
if(exist(dbName))
{
try
{
db = ctx.openDatabase(dbName, factory);
Log.log("database/"+dbName+" is opened");
flag = true;
}
catch (FileNotFoundException e)
{
Log.log("database/"+dbName+" is not opened");
flag = false;
}
}
else
{
if(created)
{
flag = createDatabase(dbName, 1, 0, factory);
}
else
{
flag = false;
}
}
return flag;
}
Ïà¹ØÎĵµ£º
//²åÈë¼°¸üвÙ×÷
int nRet = 0;
sqlite3 * db = NULL;
CString strFilePath; //Êý¾Ý¿â´æ´¢Â·¾¶
//·¾¶¸³Öµ£¨Ê¡ÂÔ£©
//Á¬½ÓÊý¾Ý¿â
nRet = sqlite3_open16(strFilePath, &db); //Óм¸¸ö´ò¿ªº¯Êý¿É¹©µ÷Óã¬Ê¹ÓÃWCHARÀàÐÍ·¾¶ÓÃÕâ¸ö
if(nRet != SQLIT ......
1) ÈçºÎ´´½¨×ÔÔö×ֶΣ¿
¼òµ¥µÄ»Ø´ð£ºÒ»¸öÉùÃ÷Ϊ INTEGER PRIMARY KEY µÄ×ֶν«×Ô¶¯Ôö¼Ó¡£
ÕâÀïÊÇÏêϸµÄ´ð°¸£º ´Ó SQLite µÄ 2.3.4 °æ±¾¿ªÊ¼£¬Èç¹ûÄ㽫һ¸ö±íÖеÄÒ»¸ö×Ö¶ÎÉùÃ÷Ϊ INTEGER PRIMARY
KEY£¬ÄÇôÎÞÂÛÄãºÎʱÏò¸Ã±íµÄ¸Ã×ֶβåÈëÒ»¸ö NULL Öµ£¬Õâ¸ö NULL Öµ½«×Ô¶¯±»¸ü»»Îª±È±íÖиÃ×Ö¶ÎËùÓÐÐеÄ×î´óÖµ´ó
......
Õª Òª: Óë³£¼ûµÄÊý¾Ý¿âÏà±È£¬Ç¶Èëʽ
Êý
¾Ý¿â¾ßÓÐÌå»ýС¡¢¹¦ÄÜÆ뱸¡¢¿ÉÒÆÖ²ÐÔ¡¢½¡×³ÐÔµÈÌص㣬±¾ÎÄ·ÖÎöºÍ±È½ÏÁ˵äÐ͵ÄǶÈëʽÊý¾Ý¿âSQLiteºÍBerkeley DB¡£Ê×ÏÈ´ÓÌåϵ½á¹¹¡¢×Óϵͳ
¼äµ÷ÓùØϵ¡¢ÈÎÎñÖ´Ðйý³ÌµÈ½Ç¶È¶ÔSQLiteºÍBerkeley DB½øÐÐÁËÏêϸ·ÖÎö£¬È»ºóÖصã´ÓÊý¾ÝÀàÐÍ¡¢´æ´¢·½Ê½¡¢Ä£Ê½¡¢Êý¾Ý¿âÒýÇ ......
1 TOP
ÕâÊÇÒ»¸ö´ó¼Ò¾³£Îʵ½µÄÎÊÌ⣬ÀýÈçÔÚSQLSERVERÖпÉÒÔʹÓÃÈçÏÂÓï¾äÀ´È¡µÃ¼Ç¼¼¯ÖеÄÇ°Ê®Ìõ¼Ç¼£º
SELECT TOP 10 * from [index] ORDER BY indexid DESC;
µ«ÊÇÕâÌõSQLÓï¾äÔÚSQLiteÖÐÊÇÎÞ·¨Ö´Ðеģ¬Ó¦¸Ã¸ÄΪ£º
SELECT * from [index] ORDER BY indexid DESC limit 0,10;
ÆäÖÐlimit 0,10±íʾ´ÓµÚ0Ìõ¼Ç¼¿ªÊ¼£¬Íùºó ......