aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/btree.c5
-rw-r--r--src/expr.c4
-rw-r--r--src/pcache.c8
-rw-r--r--src/pcache.h6
-rw-r--r--src/resolve.c3
-rw-r--r--src/shell.c.in23
-rw-r--r--src/where.c8
7 files changed, 37 insertions, 20 deletions
diff --git a/src/btree.c b/src/btree.c
index 918388a64..e90d0c1f1 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -6132,7 +6132,8 @@ static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){
pPage = pCur->pPage;
idx = ++pCur->ix;
- if( !pPage->isInit || sqlite3FaultSim(412) ){
+ if( sqlite3FaultSim(412) ) pPage->isInit = 0;
+ if( !pPage->isInit ){
return SQLITE_CORRUPT_BKPT;
}
@@ -9261,6 +9262,7 @@ int sqlite3BtreeInsert(
assert( szNew==pPage->xCellSize(pPage, newCell) );
assert( szNew <= MX_CELL_SIZE(p->pBt) );
idx = pCur->ix;
+ pCur->info.nSize = 0;
if( loc==0 ){
CellInfo info;
assert( idx>=0 );
@@ -9333,7 +9335,6 @@ int sqlite3BtreeInsert(
** larger than the largest existing key, it is possible to insert the
** row without seeking the cursor. This can be a big performance boost.
*/
- pCur->info.nSize = 0;
if( pPage->nOverflow ){
assert( rc==SQLITE_OK );
pCur->curFlags &= ~(BTCF_ValidNKey);
diff --git a/src/expr.c b/src/expr.c
index 223ebf1cb..0a52e6230 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -3839,9 +3839,10 @@ void sqlite3ExprCodeGeneratedColumn(
){
int iAddr;
Vdbe *v = pParse->pVdbe;
+ int nErr = pParse->nErr;
assert( v!=0 );
assert( pParse->iSelfTab!=0 );
- if( pParse->iSelfTab>0 ){
+ if( pParse->iSelfTab>0 ){
iAddr = sqlite3VdbeAddOp3(v, OP_IfNullRow, pParse->iSelfTab-1, 0, regOut);
}else{
iAddr = 0;
@@ -3851,6 +3852,7 @@ void sqlite3ExprCodeGeneratedColumn(
sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
}
if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
+ if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
}
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
diff --git a/src/pcache.c b/src/pcache.c
index 0407e06b2..153628dc9 100644
--- a/src/pcache.c
+++ b/src/pcache.c
@@ -41,7 +41,7 @@
struct PCache {
PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
PgHdr *pSynced; /* Last synced page in dirty page list */
- int nRefSum; /* Sum of ref counts over all pages */
+ i64 nRefSum; /* Sum of ref counts over all pages */
int szCache; /* Configured cache size */
int szSpill; /* Size before spilling occurs */
int szPage; /* Size of every page in this cache */
@@ -71,7 +71,7 @@ struct PCache {
unsigned char *a;
int j;
pPg = (PgHdr*)pLower->pExtra;
- printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
+ printf("%3lld: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
a = (unsigned char *)pLower->pBuf;
for(j=0; j<12; j++) printf("%02x", a[j]);
printf(" ptr %p\n", pPg);
@@ -815,14 +815,14 @@ PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
** This is not the total number of pages referenced, but the sum of the
** reference count for all pages.
*/
-int sqlite3PcacheRefCount(PCache *pCache){
+i64 sqlite3PcacheRefCount(PCache *pCache){
return pCache->nRefSum;
}
/*
** Return the number of references to the page supplied as an argument.
*/
-int sqlite3PcachePageRefcount(PgHdr *p){
+i64 sqlite3PcachePageRefcount(PgHdr *p){
return p->nRef;
}
diff --git a/src/pcache.h b/src/pcache.h
index eb55396af..f945dab1a 100644
--- a/src/pcache.h
+++ b/src/pcache.h
@@ -40,7 +40,7 @@ struct PgHdr {
** private to pcache.c and should not be accessed by other modules.
** pCache is grouped with the public elements for efficiency.
*/
- i16 nRef; /* Number of users of this page */
+ i64 nRef; /* Number of users of this page */
PgHdr *pDirtyNext; /* Next element in list of dirty pages */
PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
/* NB: pDirtyNext and pDirtyPrev are undefined if the
@@ -121,12 +121,12 @@ void sqlite3PcacheClearSyncFlags(PCache *);
void sqlite3PcacheClear(PCache*);
/* Return the total number of outstanding page references */
-int sqlite3PcacheRefCount(PCache*);
+i64 sqlite3PcacheRefCount(PCache*);
/* Increment the reference count of an existing page */
void sqlite3PcacheRef(PgHdr*);
-int sqlite3PcachePageRefcount(PgHdr*);
+i64 sqlite3PcachePageRefcount(PgHdr*);
/* Return the total number of pages stored in the cache */
int sqlite3PcachePagecount(PCache*);
diff --git a/src/resolve.c b/src/resolve.c
index 4b36ecca3..adfcc8dbe 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -467,7 +467,8 @@ static int lookupName(
assert( op==TK_DELETE || op==TK_UPDATE || op==TK_INSERT );
if( pParse->bReturning ){
if( (pNC->ncFlags & NC_UBaseReg)!=0
- && (zTab==0 || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0)
+ && ALWAYS(zTab==0
+ || sqlite3StrICmp(zTab,pParse->pTriggerTab->zName)==0)
){
pExpr->iTable = op!=TK_DELETE;
pTab = pParse->pTriggerTab;
diff --git a/src/shell.c.in b/src/shell.c.in
index 1f49a5056..b97889f93 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -99,6 +99,7 @@ typedef unsigned short int u16;
#include <string.h>
#include <stdio.h>
#include <assert.h>
+#include <math.h>
#include "sqlite3.h"
typedef sqlite3_int64 i64;
typedef sqlite3_uint64 u64;
@@ -2774,6 +2775,7 @@ static char *shell_error_context(const char *zSql, sqlite3 *db){
if( db==0
|| zSql==0
|| (iOffset = sqlite3_error_offset(db))<0
+ || iOffset>=strlen(zSql)
){
return sqlite3_mprintf("");
}
@@ -3386,12 +3388,13 @@ static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
if( nVar==0 ) return; /* Nothing to do */
if( sqlite3_table_column_metadata(pArg->db, "TEMP", "sqlite_parameters",
"key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
- return; /* Parameter table does not exist */
+ rc = SQLITE_NOTFOUND;
+ pQ = 0;
+ }else{
+ rc = sqlite3_prepare_v2(pArg->db,
+ "SELECT value FROM temp.sqlite_parameters"
+ " WHERE key=?1", -1, &pQ, 0);
}
- rc = sqlite3_prepare_v2(pArg->db,
- "SELECT value FROM temp.sqlite_parameters"
- " WHERE key=?1", -1, &pQ, 0);
- if( rc || pQ==0 ) return;
for(i=1; i<=nVar; i++){
char zNum[30];
const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
@@ -3400,8 +3403,12 @@ static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
zVar = zNum;
}
sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
- if( sqlite3_step(pQ)==SQLITE_ROW ){
+ if( rc==SQLITE_OK && pQ && sqlite3_step(pQ)==SQLITE_ROW ){
sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
+ }else if( sqlite3_strlike("_NAN", zVar, 0)==0 ){
+ sqlite3_bind_double(pStmt, i, NAN);
+ }else if( sqlite3_strlike("_INF", zVar, 0)==0 ){
+ sqlite3_bind_double(pStmt, i, INFINITY);
}else{
sqlite3_bind_null(pStmt, i);
}
@@ -11465,9 +11472,9 @@ static int process_input(ShellState *p){
}
/* No single-line dispositions remain; accumulate line(s). */
nLine = strlen(zLine);
- if( nSql+nLine+8>=nAlloc ){
+ if( nSql+nLine+2>=nAlloc ){
/* Grow buffer by half-again increments when big. */
- nAlloc = nSql+(nSql>>1)+nLine+104;
+ nAlloc = nSql+(nSql>>1)+nLine+100;
zSql = realloc(zSql, nAlloc);
shell_check_oom(zSql);
}
diff --git a/src/where.c b/src/where.c
index f707fab12..9de72d76d 100644
--- a/src/where.c
+++ b/src/where.c
@@ -1526,6 +1526,7 @@ static int whereKeyStats(
assert( pRec!=0 );
assert( pIdx->nSample>0 );
assert( pRec->nField>0 );
+
/* Do a binary search to find the first sample greater than or equal
** to pRec. If pRec contains a single field, the set of samples to search
@@ -1571,7 +1572,12 @@ static int whereKeyStats(
** it is extended to two fields. The duplicates that this creates do not
** cause any problems.
*/
- nField = MIN(pRec->nField, pIdx->nSample);
+ if( !HasRowid(pIdx->pTable) && IsPrimaryKeyIndex(pIdx) ){
+ nField = pIdx->nKeyCol;
+ }else{
+ nField = pIdx->nColumn;
+ }
+ nField = MIN(pRec->nField, nField);
iCol = 0;
iSample = pIdx->nSample * nField;
do{