SQLiteÓï·¨ PRAGMA
SQLiteÖ§³ÖµÄ±àÒëÖ¸Áî(pragma)
PRAGMAÃüÁî
ÊÇÓÃÓÚÐÞ¸ÄSQlite¿â»ò²éѯSQLite¿âÄÚ²¿Êý¾Ý(non-table)µÄÌØÊâÃüÁî¡£PRAGMA ÃüÁîʹÓÃÓëÆäËüSQLiteÃüÁî(e.g. SELECT, INSERT)ÏàͬµÄ½Ó¿Ú£¬µ«ÔÚÈçÏÂÖØÒª·½ÃæÓëÆäËüÃüÁͬ:
ÔÚδÀ´µÄSQLite°æ±¾Öв¿·Öpragma¿ÉÄܱ»É¾³ý»òÌí¼Ó£¬Ð¡ÐÄʹÓá£
µ±Ê¹ÓÃδ֪µÄpragmaÓï¾äʱ²»²úÉú±¨´í¡£Î´ÖªµÄpragma½ö½ö»á±»ºöÂÔ£¬¼´ÊÇ˵ÈôÊÇ´ò´íÁËpragmaÓï¾äSQLite²»»áÌáʾÓû§¡£
һЩpragmaÔÚSQL±àÒë½×¶ÎÉúЧ¶ø·ÇÖ´Ðн׶Ρ£¼´ÊÇ˵ÈôʹÓÃCÓïÑÔµÄsqlite3_compile(),
sqlite3_step(), sqlite3_finalize() API
(»òÀàËƵķâ×°½Ó¿ÚÖÐ)£¬pragma¿ÉÄÜÔÚµ÷ÓÃsqlite3_compile()ÆÚ¼äÆð×÷Óá£
pragmaÃüÁî²»ÓëÆäËüSQLÒýÇæ¼æÈÝ¡£
¿ÉÓõÄpragmaÃüÁîÓÐÈçÏÂËĸö»ù±¾ÀàÐÍ£º
ÓÃÓڲ쿴µ±Ç°Êý¾Ý¿âµÄģʽ
¡£
ÓÃÓÚÐÞ¸ÄSQLite¿âµÄ²Ù×÷
»ò²éѯµ±Ç°µÄ²Ù×÷ģʽ¡£
ÓÃÓÚ²éѯ»òÐÞ¸ÄÁ½¸öÊý¾Ý¿âµÄ°æ±¾ºÅ
£¬schema-versionºÍuser-version.
ÓÃÓÚµ÷ÊÔ¿â
ºÍУÑéÊý¾Ý¿âÎļþ¡£
PRAGMAÃüÁîÓï·¨
sql-statement
::=
PRAGMA
name
[=
value
]
|
PRAGMA
function
(
arg
)
ʹÓÃÕûÊýÖµvalue
µÄpragmaÒ²¿ÉÒÔʹÓ÷ûºÅ±íʾ£¬×Ö·û´®"on
", "true
",ºÍ "yes
" µÈͬÓÚ1
£¬"off
", "false
",ºÍ "no
"µÈͬÓÚ0
. ÕâЩ×Ö·û´®´óСд²»Ãô¸ÐÇÒÎÞÐë½øÐÐÒýÓá£ÎÞ·¨Ê¶±ðµÄ×Ö·û´®±»µ±×÷1
ÇÒ²»»á±¨´í¡£value
·µ»ØʱÊÇÕûÊý¡£
ÓÃÓÚÐÞ¸ÄSQLite¿âµÄ²Ù×÷µÄPragma
PRAGMA auto_vacuum;
PRAGMA auto_vacuum =
0 | 1
;
²éѯ»òÉèÖÃÊý¾Ý¿âµÄauto-vacuum±ê¼Ç¡£
Õý³£Çé¿öÏ£¬µ±Ìá½»Ò»¸ö´ÓÊý¾Ý¿âÖÐɾ³ýÊý¾ÝµÄÊÂÎñʱ£¬Êý¾Ý¿âÎļþ²»¸Ä±ä´óС¡£Î´Ê¹ÓõÄÎļþÒ³±»±ê¼Ç²¢ÔÚÒÔºóµÄÌí¼Ó²Ù×÷ÖÐ ÔÙ´ÎʹÓá£ÕâÖÖÇé¿öÏÂʹÓÃVACUUM
ÃüÁîÊÍ·Åɾ³ýµÃµ½µÄ¿Õ¼ä¡£
µ±¿ªÆôauto-vacuum£¬µ±Ìá½»Ò»¸ö´ÓÊý¾Ý¿âÖÐɾ³ýÊý¾ÝµÄÊÂÎñʱ£¬Êý¾Ý¿âÎļþ×Ô¶¯ÊÕËõ£¬ (VACUUMÃüÁîÔÚauto-vacuum¿ªÆôµÄÊý¾Ý¿âÖв»Æð×÷ÓÃ)¡£Êý¾Ý¿â»áÔÚÄÚ²¿´æ´¢Ò»Ð©ÐÅÏ¢ÒÔ±ãÖ§³ÖÕâÒ»¹¦ÄÜ£¬ÕâʹµÃ Êý¾Ý¿âÎļþ±È²»¿ªÆô¸ÃÑ¡ÏîʱÉÔ΢´óһЩ¡£
Ö»ÓÐÔÚÊý¾Ý¿âÖÐ佨Èκαíʱ²ÅÄܸıäauto-vacuum±ê¼Ç¡£ÊÔͼÔÚÒÑÓбíµÄÇé¿öÏÂÐ޸IJ»»áµ¼Ö±¨´í¡£
PRAGMA cache_size;
PRAGMA cache_size =
Number-of-pages
;
²éѯ»òÐÞ¸ÄSQLiteÒ»´Î´æ´¢ÔÚÄÚ´æÖеÄÊý¾Ý¿âÎļþÒ³Êý¡£Ã¿Ò³Ê¹ÓÃÔ¼1.5KÄڴ棬ȱʡµÄ»º´æ´óСÊÇ2000. ÈôÐèҪʹÓøıä´óÁ¿¶àÐеÄU
Ïà¹ØÎĵµ£º
SQLiteÊý¾Ý¿âµÄÌåϵ½á¹¹(·Òë×Ôsqlite.org)
1 ¼ò½é
±¾ÎĵµÃèÊöÁËSQLite¿âµÄÌåϵ½á¹¹£¬ÕâЩÐÅÏ¢¶ÔÄÇЩÏëÀí½âºÍÐÞ¸ÄSQLiteµÄÄÚ²¿¹¤×÷»úÖƵÄÈËÊÇÓÐÓõġ£
±¾ÎĵµÃèÊöSQLite 3.0°æ±¾£¬2.8°æ»ò¸üÔçÆڵİ汾Óë´ËÏàËÆ£¬Ö»ÊÇϸ½ÚÉÏÓÐËù²»Í¬¡£
2 ½Ó¿Ú
......
dbAccess.js
import System.Data; // we import our data class
import Mono.Data.SqliteClient; // we import our sqlite client
class dbAccess {
// variables for basic query access
private var connection : String;
private var dbcon : IDbConnection;
private ......
1¡¢ÈçºÎµÃµ½×îºó²åÈëÏîµÄ×Ô¶¯Ôö³¤IDÖµ£¿ ¶ÔÓ¦µÄC#´úÂë¶ÎÈçÏ£º
using (SQLiteConnection cn = new SQLiteConnection (¡°data source = Test.db¡±))
{
cn.Open ();
SQLiteCommand cmd = new SQLiteCommand ......
sqlite3 *db;
sqlite3_stmt *stat;
char
*zErrMsg = 0;
char
temp[256], FileRoot[256];
char
buffer2[1024]="0";
sprintf(temp, _T("%s"), _T("utf.db")) ......
½ñÌìµÄѧϰÄÚÈÝÊÇsqliteºÍPDO mysql¡£
ÓÃ×Ô¼ºµÄ»°ËµËµÁ½¸ö¶«Î÷°É£º
sqliteËãÊÇÒ»ÖÖ²»ÏµÍ³µÄÊý¾Ý¿â´æ´¢·½Ê½£¬ËüµÄ´æ·Å¸ñʽÊÇÒ»¸ö.dbºó׺µÄÎļþ£¬ÔÚphpÖÐËü´æ·ÅÔÚµ±Ç°µÄĿ¼Ï£¬Ã²ËƲ»ÓÃÓû§ÃûÃÜÂ룬°²È«ÐԽϵͣ¬È´±È½Ï·½±ã¡£PHP5ÖÐ×Ô´øµÄһЩϵͳº¯Êý£¬¶¼ÊÇÒÔsqlite_¿ªÍ·µÄ¡£
PDOÈ«³ÆPHP Data Object£¬¹ËÃû˼Òå¾ÍÊÇPHPµÄÒ ......