aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2004-05-18 01:23:38 +0000
committerdanielk1977 <danielk1977@noemail.net>2004-05-18 01:23:38 +0000
commitb4964b723c3642dccb530a0ca7af06213c38efd5 (patch)
treec8a55418ab180fe7d22a6a68898d350a4eaafd1f /src
parente014a83880e3064cbc202de5ff92a4059faa274c (diff)
downloadsqlite-b4964b723c3642dccb530a0ca7af06213c38efd5.tar.gz
sqlite-b4964b723c3642dccb530a0ca7af06213c38efd5.zip
Omit the '\0' at the end of UTF-8 strings on disk (it is implied). Also
don't store the number of rows at the beginning of each table record. (CVS 1390) FossilOrigin-Name: 202a470f2c1804a96e69f16709d1a92e405971f0
Diffstat (limited to 'src')
-rw-r--r--src/build.c4
-rw-r--r--src/delete.c4
-rw-r--r--src/insert.c4
-rw-r--r--src/pragma.c17
-rw-r--r--src/select.c7
-rw-r--r--src/update.c4
-rw-r--r--src/vdbe.c56
-rw-r--r--src/where.c3
8 files changed, 70 insertions, 29 deletions
diff --git a/src/build.c b/src/build.c
index 3f8dffa91..d26ad6a55 100644
--- a/src/build.c
+++ b/src/build.c
@@ -23,7 +23,7 @@
** ROLLBACK
** PRAGMA
**
-** $Id: build.c,v 1.185 2004/05/16 11:57:28 danielk1977 Exp $
+** $Id: build.c,v 1.186 2004/05/18 01:23:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -407,6 +407,7 @@ char *sqlite3TableNameFromToken(Token *pName){
void sqlite3OpenMasterTable(Vdbe *v, int isTemp){
sqlite3VdbeAddOp(v, OP_Integer, isTemp, 0);
sqlite3VdbeAddOp(v, OP_OpenWrite, 0, MASTER_ROOT);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, 0, 5); /* sqlite_master has 5 columns */
}
/*
@@ -1724,6 +1725,7 @@ void sqlite3CreateIndex(
if( pTable ){
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeOp3(v, OP_OpenRead, 2, pTab->tnum, pTab->zName, 0);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, 2, pTab->nCol);
lbl2 = sqlite3VdbeMakeLabel(v);
sqlite3VdbeAddOp(v, OP_Rewind, 2, lbl2);
lbl1 = sqlite3VdbeAddOp(v, OP_Recno, 2, 0);
diff --git a/src/delete.c b/src/delete.c
index 4d6b33425..66497002f 100644
--- a/src/delete.c
+++ b/src/delete.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle DELETE FROM statements.
**
-** $Id: delete.c,v 1.65 2004/05/16 11:15:37 danielk1977 Exp $
+** $Id: delete.c,v 1.66 2004/05/18 01:23:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -173,6 +173,7 @@ void sqlite3DeleteFrom(
if( !isView ){
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
}
sqlite3VdbeAddOp(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
addr = sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
@@ -230,6 +231,7 @@ void sqlite3DeleteFrom(
if( !isView ){
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
}
sqlite3VdbeAddOp(v, OP_MoveTo, iCur, 0);
diff --git a/src/insert.c b/src/insert.c
index fd73dbba8..f572bb893 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
-** $Id: insert.c,v 1.100 2004/05/17 10:48:58 danielk1977 Exp $
+** $Id: insert.c,v 1.101 2004/05/18 01:23:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -307,6 +307,7 @@ void sqlite3Insert(
*/
sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
sqlite3VdbeAddOp(v, OP_OpenTemp, srcTab, 0);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, pTab->nCol);
sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop);
sqlite3VdbeResolveLabel(v, iCleanup);
}else{
@@ -1001,6 +1002,7 @@ int sqlite3OpenTableAndIndices(Parse *pParse, Table *pTab, int base){
assert( v!=0 );
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeOp3(v, OP_OpenWrite, base, pTab->tnum, pTab->zName, P3_STATIC);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, base, pTab->nCol);
for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
sqlite3VdbeOp3(v, OP_OpenWrite, i+base, pIdx->tnum, pIdx->zName, P3_STATIC);
diff --git a/src/pragma.c b/src/pragma.c
index 23e275a1e..b0be50a25 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
-** $Id: pragma.c,v 1.23 2004/05/16 11:15:38 danielk1977 Exp $
+** $Id: pragma.c,v 1.24 2004/05/18 01:23:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -580,17 +580,19 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
{ OP_SetInsert, 0, 0, "1"},
{ OP_Integer, 0, 0, 0}, /* 1 */
{ OP_OpenRead, 0, MASTER_ROOT, 0},
- { OP_Rewind, 0, 7, 0}, /* 3 */
- { OP_Column, 0, 3, 0}, /* 4 */
+ { OP_SetNumColumns,0,5, 0}, /* sqlite_master has 5 cols */
+
+ { OP_Rewind, 0, 8, 0}, /* 4 */
+ { OP_Column, 0, 3, 0}, /* 5 */
{ OP_SetInsert, 0, 0, 0},
- { OP_Next, 0, 4, 0}, /* 6 */
- { OP_IntegrityCk, 0, 0, 0}, /* 7 */
+ { OP_Next, 0, 5, 0}, /* 7 */
+ { OP_IntegrityCk, 0, 0, 0}, /* 8 */
{ OP_Dup, 0, 1, 0},
{ OP_String, 0, 0, "ok"},
- { OP_StrEq, 0, 12, 0}, /* 10 */
+ { OP_StrEq, 0, 13, 0}, /* 11 */
{ OP_MemIncr, 0, 0, 0},
{ OP_String, 0, 0, "*** in database "},
- { OP_String, 0, 0, 0}, /* 13 */
+ { OP_String, 0, 0, 0}, /* 14 */
{ OP_String, 0, 0, " ***\n"},
{ OP_Pull, 3, 0, 0},
{ OP_Concat, 4, 1, 0},
@@ -637,6 +639,7 @@ void sqlite3Pragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
if( pTab->pIndex==0 ) continue;
sqlite3VdbeAddOp(v, OP_Integer, i, 0);
sqlite3VdbeOp3(v, OP_OpenRead, 1, pTab->tnum, pTab->zName, 0);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, 1, pTab->nCol);
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
if( pIdx->tnum==0 ) continue;
sqlite3VdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
diff --git a/src/select.c b/src/select.c
index c4e5d1ece..ac715fa0b 100644
--- a/src/select.c
+++ b/src/select.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
-** $Id: select.c,v 1.165 2004/05/17 10:48:58 danielk1977 Exp $
+** $Id: select.c,v 1.166 2004/05/18 01:23:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -1313,7 +1313,9 @@ static int multiSelect(Parse *pParse, Select *p, int eDest, int iParm){
/* Create the destination temporary table if necessary
*/
if( eDest==SRT_TempTable ){
+ assert( p->pEList );
sqlite3VdbeAddOp(v, OP_OpenTemp, iParm, 0);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, p->pEList->nExpr);
eDest = SRT_Table;
}
@@ -1904,6 +1906,7 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
*/
if( eDest==SRT_TempTable ){
sqlite3VdbeAddOp(v, OP_OpenTemp, iParm, 0);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, 1);
}
/* Generating code to find the min or the max. Basically all we have
@@ -1917,6 +1920,7 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
if( pSrc->a[0].pSelect==0 ){
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeOp3(v, OP_OpenRead, base, pTab->tnum, pTab->zName, 0);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, base, pTab->nCol);
}
cont = sqlite3VdbeMakeLabel(v);
if( pIdx==0 ){
@@ -2244,6 +2248,7 @@ int sqlite3Select(
*/
if( eDest==SRT_TempTable ){
sqlite3VdbeAddOp(v, OP_OpenTemp, iParm, 0);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, iParm, pEList->nExpr);
}
/* Do an analysis of aggregate expressions.
diff --git a/src/update.c b/src/update.c
index f8dca1bef..d234f5e35 100644
--- a/src/update.c
+++ b/src/update.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
-** $Id: update.c,v 1.74 2004/05/16 11:15:39 danielk1977 Exp $
+** $Id: update.c,v 1.75 2004/05/18 01:23:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -258,6 +258,7 @@ void sqlite3Update(
if( !isView ){
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeAddOp(v, OP_OpenRead, iCur, pTab->tnum);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
}
sqlite3VdbeAddOp(v, OP_MoveTo, iCur, 0);
@@ -313,6 +314,7 @@ void sqlite3Update(
*/
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, iCur, pTab->nCol);
if( onError==OE_Replace ){
openAll = 1;
}else{
diff --git a/src/vdbe.c b/src/vdbe.c
index 0126b9cef..52b8c8ac5 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
-** $Id: vdbe.c,v 1.296 2004/05/17 10:48:58 danielk1977 Exp $
+** $Id: vdbe.c,v 1.297 2004/05/18 01:23:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -1992,6 +1992,19 @@ case OP_Class: {
break;
}
+/* Opcode: SetNumColumns P1 P2 *
+**
+** Before the OP_Column opcode can be executed on a cursor, this
+** opcode must be called to set the number of fields in the table.
+**
+** This opcode sets the number of columns for cursor P1 to P2.
+*/
+case OP_SetNumColumns: {
+ assert( (pOp->p1)<p->nCursor );
+ p->apCsr[pOp->p1]->nField = pOp->p2;
+ break;
+}
+
/* Opcode: Column P1 P2 *
**
** Interpret the data that cursor P1 points to as a structure built using
@@ -2012,7 +2025,7 @@ case OP_Column: {
int payloadSize; /* Number of bytes in the record */
int i = pOp->p1;
int p2 = pOp->p2; /* column number to retrieve */
- Cursor *pC;
+ Cursor *pC = 0;
char *zRec; /* Pointer to record-data from stack or pseudo-table. */
BtCursor *pCrsr;
@@ -2022,7 +2035,7 @@ case OP_Column: {
u64 nField; /* number of fields in the record */
int len; /* The length of the serialized data for the column */
- int offset;
+ int offset = 0;
int nn;
assert( i<p->nCursor );
@@ -2038,6 +2051,7 @@ case OP_Column: {
zRec = pTos[i].z;
payloadSize = pTos[i].n;
pC->cacheValid = 0;
+ assert(!"broken for now");
}else if( (pC = p->apCsr[i])->pCursor!=0 ){
sqlite3VdbeCursorMoveto(pC);
zRec = 0;
@@ -2068,11 +2082,20 @@ case OP_Column: {
break;
}
+ /* If the row data is coming from a cursor, then OP_SetNumColumns must of
+ ** been executed on that cursor. Also, p2 (the column to read) must be
+ ** less than nField.
+ */
+ assert( !pC || pC->nField>0 );
+ assert( p2<pC->nField );
+ nField = pC->nField;
+
/* Read and parse the table header. Store the results of the parse
** into the record header cache fields of the cursor.
*/
if( !pC->cacheValid ){
pC->payloadSize = payloadSize;
+#if 0
if( zRec ){
zData = zRec;
}else{
@@ -2088,15 +2111,19 @@ case OP_Column: {
}
assert( zData );
}
- offset = sqlite3GetVarint(zData, &nField);
- if( nField>pC->nField ){
- sqliteFree(pC->aType);
+ {
+ u64 x;
+ offset = sqlite3GetVarint(zData, &x);
+ assert( x==nField );
+ }
+#endif
+
+ if( !pC->aType ){
pC->aType = sqliteMallocRaw( nField*sizeof(pC->aType[0]) );
if( pC->aType==0 ){
goto no_mem;
}
}
- pC->nField = nField;
if( !zRec ){
/* If the record is stored in a table, see if enough of it is on
@@ -2257,7 +2284,7 @@ case OP_MakeRecord: {
unsigned char *zCsr;
char *zAffinity;
Mem *pRec;
- int nBytes; /* Space required for this record */
+ int nBytes = 0; /* Space required for this record */
Mem *pData0 = &pTos[1-nField];
assert( pData0>=p->aStack );
@@ -2266,7 +2293,7 @@ case OP_MakeRecord: {
/* Loop through the elements that will make up the record to figure
** out how much space is required for the new record.
*/
- nBytes = sqlite3VarintLen(nField);
+ // nBytes = sqlite3VarintLen(nField);
for(pRec=pData0; pRec<=pTos; pRec++){
u64 serial_type;
if( zAffinity ){
@@ -2285,13 +2312,12 @@ case OP_MakeRecord: {
/* Allocate space for the new record. */
zNewRecord = sqliteMallocRaw(nBytes);
if( !zNewRecord ){
- rc = SQLITE_NOMEM;
- goto abort_due_to_error;
+ goto no_mem;
}
/* Write the record */
zCsr = zNewRecord;
- zCsr += sqlite3PutVarint(zCsr, nField); /* number of fields */
+ // zCsr += sqlite3PutVarint(zCsr, nField); /* number of fields */
for(pRec=pData0; pRec<=pTos; pRec++){
u64 serial_type = sqlite3VdbeSerialType(pRec);
zCsr += sqlite3PutVarint(zCsr, serial_type); /* serial type */
@@ -2421,8 +2447,7 @@ case OP_MakeIdxKey: {
/* Allocate space for the new key */
zKey = (char *)sqliteMallocRaw(nByte);
if( !zKey ){
- rc = SQLITE_NOMEM;
- goto abort_due_to_error;
+ goto no_mem;
}
/* Build the key in the buffer pointed to by zKey. */
@@ -3564,8 +3589,7 @@ case OP_IdxColumn: {
if( !zData ){
zData = (char *)sqliteMalloc(n);
if( !zData ){
- rc = SQLITE_NOMEM;
- goto abort_due_to_error;
+ goto no_mem;
}
rc = sqlite3BtreeKey(pCsr, len, n, zData);
if( rc!=SQLITE_OK ){
diff --git a/src/where.c b/src/where.c
index e65362e82..41a37e287 100644
--- a/src/where.c
+++ b/src/where.c
@@ -12,7 +12,7 @@
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.
**
-** $Id: where.c,v 1.95 2004/05/17 10:48:58 danielk1977 Exp $
+** $Id: where.c,v 1.96 2004/05/18 01:23:39 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -680,6 +680,7 @@ WhereInfo *sqlite3WhereBegin(
sqlite3VdbeAddOp(v, OP_Integer, pTab->iDb, 0);
sqlite3VdbeOp3(v, OP_OpenRead, pTabList->a[i].iCursor, pTab->tnum,
pTab->zName, P3_STATIC);
+ sqlite3VdbeAddOp(v, OP_SetNumColumns, pTabList->a[i].iCursor, pTab->nCol);
sqlite3CodeVerifySchema(pParse, pTab->iDb);
if( (pIx = pWInfo->a[i].pIdx)!=0 ){
sqlite3VdbeAddOp(v, OP_Integer, pIx->iDb, 0);