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

📄 main.c

📁 sqlite的最新源码 This ZIP archive contains preprocessed C code for the SQLite library as individual sour
💻 C
📖 第 1 页 / 共 5 页
字号:
/*** Cause any pending operation to stop at its earliest opportunity.*/void sqlite3_interrupt(sqlite3 *db){  db->u1.isInterrupted = 1;}/*** This function is exactly the same as sqlite3_create_function(), except** that it is designed to be called by internal code. The difference is** that if a malloc() fails in sqlite3_create_function(), an error code** is returned and the mallocFailed flag cleared. */int sqlite3CreateFunc(  sqlite3 *db,  const char *zFunctionName,  int nArg,  int enc,  void *pUserData,  void (*xFunc)(sqlite3_context*,int,sqlite3_value **),  void (*xStep)(sqlite3_context*,int,sqlite3_value **),  void (*xFinal)(sqlite3_context*)){  FuncDef *p;  int nName;  assert( sqlite3_mutex_held(db->mutex) );  if( zFunctionName==0 ||      (xFunc && (xFinal || xStep)) ||       (!xFunc && (xFinal && !xStep)) ||      (!xFunc && (!xFinal && xStep)) ||      (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||      (255<(nName = sqlite3Strlen(db, zFunctionName))) ){    sqlite3Error(db, SQLITE_ERROR, "bad parameters");    return SQLITE_ERROR;  }  #ifndef SQLITE_OMIT_UTF16  /* If SQLITE_UTF16 is specified as the encoding type, transform this  ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the  ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.  **  ** If SQLITE_ANY is specified, add three versions of the function  ** to the hash table.  */  if( enc==SQLITE_UTF16 ){    enc = SQLITE_UTF16NATIVE;  }else if( enc==SQLITE_ANY ){    int rc;    rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,         pUserData, xFunc, xStep, xFinal);    if( rc==SQLITE_OK ){      rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,          pUserData, xFunc, xStep, xFinal);    }    if( rc!=SQLITE_OK ){      return rc;    }    enc = SQLITE_UTF16BE;  }#else  enc = SQLITE_UTF8;#endif    /* Check if an existing function is being overridden or deleted. If so,  ** and there are active VMs, then return SQLITE_BUSY. If a function  ** is being overridden/deleted but there are no active VMs, allow the  ** operation to continue but invalidate all precompiled statements.  */  p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 0);  if( p && p->iPrefEnc==enc && p->nArg==nArg ){    if( db->activeVdbeCnt ){      sqlite3Error(db, SQLITE_BUSY,         "Unable to delete/modify user-function due to active statements");      assert( !db->mallocFailed );      return SQLITE_BUSY;    }else{      sqlite3ExpirePreparedStatements(db);    }  }  p = sqlite3FindFunction(db, zFunctionName, nName, nArg, enc, 1);  assert(p || db->mallocFailed);  if( !p ){    return SQLITE_NOMEM;  }  p->flags = 0;  p->xFunc = xFunc;  p->xStep = xStep;  p->xFinalize = xFinal;  p->pUserData = pUserData;  p->nArg = nArg;  return SQLITE_OK;}/*** Create new user functions.*/int sqlite3_create_function(  sqlite3 *db,  const char *zFunctionName,  int nArg,  int enc,  void *p,  void (*xFunc)(sqlite3_context*,int,sqlite3_value **),  void (*xStep)(sqlite3_context*,int,sqlite3_value **),  void (*xFinal)(sqlite3_context*)){  int rc;  sqlite3_mutex_enter(db->mutex);  rc = sqlite3CreateFunc(db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal);  rc = sqlite3ApiExit(db, rc);  sqlite3_mutex_leave(db->mutex);  return rc;}#ifndef SQLITE_OMIT_UTF16int sqlite3_create_function16(  sqlite3 *db,  const void *zFunctionName,  int nArg,  int eTextRep,  void *p,  void (*xFunc)(sqlite3_context*,int,sqlite3_value**),  void (*xStep)(sqlite3_context*,int,sqlite3_value**),  void (*xFinal)(sqlite3_context*)){  int rc;  char *zFunc8;  sqlite3_mutex_enter(db->mutex);  assert( !db->mallocFailed );  zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1);  rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal);  sqlite3DbFree(db, zFunc8);  rc = sqlite3ApiExit(db, rc);  sqlite3_mutex_leave(db->mutex);  return rc;}#endif/*** Declare that a function has been overloaded by a virtual table.**** If the function already exists as a regular global function, then** this routine is a no-op.  If the function does not exist, then create** a new one that always throws a run-time error.  **** When virtual tables intend to provide an overloaded function, they** should call this routine to make sure the global function exists.** A global function must exist in order for name resolution to work** properly.*/int sqlite3_overload_function(  sqlite3 *db,  const char *zName,  int nArg){  int nName = sqlite3Strlen(db, zName);  int rc;  sqlite3_mutex_enter(db->mutex);  if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){    sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,                      0, sqlite3InvalidFunction, 0, 0);  }  rc = sqlite3ApiExit(db, SQLITE_OK);  sqlite3_mutex_leave(db->mutex);  return rc;}#ifndef SQLITE_OMIT_TRACE/*** 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** SQL statement.*/void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){  void *pOld;  sqlite3_mutex_enter(db->mutex);  pOld = db->pTraceArg;  db->xTrace = xTrace;  db->pTraceArg = pArg;  sqlite3_mutex_leave(db->mutex);  return pOld;}/*** Register a profile function.  The pArg from the previously registered ** profile function is returned.  **** A NULL profile function means that no profiling is executes.  A non-NULL** profile is a pointer to a function that is invoked at the conclusion of** each SQL statement that is run.*/void *sqlite3_profile(  sqlite3 *db,  void (*xProfile)(void*,const char*,sqlite_uint64),  void *pArg){  void *pOld;  sqlite3_mutex_enter(db->mutex);  pOld = db->pProfileArg;  db->xProfile = xProfile;  db->pProfileArg = pArg;  sqlite3_mutex_leave(db->mutex);  return pOld;}#endif /* SQLITE_OMIT_TRACE *//*** EXPERIMENTAL ******* Register a function to be invoked when a transaction comments.** If the invoked function returns non-zero, then the commit becomes a** rollback.*/void *sqlite3_commit_hook(  sqlite3 *db,              /* Attach the hook to this database */  int (*xCallback)(void*),  /* Function to invoke on each commit */  void *pArg                /* Argument to the function */){  void *pOld;  sqlite3_mutex_enter(db->mutex);  pOld = db->pCommitArg;  db->xCommitCallback = xCallback;  db->pCommitArg = pArg;  sqlite3_mutex_leave(db->mutex);  return pOld;}/*** Register a callback to be invoked each time a row is updated,** inserted or deleted using this database connection.*/void *sqlite3_update_hook(  sqlite3 *db,              /* Attach the hook to this database */  void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),  void *pArg                /* Argument to the function */){  void *pRet;  sqlite3_mutex_enter(db->mutex);  pRet = db->pUpdateArg;  db->xUpdateCallback = xCallback;  db->pUpdateArg = pArg;  sqlite3_mutex_leave(db->mutex);  return pRet;}/*** Register a callback to be invoked each time a transaction is rolled** back by this database connection.*/void *sqlite3_rollback_hook(  sqlite3 *db,              /* Attach the hook to this database */  void (*xCallback)(void*), /* Callback function */  void *pArg                /* Argument to the function */){  void *pRet;  sqlite3_mutex_enter(db->mutex);  pRet = db->pRollbackArg;  db->xRollbackCallback = xCallback;  db->pRollbackArg = pArg;  sqlite3_mutex_leave(db->mutex);  return pRet;}/*** 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 a "virtual" database for transient use only and is deleted as** soon as the connection is closed.**** A virtual database can be either a disk file (that is automatically** deleted when the file is closed) or it an be held entirely in memory,** depending on the values of the SQLITE_TEMP_STORE compile-time macro and the** db->temp_store variable, according to the following chart:****   SQLITE_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 sqlite3BtreeFactory(  const sqlite3 *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 */  int vfsFlags,             /* Flags passed through to vfsOpen */  Btree **ppBtree           /* Pointer to new Btree object written here */){  int btFlags = 0;  int rc;    assert( sqlite3_mutex_held(db->mutex) );  assert( ppBtree != 0);  if( omitJournal ){    btFlags |= BTREE_OMIT_JOURNAL;  }  if( db->flags & SQLITE_NoReadlock ){    btFlags |= BTREE_NO_READLOCK;  }  if( zFilename==0 ){#if SQLITE_TEMP_STORE==0    /* Do nothing */#endif#ifndef SQLITE_OMIT_MEMORYDB#if SQLITE_TEMP_STORE==1    if( db->temp_store==2 ) zFilename = ":memory:";#endif#if SQLITE_TEMP_STORE==2    if( db->temp_store!=1 ) zFilename = ":memory:";#endif#if SQLITE_TEMP_STORE==3    zFilename = ":memory:";#endif#endif /* SQLITE_OMIT_MEMORYDB */  }  if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (zFilename==0 || *zFilename==0) ){    vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;  }  rc = sqlite3BtreeOpen(zFilename, (sqlite3 *)db, ppBtree, btFlags, vfsFlags);  /* If the B-Tree was successfully opened, set the pager-cache size to the  ** default value. Except, if the call to BtreeOpen() returned a handle  ** open on an existing shared pager-cache, do not change the pager-cache   ** size.  */  if( rc==SQLITE_OK && 0==sqlite3BtreeSchema(*ppBtree, 0, 0) ){    sqlite3BtreeSetCacheSize(*ppBtree, nCache);  }  return rc;}/*** Return UTF-8 encoded English language explanation of the most recent** error.*/const char *sqlite3_errmsg(sqlite3 *db){  const char *z;  if( !db ){    return sqlite3ErrStr(SQLITE_NOMEM);  }  if( !sqlite3SafetyCheckSickOrOk(db) ){    return sqlite3ErrStr(SQLITE_MISUSE);  }  sqlite3_mutex_enter(db->mutex);  assert( !db->mallocFailed );  z = (char*)sqlite3_value_text(db->pErr);  assert( !db->mallocFailed );  if( z==0 ){    z = sqlite3ErrStr(db->errCode);  }  sqlite3_mutex_leave(db->mutex);  return z;}#ifndef SQLITE_OMIT_UTF16/*** Return UTF-16 encoded English language explanation of the most recent** error.*/const void *sqlite3_errmsg16(sqlite3 *db){  /* Because all the characters in the string are in the unicode  ** range 0x00-0xFF, if we pad the big-endian string with a   ** zero byte, we can obtain the little-endian string with  ** &big_endian[1].  */  static const char outOfMemBe[] = {    0, 'o', 0, 'u', 0, 't', 0, ' ',     0, 'o', 0, 'f', 0, ' ',     0, 'm', 0, 'e', 0, 'm', 0, 'o', 0, 'r', 0, 'y', 0, 0, 0  };  static const char misuseBe [] = {    0, 'l', 0, 'i', 0, 'b', 0, 'r', 0, 'a', 0, 'r', 0, 'y', 0, ' ',     0, 'r', 0, 'o', 0, 'u', 0, 't', 0, 'i', 0, 'n', 0, 'e', 0, ' ',     0, 'c', 0, 'a', 0, 'l', 0, 'l', 0, 'e', 0, 'd', 0, ' ',     0, 'o', 0, 'u', 0, 't', 0, ' ',     0, 'o', 0, 'f', 0, ' ',     0, 's', 0, 'e', 0, 'q', 0, 'u', 0, 'e', 0, 'n', 0, 'c', 0, 'e', 0, 0, 0  };  const void *z;  if( !db ){    return (void *)(&outOfMemBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);  }  if( !sqlite3SafetyCheckSickOrOk(db) ){    return (void *)(&misuseBe[SQLITE_UTF16NATIVE==SQLITE_UTF16LE?1:0]);  }  sqlite3_mutex_enter(db->mutex);  assert( !db->mallocFailed );  z = sqlite3_value_text16(db->pErr);  if( z==0 ){    sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),         SQLITE_UTF8, SQLITE_STATIC);    z = sqlite3_value_text16(db->pErr);  }  /* A malloc() may have failed within the call to sqlite3_value_text16()  ** above. If this is the case, then the db->mallocFailed flag needs to  ** be cleared before returning. Do this directly, instead of via  ** sqlite3ApiExit(), to avoid setting the database handle error message.  */  db->mallocFailed = 0;  sqlite3_mutex_leave(db->mutex);  return z;}#endif /* SQLITE_OMIT_UTF16 *//*** Return the most recent error code generated by an SQLite routine. If NULL is** passed to this function, we assume a malloc() failed during sqlite3_open().*/int sqlite3_errcode(sqlite3 *db){  if( db && !sqlite3SafetyCheckSickOrOk(db) ){

⌨️ 快捷键说明

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