现在的位置: 首页 > 综合 > 正文

sqlite 句柄-sqlite 基础教程(3)

2013年06月04日 ⁄ 综合 ⁄ 共 4694字 ⁄ 字号 评论关闭
分类: IOS开发(所有IOS文章) ---sqlite(IOS) C/C++ 2457人阅读 评论(2) 收藏 举报

声明

欢迎转载,但是请尊重作者劳动成果,转载请保留此框内声明,谢谢。
文章出处:http://blog.csdn.net/iukey

要操纵一个数据库你就得有一个这个数据库的句柄(又碰到这个难以理解的词了,不过确实还没得一个更好的词来替代它)。其实你跟本不需要去在乎这个词叫什么,你只要搞清楚他是一个什么玩意儿。就如同鞋子为什么叫鞋子,仔细想想确实也难以理解,不过 清楚他的功能就OK了,不是吗?

句柄在很多地方我们见到过,最常见的就是文件的句柄,我们要操纵一个文件,我们就要取得一个文件的句柄。句柄是个什么东东呢?其实很简单,句柄是一个东东的描述,他被定义为一个结构体,这个结构体可能会包含要描述的东东的具体信息,比如位置、大小、类型等等。我们有了这个描述信息我们就能去找到这个东东,然后操纵它。

一句话:句柄是物体的描述结构体。

我们来看看sqlite的句柄是怎么定义的(不要被吓到了,代码直接跳过就好):

  1. struct sqlite3 {  
  2.   sqlite3_vfs *pVfs;            /* OS Interface */  
  3.   int nDb;                      /* Number of backends currently in use */  
  4.   Db *aDb;                      /* All backends */  
  5.   int flags;                    /* Miscellaneous flags. See below */  
  6.   unsigned int openFlags;       /* Flags passed to sqlite3_vfs.xOpen() */  
  7.   int errCode;                  /* Most recent error code (SQLITE_*) */  
  8.   int errMask;                  /* & result codes with this before returning */  
  9.   u8 autoCommit;                /* The auto-commit flag. */  
  10.   u8 temp_store;                /* 1: file 2: memory 0: default */  
  11.   u8 mallocFailed;              /* True if we have seen a malloc failure */  
  12.   u8 dfltLockMode;              /* Default locking-mode for attached dbs */  
  13.   signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */  
  14.   u8 suppressErr;               /* Do not issue error messages if true */  
  15.   u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */  
  16.   int nextPagesize;             /* Pagesize after VACUUM if >0 */  
  17.   int nTable;                   /* Number of tables in the database */  
  18.   CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */  
  19.   i64 lastRowid;                /* ROWID of most recent insert (see above) */  
  20.   u32 magic;                    /* Magic number for detect library misuse */  
  21.   int nChange;                  /* Value returned by sqlite3_changes() */  
  22.   int nTotalChange;             /* Value returned by sqlite3_total_changes() */  
  23.   sqlite3_mutex *mutex;         /* Connection mutex */  
  24.   int aLimit[SQLITE_N_LIMIT];   /* Limits */  
  25.   struct sqlite3InitInfo {      /* Information used during initialization */  
  26.     int iDb;                    /* When back is being initialized */  
  27.     int newTnum;                /* Rootpage of table being initialized */  
  28.     u8 busy;                    /* TRUE if currently initializing */  
  29.     u8 orphanTrigger;           /* Last statement is orphaned TEMP trigger */  
  30.   } init;  
  31.   int nExtension;               /* Number of loaded extensions */  
  32.   void **aExtension;            /* Array of shared library handles */  
  33.   struct Vdbe *pVdbe;           /* List of active virtual machines */  
  34.   int activeVdbeCnt;            /* Number of VDBEs currently executing */  
  35.   int writeVdbeCnt;             /* Number of active VDBEs that are writing */  
  36.   int vdbeExecCnt;              /* Number of nested calls to VdbeExec() */  
  37.   void (*xTrace)(void*,const char*);        /* Trace function */  
  38.   void *pTraceArg;                          /* Argument to the trace function */  
  39.   void (*xProfile)(void*,const char*,u64);  /* Profiling function */  
  40.   void *pProfileArg;                        /* Argument to profile function */  
  41.   void *pCommitArg;                 /* Argument to xCommitCallback() */     
  42.   int (*xCommitCallback)(void*);    /* Invoked at every commit. */  
  43.   void *pRollbackArg;               /* Argument to xRollbackCallback() */     
  44.   void (*xRollbackCallback)(void*); /* Invoked at every commit. */  
  45.   void *pUpdateArg;  
  46.   void (*xUpdateCallback)(void*,intconst char*,const char*,sqlite_int64);  
  47. #ifndef SQLITE_OMIT_WAL  
  48.   int (*xWalCallback)(void *, sqlite3 *, const char *, int);  
  49.   void *pWalArg;  
  50. #endif  
  51.   void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);  
  52.   void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);  
  53.   void *pCollNeededArg;  
  54.   sqlite3_value *pErr;          /* Most recent error message */  
  55.   char *zErrMsg;                /* Most recent error message (UTF-8 encoded) */  
  56.   char *zErrMsg16;              /* Most recent error message (UTF-16 encoded) */  
  57.   union {  
  58.     volatile int isInterrupted; /* True if sqlite3_interrupt has been called */  
  59.     double notUsed1;            /* Spacer */  
  60.   } u1;  
  61.   Lookaside lookaside;          /* Lookaside malloc configuration */  
  62. #ifndef SQLITE_OMIT_AUTHORIZATION  
  63.   int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);  
  64.                                 /* Access authorization function */  
  65.   void *pAuthArg;               /* 1st argument to the access auth function */  
  66. #endif  
  67. #ifndef SQLITE

抱歉!评论已关闭.