SQLiteÊý¾Ý¿âµÄÌåϵ½á¹¹(·Òë×Ôsqlite.org)
SQLiteÊý¾Ý¿âµÄÌåϵ½á¹¹(·Òë×Ôsqlite.org)
1 ¼ò½é
±¾ÎĵµÃèÊöÁËSQLite¿âµÄÌåϵ½á¹¹£¬ÕâЩÐÅÏ¢¶ÔÄÇЩÏëÀí½âºÍÐÞ¸ÄSQLiteµÄÄÚ²¿¹¤×÷»úÖƵÄÈËÊÇÓÐÓõġ£
±¾ÎĵµÃèÊöSQLite 3.0°æ±¾£¬2.8°æ»ò¸üÔçÆڵİ汾Óë´ËÏàËÆ£¬Ö»ÊÇϸ½ÚÉÏÓÐËù²»Í¬¡£
2 ½Ó¿Ú
ËäÈ»ÓÐЩº¯Êý·Ö²¼ÔÚÆäËüµÄÎļþÖУ¬µ«ÊÇÖ÷ÒªµÄSQLite¿âµÄ¹«Óýӿں¯ÊýÊÇÔÚmain.c£¬legacy.cºÍvdbeapi.cÔ´´úÂëÎļþÖÐʵÏֵġ£
sqlite3_get_table()º¯ÊýÔÚtable.cÖÐʵÏÖ£¬sqlite3_mprintf()ÔÚprintf.cÖÐʵÏÖ£¬sqlite3_complete()ÊÇÔÚtokenize.cÖÐʵÏֵġ£Tcl½Ó¿Ú
ÔÚtclsqlite.cÖÐʵÏֵġ£¹ØÓÚSQLiteµÄC½Ó¿Ú¸üÍêÕûµÄÐÅÏ¢ÔÚhttp://www.sqlite.org/capi3ref.htmlÖÐÃèÊöÁË¡£
Ϊ±ÜÃâºÍÆäËüÈí¼þµÄÃüÃû³åÍ»£¬SQLite¿âÖÐËùÓеÄÍⲿ·ûºÅ¶¼ÒÔsqlite3Ϊǰ׺¡£ÕâЩ·ûºÅÄ¿µÄ¾ÍÊÇΪÍⲿʹÓ㬻»¾ä»°Ëµ£¬ËùÓÐÒÔ
sqlite3_¿ªÊ¼µÄ·ûºÅ£¬ÐγÉÁËSQLiteµÄAPI¡£
3 ´Ê·¨·ÖÎöÆ÷
µ±Ò»¸öSQLÓï¾äÖ´ÐÐʱ£¬½Ó¿ÚÊ×ÏÈ°Ñ°üº¬¸ÃSQLÓï¾äµÄ×Ö·û´®´«¸ø´Ê·¨·ÖÎöÆ÷À´½øÐд¦Àí¡£´Ê·¨·ÖÎöÆ÷¸ºÔð°Ñ×Ö·û´®·Ö³ÉÒ»¸öÒ»¸öµÄ´Ê·¨µ¥
Ôª£¬È»ºó°Ñ´Ê·¨µ¥Ôª´«µÝ¸øÓï·¨·ÖÎöÆ÷£¬´Ê·¨·ÖÎöÆ÷ÊÇÔÚtokenize.cÎļþÖÐʵÏÖ£¬Õâ¸ö´úÂëÊÇÊÖ±àµÄ£¬¶ø²»ÊÇʹÓÃlexÖ®ÀàµÄ¹¤¾ßÉú³ÉµÄ¡£
ÐèҪעÒâµÄÊÇ£¬ÔÚ±¾Éè¼ÆÖУ¬´Ê·¨·ÖÎöÆ÷µ÷ÓÃÓï·¨·ÖÎöÆ÷£¬ÊìϤYACCºÍBISONµÄÈËÒ»°ã×ÜÊÇÔÚÓï·¨·ÖÎöÆ÷Öе÷Óôʷ¨·ÖÎöÆ÷£¬SQLiteµÄ×÷Õß
ÕâÁ½ÖÖ·½·¨¶¼ÊÔ¹ý£¬·¢ÏÖÔÚ´Ê·¨·ÖÎöÆ÷Öе÷ÓÃÓï·¨·ÖÎöÆ÷¸üºÃ¡£
4 Óï·¨·ÖÎöÆ÷
Óï·¨·ÖÎöÆ÷¸ù¾ÝÉÏÏÂÎĶԴʷ¨·ÖÎö³öÀ´µÄµ¥ÔªÀí½âÆäºÒå¡£SQLiteµÄÓï·¨·ÖÎöÆ÷ÊÇʹÓÃLemon(http://www.hwaci.com/sw/lemon/)µÄLALR
(1)¹¤¾ß²úÉúÆ÷Éú³ÉµÄ¡£LemonºÍYACC/BISON¹¤¾ß²î²»¶à£¬µ«ÊÇLemonʹÓÃÒ»ÖÖ²»Í¬µÄÊäÈëÓï·¨£¬ÕâÖÖÓï·¨¸üÄÑÒÔ³ö´í¡£LemonÄܲúÉúÒ»¸ö¿ÉÖØÈë
ºÍḬ̈߳²È«µÄÓï·¨·ÖÎöÆ÷£¬Lemon¶¨ÒåÁËÒ»ÖÖ·ÇÖÕ½á·ûÎö¹¹Æ÷£¬ÒÔÖÂÔÚÓï·¨³öÏÖ´íÎóʱ²»ÖÁÓÚ³öÏÖÄÚ´æй©¡£Lemon·ÖÎöÆ÷µÄÊäÈëÎļþÔÚparse.y
Öж¨Òå¡£
ÓÉÓÚLemon²»ÊÇÒ»¸ö³£¼ûµÄ³ÌÐò£¬ÆäÍêÕûµÄÔ´´úÂë½öÒ»¸öCÎļþÔÚSQLiteµÄtool×ÓĿ¼ÖС£LemonµÄÎĵµÔÚdoc×ÓĿ¼ÖС£
5 ´úÂëÉú³ÉÆ÷
ÔÚÓï·¨·ÖÎöÆ÷·ÖÎöÍêSQLÓï¾äºó£¬Ëüµ÷ÓôúÂëÉú³ÉÆ÷À´Éú³ÉÔÚÐéÄâ»úÉÏÖ´ÐеĴúÂ룬ÕâЩ´úÂëµÄÖ´ÐÐÊÇ°´ÕÕSQLÓï¾äµÄÒªÇóÀ´Ö´Ðеġ£´úÂ
Ïà¹ØÎĵµ£º
SQLite°üº¬ÁËÈçÏÂʱ¼ä/ÈÕÆÚº¯Êý£º
datetime().......................²úÉúÈÕÆÚºÍʱ¼ä
date()...........................²úÉúÈÕÆÚ
time()...........................²úÉúʱ¼ä
strftime().......................¶ÔÒÔÉÏÈý¸öº¯Êý²úÉúµÄÈÕÆÚºÍʱ¼ä½øÐиñʽ»¯
datetime()µÄÓ÷¨ÊÇ£ºdatetime(ÈÕÆÚ/ʱ¼ä,ÐÞÕý·û,ÐÞÕý·û...)
......
SQLiteѧϰ±Ê¼Ç
1.²é¿´ÓÐÄÄЩÊý¾Ý¿â,ÏÔʾÊý¾Ý¿âÁбí
show databases;
2.ÏÔʾ±íµÄ½á¹¹
·½·¨Ò»£º
use student;
describe student;
·½·¨¶þ£º
des student.student;
·½·¨Èý£º
show columns from student;
3.ÏÔʾMYSQLµÄ°æ±¾
select version();
4.ÏÔʾ¿âÖеÄÊý¾Ý±í
use mysql;
show tables;
5.½¨¿â
......
1¡¢.back ?DB? FILE ±¸·ÝDB(ĬÈÏΪmain)µ½Îļþ
2¡¢.bail ON|OFF Óöµ½Ò»¸ö´íÎó¿ÛÍ£Ö¹£¬¸ÃֵĬÈÏΪOFF
3¡¢.databases Áоٸ½¼Óµ½Êý¾Ý¿âµÄÊý¾Ý¿âÃûºÍÎļþÃû
4¡¢.dump ?TABLE? ... ÓÃSQLÎı¾¸ñʽÁоÙÊý¾Ý¿â£¬Èç¹ûÖ¸¶¨TABLE£¬½ö½öÁоÙÆ¥ÅäµÄ±í£¬LIKEÀàÐÍTABLE
5¡¢.echo ON|OFF ÉèÖÃechoµÄ״̬ ......
¿ÉÒÔ½Ó×ÅÉÏÒ»²½²Ù×÷£¬Ö±½ÓÏòDOS´°¿ÚÊäÈë.helpÃüÁîÀ´²é¿´SQLiteµÄËùÓÐÃüÁîÐм°½âÊÍÈçÏ£º
F:\>sqlite3
SQLite version 3.6.16
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .help
Ò²¿ÉÒÔctrl+c½áÊøÃüÁÏëDOS´°¿Ú ÊäÈësqlite3Ö´ÐкóÔÙÊäÈë.helpÃüÁîÈçÏ£º
F:\>sqli ......
SQLiteÇý¶¯Ö§³ÖµÄSQL ÁÐÀàÐÍ
ÀàÐÍÃèÊö
TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB, BYTEA
²»ÏÞÖƳ¤¶ÈµÄ×Ö·û´®ÀàÐÍ. ¶þ½øÖÆÊý¾Ý±ØÐ밲ȫµØ±àÂë´æ´¢, ¼ûtextÀàÐÍ.
CHAR(), VARCHAR(), TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT
²»ÏÞÖƳ¤¶ÈµÄ×Ö·û´®ÀàÐÍ. ²»»á±»½Ø¶Ï»òÕßÌî³ä
ENUM
²»ÏÞÖƳ¤¶ÈµÄ×Ö·û´®ÀàÐÍ. ²»Ïñ MySQL, ʹÓà ......