summaryrefslogtreecommitdiffstats
path: root/third_party/sqlite/src/vdbeblob.c
diff options
context:
space:
mode:
authormdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 18:27:25 +0000
committermdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 18:27:25 +0000
commit997e22224e1062a4cd39373057a68879a1d7a3ac (patch)
treea90a9ce4272fc78f2459b1b2c78b52a3f6d4e5d3 /third_party/sqlite/src/vdbeblob.c
parent0d683c611a18dc6ea0e99f38c73b4fb96611041f (diff)
downloadchromium_src-997e22224e1062a4cd39373057a68879a1d7a3ac.zip
chromium_src-997e22224e1062a4cd39373057a68879a1d7a3ac.tar.gz
chromium_src-997e22224e1062a4cd39373057a68879a1d7a3ac.tar.bz2
Update sqlite to version 3.6.18, porting our patches.
Hopefully this will help to address some valgrind issues. BUG=none TEST=none git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26596 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/sqlite/src/vdbeblob.c')
-rw-r--r--third_party/sqlite/src/vdbeblob.c148
1 files changed, 87 insertions, 61 deletions
diff --git a/third_party/sqlite/src/vdbeblob.c b/third_party/sqlite/src/vdbeblob.c
index 746bfe4..009234f 100644
--- a/third_party/sqlite/src/vdbeblob.c
+++ b/third_party/sqlite/src/vdbeblob.c
@@ -12,7 +12,7 @@
**
** This file contains code used to implement incremental BLOB I/O.
**
-** $Id: vdbeblob.c,v 1.25 2008/07/28 19:34:54 drh Exp $
+** $Id: vdbeblob.c,v 1.35 2009/07/02 07:47:33 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -66,58 +66,62 @@ int sqlite3_blob_open(
static const VdbeOpList openBlob[] = {
{OP_Transaction, 0, 0, 0}, /* 0: Start a transaction */
{OP_VerifyCookie, 0, 0, 0}, /* 1: Check the schema cookie */
+ {OP_TableLock, 0, 0, 0}, /* 2: Acquire a read or write lock */
- /* One of the following two instructions is replaced by an
- ** OP_Noop before exection.
- */
- {OP_SetNumColumns, 0, 0, 0}, /* 2: Num cols for cursor */
+ /* One of the following two instructions is replaced by an OP_Noop. */
{OP_OpenRead, 0, 0, 0}, /* 3: Open cursor 0 for reading */
- {OP_SetNumColumns, 0, 0, 0}, /* 4: Num cols for cursor */
- {OP_OpenWrite, 0, 0, 0}, /* 5: Open cursor 0 for read/write */
-
- {OP_Variable, 1, 1, 0}, /* 6: Push the rowid to the stack */
- {OP_NotExists, 0, 10, 1}, /* 7: Seek the cursor */
- {OP_Column, 0, 0, 1}, /* 8 */
- {OP_ResultRow, 1, 0, 0}, /* 9 */
- {OP_Close, 0, 0, 0}, /* 10 */
- {OP_Halt, 0, 0, 0}, /* 11 */
+ {OP_OpenWrite, 0, 0, 0}, /* 4: Open cursor 0 for read/write */
+
+ {OP_Variable, 1, 1, 1}, /* 5: Push the rowid to the stack */
+ {OP_NotExists, 0, 9, 1}, /* 6: Seek the cursor */
+ {OP_Column, 0, 0, 1}, /* 7 */
+ {OP_ResultRow, 1, 0, 0}, /* 8 */
+ {OP_Close, 0, 0, 0}, /* 9 */
+ {OP_Halt, 0, 0, 0}, /* 10 */
};
Vdbe *v = 0;
int rc = SQLITE_OK;
- char zErr[128];
+ char *zErr = 0;
+ Table *pTab;
+ Parse *pParse;
- zErr[0] = 0;
+ *ppBlob = 0;
sqlite3_mutex_enter(db->mutex);
+ pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
+ if( pParse==0 ){
+ rc = SQLITE_NOMEM;
+ goto blob_open_out;
+ }
do {
- Parse sParse;
- Table *pTab;
-
- memset(&sParse, 0, sizeof(Parse));
- sParse.db = db;
+ memset(pParse, 0, sizeof(Parse));
+ pParse->db = db;
if( sqlite3SafetyOn(db) ){
+ sqlite3DbFree(db, zErr);
+ sqlite3StackFree(db, pParse);
sqlite3_mutex_leave(db->mutex);
return SQLITE_MISUSE;
}
sqlite3BtreeEnterAll(db);
- pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
+ pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
if( pTab && IsVirtual(pTab) ){
pTab = 0;
- sqlite3ErrorMsg(&sParse, "cannot open virtual table: %s", zTable);
+ sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
}
#ifndef SQLITE_OMIT_VIEW
if( pTab && pTab->pSelect ){
pTab = 0;
- sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable);
+ sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable);
}
#endif
if( !pTab ){
- if( sParse.zErrMsg ){
- sqlite3_snprintf(sizeof(zErr), zErr, "%s", sParse.zErrMsg);
+ if( pParse->zErrMsg ){
+ sqlite3DbFree(db, zErr);
+ zErr = pParse->zErrMsg;
+ pParse->zErrMsg = 0;
}
- sqlite3DbFree(db, sParse.zErrMsg);
rc = SQLITE_ERROR;
(void)sqlite3SafetyOff(db);
sqlite3BtreeLeaveAll(db);
@@ -131,7 +135,8 @@ int sqlite3_blob_open(
}
}
if( iCol==pTab->nCol ){
- sqlite3_snprintf(sizeof(zErr), zErr, "no such column: \"%s\"", zColumn);
+ sqlite3DbFree(db, zErr);
+ zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
rc = SQLITE_ERROR;
(void)sqlite3SafetyOff(db);
sqlite3BtreeLeaveAll(db);
@@ -148,7 +153,8 @@ int sqlite3_blob_open(
int j;
for(j=0; j<pIdx->nColumn; j++){
if( pIdx->aiColumn[j]==iCol ){
- sqlite3_snprintf(sizeof(zErr), zErr,
+ sqlite3DbFree(db, zErr);
+ zErr = sqlite3MPrintf(db,
"cannot open indexed column for writing");
rc = SQLITE_ERROR;
(void)sqlite3SafetyOff(db);
@@ -163,10 +169,11 @@ int sqlite3_blob_open(
if( v ){
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
sqlite3VdbeAddOpList(v, sizeof(openBlob)/sizeof(VdbeOpList), openBlob);
+ flags = !!flags; /* flags = (flags ? 1 : 0); */
/* Configure the OP_Transaction */
sqlite3VdbeChangeP1(v, 0, iDb);
- sqlite3VdbeChangeP2(v, 0, (flags ? 1 : 0));
+ sqlite3VdbeChangeP2(v, 0, flags);
/* Configure the OP_VerifyCookie */
sqlite3VdbeChangeP1(v, 1, iDb);
@@ -175,30 +182,35 @@ int sqlite3_blob_open(
/* Make sure a mutex is held on the table to be accessed */
sqlite3VdbeUsesBtree(v, iDb);
+ /* Configure the OP_TableLock instruction */
+ sqlite3VdbeChangeP1(v, 2, iDb);
+ sqlite3VdbeChangeP2(v, 2, pTab->tnum);
+ sqlite3VdbeChangeP3(v, 2, flags);
+ sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
+
/* Remove either the OP_OpenWrite or OpenRead. Set the P2
- ** parameter of the other to pTab->tnum.
- */
- sqlite3VdbeChangeToNoop(v, (flags ? 3 : 5), 1);
- sqlite3VdbeChangeP2(v, (flags ? 5 : 3), pTab->tnum);
- sqlite3VdbeChangeP3(v, (flags ? 5 : 3), iDb);
+ ** parameter of the other to pTab->tnum. */
+ sqlite3VdbeChangeToNoop(v, 4 - flags, 1);
+ sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
+ sqlite3VdbeChangeP3(v, 3 + flags, iDb);
- /* Configure the OP_SetNumColumns. Configure the cursor to
+ /* Configure the number of columns. Configure the cursor to
** think that the table has one more column than it really
** does. An OP_Column to retrieve this imaginary column will
** always return an SQL NULL. This is useful because it means
** we can invoke OP_Column to fill in the vdbe cursors type
** and offset cache without causing any IO.
*/
- sqlite3VdbeChangeP2(v, flags ? 4 : 2, pTab->nCol+1);
- sqlite3VdbeChangeP2(v, 8, pTab->nCol);
+ sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
+ sqlite3VdbeChangeP2(v, 7, pTab->nCol);
if( !db->mallocFailed ){
- sqlite3VdbeMakeReady(v, 1, 1, 1, 0);
+ sqlite3VdbeMakeReady(v, 1, 1, 1, 0, 0, 0);
}
}
sqlite3BtreeLeaveAll(db);
rc = sqlite3SafetyOff(db);
- if( rc!=SQLITE_OK || db->mallocFailed ){
+ if( NEVER(rc!=SQLITE_OK) || db->mallocFailed ){
goto blob_open_out;
}
@@ -207,7 +219,8 @@ int sqlite3_blob_open(
if( rc!=SQLITE_ROW ){
nAttempt++;
rc = sqlite3_finalize((sqlite3_stmt *)v);
- sqlite3_snprintf(sizeof(zErr), zErr, sqlite3_errmsg(db));
+ sqlite3DbFree(db, zErr);
+ zErr = sqlite3MPrintf(db, sqlite3_errmsg(db));
v = 0;
}
} while( nAttempt<5 && rc==SQLITE_SCHEMA );
@@ -221,7 +234,8 @@ int sqlite3_blob_open(
u32 type = v->apCsr[0]->aType[iCol];
if( type<12 ){
- sqlite3_snprintf(sizeof(zErr), zErr, "cannot open value of type %s",
+ sqlite3DbFree(db, zErr);
+ zErr = sqlite3MPrintf(db, "cannot open value of type %s",
type==0?"null": type==7?"real": "integer"
);
rc = SQLITE_ERROR;
@@ -244,16 +258,18 @@ int sqlite3_blob_open(
*ppBlob = (sqlite3_blob *)pBlob;
rc = SQLITE_OK;
}else if( rc==SQLITE_OK ){
- sqlite3_snprintf(sizeof(zErr), zErr, "no such rowid: %lld", iRow);
+ sqlite3DbFree(db, zErr);
+ zErr = sqlite3MPrintf(db, "no such rowid: %lld", iRow);
rc = SQLITE_ERROR;
}
blob_open_out:
- zErr[sizeof(zErr)-1] = '\0';
- if( rc!=SQLITE_OK || db->mallocFailed ){
- sqlite3_finalize((sqlite3_stmt *)v);
+ if( v && (rc!=SQLITE_OK || db->mallocFailed) ){
+ sqlite3VdbeFinalize(v);
}
- sqlite3Error(db, rc, (rc==SQLITE_OK?0:zErr));
+ sqlite3Error(db, rc, zErr);
+ sqlite3DbFree(db, zErr);
+ sqlite3StackFree(db, pParse);
rc = sqlite3ApiExit(db, rc);
sqlite3_mutex_leave(db->mutex);
return rc;
@@ -266,9 +282,17 @@ blob_open_out:
int sqlite3_blob_close(sqlite3_blob *pBlob){
Incrblob *p = (Incrblob *)pBlob;
int rc;
-
- rc = sqlite3_finalize(p->pStmt);
- sqlite3DbFree(p->db, p);
+ sqlite3 *db;
+
+ if( p ){
+ db = p->db;
+ sqlite3_mutex_enter(db->mutex);
+ rc = sqlite3_finalize(p->pStmt);
+ sqlite3DbFree(db, p);
+ sqlite3_mutex_leave(db->mutex);
+ }else{
+ rc = SQLITE_OK;
+ }
return rc;
}
@@ -285,19 +309,21 @@ static int blobReadWrite(
int rc;
Incrblob *p = (Incrblob *)pBlob;
Vdbe *v;
- sqlite3 *db = p->db;
+ sqlite3 *db;
- /* Request is out of range. Return a transient error. */
- if( (iOffset+n)>p->nByte ){
- return SQLITE_ERROR;
- }
+ if( p==0 ) return SQLITE_MISUSE;
+ db = p->db;
sqlite3_mutex_enter(db->mutex);
-
- /* If there is no statement handle, then the blob-handle has
- ** already been invalidated. Return SQLITE_ABORT in this case.
- */
v = (Vdbe*)p->pStmt;
- if( v==0 ){
+
+ if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
+ /* Request is out of range. Return a transient error. */
+ rc = SQLITE_ERROR;
+ sqlite3Error(db, SQLITE_ERROR, 0);
+ } else if( v==0 ){
+ /* If there is no statement handle, then the blob-handle has
+ ** already been invalidated. Return SQLITE_ABORT in this case.
+ */
rc = SQLITE_ABORT;
}else{
/* Call either BtreeData() or BtreePutData(). If SQLITE_ABORT is
@@ -342,7 +368,7 @@ int sqlite3_blob_write(sqlite3_blob *pBlob, const void *z, int n, int iOffset){
*/
int sqlite3_blob_bytes(sqlite3_blob *pBlob){
Incrblob *p = (Incrblob *)pBlob;
- return p->nByte;
+ return p ? p->nByte : 0;
}
#endif /* #ifndef SQLITE_OMIT_INCRBLOB */