⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 sqlite数据库管理系统开放源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    sqliteResetInternalSchema(db, 0);  }  assert( ppVm );  *ppVm = (sqlite_vm*)sParse.pVdbe;  if( pzTail ) *pzTail = sParse.zTail;  if( sqliteSafetyOff(db) ) goto exec_misuse;  return sParse.rc;exec_misuse:  if( pzErrMsg ){    *pzErrMsg = 0;    sqliteSetString(pzErrMsg, sqlite_error_string(SQLITE_MISUSE), (char*)0);    sqliteStrRealloc(pzErrMsg);  }  return SQLITE_MISUSE;}/*** The following routine destroys a virtual machine that is created by** the sqlite_compile() routine.**** The integer returned is an SQLITE_ success/failure code that describes** the result of executing the virtual machine.  An error message is** written into memory obtained from malloc and *pzErrMsg is made to** point to that error if pzErrMsg is not NULL.  The calling routine** should use sqlite_freemem() to delete the message when it has finished** with it.*/int sqlite_finalize(  sqlite_vm *pVm,            /* The virtual machine to be destroyed */  char **pzErrMsg            /* OUT: Write error messages here */){  int rc = sqliteVdbeFinalize((Vdbe*)pVm, pzErrMsg);  sqliteStrRealloc(pzErrMsg);  return rc;}/*** Terminate the current execution of a virtual machine then** reset the virtual machine back to its starting state so that it** can be reused.  Any error message resulting from the prior execution** is written into *pzErrMsg.  A success code from the prior execution** is returned.*/int sqlite_reset(  sqlite_vm *pVm,            /* The virtual machine to be destroyed */  char **pzErrMsg            /* OUT: Write error messages here */){  int rc = sqliteVdbeReset((Vdbe*)pVm, pzErrMsg);  sqliteVdbeMakeReady((Vdbe*)pVm, -1, 0);  sqliteStrRealloc(pzErrMsg);  return rc;}/*** Return a static string that describes the kind of error specified in the** argument.*/const char *sqlite_error_string(int rc){  const char *z;  switch( rc ){    case SQLITE_OK:         z = "not an error";                          break;    case SQLITE_ERROR:      z = "SQL logic error or missing database";   break;    case SQLITE_INTERNAL:   z = "internal SQLite implementation flaw";   break;    case SQLITE_PERM:       z = "access permission denied";              break;    case SQLITE_ABORT:      z = "callback requested query abort";        break;    case SQLITE_BUSY:       z = "database is locked";                    break;    case SQLITE_LOCKED:     z = "database table is locked";              break;    case SQLITE_NOMEM:      z = "out of memory";                         break;    case SQLITE_READONLY:   z = "attempt to write a readonly database";  break;    case SQLITE_INTERRUPT:  z = "interrupted";                           break;    case SQLITE_IOERR:      z = "disk I/O error";                        break;    case SQLITE_CORRUPT:    z = "database disk image is malformed";      break;    case SQLITE_NOTFOUND:   z = "table or record not found";             break;    case SQLITE_FULL:       z = "database is full";                      break;    case SQLITE_CANTOPEN:   z = "unable to open database file";          break;    case SQLITE_PROTOCOL:   z = "database locking protocol failure";     break;    case SQLITE_EMPTY:      z = "table contains no data";                break;    case SQLITE_SCHEMA:     z = "database schema has changed";           break;    case SQLITE_TOOBIG:     z = "too much data for one table row";       break;    case SQLITE_CONSTRAINT: z = "constraint failed";                     break;    case SQLITE_MISMATCH:   z = "datatype mismatch";                     break;    case SQLITE_MISUSE:     z = "library routine called out of sequence";break;    case SQLITE_NOLFS:      z = "kernel lacks large file support";       break;    case SQLITE_AUTH:       z = "authorization denied";                  break;    case SQLITE_FORMAT:     z = "auxiliary database format error";       break;    case SQLITE_RANGE:      z = "bind index out of range";               break;    case SQLITE_NOTADB:     z = "file is encrypted or is not a database";break;    default:                z = "unknown error";                         break;  }  return z;}/*** This routine implements a busy callback that sleeps and tries** again until a timeout value is reached.  The timeout value is** an integer number of milliseconds passed in as the first** argument.*/static int sqliteDefaultBusyCallback( void *Timeout,           /* Maximum amount of time to wait */ const char *NotUsed,     /* The name of the table that is busy */ int count                /* Number of times table has been busy */){#if SQLITE_MIN_SLEEP_MS==1  static const char delays[] =     { 1, 2, 5, 10, 15, 20, 25, 25,  25,  50,  50,  50, 100};  static const short int totals[] =     { 0, 1, 3,  8, 18, 33, 53, 78, 103, 128, 178, 228, 287};# define NDELAY (sizeof(delays)/sizeof(delays[0]))  int timeout = (int)(long)Timeout;  int delay, prior;  if( count <= NDELAY ){    delay = delays[count-1];    prior = totals[count-1];  }else{    delay = delays[NDELAY-1];    prior = totals[NDELAY-1] + delay*(count-NDELAY-1);  }  if( prior + delay > timeout ){    delay = timeout - prior;    if( delay<=0 ) return 0;  }  sqliteOsSleep(delay);  return 1;#else  int timeout = (int)(long)Timeout;  if( (count+1)*1000 > timeout ){    return 0;  }  sqliteOsSleep(1000);  return 1;#endif}/*** This routine sets the busy callback for an Sqlite database to the** given callback function with the given argument.*/void sqlite_busy_handler(  sqlite *db,  int (*xBusy)(void*,const char*,int),  void *pArg){  db->xBusyCallback = xBusy;  db->pBusyArg = pArg;}#ifndef SQLITE_OMIT_PROGRESS_CALLBACK/*** This routine sets the progress callback for an Sqlite database to the** given callback function with the given argument. The progress callback will** be invoked every nOps opcodes.*/void sqlite_progress_handler(  sqlite *db,   int nOps,  int (*xProgress)(void*),   void *pArg){  if( nOps>0 ){    db->xProgress = xProgress;    db->nProgressOps = nOps;    db->pProgressArg = pArg;  }else{    db->xProgress = 0;    db->nProgressOps = 0;    db->pProgressArg = 0;  }}#endif/*** This routine installs a default busy handler that waits for the** specified number of milliseconds before returning 0.*/void sqlite_busy_timeout(sqlite *db, int ms){  if( ms>0 ){    sqlite_busy_handler(db, sqliteDefaultBusyCallback, (void*)(long)ms);  }else{    sqlite_busy_handler(db, 0, 0);  }}/*** Cause any pending operation to stop at its earliest opportunity.*/void sqlite_interrupt(sqlite *db){  db->flags |= SQLITE_Interrupt;}/*** Windows systems should call this routine to free memory that** is returned in the in the errmsg parameter of sqlite_open() when** SQLite is a DLL.  For some reason, it does not work to call free()** directly.**** Note that we need to call free() not sqliteFree() here, since every** string that is exported from SQLite should have already passed through** sqliteStrRealloc().*/void sqlite_freemem(void *p){ free(p); }/*** Windows systems need functions to call to return the sqlite_version** and sqlite_encoding strings since they are unable to access constants** within DLLs.*/const char *sqlite_libversion(void){ return sqlite_version; }const char *sqlite_libencoding(void){ return sqlite_encoding; }/*** Create new user-defined functions.  The sqlite_create_function()** routine creates a regular function and sqlite_create_aggregate()** creates an aggregate function.**** Passing a NULL xFunc argument or NULL xStep and xFinalize arguments** disables the function.  Calling sqlite_create_function() with the** same name and number of arguments as a prior call to** sqlite_create_aggregate() disables the prior call to** sqlite_create_aggregate(), and vice versa.**** If nArg is -1 it means that this function will accept any number** of arguments, including 0.  The maximum allowed value of nArg is 127.*/int sqlite_create_function(  sqlite *db,          /* Add the function to this database connection */  const char *zName,   /* Name of the function to add */  int nArg,            /* Number of arguments */  void (*xFunc)(sqlite_func*,int,const char**),  /* The implementation */  void *pUserData      /* User data */){  FuncDef *p;  int nName;  if( db==0 || zName==0 || sqliteSafetyCheck(db) ) return 1;  if( nArg<-1 || nArg>127 ) return 1;  nName = strlen(zName);  if( nName>255 ) return 1;  p = sqliteFindFunction(db, zName, nName, nArg, 1);  if( p==0 ) return 1;  p->xFunc = xFunc;  p->xStep = 0;  p->xFinalize = 0;  p->pUserData = pUserData;  return 0;}int sqlite_create_aggregate(  sqlite *db,          /* Add the function to this database connection */  const char *zName,   /* Name of the function to add */  int nArg,            /* Number of arguments */  void (*xStep)(sqlite_func*,int,const char**), /* The step function */  void (*xFinalize)(sqlite_func*),              /* The finalizer */  void *pUserData      /* User data */){  FuncDef *p;  int nName;  if( db==0 || zName==0 || sqliteSafetyCheck(db) ) return 1;  if( nArg<-1 || nArg>127 ) return 1;  nName = strlen(zName);  if( nName>255 ) return 1;  p = sqliteFindFunction(db, zName, nName, nArg, 1);  if( p==0 ) return 1;  p->xFunc = 0;  p->xStep = xStep;  p->xFinalize = xFinalize;  p->pUserData = pUserData;  return 0;}/*** Change the datatype for all functions with a given name.  See the** header comment for the prototype of this function in sqlite.h for** additional information.*/int sqlite_function_type(sqlite *db, const char *zName, int dataType){  FuncDef *p = (FuncDef*)sqliteHashFind(&db->aFunc, zName, strlen(zName));  while( p ){    p->dataType = dataType;     p = p->pNext;  }  return SQLITE_OK;}/*** Register a trace function.  The pArg from the previously registered trace** is returned.  **** A NULL trace function means that no tracing is executes.  A non-NULL** trace is a pointer to a function that is invoked at the start of each** sqlite_exec().*/void *sqlite_trace(sqlite *db, void (*xTrace)(void*,const char*), void *pArg){  void *pOld = db->pTraceArg;  db->xTrace = xTrace;  db->pTraceArg = pArg;  return pOld;}/*** EXPERIMENTAL ******* Register a function to be invoked when a transaction comments.** If either function returns non-zero, then the commit becomes a** rollback.*/void *sqlite_commit_hook(  sqlite *db,               /* Attach the hook to this database */  int (*xCallback)(void*),  /* Function to invoke on each commit */  void *pArg                /* Argument to the function */){  void *pOld = db->pCommitArg;  db->xCommitCallback = xCallback;  db->pCommitArg = pArg;  return pOld;}/*** This routine is called to create a connection to a database BTree** driver.  If zFilename is the name of a file, then that file is** opened and used.  If zFilename is the magic name ":memory:" then** the database is stored in memory (and is thus forgotten as soon as** the connection is closed.)  If zFilename is NULL then the database** is for temporary use only and is deleted as soon as the connection** is closed.**** A temporary database can be either a disk file (that is automatically** deleted when the file is closed) or a set of red-black trees held in memory,** depending on the values of the TEMP_STORE compile-time macro and the** db->temp_store variable, according to the following chart:****       TEMP_STORE     db->temp_store     Location of temporary database**       ----------     --------------     ------------------------------**           0               any             file**           1                1              file**           1                2              memory**           1                0              file**           2                1              file**           2                2              memory**           2                0              memory**           3               any             memory*/int sqliteBtreeFactory(  const sqlite *db,	    /* Main database when opening aux otherwise 0 */  const char *zFilename,    /* Name of the file containing the BTree database */  int omitJournal,          /* if TRUE then do not journal this file */  int nCache,               /* How many pages in the page cache */  Btree **ppBtree){         /* Pointer to new Btree object written here */  assert( ppBtree != 0);#ifndef SQLITE_OMIT_INMEMORYDB  if( zFilename==0 ){    if (TEMP_STORE == 0) {      /* Always use file based temporary DB */      return sqliteBtreeOpen(0, omitJournal, nCache, ppBtree);    } else if (TEMP_STORE == 1 || TEMP_STORE == 2) {      /* Switch depending on compile-time and/or runtime settings. */      int location = db->temp_store==0 ? TEMP_STORE : db->temp_store;      if (location == 1) {        return sqliteBtreeOpen(zFilename, omitJournal, nCache, ppBtree);      } else {        return sqliteRbtreeOpen(0, 0, 0, ppBtree);      }    } else {      /* Always use in-core DB */      return sqliteRbtreeOpen(0, 0, 0, ppBtree);    }  }else if( zFilename[0]==':' && strcmp(zFilename,":memory:")==0 ){    return sqliteRbtreeOpen(0, 0, 0, ppBtree);  }else#endif  {    return sqliteBtreeOpen(zFilename, omitJournal, nCache, ppBtree);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -