/ Check-in [bf2181f1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Bug fix associated with OP_SetNumColumns in insert.c. Also changed a variable name in OP_Column. (CVS 1413)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bf2181f13fdad72d8c90eccc2d29034178181731
User & Date: drh 2004-05-20 02:42:16
Context
2004-05-20
03:02
Bug fix associated with misc3.test. (CVS 1414) check-in: a7f02db7 user: drh tags: trunk
02:42
Bug fix associated with OP_SetNumColumns in insert.c. Also changed a variable name in OP_Column. (CVS 1413) check-in: bf2181f1 user: drh tags: trunk
02:01
VACUUM works again. (CVS 1412) check-in: c4e1d02f user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/insert.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.103 2004/05/19 14:56:56 drh Exp $
*/
#include "sqliteInt.h"

/*
** Set P3 of the most recently inserted opcode to a column affinity
** string for index pIdx. A column affinity string has one character
** for each column in the table, according to the affinity of the column:
................................................................................

      /* The following code runs first because the GOTO at the very top
      ** of the program jumps to it.  Create the temporary table, then jump
      ** back up and execute the SELECT code above.
      */
      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{
      sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
    }
  }else{
    /* This is the case if the data for the INSERT is coming from a VALUES







|







 







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.104 2004/05/20 02:42:16 drh Exp $
*/
#include "sqliteInt.h"

/*
** Set P3 of the most recently inserted opcode to a column affinity
** string for index pIdx. A column affinity string has one character
** for each column in the table, according to the affinity of the column:
................................................................................

      /* The following code runs first because the GOTO at the very top
      ** of the program jumps to it.  Create the temporary table, then jump
      ** back up and execute the SELECT code above.
      */
      sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
      sqlite3VdbeAddOp(v, OP_OpenTemp, srcTab, 0);
      sqlite3VdbeAddOp(v, OP_SetNumColumns, srcTab, nColumn);
      sqlite3VdbeAddOp(v, OP_Goto, 0, iSelectLoop);
      sqlite3VdbeResolveLabel(v, iCleanup);
    }else{
      sqlite3VdbeChangeP2(v, iInitCode, sqlite3VdbeCurrentAddr(v));
    }
  }else{
    /* This is the case if the data for the INSERT is coming from a VALUES

Changes to src/vdbe.c.

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
496
497
498
499
500
501
502







503
504
505
506
507
508
509
....
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
....
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
....
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** 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.306 2004/05/20 01:12:35 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include "vdbeInt.h"

/*
................................................................................
      break;

    default:
      assert(0);
  }
}








static int getBtreeMem(
  BtCursor *pCur,   /* Cursor pointing at record to retrieve. */
  int offset,       /* Offset from the start of data to return bytes from. */
  int amt,          /* Number of bytes to return. */
  int key,          /* If true, retrieve from the btree key, not data. */
  Mem *pMem         /* OUT: Return data in this Mem structure. */
){
................................................................................

  u64 nField;        /* number of fields in the record */
  int len;           /* The length of the serialized data for the column */
  int offset = 0;
  int nn;

  char *zData;       
  Mem zMem;
  zMem.flags = 0;

  assert( i<p->nCursor );
  pTos++;

  /* If the record is coming from the stack, not from a cursor, then there
  ** is nowhere to cache the record header infomation. This simplifies
  ** things greatly, so deal with this case seperately.
................................................................................
      ** three bytes or less. 
      */
      int max_space = sqlite3VarintLen((((u64)payloadSize)<<1)+13)*nField;
      if( max_space>payloadSize ){
        max_space = payloadSize;
      }

      rc = getBtreeMem(pCrsr, 0, max_space, pC->keyAsData, &zMem);
      if( rc!=SQLITE_OK ){
        goto abort_due_to_error;
      }
      zData = zMem.z;
    }

    /* Read all the serial types for the record.  At the end of this block
    ** variable offset is set to the offset to the start of Data0 in the record.
    */
    for(nn=0; nn<nField; nn++){
      offset += sqlite3GetVarint(&zData[offset], &pC->aType[nn]);
    }
    pC->nHeader = offset;
    pC->cacheValid = 1;

    Release(&zMem);
    zMem.flags = 0;
  }

  /* Compute the offset from the beginning of the record to the beginning
  ** of the data.  And get the length of the data.
  */
  offset = pC->nHeader;
  for(nn=0; nn<p2; nn++){
................................................................................
    offset += sqlite3VdbeSerialTypeLen(pC->aType[nn]);
  }

  if( zRec ){
    zData = &zRec[offset];
  }else{
    len = sqlite3VdbeSerialTypeLen(pC->aType[p2]);
    getBtreeMem(pCrsr, offset, len, pC->keyAsData, &zMem);
    zData = zMem.z;
  }
  sqlite3VdbeSerialGet(zData, pC->aType[p2], pTos);

  Release(&zMem);
  break;
}

