Using SQLite from Shell in Android
Where is SQLite?
SQLite is available on the Android device itself. The executable is in the /system/bin directory of the device. You can see that this directory contains the shell commands like ls, ps, etc., as well as sqlite3, dalvikvm, and dexdump utilities.
Code Listing 1. Contents of system/bin
# pwd
pwd
/system/bin
# ls -l
ls -l
-rwxr-xr-x root root 196 2008-02-29 01:09 am
-rwxr-xr-x root root 2342 2008-02-29 01:09 dumpstate
-rwxr-xr-x root root 208 2008-02-29 01:09 input
-rwxr-xr-x root root 212 2008-02-29 01:09 monkey
-rwxr-xr-x root root 196 2008-02-29 01:09 pm
…
lrwxr-xr-x root root 2008-02-29 01:16 mount -> toolbox
lrwxr-xr-x root root 2008-02-29 01:16 notify -> toolbox
-rwxr-xr-x root root 28032 2008-02-29 01:16 dexdump
-rwxr-xr-x root root 7100 2008-02-29 01:16 dumpsys
-rwxr-xr-x root root 7904 2008-02-29 01:16 mem_profiler
-rwxr-xr-x root root 6480 2008-02-29 01:16 service
-rwxr-xr-x root root 4320 2008-02-29 01:16 rild
-rwxr-xr-x root root 4928 2008-02-29 01:16 sdutil
-rwxr-xr-x root root 26488 2008-02-29 01:16 sqlite3
-rwxr-xr-x root root 4148 2008-02-29 01:16 dexopt
-rwxr-xr-x root root 4908 2008-02-29 01:16 dalvikvm
-rwsr-sr-x root root 3200 2008-02-29 01:16 surfaceflinger
-rwxr-xr-x root root 5420 2008-02-29 01:16 app_process
-rwxr-xr-x root root 39408 2008-02-29 01:16 runtime
-rwxr-xr-x root root 2920 2008-02-29 01:16 system_server
-rwxr-xr-x root root 9168 2008-02-29 01:17 pv
Where are the SQLite databases on an Android Device?
By default, the SQLite databases have an extension .db. For example, a NotePad application may use note_pad.db database. This might be created from code using Android SDK’s SQLite classes/methods. By default, the SQLite database for an application is in the /data/data/<app>/databases directory. As you can see from the listing below, the notepad database is in the /data/data/com.google.android.notepad/databases directory.
Code Listing 2.
Ïà¹ØÎĵµ£º
ÎÒÏÖÔÚҪʹÓÃSQLite3.0´´½¨Ò»¸öÊý¾Ý¿â£¬È»ºóÔÚÊý¾Ý¿âÖд´½¨Ò»¸ö±í¸ñ¡£
Ê×ÏÈÒªÒýÈëSQLite3.0µÄlib¿â¡£È»ºó°üº¬Í·Îļþ#import <sqlite3.h>
¡¾1¡¿´ò¿ªÊý¾Ý¿â£¬Èç¹ûûÓУ¬ÄÇô´´½¨Ò»¸ö
sqlite3* database_;
-(BOOL) open{
NSArray *paths = NSSearchPathForDirectoriesInDomai ......
[±à¼±¾¶Î
]
SQLite¼ò½é
SQLite
µÚÒ»¸öAlpha°æ±¾µ®ÉúÓÚ2000Äê5ÔÂ. ÖÁ½ñÒѾÓÐ10¸öÄêÍ·ÁË. SQLiteÒ²ÓÀ´ÁËÒ»¸ö°æ±¾ SQLite 3ÒѾ·¢²¼.
¡¡¡¡SQLiteÊÇÒ»¿îÇáÐ͵ÄÊý¾Ý¿â£¬ÊÇ×ñÊØACIDµÄ¹ØÁªÊ½Êý¾Ý¿â¹ÜÀíϵͳ£¬ËüµÄÉè¼ÆÄ¿±êÊÇǶÈë
ʽµÄ£¬¶øÇÒÄ¿Ç°ÒѾÔںܶàǶÈëʽ²úÆ·ÖÐʹÓÃÁËËü£¬ËüÕ¼ÓÃ×ÊÔ´·Ç³£µÄµÍ£¬ÔÚǶÈëʽÉ豸ÖУ¬¿ ......
Ò»¡¢SQLite¼ò½é
SQLite ÊÇÓÃCÓïÑÔ±àдµÄ¿ªÔ´Êý¾Ý¿â£¬Ö÷ÒªÓÃÓÚǶÈëʽ£¬ÄãÒ²¿ÉÒÔ°ÑËü¼¯³ÉÔÚ×Ô¼ºµÄ×ÀÃæ³ÌÐòÖУ¬Ò²ÓÐÈ˽«ÆäÌæ´úAccess£¬ÓÃ×÷ºǫ́Êý¾Ý¿â¡£
SQLite Ö§³Ö¶àÊýSQL92±ê×¼£¬ÀýÈ磺Ë÷Òý¡¢ÏÞÖÆ¡¢´¥·¢ºÍ²é¿´Ö§³Ö¡£
Ö§³Ö NULL¡¢INTEGER¡¢REAL¡¢TEXT ºÍ BLOB Êý¾ÝÀàÐÍ£¬Ö§³ÖÊÂÎñ¡£
¶þ¡¢ÏÂÔØSQLite
SQLite¿ÉÒÔµ½¹Ù·½Õ ......
Step-1: Ê×ÏÈ將.mp3檔°¸·ÅÈëProjectµÄ/res/raw/裡£¬ÈçÏ£º
³Ìʽһ開ʼ執ÐУ¬½¨Á¢Ò»個資ÁÏ庫£¬º¬ÓÐBLOB欄룬ÈçÏÂÖ®Ö¸Á
sql ......