/ Check-in [45169ce0]
Login

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

Overview
Comment:Variable name change: azVar to apVar. (CVS 1404)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:45169ce015da07da9a874b5b075ea6a05f59f162
User & Date: drh 2004-05-19 11:24:26
Context
2004-05-19
11:31
Really remove the OP_StrEq opcode this time - appearently I didn't save the file out of the editor before doing the check-in (1397). (CVS 1405) check-in: 821b0b29 user: drh tags: trunk
11:24
Variable name change: azVar to apVar. (CVS 1404) check-in: 45169ce0 user: drh tags: trunk
10:36
Tests for text encoding conversion functions. Also new sqlite3_bindXX APIs. (CVS 1403) check-in: f71844bc user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
**
** 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.300 2004/05/19 10:35:01 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include "vdbeInt.h"

/*
................................................................................
*/
case OP_Variable: {
  int j = pOp->p1 - 1;
  Mem *pVar;
  assert( j>=0 && j<p->nVar );

  /* If we need to translate between text encodings, do it now. If this is
  ** required, then put the new string in p->azVar. This way, if the
  ** variable is used again, even after the virtual machine is reset, the
  ** conversion won't have to be done again.
  **
  ** TODO: This is where we need to support databases that use other than
  ** UTF-8 on disk.
  */
  pVar = &p->azVar[j];
  if( pVar->flags&MEM_Str && !(pVar->flags&MEM_Utf8) ){
    char *zUtf8;
    assert( pVar->flags&(MEM_Utf16le|MEM_Utf16be) );
    zUtf8 = sqlite3utf16to8(pVar->z, pVar->n);
    if( !zUtf8 ){
      goto no_mem;
    }







|







 







|






|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
**
** 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.301 2004/05/19 11:24:26 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <ctype.h>
#include "vdbeInt.h"

/*
................................................................................
*/
case OP_Variable: {
  int j = pOp->p1 - 1;
  Mem *pVar;
  assert( j>=0 && j<p->nVar );

  /* If we need to translate between text encodings, do it now. If this is
  ** required, then put the new string in p->apVar. This way, if the
  ** variable is used again, even after the virtual machine is reset, the
  ** conversion won't have to be done again.
  **
  ** TODO: This is where we need to support databases that use other than
  ** UTF-8 on disk.
  */
  pVar = &p->apVar[j];
  if( pVar->flags&MEM_Str && !(pVar->flags&MEM_Utf8) ){
    char *zUtf8;
    assert( pVar->flags&(MEM_Utf16le|MEM_Utf16be) );
    zUtf8 = sqlite3utf16to8(pVar->z, pVar->n);
    if( !zUtf8 ){
      goto no_mem;
    }

Changes to src/vdbeInt.h.

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
  char **azColName;   /* Becomes the 4th parameter to callbacks */
  int nCursor;        /* Number of slots in apCsr[] */
  Cursor **apCsr;     /* One element of this array for each open cursor */
  Sorter *pSort;      /* A linked list of objects to be sorted */
  FILE *pFile;        /* At most one open file handler */
  int nField;         /* Number of file fields */
  char **azField;     /* Data for each file field */
  int nVar;           /* Number of entries in azVariable[] */
  Mem *azVar;         /* Values for the OP_Variable opcode. */
  char *zLine;            /* A single line from the input file */
  int nLineAlloc;         /* Number of spaces allocated for zLine */
  int magic;              /* Magic number for sanity checking */
  int nMem;               /* Number of memory locations currently allocated */
  Mem *aMem;              /* The memory locations */
  Agg agg;                /* Aggregate information */
  int nSet;               /* Number of sets allocated */







|
|







267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
  char **azColName;   /* Becomes the 4th parameter to callbacks */
  int nCursor;        /* Number of slots in apCsr[] */
  Cursor **apCsr;     /* One element of this array for each open cursor */
  Sorter *pSort;      /* A linked list of objects to be sorted */
  FILE *pFile;        /* At most one open file handler */
  int nField;         /* Number of file fields */
  char **azField;     /* Data for each file field */
  int nVar;           /* Number of entries in apVar[] */
  Mem *apVar;         /* Values for the OP_Variable opcode. */
  char *zLine;            /* A single line from the input file */
  int nLineAlloc;         /* Number of spaces allocated for zLine */
  int magic;              /* Magic number for sanity checking */
  int nMem;               /* Number of memory locations currently allocated */
  Mem *aMem;              /* The memory locations */
  Agg agg;                /* Aggregate information */
  int nSet;               /* Number of sets allocated */

Changes to src/vdbeaux.c.

612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
...
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
...
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
...
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
....
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
....
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
....
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
  */
  if( p->aStack==0 ){
    p->nVar = nVar;
    assert( nVar>=0 );
    n = isExplain ? 10 : p->nOp;
    p->aStack = sqliteMalloc(
      n*(sizeof(p->aStack[0]) + 2*sizeof(char*))     /* aStack and zArgv */
      + p->nVar*sizeof(Mem)                          /* azVar */
    );
    p->zArgv = (char**)&p->aStack[n];
    p->azColName = (char**)&p->zArgv[n];
    p->azVar = (Mem *)&p->azColName[n];
    for(n=0; n<p->nVar; n++){
      p->azVar[n].flags = MEM_Null;
    }
  }

  sqlite3HashInit(&p->agg.hash, SQLITE_HASH_BINARY, 0);
  p->agg.pSearch = 0;
#ifdef MEMORY_DEBUG
  if( sqlite3OsFileExists("vdbe_trace") ){
................................................................................
}

/*
** Clean up the VM after execution.
**
** This routine will automatically close any cursors, lists, and/or
** sorters that were left open.  It also deletes the values of
** variables in the azVariable[] array.
*/
static void Cleanup(Vdbe *p){
  int i;
  if( p->aStack ){
    Mem *pTos = p->pTos;
    while( pTos>=p->aStack ){
      if( pTos->flags & MEM_Dyn ){
................................................................................
  if( p->magic!=VDBE_MAGIC_RUN || p->pc!=0 ){
    return SQLITE_MISUSE;
  }
  if( i<1 || i>p->nVar ){
    return SQLITE_RANGE;
  }
  i--;
  pVar = &p->azVar[i];
  if( pVar->flags&MEM_Dyn ){
    sqliteFree(pVar->z);
  }
  pVar->flags = MEM_Null;
  return SQLITE_OK;
}

................................................................................
  int bytes,         /* Number of bytes to copy */
  int copy,          /* True to copy the memory, false to copy a pointer */
  int flags          /* Valid combination of MEM_Blob, MEM_Str, MEM_UtfXX */
){
  Mem *pVar;

  vdbeUnbind(p, i);
  pVar = &p->azVar[i-1];

  if( zVal ){
    pVar->n = bytes;
    pVar->flags = flags;
    if( !copy ){
      pVar->z = (char *)zVal;
      pVar->flags |= MEM_Static;
................................................................................
}

int sqlite3_bind_int64(sqlite3_stmt *p, int i, long long int iValue){
  int rc;
  Vdbe *v = (Vdbe *)p;
  rc = vdbeUnbind(v, i);
  if( rc==SQLITE_OK ){
    Mem *pVar = &v->azVar[i-1];
    pVar->flags = MEM_Int;
    pVar->i = iValue;
  }
  return SQLITE_OK;
}

int sqlite3_bind_int32(sqlite3_stmt *p, int i, int iValue){
................................................................................
}

int sqlite3_bind_double(sqlite3_stmt *p, int i, double iValue){
  int rc;
  Vdbe *v = (Vdbe *)p;
  rc = vdbeUnbind(v, i);
  if( rc==SQLITE_OK ){
    Mem *pVar = &v->azVar[i-1];
    pVar->flags = MEM_Real;
    pVar->r = iValue;
  }
  return SQLITE_OK;
}

int sqlite3_bind_null(sqlite3_stmt* p, int i){
................................................................................
  }
  for(i=0; i<p->nOp; i++){
    if( p->aOp[i].p3type==P3_DYNAMIC ){
      sqliteFree(p->aOp[i].p3);
    }
  }
  for(i=0; i<p->nVar; i++){
    if( p->azVar[i].flags&MEM_Dyn ){
      sqliteFree(p->azVar[i].z);
    }
  }
  sqliteFree(p->aOp);
  sqliteFree(p->aLabel);
  sqliteFree(p->aStack);
  p->magic = VDBE_MAGIC_DEAD;
  sqliteFree(p);







|



|

|







 







|







 







|







 







|







 







|







 







|







 







|
|







612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
...
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
...
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
...
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
....
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
....
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
....
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
  */
  if( p->aStack==0 ){
    p->nVar = nVar;
    assert( nVar>=0 );
    n = isExplain ? 10 : p->nOp;
    p->aStack = sqliteMalloc(
      n*(sizeof(p->aStack[0]) + 2*sizeof(char*))     /* aStack and zArgv */
      + p->nVar*sizeof(Mem)                          /* apVar */
    );
    p->zArgv = (char**)&p->aStack[n];
    p->azColName = (char**)&p->zArgv[n];
    p->apVar = (Mem *)&p->azColName[n];
    for(n=0; n<p->nVar; n++){
      p->apVar[n].flags = MEM_Null;
    }
  }

  sqlite3HashInit(&p->agg.hash, SQLITE_HASH_BINARY, 0);
  p->agg.pSearch = 0;
#ifdef MEMORY_DEBUG
  if( sqlite3OsFileExists("vdbe_trace") ){
................................................................................
}

/*
** Clean up the VM after execution.
**
** This routine will automatically close any cursors, lists, and/or
** sorters that were left open.  It also deletes the values of
** variables in the aVar[] array.
*/
static void Cleanup(Vdbe *p){
  int i;
  if( p->aStack ){
    Mem *pTos = p->pTos;
    while( pTos>=p->aStack ){
      if( pTos->flags & MEM_Dyn ){
................................................................................
  if( p->magic!=VDBE_MAGIC_RUN || p->pc!=0 ){
    return SQLITE_MISUSE;
  }
  if( i<1 || i>p->nVar ){
    return SQLITE_RANGE;
  }
  i--;
  pVar = &p->apVar[i];
  if( pVar->flags&MEM_Dyn ){
    sqliteFree(pVar->z);
  }
  pVar->flags = MEM_Null;
  return SQLITE_OK;
}

................................................................................
  int bytes,         /* Number of bytes to copy */
  int copy,          /* True to copy the memory, false to copy a pointer */
  int flags          /* Valid combination of MEM_Blob, MEM_Str, MEM_UtfXX */
){
  Mem *pVar;

  vdbeUnbind(p, i);
  pVar = &p->apVar[i-1];

  if( zVal ){
    pVar->n = bytes;
    pVar->flags = flags;
    if( !copy ){
      pVar->z = (char *)zVal;
      pVar->flags |= MEM_Static;
................................................................................
}

int sqlite3_bind_int64(sqlite3_stmt *p, int i, long long int iValue){
  int rc;
  Vdbe *v = (Vdbe *)p;
  rc = vdbeUnbind(v, i);
  if( rc==SQLITE_OK ){
    Mem *pVar = &v->apVar[i-1];
    pVar->flags = MEM_Int;
    pVar->i = iValue;
  }
  return SQLITE_OK;
}

int sqlite3_bind_int32(sqlite3_stmt *p, int i, int iValue){
................................................................................
}

int sqlite3_bind_double(sqlite3_stmt *p, int i, double iValue){
  int rc;
  Vdbe *v = (Vdbe *)p;
  rc = vdbeUnbind(v, i);
  if( rc==SQLITE_OK ){
    Mem *pVar = &v->apVar[i-1];
    pVar->flags = MEM_Real;
    pVar->r = iValue;
  }
  return SQLITE_OK;
}

int sqlite3_bind_null(sqlite3_stmt* p, int i){
................................................................................
  }
  for(i=0; i<p->nOp; i++){
    if( p->aOp[i].p3type==P3_DYNAMIC ){
      sqliteFree(p->aOp[i].p3);
    }
  }
  for(i=0; i<p->nVar; i++){
    if( p->apVar[i].flags&MEM_Dyn ){
      sqliteFree(p->apVar[i].z);
    }
  }
  sqliteFree(p->aOp);
  sqliteFree(p->aLabel);
  sqliteFree(p->aStack);
  p->magic = VDBE_MAGIC_DEAD;
  sqliteFree(p);