å ã®åé¡ã«é¢ããããã€ãã®èšèã ç§ãã¡ã®äž»ãªãšãã»ã³ã¹ã¯ãé£çµ¡å ã®ãªã¹ãããããã¡ãã»ãŒãžãå«ãŸããŠããICQãããã¡ã€ã«ã§ãã ç§ãã¡ã®ã¢ããªã±ãŒã·ã§ã³ã¯é·å¹Žã«ããã£ãŠååšããããŸããŸãªã¢ãããŒããæã€ããŸããŸãªäººã ã«ãã£ãŠéçºãããŸãããã¡ã€ã³ããŒã¿ããŒã¹ã®ããŒãžã§ã³çªå·ã¯èªä¿¡ãæã£ãŠ30ã«è¿ã¥ããŸãããããã«ã補åã®æ©èœã®æ°ã¯äºåã«äºæž¬ã§ããŸããã äžè¬ã«ãããŒã¿ã¢ãã«ã¯ããšããšæ¬¡ã®ãããªãã®ã§ããã
ãã€ããªåœ¢åŒã®ãããã¡ã€ã«ãé£çµ¡å ãã¢ã¯ãã£ããªãã£ããã®ãªã¹ãã«ä¿åãããã¡ã€ã«ãããã€ããããŸããã 察å¿ã¯ãæåã¯ããŒã¿ããŒã¹ããšã«å¥ã ã«ä¿åããããããã¡ã€ã«ããšã«ç°ãªã£ãŠããŸããã ããæç¹ã§ãé£çµ¡å ããŒã¿ãæ°ããããŒã¿ããŒã¹ã«è»¢éãããŸããã 次ã«ãã¢ããªã±ãŒã·ã§ã³ã¯ã¡ãã£ã¢ã¡ãã»ãŒãžã®ãµããŒããè¿œå ããŸããïŒãã¡ã€ã«ãåçããããªã [ç®è]è«ççã«[/ç®è]ã圌ãã¯å¥ã®ããŒã¿ããŒã¹ãäœæããŸããã ããã«ãå ±æèšå®ã䜿çšããŠããããã¯ãŒã¯ãžã®ã¢ã¯ã»ã¹ã«é¢ããéèŠãªããŒã¿ãä¿åããã¡ã€ã³ããŒã¿ããŒã¹ã«ãã€ã³ãããªãããã«ããŸããã 次第ã«ããã¡ã€ã«ã®æäœã«å€§ããªè² æ ããããå§ããŸããã 1ã€ã®é£çµ¡å ãå€æŽãããšããŸããããã¹ãŠã®é£çµ¡å ãã·ãªã¢ã«åããŠãã¡ã€ã«ã«æžã蟌ãå¿ èŠããããŸãã ãã®æ§é ãç解ããã³éçºããããšã¯ãã¯ãäžå¯èœã§ãããšå€æããåŸãããšãã°ããã¡ã€ã«ãšããŒã¿ããŒã¹ã®äž¡æ¹ã«ã¢ãããã¯ã«æžã蟌ãå¿ èŠãããå ŽåïŒããã³ãã©ã³ã¶ã¯ã·ã§ã³ã¯å©çšã§ããŸããïŒïŒãåæã®åé¡ãçºçãå§ããŸããã ãã¹ãŠã®ããŒã¿ãåäžã®ããŒã¿ããŒã¹ã«å ¥ãããªã¬ãŒã·ã§ãã«æ§é ãšDBMSã®å©ç¹ã享åãããã£ãã®ã§ãã éä¿¡ã®å±¥æŽãé€ããã¹ãŠã®ããŒã¿ã«ã€ããŠãã¹ãã¬ãŒãžã®åé¡ã¯ãããŸããã§ããã
ããã¯ãµã³ãã«ã®ã¡ãã»ãŒãžããŒãã«ã§ããããã«ã¯ãããã¹ããšæŽæ°ã®2ã€ã®ããŒãã£ãŒã«ãããããŸãã
å±¥æŽãä¿åããããã®2ã€ã®ãªãã·ã§ã³ããéžæããŸãããåé£çµ¡å ã«ã€ããŠãäžèšã®æ§é ã§åå¥ã®ããŒãã«ãäœæããããå±¥æŽå šäœã1ã€ã®ããŒãã«ã«ä¿æããé£çµ¡å æ å ±ãåå¥ã®ããŒãã£ãŒã«ãã«å ¥ããŸããã ãããã£ãŠã第ïŒã®å®æœåœ¢æ ã§ã¯ãé£çµ¡å ã¯ããŒãã«åã«å«ãŸããŠããã ãã®ãããªãã®ïŒ
1ã€ã®ãã£ããã§å€ãã®äœæ¥ãè¡ãå Žåãæåã®ãªãã·ã§ã³ã¯ããªãé«éã§ãã 1ã€ã®é£çµ¡å ã®ã¡ãã»ãŒãžãèªã¿æžãããå¿ èŠãããå Žåã ãã ããã¢ããªã±ãŒã·ã§ã³ã«ã¯ãæžã蟌ãããŒãã«ã䜿çšããã€ã³ããã¯ã¹ã決å®ããå€ãã®ã³ãŒããå«ãŸããŠãããããããããã¹ãŠã1ã€ã®å€§ããªããŒãã«ã«è»¢éããããšã¯è«ççã«æããŸããã ããããããã©ãŒãã³ã¹ã®åé¡ãå¿é ã§ããã ã€ã³ã¿ãŒãããã§è³ªåã®çããæ¢ããŠããå Žåããã®ãããªç¶æ³ã§ããŒã¿ãä¿åããæ¹ãè¯ãæ¹æ³ã¯æ¬¡ã®ããã«ãªããŸããã»ãšãã©ã®å Žåãçãã¯æ¬¡ã®ããã«ãªããŸãããããŒãã«ã®æ°ãå°ãªããäºåã«ç¥ã£ãŠããå Žåã¯ãããããå解ããããšããå§ãããŸãã ç°ãªãããŒãã«ã®ããŒã¿ã«é »ç¹ã«ã¢ã¯ã»ã¹ããå Žåã¯ãããããçµåããããšããå§ãããŸãã ã©ã®æ§é ãåªããŠããããæ£ç¢ºã«ç解ããããã«ãå°ããªãã¹ãã¢ããªã±ãŒã·ã§ã³ãäœæããã¯ãšãªã®é床ãæ¯èŒããŸããã 人çã®äŸãèããŠã¿ãŸãããã ãŠãŒã¶ãŒã«ã¯30件ã®é£çµ¡å ããããåèš20,000件ã®ã¡ãã»ãŒãžãä¿åãããŠããŸãã ã¢ã¯ãã£ããªãŠãŒã¶ãŒã¯ã1æ¥ã«å¹³åçŽ30ã®ã¡ãã»ãŒãžãéä¿¡ããçŽ2åã®ã¡ãã»ãŒãžãåä¿¡ããŸãã 1æ¥ã«åèš100éã®ã¡ãã»ãŒãžãã€ãŸã2äžéã¯ãçŽ6ãæã®éä¿¡ã§ãã
2ã€ã®ããŒã¿ããŒã¹ãäœæããŸãããã1ã€ã¯ããŒã¿ãç°ãªãããŒãã«ã«æ£åšããŠããããã1ã€ã¯ãã¹ãŠã1ã€ã®ããŒãã«ã«æ ŒçŽãããŠããŸãã ãã¡ã€ã«ãäœæããçŽåŸã«ãæåã®ã±ãŒã¹ã§ã¯ããŒã¿ããŒã¹ã®ãµã€ãºãã»ãŒ400 KBã§ããã2çªç®ã®ã±ãŒã¹ã§ã¯ããã32 KBã§ããããšãããããŸãã ãªããããèµ·ãã£ãŠããã®ã§ããïŒ ããŒã¿ããŒã¹ãã¡ã€ã«ã®ãµã€ãºã¯ãåžžã«ç¹å®ã®ãµã€ãºïŒããŒãžã®ãµã€ãºïŒã®åæ°ã§ãã ããŒã¿ããŒã¹ã¯ãããŒãžããšã«ããŒã¿ããŒã¹å ã«ããŒã¿ãä¿åããŸãã ããŒãžãµã€ãºã¯ãAndroidã®Pragma page_sizeã³ãã³ãã䜿çšããŠã·ã¹ãã ã§èª¿æŽã§ããŸããããã©ã«ãã§ã¯4ãããã€ãã§ãã ãã®ãã©ã¡ãŒã¿ãŒãè©Šããå¢æžãããããšããŸããã ããã¥ã¡ã³ãã«ãããšãæ倧ããŒãžãµã€ãºã¯64ãããã€ãã§ãæå°ã¯512ãã€ãã§ãã ãã®ãã©ã¡ãŒã¿ãŒãå€æŽãããšããã¹ããæªåããŸãã å®éãåãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ããŒãžãµã€ãºã¯ãã£ã¹ã¯æäœçšã«æé©åãããŠããŸãã ããŒã¿ã¯ã»ã¯ã¿ãŒããšã«èªã¿åãããããšãç¥ãããŠããããã®ããŒãžãµã€ãºã¯ãã£ã¹ã¯ã§ã®äœæ¥ã«æé©ã§ãã ãã¡ã€ã«åœ¢åŒã®è©³çŽ°ã«ã€ããŠã¯ã å ¬åŒããã¥ã¡ã³ããåç §ããŠãã ããã
ãã¹ãããŒã¿ãè¿œå ããåŸãããŒãžå ã®ãã¡ã€ã«ã®ãµã€ãºã¯èª¿æŽãããŸããããå€æ°ã®ããŒãã«ã䜿çšããã¢ãããŒãã¯å€±ãããããšãäºæ³ãããŸãã
æ¿å ¥ã®æé©å
æ¿å ¥ã®ãªãã·ã§ã³ãèŠãŠã¿ãŸãããã æã倧ãŸããªãªãã·ã§ã³ïŒãã©ã³ã¶ã¯ã·ã§ã³ãªãã§ã«ãŒãã«ã¡ãã»ãŒãžãè¿œå ãããŸããã©ã¡ãã®å Žåãããããããã5.5åããããŸãã ãã®äŸã§1ã€ã®ãã©ã³ã¶ã¯ã·ã§ã³ã§1000ã¬ã³ãŒããã°ã«ãŒãåãããšãè²»ããããæéãå€§å¹ ã«åæžãããŸãã ãã©ã³ã¶ã¯ã·ã§ã³ä»¥å€ã«äœãã§ããŸããïŒ SQLiteDatabaseã¯ã©ã¹ããinsertïŒïŒã¡ãœãããåŒã³åºããšãæ¯åããŒã¿ããŒã¹å ã«æºåæžã¿ã¹ããŒãã¡ã³ãïŒã³ã³ãã€ã«æžã¿SQLã¹ããŒãã¡ã³ãïŒãäœæãããåã¯ãšãªã«å¯ŸããŠãã®ã¹ããŒãã¡ã³ããå®è¡ãããŸãã ããã¯ããã©ãŒãã³ã¹ã®ç¹ã§ããªãã®ãªãŒããŒãããã§ãã ãããã£ãŠãæ¿å ¥ã«äœ¿çšããSQLã¹ããŒãã¡ã³ããåŒãåºãããšãã§ããŸãã æ¯åãæ°ããããŒã¿ãå ¥åããã ãã§æžã¿ãŸãã ãã®ã¢ãããŒããé©çšãããšãããã«20ïŒ ãç²åŸã§ããŸãã
ããã©ãŒãã³ã¹ãããã«åäžãããã«ã¯ãããŒã¿ããŒã¹èšå®ãå°ã調æŽããå¿ èŠããããŸãã ãã©ã³ã¶ã¯ã·ã§ã³ã®ãããã¯ã«é¢ããå°ããªæè¡çäœè«ã ããŒã¿ããŒã¹å ã®ãã©ã³ã¶ã¯ã·ã§ã³ã«ã¯ãååæ§ãäžè²«æ§ãç¬ç«æ§ãä¿¡é Œæ§ïŒ https://ru.wikipedia.org/wiki/ACID ïŒã®ããããã£ãå¿ èŠã§ãã ãããã®ããããã£ããã¹ãŠç¶æããããã«ãããŒã¿ããŒã¹ã¯ãã£ã¹ã¯äžã®ããŒã¿ããŒã¹ãã¡ã€ã«ã«çŽæ¥ãã©ã³ã¶ã¯ã·ã§ã³ãçŽæ¥æžã蟌ãããšã¯ã§ããŸããã 圌女ã¯ããã©ã³ã¶ã¯ã·ã§ã³ãã°ãšããå¥ã®æ§é ãç¶æããå¿ èŠããããŸãã ããã¯ãäžèšã®ãã©ã³ã¶ã¯ã·ã§ã³ããããã£ããµããŒãã§ããéåžžã«åŒ·åãªããŒã«ã§ãã
SQLiteã«ã¯ãã¡ã¢ãªå ãªã©ãå€ãã®èå³æ·±ããã©ã³ã¶ã¯ã·ã§ã³ãã°ã¢ãŒãããããŸãã ãã®ã¢ãŒãã§ã¯ããã©ã³ã¶ã¯ã·ã§ã³ãã°ãã¡ã¢ãªã«çŽæ¥ä¿æãããããŒã¿ããŒã¹ã®ããã©ãŒãã³ã¹ãå€§å¹ ã«åäžããŸãã ãã ãã誀ã£ãŠé»æºãåã£ãå ŽåãããŒã¿ã¯å€±ãããŸãã ãã©ã³ã¶ã¯ã·ã§ã³ãã°ã®è©³çŽ°ãã芧ãã ããã
ããŒã¿ãå®å šã«ä¿åãã2ã€ã®åäœã¢ãŒãã«é¢å¿ããããŸãã æåã¯Androidã®ããã©ã«ãã¢ãŒã-journal_modeããŒã«ããã¯ã§ãã ããã©ã°ããã䜿çšããŠæ§æãããšããjournal_mode = deleteããšããŠèšå®ãããŸãã ãã®å ŽåãããŒã¿ããŒã¹ã¯ç¹å¥ãªdb-journalãã¡ã€ã«ãäœæããŸãã äœãåé¡ãçºçããå Žåããã©ã³ã¶ã¯ã·ã§ã³ã®ããŒã«ããã¯ã«å¿ èŠãªããŒã¿ãæžã蟌ã¿ãŸãã ãŸãããã©ã³ã¶ã¯ã·ã§ã³ããŒã¿ã¯ã¡ã€ã³ããŒã¿ããŒã¹ãã¡ã€ã«ã«æžã蟌ãŸããŸãã ãã©ã³ã¶ã¯ã·ã§ã³ãæ£åžžã«å®äºãããšããžã£ãŒãã«ãã¡ã€ã«ã¯äœ¿çšãããŠããªãç¹å¥ãªãã©ã°ã§ããŒã¯ãããŸãã ãã®ã¢ãŒãã§ã¯ãããŒã¿ããŒã¹ãããŒã«ããã¯ãã¡ã€ã«ãšã¡ã€ã³ããŒã¿ããŒã¹ãã¡ã€ã«ã®2ã€ã®ãã¡ã€ã«ã«äžåºŠã«æžã蟌ãããšãéèŠã§ãã
SQLiteããŒãžã§ã³3.7ïŒAndroid API 16ïŒã¯ãæ°ãããã©ã³ã¶ã¯ã·ã§ã³ãã°ã¢ãŒããWrite Ahead Loggingãå°å ¥ããŸããã ãã®ã¢ãŒãã§ã¯ãããŒã¿ã¯ã¡ã€ã³ããŒã¿ããŒã¹ãã¡ã€ã«ã§ã¯ãªããdb-walãšããäžæãã¡ã€ã«ã«æžã蟌ãŸããŸãã ãããŠãã¢ããªã±ãŒã·ã§ã³ãã¡ã€ã³ããŒã¿ããŒã¹ãšåãæ¹æ³ã§ãããæäœã§ããããã«ãã€ã³ããã¯ã¹ä»ãã®ãã¡ã€ã«ãäœæãããŸã-db-shmã ãã®ããã«åäœããŸãã ãã©ã³ã¶ã¯ã·ã§ã³ããŒã¿ã¯ãåãããŒãžæ§é ãæã€äžæçãªWALãã¡ã€ã«ã«æžã蟌ãŸããŸãã ããŒãžæ°ãç¹å®ã®ãããå€ã«éãããšãWALãã¡ã€ã«ã®ããŒã¿ãã¡ã€ã³ããŒã¿ããŒã¹ã«è»¢éãããŸãã ãã®æç¹ã§é»æºããªãã«ãªããããŒã¿ã転éãããªãå ŽåãSQLiteã¯æ¬¡ã®èµ·åæã«ãã®ãã¡ã€ã«ãèŠã€ããæ§é ã埩å ããŸãã ãã¹ãã«é¢ããŠã¯ããã®ã¢ãŒãããªã³ã«ããŠãããã©ãŒãã³ã¹ã¯åäžããŸãã 20件ã®ãã©ã³ã¶ã¯ã·ã§ã³ãããªããããããã§å°ãåã¡ãŸãã ããããããããå€æ°ããå ŽåãããŸããŸãªãã¹ãã§å éã40ïŒ ã«éããå¯èœæ§ããããŸãã ãããã£ãŠãæ°ããã¬ãžã§ããã¢ãã«ã§walã䜿çšããã®ãè¯ã解決çã«ãªããŸãã
以äžã®ã°ã©ãã¯ãã¬ã³ãŒãã®æ¿å ¥ãã©ãã ãé«éåãããã瀺ããŠããŸãã
ãµã³ãã«ã®æé©å
ããŒã¿ã®ãµã³ããªã³ã°ãèŠãŠã¿ãŸãããã ç§ãã¡ã®ã¢ããªã±ãŒã·ã§ã³ã«ãšã£ãŠãã¢ããªã±ãŒã·ã§ã³ã¯ããŒã¿ãèªã¿åãããšãæãå€ããããããã¯ããããããéèŠã§ãã ããã§ã¯ãã»ãšãã©ã®äººããããã䜿çšããããªãæçœãªããšã説æããŸãã ãã ããå€ãã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãããã¯äŸç¶ãšããŠé¢é£ããŠããŸãã ãŸããã€ã³ããã¯ã¹ã䜿çšããå¿ èŠããããŸãã ããã¯ãããŒãã«ãšã¯å¥ã«ä¿åãããç¹å¥ãªæ§é ã§ãç¹å®ã®ããŒã®ããŒã¿ãã¡ã€ã³ããŒãã«ã®ãšã³ããªãšæ¯èŒããŸãã ã€ã³ããã¯ã¹ã䜿çšããå ŽåãDBMSã¯ãããŒãã«å šäœã®ãã«ã¹ãã£ã³ã®ä»£ããã«ãæåã«OïŒlog NïŒã®ããŒãã£ãŒã«ãã§ã€ã³ããã¯ã¹å ã®ã¬ã³ãŒãã®IDãæ€çŽ¢ãã次ã«ããŒãã«ããå¿ èŠãªããŒã¿ããã€ã³ãããšã«èªã¿åããŸãã
ãã ããã€ã³ããã¯ã¹ã䜿çšããŠããé«éåã§ãããã®ã¯ãŸã ãããããããŸãã ãã®äŸãèããŠã¿ãŸããããã¢ããªã±ãŒã·ã§ã³ãèµ·åãããšããã£ããã衚瀺ããããã«é£çµ¡å ããšã«1ã€ã®ã¡ãã»ãŒãžãèªãå¿ èŠããããŸãã åã¡ãã»ãŒãžãã«ãŒãã§åçŽã«èªã¿åãå Žåãããšãã°100åã®ç¹°ãè¿ãã§ãåèšèªã¿åãæéã¯çŽ5ã6ç§ã«ãªããŸãã åå¥ã®ãªã¯ãšã¹ãã§ã¯ãªããå¿ èŠãªããŒãåäžã®ãªã¯ãšã¹ãã«ã°ã«ãŒãåããããšããå§ãããŸãã ããšãã°ãwhereæ§é ã䜿çšããŠãidãªã¹ããæž¡ãããšãã§ããŸãã ãã ããæãå¹æçãªãªãã·ã§ã³ã¯ãã€ã³ããã¯ã¹èªäœããããŒã¿ãèªã¿åãããšã§ãã ã€ã³ããã¯ã¹ã§ã¯ã1ã€ã®ãã£ãŒã«ãã§ã¯ãªããè€æ°ã®ãã£ãŒã«ããä¿åã§ããŸãã ãã®ãããªã€ã³ããã¯ã¹ã¯è€åãšåŒã°ããŸãã ããã«ããæ¿ââå ¥ãé ããªããŸãããã€ã³ããã¯ã¹ãæ§æãããã£ãŒã«ããéžæãããšãããŒã¿ããŒã¹ã¯2ã€ã®æ§é ïŒã€ã³ããã¯ã¹ãšã¡ã€ã³ãã¡ã€ã«ïŒã§ã¯ãªããã€ã³ããã¯ã¹ã®ã¿ãèªã¿åããŸãã æ¢ã«ã€ã³ããã¯ã¹ã«ç»é²ãããŠããIDã§ããŒã¿ãååŸãããšãå€§å¹ ã«é«éåã§ããŸãã
è¯ãçµæã®ããã«æããŸãããwalãæå¹ã«ãããšãç¹å®ã®æ¡ä»¶äžã§ã¢ããªã±ãŒã·ã§ã³ãããã«é«éåã§ããŸãã ãã®çç±ã¯ããã®ã¢ãŒãã§ã¯ãæžã蟌ã¿ãšèªã¿åãã«å¥ã ã®ããŒã¿ãã£ãã«ã䜿çšãããããã§ãïŒæžã蟌ã¿ã¯èªã¿åãããããã¯ããŸããïŒ www.sqlite.org/wal.html ïŒã
ã¯ãšãªããããã°ããããã®éåžžã«äŸ¿å©ãªããŒã«ã«èšåãããããããŸããã SQLiteã«ã¯ãã¯ãšãªãã©ã³ã®èª¬æãã³ãã³ãããããŸãã ãã®ã³ãã³ãã®äŸãèããŠã¿ãŸãããã
ãã®ã¯ãšãªãå®è¡ãããšãDBãã©ãŠã¶ãŒã¯ãSQLã¯ãšãªã®å®è¡æã«DBMSãäœããããã瀺ããŸãã ãã®å ŽåãSQLiteã¯ã€ã³ããã¯ã¹ã§æ€çŽ¢ããããšãããããŸãïŒã«ããŒã€ã³ããã¯ã¹ã䜿çšïŒã ãã®ã³ãã³ãã¯ã4ã€ã®ç°ãªãçµæãè¿ãããšãã§ããŸãã
- ã¹ãã£ã³ããŒãã« -ããŒã¿ããŒã¹ã¯å šææ€çŽ¢ãããåã¬ã³ãŒããå埩åŠçããŠäžèŽãæ€çŽ¢ããŸããããã¯æãéå¹ççãªãªãã·ã§ã³ã§ãã
- ã€ã³ããã¯ã¹ã䜿çšããæ€çŽ¢ããŒãã« -ã¬ã³ãŒãã®æ€çŽ¢ã«å¿ èŠãªã€ã³ããã¯ã¹ã¯ãããŸãããæ€çŽ¢ããŒã¿ã¯å«ãŸããŸããã
- ã«ããŒã€ã³ããã¯ã¹ã䜿çšããæ€çŽ¢ããŒãã« -æãå¹æçãªã±ãŒã¹ã¯ãæ€çŽ¢ãããããŒã¿ãæ¢ã«ã€ã³ããã¯ã¹ã«ããããšã§ãã
- äžæB-TREEã䜿çšãã-ã¯ãšãªã§äžŠã¹æ¿ãã¿ã€ãã®æ§é ã䜿çšãããã®ãã£ãŒã«ãã«ã€ã³ããã¯ã¹ããªãå Žåãã»ãšãã©ã®å ŽåãããŒã¿ããŒã¹ã¯ä»¥äžãå®è¡ããå¿ èŠããããŸãïŒåºæºãæºãããã¹ãŠã®ã¬ã³ãŒããååŸãããœãŒãçšã®ã¡ã¢ãªã«ããªãŒãæ§ç¯ãã®ããŒã¿ã ããã¯éåžžãé ãããã»ã¹ã§ãã äœããã°ã«ãŒãåãŸãã¯æŽçããå¿ èŠãããå Žåã¯ããã®ãã£ãŒã«ãã«ã€ã³ããã¯ã¹ãä¿æããããšããå§ãããŸãã
ç¹°ãè¿ããŸããããexplain query planãã䜿çšããŠæé©åããåã¯ãšãªãå®è¡ããããŒã¿ããŒã¹ã®æ©èœã確èªããããšããå§ãããŸãã 次ã«ã移è¡ã«ç§»ããŸããããŒã¿ã倱ããªãããã«ãããã°ãæ§é ãåäžã®ããŒã¿ããŒã¹ã«è»¢éããå¿ èŠããããŸãã
å€ãã®å Žåãå€ãã¯SQLiteOpenHelperã¯ã©ã¹ã䜿çšããŸããããã«ãããããŒã¿ããŒã¹ã®ããŒãžã§ã³ã®å€æŽã远跡ããonUpgradeã¡ãœããã§æ§é ãå€æŽããã³ãŒããå®è¡ã§ããŸãã ãã®ã¡ãœããã¯ãåäžã®ãã©ã³ã¶ã¯ã·ã§ã³å ã§åŒã³åºããããšèšããªããã°ãªããŸããã onUpgradeã¡ãœããã§ããŒã¿ãã³ããŒããããšããããäŸå€ãã¹ããŒããå¯èœæ§ã®ããè€éãªã¢ã¯ã·ã§ã³ãå®è¡ããããšãããšãäœãæŽæ°ãããªããªã¹ã¯ãçºçããŸãã ãã®æ¹æ³ã¯ãæ§é ãå€æŽããå Žåã«ã®ã¿äœ¿çšããããšããå§ãããŸãã ããŒã¿èªäœã転éããã«ã¯ãå¥ã®ã¡ãœãããåŒã³åºãããšããå§ãããŸãã
ãšããã§ãã¢ããã°ã¬ãŒãã®1ã€ã§ãæ®å¿µãªãã¹ããããŸããã SQLã³ãŒãã§å®æ°ã䜿çšããŸããããããæç¹ã§å®æ°ãå€æŽãããŸããã ãããŠãæ§é ãã¢ããã°ã¬ãŒãããããšããã¢ããªã±ãŒã·ã§ã³ã®ããŒãžã§ã³ã¯ãå€ãããŒãã«åãšãã£ãŒã«ãåã§èªç¶ã«æ©èœããŸããã åæã«ã以åã®ããŒãžã§ã³ããã®çŸåšã®ã¢ããã°ã¬ãŒãã§ã¯ã³ãŒãã§ãã¹ãŠãæ©èœããŸããããå®æ°ãå€æŽãããããå幎ããã®ã¢ããã°ã¬ãŒãã§ã¯æ©èœããŸããã§ããããšã©ãŒãæ¢ãå Žæã¯å®å šã«äžæã§ãã ãã®ãããSQLã¯ãšãªã§å®æ°ã䜿çšããªãããšã«ããŸããã
ããŒã¿ããŒã¹æ§é ãæŽæ°ããåŸãããŸããŸãªå€ãããŒã¿ããŒã¹ãã倧éã®ã¬ã³ãŒããã³ããŒããå¿ èŠããããŸããã æãç°¡åãªè§£æ±ºçã¯ãå€ãããŒã¿ããã¹ãŠã«ãŒãœã«ã«èªã¿èŸŒã¿ãåã¬ã³ãŒãã解æããŠæ°ããããŒã¿ããŒã¹ã«è¿œå ããããšã§ãããããã¯éåžžã«é ãã§ãã æ°äžã¡ãã»ãŒãžã®é·ãéä¿¡å±¥æŽãããå Žåããã®ããã»ã¹ã«ã¯æ°ç§ããããŸãã ãŠãŒã¶ãŒã¯éå±ãå§ããŸããã¢ããªã±ãŒã·ã§ã³ããã³ã°ãããšæããããããŸããããææªã®å Žåããããå®å šã«æåŠããŸãã ãããã£ãŠããã®æé ãä¿é²ããããšãéèŠã§ããã SQLiteã«ã¯éåžžã«äŸ¿å©ãªãããŒã¿ããŒã¹ã®æ¥ç¶ãã³ãã³ããããããµãŒãããŒãã£ã®ããŒã¿ããŒã¹ãããŒã¿ããŒã¹ã«æ¥ç¶ã§ããããšãããããŸããã æ¥ç¶ãããããŒã¿ããŒã¹ããããŒãã«ã«ã¢ã¯ã»ã¹ããã«ã¯ãããŒã¿ããŒã¹åãããŒãã«åã«è¿œå ããã ãã§ãã ãããã£ãŠã解æããã«SQLiteããŒã«ã移è¡ã«äœ¿çšã§ããŸãã
ãã®ã¢ãããŒãã«ã¯ããã€ãã®å¶éããããŸãã SQLiteã®æ¡åŒµæ©èœã§ããAttach databaseã³ãã³ãèªäœã¯ãã©ã³ã¶ã¯ã·ã§ã³å ã§ã¯æ©èœããªããããonUpgradeã¡ãœããå ã§åŒã³åºãããšã¯ã§ããŸããã ããã«ãAttachããŒã¿ããŒã¹å ã®ãã©ã³ã¶ã¯ã·ã§ã³ã¯ã1ã€ã®ããŒã¿ããŒã¹ãžã®ã¯ãšãªã§ã®ã¿æ©èœããŸãã ãã®ããŒãžã§ã³ã§ã¯ãè€æ°ã®ããŒã¿ããŒã¹ã1ã€ã«ããŒãžããå¿ èŠãããå ŽåãåããŒã¿ããŒã¹ã䜿çšããŠãã©ã³ã¶ã¯ã·ã§ã³ãäœæããå¿ èŠããããŸããã ããããã«ãŒãœã«ãããã¯ããã«é«éã«åäœãããã¹ãŠã®ããŒã¿ã1ç§æªæºã§æ£ç¢ºã«è»¢éã§ããŸãã
ãŸããã¢ããã°ã¬ãŒãåŸã¯ãWALãªã©ã®ããŒã¿ããŒã¹ãæäœããå¹æçãªã¢ãŒããæå¹ã«ããããšãæ€èšããŠãã ããã ã¢ããªã±ãŒã·ã§ã³ãå€ãAPIããµããŒãããŠããå ŽåãçŸåšã®APIãããŒãžã§ã³16ãããé«ãããšã確èªããå¿ èŠããããŸãã
ããŒã¿ããŒã¹å ã®ããŒã¿ã®æé©åãå®è¡ããããšã圹ç«ã¡ãŸãã SQLiteã«ã¯éåžžã«äŸ¿å©ãªç空ã³ãã³ãããããæªäœ¿çšã®ããŒãžããã¹ãŠåé€ããŠããŒã¿ãæé©åã§ããŸãã deleteã³ãã³ããå®è¡ããã ãã§ããã£ã¹ã¯ã®ããŒã¿ãç©ççã«åé€ããããã¬ã³ãŒããŸãã¯ããŒãžå šäœãåé€æžã¿ãšããŠããŒã¯ãããããšã¯ç§å¯ã§ã¯ãããŸããã ãã®ã³ãã³ãã䜿çšãããšãæªäœ¿çšã®ãã©ã°ã¡ã³ããåé€ããã€ã³ããã¯ã¹ãåæ§ç¯ã§ããŸãã
ãããã«
ãã®ããããã®èšäºã§ã¯ãICQã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ã®äŸã䜿çšããŠãããŒã¿ããŒã¹æé©åãžã®ããã€ãã®ã¢ãããŒããæ€èšããŸããã ãã¡ãããã»ãŒãã¹ãŠã®æšå¥šäºé ã¯www.sqlite.orgããã³ãã®ä»ã®ããŒããªãœãŒã¹ã§èŠã€ããããšãã§ããŸãããç¹å®ã®åé¡ã解決ãããšãDBMSã®è žã§äœãèµ·ãã£ãŠããããæ£ç¢ºã«ç解ã§ããŸãã