/* Opcode MakeRecord P1 * P3
**
** This opcode (not yet in use) is a replacement for the current
** OP_MakeRecord that supports the SQLite3 manifest typing feature.







|







 







>
>
>
>
>
>
>







 







|
|







 







|



|











|
|







 







|
|



|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
....
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
....
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
....
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
**
** Various scripts scan this source file in order to generate HTML
** documentation, headers files, or other derived files.  The formatting
** of the code in this file is, therefore, important.  See other comments
** 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.307 2004/05/20 02:42:17 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include "vdbeInt.h"

/*
................................................................................
      break;

    default:
      assert(0);
  }
}

/*
** Move data out of a btree key or data field and into a Mem structure.
** The data or key is taken from the entry that pCur is currently pointing
** to.  offset and amt determine what portion of the data or key to retrieve.
** key is true to get the key or false to get data.  The result is written
** into the pMem element.
*/
static int getBtreeMem(
  BtCursor *pCur,   /* Cursor pointing at record to retrieve. */
  int offset,       /* Offset from the start of data to return bytes from. */
  int amt,          /* Number of bytes to return. */
  int key,          /* If true, retrieve from the btree key, not data. */
  Mem *pMem         /* OUT: Return data in this Mem structure. */
){
................................................................................

  u64 nField;        /* number of fields in the record */
  int len;           /* The length of the serialized data for the column */
  int offset = 0;
  int nn;

  char *zData;       
  Mem sMem;
  sMem.flags = 0;

  assert( i<p->nCursor );
  pTos++;

  /* If the record is coming from the stack, not from a cursor, then there
  ** is nowhere to cache the record header infomation. This simplifies
  ** things greatly, so deal with this case seperately.
................................................................................
      ** three bytes or less. 
      */
      int max_space = sqlite3VarintLen((((u64)payloadSize)<<1)+13)*nField;
      if( max_space>payloadSize ){
        max_space = payloadSize;
      }

      rc = getBtreeMem(pCrsr, 0, max_space, pC->keyAsData, &sMem);
      if( rc!=SQLITE_OK ){
        goto abort_due_to_error;
      }
      zData = sMem.z;
    }

    /* Read all the serial types for the record.  At the end of this block
    ** variable offset is set to the offset to the start of Data0 in the record.
    */
    for(nn=0; nn<nField; nn++){
      offset += sqlite3GetVarint(&zData[offset], &pC->aType[nn]);
    }
    pC->nHeader = offset;
    pC->cacheValid = 1;

    Release(&sMem);
    sMem.flags = 0;
  }

  /* Compute the offset from the beginning of the record to the beginning
  ** of the data.  And get the length of the data.
  */
  offset = pC->nHeader;
  for(nn=0; nn<p2; nn++){
................................................................................
    offset += sqlite3VdbeSerialTypeLen(pC->aType[nn]);
  }

  if( zRec ){
    zData = &zRec[offset];
  }else{
    len = sqlite3VdbeSerialTypeLen(pC->aType[p2]);
    getBtreeMem(pCrsr, offset, len, pC->keyAsData, &sMem);
    zData = sMem.z;
  }
  sqlite3VdbeSerialGet(zData, pC->aType[p2], pTos);

  Release(&sMem);
  break;
}

/* Opcode MakeRecord P1 * P3
**
** This opcode (not yet in use) is a replacement for the current
** OP_MakeRecord that supports the SQLite3 manifest typing feature.