mirror of
https://github.com/php/php-src.git
synced 2025-08-20 01:14:28 +02:00
MFB: Upgraded libsqlite in pdo_sqlite to 3.3.7
This commit is contained in:
parent
3717342c9f
commit
5c01690d9b
83 changed files with 17303 additions and 7927 deletions
|
@ -58,7 +58,7 @@ sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
|
|||
return sqlite3VdbeIntValue((Mem*)pVal);
|
||||
}
|
||||
const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
|
||||
return (const char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_value_text16(sqlite3_value* pVal){
|
||||
|
@ -74,6 +74,7 @@ const void *sqlite3_value_text16le(sqlite3_value *pVal){
|
|||
int sqlite3_value_type(sqlite3_value* pVal){
|
||||
return pVal->type;
|
||||
}
|
||||
/* sqlite3_value_numeric_type() defined in vdbe.c */
|
||||
|
||||
/**************************** sqlite3_result_ *******************************
|
||||
** The following routines are used by user-defined functions to specify
|
||||
|
@ -95,10 +96,12 @@ void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
|
|||
pCtx->isError = 1;
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
|
||||
pCtx->isError = 1;
|
||||
sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT);
|
||||
}
|
||||
#endif
|
||||
void sqlite3_result_int(sqlite3_context *pCtx, int iVal){
|
||||
sqlite3VdbeMemSetInt64(&pCtx->s, (i64)iVal);
|
||||
}
|
||||
|
@ -156,6 +159,9 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
|||
sqlite3 *db;
|
||||
int rc;
|
||||
|
||||
/* Assert that malloc() has not failed */
|
||||
assert( !sqlite3MallocFailed() );
|
||||
|
||||
if( p==0 || p->magic!=VDBE_MAGIC_RUN ){
|
||||
return SQLITE_MISUSE;
|
||||
}
|
||||
|
@ -174,6 +180,14 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
|||
return SQLITE_MISUSE;
|
||||
}
|
||||
if( p->pc<0 ){
|
||||
/* If there are no other statements currently running, then
|
||||
** reset the interrupt flag. This prevents a call to sqlite3_interrupt
|
||||
** from interrupting a statement that has not yet started.
|
||||
*/
|
||||
if( db->activeVdbeCnt==0 ){
|
||||
db->u1.isInterrupted = 0;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_TRACE
|
||||
/* Invoke the trace callback if there is one
|
||||
*/
|
||||
|
@ -238,7 +252,8 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
|||
}
|
||||
#endif
|
||||
|
||||
sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
|
||||
sqlite3Error(p->db, rc, 0);
|
||||
p->rc = sqlite3ApiExit(p->db, p->rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -329,9 +344,10 @@ void sqlite3_set_auxdata(
|
|||
** Return the number of times the Step function of a aggregate has been
|
||||
** called.
|
||||
**
|
||||
** This routine is defined here in vdbe.c because it depends on knowing
|
||||
** the internals of the sqlite3_context structure which is only defined in
|
||||
** this source file.
|
||||
** This function is deprecated. Do not use it for new code. It is
|
||||
** provide only to avoid breaking legacy code. New aggregate function
|
||||
** implementations should keep their own counts within their aggregate
|
||||
** context.
|
||||
*/
|
||||
int sqlite3_aggregate_count(sqlite3_context *p){
|
||||
assert( p && p->pFunc && p->pFunc->xStep );
|
||||
|
@ -367,53 +383,105 @@ static Mem *columnMem(sqlite3_stmt *pStmt, int i){
|
|||
Vdbe *pVm = (Vdbe *)pStmt;
|
||||
int vals = sqlite3_data_count(pStmt);
|
||||
if( i>=vals || i<0 ){
|
||||
static Mem nullMem;
|
||||
if( nullMem.flags==0 ){ nullMem.flags = MEM_Null; }
|
||||
static const Mem nullMem = {0, 0.0, "", 0, MEM_Null, MEM_Null };
|
||||
sqlite3Error(pVm->db, SQLITE_RANGE, 0);
|
||||
return &nullMem;
|
||||
return (Mem*)&nullMem;
|
||||
}
|
||||
return &pVm->pTos[(1-vals)+i];
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called after invoking an sqlite3_value_XXX function on a
|
||||
** column value (i.e. a value returned by evaluating an SQL expression in the
|
||||
** select list of a SELECT statement) that may cause a malloc() failure. If
|
||||
** malloc() has failed, the threads mallocFailed flag is cleared and the result
|
||||
** code of statement pStmt set to SQLITE_NOMEM.
|
||||
**
|
||||
** Specificly, this is called from within:
|
||||
**
|
||||
** sqlite3_column_int()
|
||||
** sqlite3_column_int64()
|
||||
** sqlite3_column_text()
|
||||
** sqlite3_column_text16()
|
||||
** sqlite3_column_real()
|
||||
** sqlite3_column_bytes()
|
||||
** sqlite3_column_bytes16()
|
||||
**
|
||||
** But not for sqlite3_column_blob(), which never calls malloc().
|
||||
*/
|
||||
static void columnMallocFailure(sqlite3_stmt *pStmt)
|
||||
{
|
||||
/* If malloc() failed during an encoding conversion within an
|
||||
** sqlite3_column_XXX API, then set the return code of the statement to
|
||||
** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR
|
||||
** and _finalize() will return NOMEM.
|
||||
*/
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
p->rc = sqlite3ApiExit(0, p->rc);
|
||||
}
|
||||
|
||||
/**************************** sqlite3_column_ *******************************
|
||||
** The following routines are used to access elements of the current row
|
||||
** in the result set.
|
||||
*/
|
||||
const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_blob( columnMem(pStmt,i) );
|
||||
const void *val;
|
||||
sqlite3MallocDisallow();
|
||||
val = sqlite3_value_blob( columnMem(pStmt,i) );
|
||||
sqlite3MallocAllow();
|
||||
return val;
|
||||
}
|
||||
int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_bytes( columnMem(pStmt,i) );
|
||||
int val = sqlite3_value_bytes( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_bytes16( columnMem(pStmt,i) );
|
||||
int val = sqlite3_value_bytes16( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
double sqlite3_column_double(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_double( columnMem(pStmt,i) );
|
||||
double val = sqlite3_value_double( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_int( columnMem(pStmt,i) );
|
||||
int val = sqlite3_value_int( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_int64( columnMem(pStmt,i) );
|
||||
sqlite_int64 val = sqlite3_value_int64( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_text( columnMem(pStmt,i) );
|
||||
const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
#if 0
|
||||
sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
|
||||
return columnMem(pStmt, i);
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_text16( columnMem(pStmt,i) );
|
||||
const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
|
||||
columnMallocFailure(pStmt);
|
||||
return val;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
|
||||
return sqlite3_value_type( columnMem(pStmt,i) );
|
||||
}
|
||||
|
||||
/* The following function is experimental and subject to change or
|
||||
** removal */
|
||||
/*int sqlite3_column_numeric_type(sqlite3_stmt *pStmt, int i){
|
||||
** return sqlite3_value_numeric_type( columnMem(pStmt,i) );
|
||||
**}
|
||||
*/
|
||||
|
||||
/*
|
||||
** Convert the N-th element of pStmt->pColName[] into a string using
|
||||
** xFunc() then return that string. If N is out of range, return 0.
|
||||
|
@ -436,6 +504,7 @@ static const void *columnName(
|
|||
const void *(*xFunc)(Mem*),
|
||||
int useType
|
||||
){
|
||||
const void *ret;
|
||||
Vdbe *p = (Vdbe *)pStmt;
|
||||
int n = sqlite3_column_count(pStmt);
|
||||
|
||||
|
@ -443,20 +512,27 @@ static const void *columnName(
|
|||
return 0;
|
||||
}
|
||||
N += useType*n;
|
||||
return xFunc(&p->aColName[N]);
|
||||
}
|
||||
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.
|
||||
*/
|
||||
sqlite3ApiExit(0, 0);
|
||||
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, 0);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -465,26 +541,30 @@ const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
|
|||
** 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, 1);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 1);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
#if !defined(SQLITE_OMIT_ORIGIN_NAMES) && 0
|
||||
#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, 2);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 2);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
|
@ -494,11 +574,13 @@ const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
|
|||
** 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, 3);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 3);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
|
||||
|
@ -508,16 +590,16 @@ const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
|
|||
** 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, 4);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
|
||||
}
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
|
||||
return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 4);
|
||||
return columnName(
|
||||
pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
#endif /* SQLITE_OMIT_ORIGIN_NAMES */
|
||||
|
||||
|
||||
#endif /* SQLITE_ENABLE_COLUMN_METADATA */
|
||||
|
||||
|
||||
/******************************* sqlite3_bind_ ***************************
|
||||
|
@ -571,13 +653,12 @@ static int bindText(
|
|||
}
|
||||
pVar = &p->aVar[i-1];
|
||||
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
|
||||
if( rc ){
|
||||
return rc;
|
||||
}
|
||||
if( rc==SQLITE_OK && encoding!=0 ){
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, p->db->enc);
|
||||
rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
|
||||
}
|
||||
return rc;
|
||||
|
||||
sqlite3Error(((Vdbe *)pStmt)->db, rc, 0);
|
||||
return sqlite3ApiExit(((Vdbe *)pStmt)->db, rc);
|
||||
}
|
||||
|
||||
|
||||
|
@ -637,6 +718,15 @@ int sqlite3_bind_text16(
|
|||
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 ){
|
||||
sqlite3VdbeMemCopy(&p->aVar[i-1], pValue);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the number of wildcards that can be potentially bound to.
|
||||
|
@ -721,7 +811,9 @@ int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
|
|||
return SQLITE_ERROR;
|
||||
}
|
||||
for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){
|
||||
sqlite3MallocDisallow();
|
||||
rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
|
||||
sqlite3MallocAllow();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue