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

📄 vdbeapi.c

📁 sqlite的最新源码 This ZIP archive contains preprocessed C code for the SQLite library as individual sour
💻 C
📖 第 1 页 / 共 3 页
字号:
** name is returned.  Here are the names:****    0      The column name as it should be displayed for output**    1      The datatype name for the column**    2      The name of the database that the column derives from**    3      The name of the table that the column derives from**    4      The name of the table column that the result column derives from**** If the result is not a simple column reference (if it is an expression** or a constant) then useTypes 2, 3, and 4 return NULL.*/static const void *columnName(  sqlite3_stmt *pStmt,  int N,  const void *(*xFunc)(Mem*),  int useType){  const void *ret = 0;  Vdbe *p = (Vdbe *)pStmt;  int n;    if( p!=0 ){    n = sqlite3_column_count(pStmt);    if( N<n && N>=0 ){      N += useType*n;      sqlite3_mutex_enter(p->db->mutex);      ret = xFunc(&p->aColName[N]);      /* A malloc may have failed inside of the xFunc() call. If this      ** is the case, clear the mallocFailed flag and return NULL.      */      if( p->db && p->db->mallocFailed ){        p->db->mallocFailed = 0;        ret = 0;      }      sqlite3_mutex_leave(p->db->mutex);    }  }  return ret;}/*** Return the name of the Nth column of the result set returned by SQL** statement pStmt.*/const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);}#ifndef SQLITE_OMIT_UTF16const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);}#endif/*** Constraint:  If you have ENABLE_COLUMN_METADATA then you must** not define OMIT_DECLTYPE.*/#if defined(SQLITE_OMIT_DECLTYPE) && defined(SQLITE_ENABLE_COLUMN_METADATA)# error "Must not define both SQLITE_OMIT_DECLTYPE \         and SQLITE_ENABLE_COLUMN_METADATA"#endif#ifndef SQLITE_OMIT_DECLTYPE/*** Return the column declaration type (if applicable) of the 'i'th column** of the result set of SQL statement pStmt.*/const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);}#ifndef SQLITE_OMIT_UTF16const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);}#endif /* SQLITE_OMIT_UTF16 */#endif /* SQLITE_OMIT_DECLTYPE */#ifdef SQLITE_ENABLE_COLUMN_METADATA/*** Return the name of the database from which a result column derives.** NULL is returned if the result column is an expression or constant or** anything else which is not an unabiguous reference to a database column.*/const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);}#ifndef SQLITE_OMIT_UTF16const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);}#endif /* SQLITE_OMIT_UTF16 *//*** Return the name of the table from which a result column derives.** NULL is returned if the result column is an expression or constant or** anything else which is not an unabiguous reference to a database column.*/const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);}#ifndef SQLITE_OMIT_UTF16const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);}#endif /* SQLITE_OMIT_UTF16 *//*** Return the name of the table column from which a result column derives.** NULL is returned if the result column is an expression or constant or** anything else which is not an unabiguous reference to a database column.*/const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);}#ifndef SQLITE_OMIT_UTF16const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){  return columnName(      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);}#endif /* SQLITE_OMIT_UTF16 */#endif /* SQLITE_ENABLE_COLUMN_METADATA *//******************************* sqlite3_bind_  ***************************** ** Routines used to attach values to wildcards in a compiled SQL statement.*//*** Unbind the value bound to variable i in virtual machine p. This is the ** the same as binding a NULL value to the column. If the "i" parameter is** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.**** A successful evaluation of this routine acquires the mutex on p.** the mutex is released if any kind of error occurs.**** The error code stored in database p->db is overwritten with the return** value in any case.*/static int vdbeUnbind(Vdbe *p, int i){  Mem *pVar;  if( p==0 ) return SQLITE_MISUSE;  sqlite3_mutex_enter(p->db->mutex);  if( p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){    sqlite3Error(p->db, SQLITE_MISUSE, 0);    sqlite3_mutex_leave(p->db->mutex);    return SQLITE_MISUSE;  }  if( i<1 || i>p->nVar ){    sqlite3Error(p->db, SQLITE_RANGE, 0);    sqlite3_mutex_leave(p->db->mutex);    return SQLITE_RANGE;  }  i--;  pVar = &p->aVar[i];  sqlite3VdbeMemRelease(pVar);  pVar->flags = MEM_Null;  sqlite3Error(p->db, SQLITE_OK, 0);  return SQLITE_OK;}/*** Bind a text or BLOB value.*/static int bindText(  sqlite3_stmt *pStmt,   /* The statement to bind against */  int i,                 /* Index of the parameter to bind */  const void *zData,     /* Pointer to the data to be bound */  int nData,             /* Number of bytes of data to be bound */  void (*xDel)(void*),   /* Destructor for the data */  int encoding           /* Encoding for the data */){  Vdbe *p = (Vdbe *)pStmt;  Mem *pVar;  int rc;  rc = vdbeUnbind(p, i);  if( rc==SQLITE_OK ){    if( zData!=0 ){      pVar = &p->aVar[i-1];      rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);      if( rc==SQLITE_OK && encoding!=0 ){        rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));      }      sqlite3Error(p->db, rc, 0);      rc = sqlite3ApiExit(p->db, rc);    }    sqlite3_mutex_leave(p->db->mutex);  }  return rc;}/*** Bind a blob value to an SQL statement variable.*/int sqlite3_bind_blob(  sqlite3_stmt *pStmt,   int i,   const void *zData,   int nData,   void (*xDel)(void*)){  return bindText(pStmt, i, zData, nData, xDel, 0);}int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){  int rc;  Vdbe *p = (Vdbe *)pStmt;  rc = vdbeUnbind(p, i);  if( rc==SQLITE_OK ){    sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);    sqlite3_mutex_leave(p->db->mutex);  }  return rc;}int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){  return sqlite3_bind_int64(p, i, (i64)iValue);}int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){  int rc;  Vdbe *p = (Vdbe *)pStmt;  rc = vdbeUnbind(p, i);  if( rc==SQLITE_OK ){    sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);    sqlite3_mutex_leave(p->db->mutex);  }  return rc;}int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){  int rc;  Vdbe *p = (Vdbe*)pStmt;  rc = vdbeUnbind(p, i);  if( rc==SQLITE_OK ){    sqlite3_mutex_leave(p->db->mutex);  }  return rc;}int sqlite3_bind_text(   sqlite3_stmt *pStmt,   int i,   const char *zData,   int nData,   void (*xDel)(void*)){  return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);}#ifndef SQLITE_OMIT_UTF16int sqlite3_bind_text16(  sqlite3_stmt *pStmt,   int i,   const void *zData,   int nData,   void (*xDel)(void*)){  return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);}#endif /* SQLITE_OMIT_UTF16 */int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){  int rc;  Vdbe *p = (Vdbe *)pStmt;  rc = vdbeUnbind(p, i);  if( rc==SQLITE_OK ){    rc = sqlite3VdbeMemCopy(&p->aVar[i-1], pValue);    if( rc==SQLITE_OK ){      rc = sqlite3VdbeChangeEncoding(&p->aVar[i-1], ENC(p->db));    }    sqlite3_mutex_leave(p->db->mutex);  }  rc = sqlite3ApiExit(p->db, rc);  return rc;}int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){  int rc;  Vdbe *p = (Vdbe *)pStmt;  rc = vdbeUnbind(p, i);  if( rc==SQLITE_OK ){    sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);    sqlite3_mutex_leave(p->db->mutex);  }  return rc;}/*** Return the number of wildcards that can be potentially bound to.** This routine is added to support DBD::SQLite.  */int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){  Vdbe *p = (Vdbe*)pStmt;  return p ? p->nVar : 0;}/*** Create a mapping from variable numbers to variable names** in the Vdbe.azVar[] array, if such a mapping does not already** exist.*/static void createVarMap(Vdbe *p){  if( !p->okVar ){    sqlite3_mutex_enter(p->db->mutex);    if( !p->okVar ){      int j;      Op *pOp;      for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){        if( pOp->opcode==OP_Variable ){          assert( pOp->p1>0 && pOp->p1<=p->nVar );          p->azVar[pOp->p1-1] = pOp->p4.z;        }      }      p->okVar = 1;    }    sqlite3_mutex_leave(p->db->mutex);  }}/*** Return the name of a wildcard parameter.  Return NULL if the index** is out of range or if the wildcard is unnamed.**** The result is always UTF-8.*/const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){  Vdbe *p = (Vdbe*)pStmt;  if( p==0 || i<1 || i>p->nVar ){    return 0;  }  createVarMap(p);  return p->azVar[i-1];}/*** Given a wildcard parameter name, return the index of the variable** with that name.  If there is no variable with the given name,** return 0.*/int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){  Vdbe *p = (Vdbe*)pStmt;  int i;  if( p==0 ){    return 0;  }  createVarMap(p);   if( zName ){    for(i=0; i<p->nVar; i++){      const char *z = p->azVar[i];      if( z && strcmp(z,zName)==0 ){        return i+1;      }    }  }  return 0;}/*** Transfer all bindings from the first statement over to the second.** If the two statements contain a different number of bindings, then** an SQLITE_ERROR is returned.*/int sqlite3TransferBindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){  Vdbe *pFrom = (Vdbe*)pFromStmt;  Vdbe *pTo = (Vdbe*)pToStmt;  int i, rc = SQLITE_OK;  if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT)    || (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT)    || pTo->db!=pFrom->db ){    return SQLITE_MISUSE;  }  if( pFrom->nVar!=pTo->nVar ){    return SQLITE_ERROR;  }  sqlite3_mutex_enter(pTo->db->mutex);  for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){    sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);  }  sqlite3_mutex_leave(pTo->db->mutex);  assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );  return rc;}#ifndef SQLITE_OMIT_DEPRECATED/*** Deprecated external interface.  Internal/core SQLite code** should call sqlite3TransferBindings.*/int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){  return sqlite3TransferBindings(pFromStmt, pToStmt);}#endif/*** Return the sqlite3* database handle to which the prepared statement given** in the argument belongs.  This is the same database handle that was** the first argument to the sqlite3_prepare() that was used to create** the statement in the first place.*/sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){  return pStmt ? ((Vdbe*)pStmt)->db : 0;}/*** Return a pointer to the next prepared statement after pStmt associated** with database connection pDb.  If pStmt is NULL, return the first** prepared statement for the database connection.  Return NULL if there** are no more.*/sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){  sqlite3_stmt *pNext;  sqlite3_mutex_enter(pDb->mutex);  if( pStmt==0 ){    pNext = (sqlite3_stmt*)pDb->pVdbe;  }else{    pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext;  }  sqlite3_mutex_leave(pDb->mutex);  return pNext;}/*** Return the value of a status counter for a prepared statement*/int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){  Vdbe *pVdbe = (Vdbe*)pStmt;  int v = pVdbe->aCounter[op-1];  if( resetFlag ) pVdbe->aCounter[op-1] = 0;  return v;}

⌨️ 快捷键说明

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