/ Check-in [356cdd64]
Login

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

Overview
Comment:documentation and speed updates (CVS 164)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 356cdd64860b714f52529159fada799dca7bb1c0
User & Date: drh 2000-10-23 13:16:32
Context
2000-10-23
13:20
Version 1.0.15 (CVS 488) check-in: d2ad3d2b user: drh tags: trunk
13:16
documentation and speed updates (CVS 164) check-in: 356cdd64 user: drh tags: trunk
01:08
remove unnecessary code when NDEBUG is defined (CVS 163) check-in: 738e3e49 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to VERSION.

     1         -1.0.14
            1  +1.0.15

Changes to src/vdbe.c.

    37     37   ** inplicit conversion from one type to the other occurs as necessary.
    38     38   ** 
    39     39   ** Most of the code in this file is taken up by the sqliteVdbeExec()
    40     40   ** function which does the work of interpreting a VDBE program.
    41     41   ** But other routines are also provided to help in building up
    42     42   ** a program instruction by instruction.
    43     43   **
    44         -** $Id: vdbe.c,v 1.46 2000/10/23 01:08:00 drh Exp $
           44  +** $Id: vdbe.c,v 1.47 2000/10/23 13:16:33 drh Exp $
    45     45   */
    46     46   #include "sqliteInt.h"
    47     47   #include <unistd.h>
    48     48   #include <ctype.h>
    49     49   
    50     50   /*
    51     51   ** SQL is translated into a sequence of instructions to be
................................................................................
   951    951     int (*xBusy)(void*,const char*,int)  /* Called when a file is busy */
   952    952   ){
   953    953     int pc;                    /* The program counter */
   954    954     Op *pOp;                   /* Current operation */
   955    955     int rc;                    /* Value to return */
   956    956     Dbbe *pBe = p->pBe;        /* The backend driver */
   957    957     sqlite *db = p->db;        /* The database */
          958  +  char **zStack;
          959  +  Stack *aStack;
   958    960     char zBuf[100];            /* Space to sprintf() and integer */
   959    961   
   960    962   
   961    963     /* No instruction ever pushes more than a single element onto the
   962    964     ** stack.  And the stack never grows on successive executions of the
   963    965     ** same loop.  So the total number of instructions is an upper bound
   964    966     ** on the maximum stack depth required.
   965    967     **
   966    968     ** Allocation all the stack space we will ever need.
   967    969     */
   968    970     NeedStack(p, p->nOp);
          971  +  zStack = p->zStack;
          972  +  aStack = p->aStack;
   969    973     p->tos = -1;
   970    974   
   971    975     rc = SQLITE_OK;
   972    976   #ifdef MEMORY_DEBUG
   973    977     if( access("vdbe_trace",0)==0 ){
   974    978       p->trace = stderr;
   975    979     }
................................................................................
  1023   1027         /* Opcode: Integer P1 * *
  1024   1028         **
  1025   1029         ** The integer value P1 is pushed onto the stack.
  1026   1030         */
  1027   1031         case OP_Integer: {
  1028   1032           int i = ++p->tos;
  1029   1033           VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
  1030         -        p->aStack[i].i = pOp->p1;
  1031         -        p->aStack[i].flags = STK_Int;
         1034  +        aStack[i].i = pOp->p1;
         1035  +        aStack[i].flags = STK_Int;
  1032   1036           break;
  1033   1037         }
  1034   1038   
  1035   1039         /* Opcode: String * * P3
  1036   1040         **
  1037   1041         ** The string value P3 is pushed onto the stack.
  1038   1042         */
  1039   1043         case OP_String: {
  1040   1044           int i = ++p->tos;
  1041   1045           char *z;
  1042   1046           VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
  1043   1047           z = pOp->p3;
  1044   1048           if( z==0 ) z = "";
  1045         -        p->zStack[i] = z;
  1046         -        p->aStack[i].n = strlen(z) + 1;
  1047         -        p->aStack[i].flags = STK_Str;
         1049  +        zStack[i] = z;
         1050  +        aStack[i].n = strlen(z) + 1;
         1051  +        aStack[i].flags = STK_Str;
  1048   1052           break;
  1049   1053         }
  1050   1054   
  1051   1055         /* Opcode: Null * * *
  1052   1056         **
  1053   1057         ** Push a NULL value onto the stack.
  1054   1058         */
  1055   1059         case OP_Null: {
  1056   1060           int i = ++p->tos;
  1057   1061           VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
  1058         -        p->zStack[i] = 0;
  1059         -        p->aStack[i].flags = STK_Null;
         1062  +        zStack[i] = 0;
         1063  +        aStack[i].flags = STK_Null;
  1060   1064           break;
  1061   1065         }
  1062   1066   
  1063   1067         /* Opcode: Pop P1 * *
  1064   1068         **
  1065   1069         ** P1 elements are popped off of the top of stack and discarded.
  1066   1070         */
................................................................................
  1078   1082         ** top of the stack.
  1079   1083         */
  1080   1084         case OP_Dup: {
  1081   1085           int i = p->tos - pOp->p1;
  1082   1086           int j = ++p->tos;
  1083   1087           VERIFY( if( i<0 ) goto not_enough_stack; )
  1084   1088           VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
  1085         -        p->aStack[j] = p->aStack[i];
  1086         -        if( p->aStack[i].flags & STK_Dyn ){
  1087         -          p->zStack[j] = sqliteMalloc( p->aStack[j].n );
  1088         -          if( p->zStack[j]==0 ) goto no_mem;
  1089         -          memcpy(p->zStack[j], p->zStack[i], p->aStack[j].n);
         1089  +        aStack[j] = aStack[i];
         1090  +        if( aStack[i].flags & STK_Dyn ){
         1091  +          zStack[j] = sqliteMalloc( aStack[j].n );
         1092  +          if( zStack[j]==0 ) goto no_mem;
         1093  +          memcpy(zStack[j], zStack[i], aStack[j].n);
  1090   1094           }else{
  1091         -          p->zStack[j] = p->zStack[i];
         1095  +          zStack[j] = zStack[i];
  1092   1096           }
  1093   1097           break;
  1094   1098         }
  1095   1099   
  1096   1100         /* Opcode: Pull P1 * *
  1097   1101         **
  1098   1102         ** The P1-th element is removed from its current location on 
................................................................................
  1103   1107         case OP_Pull: {
  1104   1108           int from = p->tos - pOp->p1;
  1105   1109           int to = p->tos;
  1106   1110           int i;
  1107   1111           Stack ts;
  1108   1112           char *tz;
  1109   1113           VERIFY( if( from<0 ) goto not_enough_stack; )
  1110         -        ts = p->aStack[from];
  1111         -        tz = p->zStack[from];
         1114  +        ts = aStack[from];
         1115  +        tz = zStack[from];
  1112   1116           for(i=from; i<to; i++){
  1113         -          p->aStack[i] = p->aStack[i+1];
  1114         -          p->zStack[i] = p->zStack[i+1];
         1117  +          aStack[i] = aStack[i+1];
         1118  +          zStack[i] = zStack[i+1];
  1115   1119           }
  1116         -        p->aStack[to] = ts;
  1117         -        p->zStack[to] = tz;
         1120  +        aStack[to] = ts;
         1121  +        zStack[to] = tz;
  1118   1122           break;
  1119   1123         }
  1120   1124   
  1121   1125         /* Opcode: ColumnCount P1 * *
  1122   1126         **
  1123   1127         ** Specify the number of column values that will appear in the
  1124   1128         ** array passed as the 4th parameter to the callback.  No checking
................................................................................
  1152   1156         */
  1153   1157         case OP_Callback: {
  1154   1158           int i = p->tos - pOp->p1 + 1;
  1155   1159           int j;
  1156   1160           VERIFY( if( i<0 ) goto not_enough_stack; )
  1157   1161           VERIFY( if( NeedStack(p, p->tos+2) ) goto no_mem; )
  1158   1162           for(j=i; j<=p->tos; j++){
  1159         -          if( (p->aStack[j].flags & STK_Null)==0 ){
         1163  +          if( (aStack[j].flags & STK_Null)==0 ){
  1160   1164               if( Stringify(p, j) ) goto no_mem;
  1161   1165             }
  1162   1166           }
  1163         -        p->zStack[p->tos+1] = 0;
         1167  +        zStack[p->tos+1] = 0;
  1164   1168           if( xCallback!=0 ){
  1165         -          if( xCallback(pArg, pOp->p1, &p->zStack[i], p->azColName)!=0 ){
         1169  +          if( xCallback(pArg, pOp->p1, &zStack[i], p->azColName)!=0 ){
  1166   1170               rc = SQLITE_ABORT;
  1167   1171             }
  1168   1172           }
  1169   1173           PopStack(p, pOp->p1);
  1170   1174           break;
  1171   1175         }
  1172   1176   
................................................................................
  1192   1196           nField = pOp->p1;
  1193   1197           zSep = pOp->p3;
  1194   1198           if( zSep==0 ) zSep = "";
  1195   1199           nSep = strlen(zSep);
  1196   1200           VERIFY( if( p->tos+1<nField ) goto not_enough_stack; )
  1197   1201           nByte = 1 - nSep;
  1198   1202           for(i=p->tos-nField+1; i<=p->tos; i++){
  1199         -          if( p->aStack[i].flags & STK_Null ){
         1203  +          if( aStack[i].flags & STK_Null ){
  1200   1204               nByte += nSep;
  1201   1205             }else{
  1202   1206               if( Stringify(p, i) ) goto no_mem;
  1203         -            nByte += p->aStack[i].n - 1 + nSep;
         1207  +            nByte += aStack[i].n - 1 + nSep;
  1204   1208             }
  1205   1209           }
  1206   1210           zNew = sqliteMalloc( nByte );
  1207   1211           if( zNew==0 ) goto no_mem;
  1208   1212           j = 0;
  1209   1213           for(i=p->tos-nField+1; i<=p->tos; i++){
  1210         -          if( (p->aStack[i].flags & STK_Null)==0 ){
  1211         -            memcpy(&zNew[j], p->zStack[i], p->aStack[i].n-1);
  1212         -            j += p->aStack[i].n-1;
         1214  +          if( (aStack[i].flags & STK_Null)==0 ){
         1215  +            memcpy(&zNew[j], zStack[i], aStack[i].n-1);
         1216  +            j += aStack[i].n-1;
  1213   1217             }
  1214   1218             if( nSep>0 && i<p->tos ){
  1215   1219               memcpy(&zNew[j], zSep, nSep);
  1216   1220               j += nSep;
  1217   1221             }
  1218   1222           }
  1219   1223           zNew[j] = 0;
  1220   1224           if( pOp->p2==0 ) PopStack(p, nField);
  1221   1225           VERIFY( NeedStack(p, p->tos+1); )
  1222   1226           p->tos++;
  1223         -        p->aStack[p->tos].n = nByte;
  1224         -        p->aStack[p->tos].flags = STK_Str|STK_Dyn;
  1225         -        p->zStack[p->tos] = zNew;
         1227  +        aStack[p->tos].n = nByte;
         1228  +        aStack[p->tos].flags = STK_Str|STK_Dyn;
         1229  +        zStack[p->tos] = zNew;
  1226   1230           break;
  1227   1231         }
  1228   1232   
  1229   1233         /* Opcode: Add * * *
  1230   1234         **
  1231   1235         ** Pop the top two elements from the stack, add them together,
  1232   1236         ** and push the result back onto the stack.  If either element
................................................................................
  1261   1265         case OP_Add:
  1262   1266         case OP_Subtract:
  1263   1267         case OP_Multiply:
  1264   1268         case OP_Divide: {
  1265   1269           int tos = p->tos;
  1266   1270           int nos = tos - 1;
  1267   1271           VERIFY( if( nos<0 ) goto not_enough_stack; )
  1268         -        if( (p->aStack[tos].flags & p->aStack[nos].flags & STK_Int)==STK_Int ){
         1272  +        if( (aStack[tos].flags & aStack[nos].flags & STK_Int)==STK_Int ){
  1269   1273             int a, b;
  1270         -          a = p->aStack[tos].i;
  1271         -          b = p->aStack[nos].i;
         1274  +          a = aStack[tos].i;
         1275  +          b = aStack[nos].i;
  1272   1276             switch( pOp->opcode ){
  1273   1277               case OP_Add:         b += a;       break;
  1274   1278               case OP_Subtract:    b -= a;       break;
  1275   1279               case OP_Multiply:    b *= a;       break;
  1276   1280               default: {
  1277   1281                 if( a==0 ) goto divide_by_zero;
  1278   1282                 b /= a;
  1279   1283                 break;
  1280   1284               }
  1281   1285             }
  1282   1286             PopStack(p, 2);
  1283   1287             p->tos = nos;
  1284         -          p->aStack[nos].i = b;
  1285         -          p->aStack[nos].flags = STK_Int;
         1288  +          aStack[nos].i = b;
         1289  +          aStack[nos].flags = STK_Int;
  1286   1290           }else{
  1287   1291             double a, b;
  1288   1292             Realify(p, tos);
  1289   1293             Realify(p, nos);
  1290         -          a = p->aStack[tos].r;
  1291         -          b = p->aStack[nos].r;
         1294  +          a = aStack[tos].r;
         1295  +          b = aStack[nos].r;
  1292   1296             switch( pOp->opcode ){
  1293   1297               case OP_Add:         b += a;       break;
  1294   1298               case OP_Subtract:    b -= a;       break;
  1295   1299               case OP_Multiply:    b *= a;       break;
  1296   1300               default: {
  1297   1301                 if( a==0.0 ) goto divide_by_zero;
  1298   1302                 b /= a;
  1299   1303                 break;
  1300   1304               }
  1301   1305             }
  1302   1306             PopStack(p, 1);
  1303   1307             Release(p, nos);
  1304         -          p->aStack[nos].r = b;
  1305         -          p->aStack[nos].flags = STK_Real;
         1308  +          aStack[nos].r = b;
         1309  +          aStack[nos].flags = STK_Real;
  1306   1310           }
  1307   1311           break;
  1308   1312   
  1309   1313         divide_by_zero:
  1310   1314           PopStack(p, 2);
  1311   1315           p->tos = nos;
  1312         -        p->aStack[nos].flags = STK_Null;
         1316  +        aStack[nos].flags = STK_Null;
  1313   1317           break;
  1314   1318         }
  1315   1319   
  1316   1320         /* Opcode: Max * * *
  1317   1321         **
  1318   1322         ** Pop the top two elements from the stack then push back the
  1319   1323         ** largest of the two.
................................................................................
  1320   1324         */
  1321   1325         case OP_Max: {
  1322   1326           int tos = p->tos;
  1323   1327           int nos = tos - 1;
  1324   1328           int ft, fn;
  1325   1329           int copy = 0;
  1326   1330           VERIFY( if( nos<0 ) goto not_enough_stack; )
  1327         -        ft = p->aStack[tos].flags;
  1328         -        fn = p->aStack[nos].flags;
         1331  +        ft = aStack[tos].flags;
         1332  +        fn = aStack[nos].flags;
  1329   1333           if( fn & STK_Null ){
  1330   1334             copy = 1;
  1331   1335           }else if( (ft & fn & STK_Int)==STK_Int ){
  1332         -          copy = p->aStack[nos].i<p->aStack[tos].i;
         1336  +          copy = aStack[nos].i<aStack[tos].i;
  1333   1337           }else if( ( (ft|fn) & (STK_Int|STK_Real) ) !=0 ){
  1334   1338             Realify(p, tos);
  1335   1339             Realify(p, nos);
  1336         -          copy = p->aStack[tos].r>p->aStack[nos].r;
         1340  +          copy = aStack[tos].r>aStack[nos].r;
  1337   1341           }else{
  1338   1342             Stringify(p, tos);
  1339   1343             Stringify(p, nos);
  1340         -          copy = sqliteCompare(p->zStack[tos],p->zStack[nos])>0;
         1344  +          copy = sqliteCompare(zStack[tos],zStack[nos])>0;
  1341   1345           }
  1342   1346           if( copy ){
  1343   1347             Release(p, nos);
  1344         -          p->aStack[nos] = p->aStack[tos];
  1345         -          p->zStack[nos] = p->zStack[tos];
  1346         -          p->zStack[tos] = 0;
  1347         -          p->aStack[tos].flags = 0;
         1348  +          aStack[nos] = aStack[tos];
         1349  +          zStack[nos] = zStack[tos];
         1350  +          zStack[tos] = 0;
         1351  +          aStack[tos].flags = 0;
  1348   1352           }else{
  1349   1353             Release(p, tos);
  1350   1354           }
  1351   1355           p->tos = nos;
  1352   1356           break;
  1353   1357         }
  1354   1358   
................................................................................
  1359   1363         */
  1360   1364         case OP_Min: {
  1361   1365           int tos = p->tos;
  1362   1366           int nos = tos - 1;
  1363   1367           int ft, fn;
  1364   1368           int copy = 0;
  1365   1369           VERIFY( if( nos<0 ) goto not_enough_stack; )
  1366         -        ft = p->aStack[tos].flags;
  1367         -        fn = p->aStack[nos].flags;
         1370  +        ft = aStack[tos].flags;
         1371  +        fn = aStack[nos].flags;
  1368   1372           if( fn & STK_Null ){
  1369   1373             copy = 1;
  1370   1374           }else if( ft & STK_Null ){
  1371   1375             copy = 0;
  1372   1376           }else if( (ft & fn & STK_Int)==STK_Int ){
  1373         -          copy = p->aStack[nos].i>p->aStack[tos].i;
         1377  +          copy = aStack[nos].i>aStack[tos].i;
  1374   1378           }else if( ( (ft|fn) & (STK_Int|STK_Real) ) !=0 ){
  1375   1379             Realify(p, tos);
  1376   1380             Realify(p, nos);
  1377         -          copy = p->aStack[tos].r<p->aStack[nos].r;
         1381  +          copy = aStack[tos].r<aStack[nos].r;
  1378   1382           }else{
  1379   1383             Stringify(p, tos);
  1380   1384             Stringify(p, nos);
  1381         -          copy = sqliteCompare(p->zStack[tos],p->zStack[nos])<0;
         1385  +          copy = sqliteCompare(zStack[tos],zStack[nos])<0;
  1382   1386           }
  1383   1387           if( copy ){
  1384   1388             Release(p, nos);
  1385         -          p->aStack[nos] = p->aStack[tos];
  1386         -          p->zStack[nos] = p->zStack[tos];
  1387         -          p->zStack[tos] = 0;
  1388         -          p->aStack[tos].flags = 0;
         1389  +          aStack[nos] = aStack[tos];
         1390  +          zStack[nos] = zStack[tos];
         1391  +          zStack[tos] = 0;
         1392  +          aStack[tos].flags = 0;
  1389   1393           }else{
  1390   1394             Release(p, tos);
  1391   1395           }
  1392   1396           p->tos = nos;
  1393   1397           break;
  1394   1398         }
  1395   1399   
................................................................................
  1397   1401         ** 
  1398   1402         ** Add the value P1 to whatever is on top of the stack.
  1399   1403         */
  1400   1404         case OP_AddImm: {
  1401   1405           int tos = p->tos;
  1402   1406           VERIFY( if( tos<0 ) goto not_enough_stack; )
  1403   1407           Integerify(p, tos);
  1404         -        p->aStack[tos].i += pOp->p1;
         1408  +        aStack[tos].i += pOp->p1;
  1405   1409           break;
  1406   1410         }
  1407   1411   
  1408   1412         /* Opcode: Eq * P2 *
  1409   1413         **
  1410   1414         ** Pop the top two elements from the stack.  If they are equal, then
  1411   1415         ** jump to instruction P2.  Otherwise, continue to the next instruction.
................................................................................
  1447   1451         case OP_Gt:
  1448   1452         case OP_Ge: {
  1449   1453           int tos = p->tos;
  1450   1454           int nos = tos - 1;
  1451   1455           int c;
  1452   1456           int ft, fn;
  1453   1457           VERIFY( if( nos<0 ) goto not_enough_stack; )
  1454         -        ft = p->aStack[tos].flags;
  1455         -        fn = p->aStack[nos].flags;
         1458  +        ft = aStack[tos].flags;
         1459  +        fn = aStack[nos].flags;
  1456   1460           if( (ft & fn)==STK_Int ){
  1457         -          c = p->aStack[nos].i - p->aStack[tos].i;
         1461  +          c = aStack[nos].i - aStack[tos].i;
  1458   1462           }else{
  1459   1463             Stringify(p, tos);
  1460   1464             Stringify(p, nos);
  1461         -          c = sqliteCompare(p->zStack[nos], p->zStack[tos]);
         1465  +          c = sqliteCompare(zStack[nos], zStack[tos]);
  1462   1466           }
  1463   1467           switch( pOp->opcode ){
  1464   1468             case OP_Eq:    c = c==0;     break;
  1465   1469             case OP_Ne:    c = c!=0;     break;
  1466   1470             case OP_Lt:    c = c<0;      break;
  1467   1471             case OP_Le:    c = c<=0;     break;
  1468   1472             case OP_Gt:    c = c>0;      break;
................................................................................
  1491   1495         case OP_Like: {
  1492   1496           int tos = p->tos;
  1493   1497           int nos = tos - 1;
  1494   1498           int c;
  1495   1499           VERIFY( if( nos<0 ) goto not_enough_stack; )
  1496   1500           Stringify(p, tos);
  1497   1501           Stringify(p, nos);
  1498         -        c = sqliteLikeCompare(p->zStack[tos], p->zStack[nos]);
         1502  +        c = sqliteLikeCompare(zStack[tos], zStack[nos]);
  1499   1503           PopStack(p, 2);
  1500   1504           if( pOp->p1 ) c = !c;
  1501   1505           if( c ) pc = pOp->p2-1;
  1502   1506           break;
  1503   1507         }
  1504   1508   
  1505   1509         /* Opcode: Glob P1 P2 *
................................................................................
  1523   1527         case OP_Glob: {
  1524   1528           int tos = p->tos;
  1525   1529           int nos = tos - 1;
  1526   1530           int c;
  1527   1531           VERIFY( if( nos<0 ) goto not_enough_stack; )
  1528   1532           Stringify(p, tos);
  1529   1533           Stringify(p, nos);
  1530         -        c = sqliteGlobCompare(p->zStack[tos], p->zStack[nos]);
         1534  +        c = sqliteGlobCompare(zStack[tos], zStack[nos]);
  1531   1535           PopStack(p, 2);
  1532   1536           if( pOp->p1 ) c = !c;
  1533   1537           if( c ) pc = pOp->p2-1;
  1534   1538           break;
  1535   1539         }
  1536   1540   
  1537   1541         /* Opcode: And * * *
................................................................................
  1551   1555           int tos = p->tos;
  1552   1556           int nos = tos - 1;
  1553   1557           int c;
  1554   1558           VERIFY( if( nos<0 ) goto not_enough_stack; )
  1555   1559           Integerify(p, tos);
  1556   1560           Integerify(p, nos);
  1557   1561           if( pOp->opcode==OP_And ){
  1558         -          c = p->aStack[tos].i && p->aStack[nos].i;
         1562  +          c = aStack[tos].i && aStack[nos].i;
  1559   1563           }else{
  1560         -          c = p->aStack[tos].i || p->aStack[nos].i;
         1564  +          c = aStack[tos].i || aStack[nos].i;
  1561   1565           }
  1562   1566           PopStack(p, 2);
  1563   1567           p->tos++;
  1564         -        p->aStack[nos].i = c;
  1565         -        p->aStack[nos].flags = STK_Int;
         1568  +        aStack[nos].i = c;
         1569  +        aStack[nos].flags = STK_Int;
  1566   1570           break;
  1567   1571         }
  1568   1572   
  1569   1573         /* Opcode: Negative * * *
  1570   1574         **
  1571   1575         ** Treat the top of the stack as a numeric quantity.  Replace it
  1572   1576         ** with its additive inverse.
  1573   1577         */
  1574   1578         case OP_Negative: {
  1575   1579           int tos = p->tos;
  1576   1580           VERIFY( if( tos<0 ) goto not_enough_stack; )
  1577         -        if( p->aStack[tos].flags & STK_Real ){
         1581  +        if( aStack[tos].flags & STK_Real ){
  1578   1582             Release(p, tos);
  1579         -          p->aStack[tos].r = -p->aStack[tos].r;
  1580         -          p->aStack[tos].flags = STK_Real;
  1581         -        }else if( p->aStack[tos].flags & STK_Int ){
         1583  +          aStack[tos].r = -aStack[tos].r;
         1584  +          aStack[tos].flags = STK_Real;
         1585  +        }else if( aStack[tos].flags & STK_Int ){
  1582   1586             Release(p, tos);
  1583         -          p->aStack[tos].i = -p->aStack[tos].i;
  1584         -          p->aStack[tos].flags = STK_Int;
         1587  +          aStack[tos].i = -aStack[tos].i;
         1588  +          aStack[tos].flags = STK_Int;
  1585   1589           }else{
  1586   1590             Realify(p, tos);
  1587   1591             Release(p, tos);
  1588         -          p->aStack[tos].r = -p->aStack[tos].r;
  1589         -          p->aStack[tos].flags = STK_Real;
         1592  +          aStack[tos].r = -aStack[tos].r;
         1593  +          aStack[tos].flags = STK_Real;
  1590   1594           }
  1591   1595           break;
  1592   1596         }
  1593   1597   
  1594   1598         /* Opcode: Not * * *
  1595   1599         **
  1596   1600         ** Interpret the top of the stack as a boolean value.  Replace it
................................................................................
  1597   1601         ** with its complement.
  1598   1602         */
  1599   1603         case OP_Not: {
  1600   1604           int tos = p->tos;
  1601   1605           VERIFY( if( p->tos<0 ) goto not_enough_stack; )
  1602   1606           Integerify(p, tos);
  1603   1607           Release(p, tos);
  1604         -        p->aStack[tos].i = !p->aStack[tos].i;
  1605         -        p->aStack[tos].flags = STK_Int;
         1608  +        aStack[tos].i = !aStack[tos].i;
         1609  +        aStack[tos].flags = STK_Int;
  1606   1610           break;
  1607   1611         }
  1608   1612   
  1609   1613         /* Opcode: Noop * * *
  1610   1614         **
  1611   1615         ** Do nothing.  This instruction is often useful as a jump
  1612   1616         ** destination.
................................................................................
  1622   1626         ** An integer is false if zero and true otherwise.  A string is
  1623   1627         ** false if it has zero length and true otherwise.
  1624   1628         */
  1625   1629         case OP_If: {
  1626   1630           int c;
  1627   1631           VERIFY( if( p->tos<0 ) goto not_enough_stack; )
  1628   1632           Integerify(p, p->tos);
  1629         -        c = p->aStack[p->tos].i;
         1633  +        c = aStack[p->tos].i;
  1630   1634           PopStack(p, 1);
  1631   1635           if( c ) pc = pOp->p2-1;
  1632   1636           break;
  1633   1637         }
  1634   1638   
  1635   1639         /* Opcode: IsNull * P2 *
  1636   1640         **
................................................................................
  1637   1641         ** Pop a single value from the stack.  If the value popped is NULL
  1638   1642         ** then jump to p2.  Otherwise continue to the next 
  1639   1643         ** instruction.
  1640   1644         */
  1641   1645         case OP_IsNull: {
  1642   1646           int c;
  1643   1647           VERIFY( if( p->tos<0 ) goto not_enough_stack; )
  1644         -        c = (p->aStack[p->tos].flags & STK_Null)!=0;
         1648  +        c = (aStack[p->tos].flags & STK_Null)!=0;
  1645   1649           PopStack(p, 1);
  1646   1650           if( c ) pc = pOp->p2-1;
  1647   1651           break;
  1648   1652         }
  1649   1653   
  1650   1654         /* Opcode: NotNull * P2 *
  1651   1655         **
................................................................................
  1652   1656         ** Pop a single value from the stack.  If the value popped is not an
  1653   1657         ** empty string, then jump to p2.  Otherwise continue to the next 
  1654   1658         ** instruction.
  1655   1659         */
  1656   1660         case OP_NotNull: {
  1657   1661           int c;
  1658   1662           VERIFY( if( p->tos<0 ) goto not_enough_stack; )
  1659         -        c = (p->aStack[p->tos].flags & STK_Null)==0;
         1663  +        c = (aStack[p->tos].flags & STK_Null)==0;
  1660   1664           PopStack(p, 1);
  1661   1665           if( c ) pc = pOp->p2-1;
  1662   1666           break;
  1663   1667         }
  1664   1668   
  1665   1669         /* Opcode: MakeRecord P1 * *
  1666   1670         **
................................................................................
  1683   1687           int i, j;
  1684   1688           int addr;
  1685   1689   
  1686   1690           nField = pOp->p1;
  1687   1691           VERIFY( if( p->tos+1<nField ) goto not_enough_stack; )
  1688   1692           nByte = 0;
  1689   1693           for(i=p->tos-nField+1; i<=p->tos; i++){
  1690         -          if( (p->aStack[i].flags & STK_Null)==0 ){
         1694  +          if( (aStack[i].flags & STK_Null)==0 ){
  1691   1695               if( Stringify(p, i) ) goto no_mem;
  1692         -            nByte += p->aStack[i].n;
         1696  +            nByte += aStack[i].n;
  1693   1697             }
  1694   1698           }
  1695   1699           nByte += sizeof(int)*nField;
  1696   1700           zNewRecord = sqliteMalloc( nByte );
  1697   1701           if( zNewRecord==0 ) goto no_mem;
  1698   1702           j = 0;
  1699   1703           addr = sizeof(int)*nField;
  1700   1704           for(i=p->tos-nField+1; i<=p->tos; i++){
  1701         -          if( p->aStack[i].flags & STK_Null ){
         1705  +          if( aStack[i].flags & STK_Null ){
  1702   1706               int zero = 0;
  1703   1707               memcpy(&zNewRecord[j], (char*)&zero, sizeof(int));
  1704   1708             }else{
  1705   1709               memcpy(&zNewRecord[j], (char*)&addr, sizeof(int));
  1706         -            addr += p->aStack[i].n;
         1710  +            addr += aStack[i].n;
  1707   1711             }
  1708   1712             j += sizeof(int);
  1709   1713           }
  1710   1714           for(i=p->tos-nField+1; i<=p->tos; i++){
  1711         -          if( (p->aStack[i].flags & STK_Null)==0 ){
  1712         -            memcpy(&zNewRecord[j], p->zStack[i], p->aStack[i].n);
  1713         -            j += p->aStack[i].n;
         1715  +          if( (aStack[i].flags & STK_Null)==0 ){
         1716  +            memcpy(&zNewRecord[j], zStack[i], aStack[i].n);
         1717  +            j += aStack[i].n;
  1714   1718             }
  1715   1719           }
  1716   1720           PopStack(p, nField);
  1717   1721           VERIFY( NeedStack(p, p->tos+1); )
  1718   1722           p->tos++;
  1719         -        p->aStack[p->tos].n = nByte;
  1720         -        p->aStack[p->tos].flags = STK_Str | STK_Dyn;
  1721         -        p->zStack[p->tos] = zNewRecord;
         1723  +        aStack[p->tos].n = nByte;
         1724  +        aStack[p->tos].flags = STK_Str | STK_Dyn;
         1725  +        zStack[p->tos] = zNewRecord;
  1722   1726           break;
  1723   1727         }
  1724   1728   
  1725   1729         /* Opcode: MakeKey P1 P2 *
  1726   1730         **
  1727   1731         ** Convert the top P1 entries of the stack into a single entry suitable
  1728   1732         ** for use as the key in an index or a sort.  The top P1 records are
................................................................................
  1744   1748           int nField;
  1745   1749           int i, j;
  1746   1750   
  1747   1751           nField = pOp->p1;
  1748   1752           VERIFY( if( p->tos+1<nField ) goto not_enough_stack; )
  1749   1753           nByte = 0;
  1750   1754           for(i=p->tos-nField+1; i<=p->tos; i++){
  1751         -          if( p->aStack[i].flags & STK_Null ){
         1755  +          if( aStack[i].flags & STK_Null ){
  1752   1756               nByte++;
  1753   1757             }else{
  1754   1758               if( Stringify(p, i) ) goto no_mem;
  1755         -            nByte += p->aStack[i].n;
         1759  +            nByte += aStack[i].n;
  1756   1760             }
  1757   1761           }
  1758   1762           zNewKey = sqliteMalloc( nByte );
  1759   1763           if( zNewKey==0 ) goto no_mem;
  1760   1764           j = 0;
  1761   1765           for(i=p->tos-nField+1; i<=p->tos; i++){
  1762         -          if( (p->aStack[i].flags & STK_Null)==0 ){
  1763         -            memcpy(&zNewKey[j], p->zStack[i], p->aStack[i].n-1);
  1764         -            j += p->aStack[i].n-1;
         1766  +          if( (aStack[i].flags & STK_Null)==0 ){
         1767  +            memcpy(&zNewKey[j], zStack[i], aStack[i].n-1);
         1768  +            j += aStack[i].n-1;
  1765   1769             }
  1766   1770             if( i<p->tos ) zNewKey[j++] = '\t';
  1767   1771           }
  1768   1772           zNewKey[j] = 0;
  1769   1773           if( pOp->p2==0 ) PopStack(p, nField);
  1770   1774           VERIFY( NeedStack(p, p->tos+1); )
  1771   1775           p->tos++;
  1772         -        p->aStack[p->tos].n = nByte;
  1773         -        p->aStack[p->tos].flags = STK_Str|STK_Dyn;
  1774         -        p->zStack[p->tos] = zNewKey;
         1776  +        aStack[p->tos].n = nByte;
         1777  +        aStack[p->tos].flags = STK_Str|STK_Dyn;
         1778  +        zStack[p->tos] = zNewKey;
  1775   1779           break;
  1776   1780         }
  1777   1781   
  1778   1782         /* Opcode: Open P1 P2 P3
  1779   1783         **
  1780   1784         ** Open a new cursor for the database file named P3.  Give the
  1781   1785         ** cursor an identifier P1.  The P1 values need not be
................................................................................
  1860   1864         ** in the P1 cursor until needed.
  1861   1865         */
  1862   1866         case OP_Fetch: {
  1863   1867           int i = pOp->p1;
  1864   1868           int tos = p->tos;
  1865   1869           VERIFY( if( tos<0 ) goto not_enough_stack; )
  1866   1870           if( i>=0 && i<p->nCursor && p->aCsr[i].pCursor ){
  1867         -          if( p->aStack[tos].flags & STK_Int ){
         1871  +          if( aStack[tos].flags & STK_Int ){
  1868   1872               pBe->Fetch(p->aCsr[i].pCursor, sizeof(int), 
  1869         -                           (char*)&p->aStack[tos].i);
         1873  +                           (char*)&aStack[tos].i);
  1870   1874             }else{
  1871   1875               if( Stringify(p, tos) ) goto no_mem;
  1872         -            pBe->Fetch(p->aCsr[i].pCursor, p->aStack[tos].n, 
  1873         -                           p->zStack[tos]);
         1876  +            pBe->Fetch(p->aCsr[i].pCursor, aStack[tos].n, 
         1877  +                           zStack[tos]);
  1874   1878             }
  1875   1879             p->nFetch++;
  1876   1880           }
  1877   1881           PopStack(p, 1);
  1878   1882           break;
  1879   1883         }
  1880   1884   
................................................................................
  1886   1890         ** This instruction is used to implement the special fcnt() function
  1887   1891         ** in the SQL dialect that SQLite understands.  fcnt() is used for
  1888   1892         ** testing purposes.
  1889   1893         */
  1890   1894         case OP_Fcnt: {
  1891   1895           int i = ++p->tos;
  1892   1896           VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
  1893         -        p->aStack[i].i = p->nFetch;
  1894         -        p->aStack[i].flags = STK_Int;
         1897  +        aStack[i].i = p->nFetch;
         1898  +        aStack[i].flags = STK_Int;
  1895   1899           break;
  1896   1900         }
  1897   1901   
  1898   1902         /* Opcode: Distinct P1 P2 *
  1899   1903         **
  1900   1904         ** Use the top of the stack as a key.  If a record with that key
  1901   1905         ** does not exist in file P1, then jump to P2.  If the record
................................................................................
  1926   1930         case OP_NotFound:
  1927   1931         case OP_Found: {
  1928   1932           int i = pOp->p1;
  1929   1933           int tos = p->tos;
  1930   1934           int alreadyExists = 0;
  1931   1935           VERIFY( if( tos<0 ) goto not_enough_stack; )
  1932   1936           if( VERIFY( i>=0 && i<p->nCursor && ) p->aCsr[i].pCursor ){
  1933         -          if( p->aStack[tos].flags & STK_Int ){
         1937  +          if( aStack[tos].flags & STK_Int ){
  1934   1938               alreadyExists = pBe->Test(p->aCsr[i].pCursor, sizeof(int), 
  1935         -                                          (char*)&p->aStack[tos].i);
         1939  +                                          (char*)&aStack[tos].i);
  1936   1940             }else{
  1937   1941               if( Stringify(p, tos) ) goto no_mem;
  1938         -            alreadyExists = pBe->Test(p->aCsr[i].pCursor,p->aStack[tos].n, 
  1939         -                                           p->zStack[tos]);
         1942  +            alreadyExists = pBe->Test(p->aCsr[i].pCursor,aStack[tos].n, 
         1943  +                                           zStack[tos]);
  1940   1944             }
  1941   1945           }
  1942   1946           if( pOp->opcode==OP_Found ){
  1943   1947             if( alreadyExists ) pc = pOp->p2 - 1;
  1944   1948           }else{
  1945   1949             if( !alreadyExists ) pc = pOp->p2 - 1;
  1946   1950           }
................................................................................
  1961   1965           if( VERIFY( i<0 || i>=p->nCursor || ) p->aCsr[i].pCursor==0 ){
  1962   1966             v = 0;
  1963   1967           }else{
  1964   1968             v = pBe->New(p->aCsr[i].pCursor);
  1965   1969           }
  1966   1970           VERIFY( NeedStack(p, p->tos+1); )
  1967   1971           p->tos++;
  1968         -        p->aStack[p->tos].i = v;
  1969         -        p->aStack[p->tos].flags = STK_Int;
         1972  +        aStack[p->tos].i = v;
         1973  +        aStack[p->tos].flags = STK_Int;
  1970   1974           break;
  1971   1975         }
  1972   1976   
  1973   1977         /* Opcode: Put P1 * *
  1974   1978         **
  1975   1979         ** Write an entry into the database file P1.  A new entry is
  1976   1980         ** created if it doesn't already exist, or the data for an existing
................................................................................
  1982   1986           int tos = p->tos;
  1983   1987           int nos = p->tos-1;
  1984   1988           int i = pOp->p1;
  1985   1989           VERIFY( if( nos<0 ) goto not_enough_stack; )
  1986   1990           if( VERIFY( i>=0 && i<p->nCursor && ) p->aCsr[i].pCursor!=0 ){
  1987   1991             char *zKey;
  1988   1992             int nKey;
  1989         -          if( (p->aStack[nos].flags & STK_Int)==0 ){
         1993  +          if( (aStack[nos].flags & STK_Int)==0 ){
  1990   1994               if( Stringify(p, nos) ) goto no_mem;
  1991         -            nKey = p->aStack[nos].n;
  1992         -            zKey = p->zStack[nos];
         1995  +            nKey = aStack[nos].n;
         1996  +            zKey = zStack[nos];
  1993   1997             }else{
  1994   1998               nKey = sizeof(int);
  1995         -            zKey = (char*)&p->aStack[nos].i;
         1999  +            zKey = (char*)&aStack[nos].i;
  1996   2000             }
  1997   2001             pBe->Put(p->aCsr[i].pCursor, nKey, zKey,
  1998         -                        p->aStack[tos].n, p->zStack[tos]);
         2002  +                        aStack[tos].n, zStack[tos]);
  1999   2003           }
  2000   2004           PopStack(p, 2);
  2001   2005           break;
  2002   2006         }
  2003   2007   
  2004   2008         /* Opcode: Delete P1 * *
  2005   2009         **
................................................................................
  2009   2013         case OP_Delete: {
  2010   2014           int tos = p->tos;
  2011   2015           int i = pOp->p1;
  2012   2016           VERIFY( if( tos<0 ) goto not_enough_stack; )
  2013   2017           if( VERIFY( i>=0 && i<p->nCursor && ) p->aCsr[i].pCursor!=0 ){
  2014   2018             char *zKey;
  2015   2019             int nKey;
  2016         -          if( p->aStack[tos].flags & STK_Int ){
         2020  +          if( aStack[tos].flags & STK_Int ){
  2017   2021               nKey = sizeof(int);
  2018         -            zKey = (char*)&p->aStack[tos].i;
         2022  +            zKey = (char*)&aStack[tos].i;
  2019   2023             }else{
  2020   2024               if( Stringify(p, tos) ) goto no_mem;
  2021         -            nKey = p->aStack[tos].n;
  2022         -            zKey = p->zStack[tos];
         2025  +            nKey = aStack[tos].n;
         2026  +            zKey = zStack[tos];
  2023   2027             }
  2024   2028             pBe->Delete(p->aCsr[i].pCursor, nKey, zKey);
  2025   2029           }
  2026   2030           PopStack(p, 1);
  2027   2031           break;
  2028   2032         }
  2029   2033   
................................................................................
  2073   2077           char *z;
  2074   2078   
  2075   2079           VERIFY( if( NeedStack(p, tos) ) goto no_mem; )
  2076   2080           if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){
  2077   2081             if( p->aCsr[i].keyAsData ){
  2078   2082               amt = pBe->KeyLength(pCrsr);
  2079   2083               if( amt<=sizeof(int)*(p2+1) ){
  2080         -              p->aStack[tos].flags = STK_Null;
         2084  +              aStack[tos].flags = STK_Null;
  2081   2085                 break;
  2082   2086               }
  2083   2087               pAddr = (int*)pBe->ReadKey(pCrsr, sizeof(int)*p2);
  2084   2088               if( *pAddr==0 ){
  2085         -              p->aStack[tos].flags = STK_Null;
         2089  +              aStack[tos].flags = STK_Null;
  2086   2090                 break;
  2087   2091               }
  2088   2092               z = pBe->ReadKey(pCrsr, *pAddr);
  2089   2093             }else{
  2090   2094               amt = pBe->DataLength(pCrsr);
  2091   2095               if( amt<=sizeof(int)*(p2+1) ){
  2092         -              p->aStack[tos].flags = STK_Null;
         2096  +              aStack[tos].flags = STK_Null;
  2093   2097                 break;
  2094   2098               }
  2095   2099               pAddr = (int*)pBe->ReadData(pCrsr, sizeof(int)*p2);
  2096   2100               if( *pAddr==0 ){
  2097         -              p->aStack[tos].flags = STK_Null;
         2101  +              aStack[tos].flags = STK_Null;
  2098   2102                 break;
  2099   2103               }
  2100   2104               z = pBe->ReadData(pCrsr, *pAddr);
  2101   2105             }
  2102         -          p->zStack[tos] = z;
  2103         -          p->aStack[tos].n = strlen(z) + 1;
  2104         -          p->aStack[tos].flags = STK_Str;
         2106  +          zStack[tos] = z;
         2107  +          aStack[tos].n = strlen(z) + 1;
         2108  +          aStack[tos].flags = STK_Str;
  2105   2109           }
  2106   2110           break;
  2107   2111         }
  2108   2112   
  2109   2113         /* Opcode: Key P1 * *
  2110   2114         **
  2111   2115         ** Push onto the stack an integer which is the first 4 bytes of the
................................................................................
  2118   2122           int tos = ++p->tos;
  2119   2123           DbbeCursor *pCrsr;
  2120   2124   
  2121   2125           VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
  2122   2126           if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){
  2123   2127             char *z = pBe->ReadKey(pCrsr, 0);
  2124   2128             if( p->aCsr[i].keyAsData ){
  2125         -            p->zStack[tos] = z;
  2126         -            p->aStack[tos].flags = STK_Str;
  2127         -            p->aStack[tos].n = pBe->KeyLength(pCrsr);
         2129  +            zStack[tos] = z;
         2130  +            aStack[tos].flags = STK_Str;
         2131  +            aStack[tos].n = pBe->KeyLength(pCrsr);
  2128   2132             }else{
  2129         -            memcpy(&p->aStack[tos].i, z, sizeof(int));
  2130         -            p->aStack[tos].flags = STK_Int;
         2133  +            memcpy(&aStack[tos].i, z, sizeof(int));
         2134  +            aStack[tos].flags = STK_Int;
  2131   2135             }
  2132   2136           }
  2133   2137           break;
  2134   2138         }
  2135   2139   
  2136   2140         /* Opcode: Rewind P1 * *
  2137   2141         **
................................................................................
  2195   2199         */
  2196   2200         case OP_NextIdx: {
  2197   2201           int i = pOp->p1;
  2198   2202           int tos = ++p->tos;
  2199   2203           DbbeCursor *pCrsr;
  2200   2204   
  2201   2205           VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
  2202         -        p->zStack[tos] = 0;
         2206  +        zStack[tos] = 0;
  2203   2207           if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){
  2204   2208             int *aIdx;
  2205   2209             int nIdx;
  2206   2210             int j, k;
  2207   2211             nIdx = pBe->DataLength(pCrsr)/sizeof(int);
  2208   2212             aIdx = (int*)pBe->ReadData(pCrsr, 0);
  2209   2213             if( nIdx>1 ){
................................................................................
  2210   2214               k = *(aIdx++);
  2211   2215               if( k>nIdx-1 ) k = nIdx-1;
  2212   2216             }else{
  2213   2217               k = nIdx;
  2214   2218             }
  2215   2219             for(j=p->aCsr[i].index; j<k; j++){
  2216   2220               if( aIdx[j]!=0 ){
  2217         -              p->aStack[tos].i = aIdx[j];
  2218         -              p->aStack[tos].flags = STK_Int;
         2221  +              aStack[tos].i = aIdx[j];
         2222  +              aStack[tos].flags = STK_Int;
  2219   2223                 break;
  2220   2224               }
  2221   2225             }
  2222   2226             if( j>=k ){
  2223   2227               j = -1;
  2224   2228               pc = pOp->p2 - 1;
  2225   2229               PopStack(p, 1);
................................................................................
  2244   2248           int nos = tos - 1;
  2245   2249           DbbeCursor *pCrsr;
  2246   2250           VERIFY( if( nos<0 ) goto not_enough_stack; )
  2247   2251           if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){
  2248   2252             int r;
  2249   2253             int newVal;
  2250   2254             Integerify(p, nos);
  2251         -          newVal = p->aStack[nos].i;
         2255  +          newVal = aStack[nos].i;
  2252   2256             if( Stringify(p, tos) ) goto no_mem;
  2253         -          r = pBe->Fetch(pCrsr, p->aStack[tos].n, p->zStack[tos]);
         2257  +          r = pBe->Fetch(pCrsr, aStack[tos].n, zStack[tos]);
  2254   2258             if( r==0 ){
  2255   2259               /* Create a new record for this index */
  2256         -            pBe->Put(pCrsr, p->aStack[tos].n, p->zStack[tos],
         2260  +            pBe->Put(pCrsr, aStack[tos].n, zStack[tos],
  2257   2261                             sizeof(int), (char*)&newVal);
  2258   2262             }else{
  2259   2263               /* Extend the existing record */
  2260   2264               int nIdx;
  2261   2265               int *aIdx;
  2262   2266               int k;
  2263   2267               
................................................................................
  2264   2268               nIdx = pBe->DataLength(pCrsr)/sizeof(int);
  2265   2269               if( nIdx==1 ){
  2266   2270                 aIdx = sqliteMalloc( sizeof(int)*4 );
  2267   2271                 if( aIdx==0 ) goto no_mem;
  2268   2272                 aIdx[0] = 2;
  2269   2273                 pBe->CopyData(pCrsr, 0, sizeof(int), (char*)&aIdx[1]);
  2270   2274                 aIdx[2] = newVal;
  2271         -              pBe->Put(pCrsr, p->aStack[tos].n, p->zStack[tos],
         2275  +              pBe->Put(pCrsr, aStack[tos].n, zStack[tos],
  2272   2276                       sizeof(int)*4, (char*)aIdx);
  2273   2277                 sqliteFree(aIdx);
  2274   2278               }else{
  2275   2279                 aIdx = (int*)pBe->ReadData(pCrsr, 0);
  2276   2280                 k = aIdx[0];
  2277   2281                 if( k<nIdx-1 ){
  2278   2282                   aIdx[k+1] = newVal;
  2279   2283                   aIdx[0]++;
  2280         -                pBe->Put(pCrsr, p->aStack[tos].n, p->zStack[tos],
         2284  +                pBe->Put(pCrsr, aStack[tos].n, zStack[tos],
  2281   2285                       sizeof(int)*nIdx, (char*)aIdx);
  2282   2286                 }else{
  2283   2287                   nIdx *= 2;
  2284   2288                   aIdx = sqliteMalloc( sizeof(int)*nIdx );
  2285   2289                   if( aIdx==0 ) goto no_mem;
  2286   2290                   pBe->CopyData(pCrsr, 0, sizeof(int)*(k+1), (char*)aIdx);
  2287   2291                   aIdx[k+1] = newVal;
  2288   2292                   aIdx[0]++;
  2289         -                pBe->Put(pCrsr, p->aStack[tos].n, p->zStack[tos],
         2293  +                pBe->Put(pCrsr, aStack[tos].n, zStack[tos],
  2290   2294                         sizeof(int)*nIdx, (char*)aIdx);
  2291   2295                   sqliteFree(aIdx);
  2292   2296                 }
  2293   2297               }              
  2294   2298             }
  2295   2299           }
  2296   2300           PopStack(p, 2);
................................................................................
  2319   2323           if( VERIFY( i>=0 && i<p->nCursor && ) (pCrsr = p->aCsr[i].pCursor)!=0 ){
  2320   2324             int *aIdx;
  2321   2325             int nIdx;
  2322   2326             int j, k;
  2323   2327             int r;
  2324   2328             int oldVal;
  2325   2329             Integerify(p, nos);
  2326         -          oldVal = p->aStack[nos].i;
         2330  +          oldVal = aStack[nos].i;
  2327   2331             if( Stringify(p, tos) ) goto no_mem;
  2328         -          r = pBe->Fetch(pCrsr, p->aStack[tos].n, p->zStack[tos]);
         2332  +          r = pBe->Fetch(pCrsr, aStack[tos].n, zStack[tos]);
  2329   2333             if( r==0 ) break;
  2330   2334             nIdx = pBe->DataLength(pCrsr)/sizeof(int);
  2331   2335             aIdx = (int*)pBe->ReadData(pCrsr, 0);
  2332   2336             if( (nIdx==1 && aIdx[0]==oldVal) || (aIdx[0]==1 && aIdx[1]==oldVal) ){
  2333         -            pBe->Delete(pCrsr, p->aStack[tos].n, p->zStack[tos]);
         2337  +            pBe->Delete(pCrsr, aStack[tos].n, zStack[tos]);
  2334   2338             }else{
  2335   2339               k = aIdx[0];
  2336   2340               for(j=1; j<=k && aIdx[j]!=oldVal; j++){}
  2337   2341               if( j>k ) break;
  2338   2342               aIdx[j] = aIdx[k];
  2339   2343               aIdx[k] = 0;
  2340   2344               aIdx[0]--;
  2341   2345               if( aIdx[0]*3 + 1 < nIdx ){
  2342   2346                 nIdx /= 2;
  2343   2347               }
  2344         -            pBe->Put(pCrsr, p->aStack[tos].n, p->zStack[tos], 
         2348  +            pBe->Put(pCrsr, aStack[tos].n, zStack[tos], 
  2345   2349                             sizeof(int)*nIdx, (char*)aIdx);
  2346   2350             }
  2347   2351           }
  2348   2352           PopStack(p, 2);
  2349   2353           break;
  2350   2354         }
  2351   2355   
................................................................................
  2404   2408         case OP_ListWrite: {
  2405   2409           int i = pOp->p1;
  2406   2410           VERIFY( if( i<0 ) goto bad_instruction; )
  2407   2411           VERIFY( if( p->tos<0 ) goto not_enough_stack; )
  2408   2412           if( VERIFY( i<p->nList && ) p->apList[i]!=0 ){
  2409   2413             int val;
  2410   2414             Integerify(p, p->tos);
  2411         -          val = p->aStack[p->tos].i;
         2415  +          val = aStack[p->tos].i;
  2412   2416             PopStack(p, 1);
  2413   2417             fwrite(&val, sizeof(int), 1, p->apList[i]);
  2414   2418           }
  2415   2419           break;
  2416   2420         }
  2417   2421   
  2418   2422         /* Opcode: ListRewind P1 * *
................................................................................
  2438   2442           int i = pOp->p1;
  2439   2443           int val, amt;
  2440   2444           VERIFY(if( i<0 || i>=p->nList || p->apList[i]==0 )goto bad_instruction;)
  2441   2445           amt = fread(&val, sizeof(int), 1, p->apList[i]);
  2442   2446           if( amt==1 ){
  2443   2447             p->tos++;
  2444   2448             if( NeedStack(p, p->tos) ) goto no_mem;
  2445         -          p->aStack[p->tos].i = val;
  2446         -          p->aStack[p->tos].flags = STK_Int;
  2447         -          p->zStack[p->tos] = 0;
         2449  +          aStack[p->tos].i = val;
         2450  +          aStack[p->tos].flags = STK_Int;
         2451  +          zStack[p->tos] = 0;
  2448   2452           }else{
  2449   2453             pc = pOp->p2 - 1;
  2450   2454           }
  2451   2455           break;
  2452   2456         }
  2453   2457   
  2454   2458         /* Opcode: ListClose P1 * *
................................................................................
  2495   2499           VERIFY( if( i<0 || i>=p->nSort ) goto bad_instruction; )
  2496   2500           VERIFY( if( tos<1 ) goto not_enough_stack; )
  2497   2501           if( Stringify(p, tos) || Stringify(p, nos) ) goto no_mem;
  2498   2502           pSorter = sqliteMalloc( sizeof(Sorter) );
  2499   2503           if( pSorter==0 ) goto no_mem;
  2500   2504           pSorter->pNext = p->apSort[i];
  2501   2505           p->apSort[i] = pSorter;
  2502         -        pSorter->nKey = p->aStack[tos].n;
  2503         -        pSorter->zKey = p->zStack[tos];
  2504         -        pSorter->nData = p->aStack[nos].n;
  2505         -        pSorter->pData = p->zStack[nos];
  2506         -        p->aStack[tos].flags = 0;
  2507         -        p->aStack[nos].flags = 0;
  2508         -        p->zStack[tos] = 0;
  2509         -        p->zStack[nos] = 0;
         2506  +        pSorter->nKey = aStack[tos].n;
         2507  +        pSorter->zKey = zStack[tos];
         2508  +        pSorter->nData = aStack[nos].n;
         2509  +        pSorter->pData = zStack[nos];
         2510  +        aStack[tos].flags = 0;
         2511  +        aStack[nos].flags = 0;
         2512  +        zStack[tos] = 0;
         2513  +        zStack[nos] = 0;
  2510   2514           p->tos -= 2;
  2511   2515           break;
  2512   2516         }
  2513   2517   
  2514   2518         /* Opcode: SortMakeRec P1 * *
  2515   2519         **
  2516   2520         ** The top P1 elements are the arguments to a callback.  Form these
................................................................................
  2524   2528           int nField;
  2525   2529           int i, j;
  2526   2530   
  2527   2531           nField = pOp->p1;
  2528   2532           VERIFY( if( p->tos+1<nField ) goto not_enough_stack; )
  2529   2533           nByte = 0;
  2530   2534           for(i=p->tos-nField+1; i<=p->tos; i++){
  2531         -          if( (p->aStack[i].flags & STK_Null)==0 ){
         2535  +          if( (aStack[i].flags & STK_Null)==0 ){
  2532   2536               if( Stringify(p, i) ) goto no_mem;
  2533         -            nByte += p->aStack[i].n;
         2537  +            nByte += aStack[i].n;
  2534   2538             }
  2535   2539           }
  2536   2540           nByte += sizeof(char*)*(nField+1);
  2537   2541           azArg = sqliteMalloc( nByte );
  2538   2542           if( azArg==0 ) goto no_mem;
  2539   2543           z = (char*)&azArg[nField+1];
  2540   2544           for(j=0, i=p->tos-nField+1; i<=p->tos; i++, j++){
  2541         -          if( p->aStack[i].flags & STK_Null ){
         2545  +          if( aStack[i].flags & STK_Null ){
  2542   2546               azArg[j] = 0;
  2543   2547             }else{
  2544   2548               azArg[j] = z;
  2545         -            strcpy(z, p->zStack[i]);
  2546         -            z += p->aStack[i].n;
         2549  +            strcpy(z, zStack[i]);
         2550  +            z += aStack[i].n;
  2547   2551             }
  2548   2552           }
  2549   2553           PopStack(p, nField);
  2550   2554           VERIFY( NeedStack(p, p->tos+1); )
  2551   2555           p->tos++;
  2552         -        p->aStack[p->tos].n = nByte;
  2553         -        p->zStack[p->tos] = (char*)azArg;
  2554         -        p->aStack[p->tos].flags = STK_Str|STK_Dyn;
         2556  +        aStack[p->tos].n = nByte;
         2557  +        zStack[p->tos] = (char*)azArg;
         2558  +        aStack[p->tos].flags = STK_Str|STK_Dyn;
  2555   2559           break;
  2556   2560         }
  2557   2561   
  2558   2562         /* Opcode: SortMakeKey P1 * P3
  2559   2563         **
  2560   2564         ** Convert the top few entries of the stack into a sort key.  The
  2561   2565         ** number of stack entries consumed is the number of characters in 
................................................................................
  2575   2579           int i, j, k;
  2576   2580   
  2577   2581           nField = strlen(pOp->p3);
  2578   2582           VERIFY( if( p->tos+1<nField ) goto not_enough_stack; )
  2579   2583           nByte = 1;
  2580   2584           for(i=p->tos-nField+1; i<=p->tos; i++){
  2581   2585             if( Stringify(p, i) ) goto no_mem;
  2582         -          nByte += p->aStack[i].n+2;
         2586  +          nByte += aStack[i].n+2;
  2583   2587           }
  2584   2588           zNewKey = sqliteMalloc( nByte );
  2585   2589           if( zNewKey==0 ) goto no_mem;
  2586   2590           j = 0;
  2587   2591           k = 0;
  2588   2592           for(i=p->tos-nField+1; i<=p->tos; i++){
  2589   2593             zNewKey[j++] = pOp->p3[k++];
  2590         -          memcpy(&zNewKey[j], p->zStack[i], p->aStack[i].n-1);
  2591         -          j += p->aStack[i].n-1;
         2594  +          memcpy(&zNewKey[j], zStack[i], aStack[i].n-1);
         2595  +          j += aStack[i].n-1;
  2592   2596             zNewKey[j++] = 0;
  2593   2597           }
  2594   2598           zNewKey[j] = 0;
  2595   2599           PopStack(p, nField);
  2596   2600           VERIFY( NeedStack(p, p->tos+1); )
  2597   2601           p->tos++;
  2598         -        p->aStack[p->tos].n = nByte;
  2599         -        p->aStack[p->tos].flags = STK_Str|STK_Dyn;
  2600         -        p->zStack[p->tos] = zNewKey;
         2602  +        aStack[p->tos].n = nByte;
         2603  +        aStack[p->tos].flags = STK_Str|STK_Dyn;
         2604  +        zStack[p->tos] = zNewKey;
  2601   2605           break;
  2602   2606         }
  2603   2607   
  2604   2608         /* Opcode: Sort P1 * *
  2605   2609         **
  2606   2610         ** Sort all elements on the given sorter.  The algorithm is a
  2607   2611         ** mergesort.
................................................................................
  2652   2656           int i = pOp->p1;
  2653   2657           VERIFY( if( i<0 ) goto bad_instruction; )
  2654   2658           if( VERIFY( i<p->nSort && ) p->apSort[i]!=0 ){
  2655   2659             Sorter *pSorter = p->apSort[i];
  2656   2660             p->apSort[i] = pSorter->pNext;
  2657   2661             p->tos++;
  2658   2662             VERIFY( NeedStack(p, p->tos); )
  2659         -          p->zStack[p->tos] = pSorter->pData;
  2660         -          p->aStack[p->tos].n = pSorter->nData;
  2661         -          p->aStack[p->tos].flags = STK_Str|STK_Dyn;
         2663  +          zStack[p->tos] = pSorter->pData;
         2664  +          aStack[p->tos].n = pSorter->nData;
         2665  +          aStack[p->tos].flags = STK_Str|STK_Dyn;
  2662   2666             sqliteFree(pSorter->zKey);
  2663   2667             sqliteFree(pSorter);
  2664   2668           }else{
  2665   2669             pc = pOp->p2 - 1;
  2666   2670           }
  2667   2671           break;
  2668   2672         }
................................................................................
  2675   2679         case OP_SortKey: {
  2676   2680           int i = pOp->p1;
  2677   2681           VERIFY( if( i<0 ) goto bad_instruction; )
  2678   2682           if( i<p->nSort && p->apSort[i]!=0 ){
  2679   2683             Sorter *pSorter = p->apSort[i];
  2680   2684             p->tos++;
  2681   2685             VERIFY( NeedStack(p, p->tos); )
  2682         -          sqliteSetString(&p->zStack[p->tos], pSorter->zKey, 0);
  2683         -          p->aStack[p->tos].n = pSorter->nKey;
  2684         -          p->aStack[p->tos].flags = STK_Str|STK_Dyn;
         2686  +          sqliteSetString(&zStack[p->tos], pSorter->zKey, 0);
         2687  +          aStack[p->tos].n = pSorter->nKey;
         2688  +          aStack[p->tos].flags = STK_Str|STK_Dyn;
  2685   2689           }
  2686   2690           break;
  2687   2691         }
  2688   2692   
  2689   2693         /* Opcode: SortCallback P1 P2 *
  2690   2694         **
  2691   2695         ** The top of the stack contains a callback record built using
................................................................................
  2693   2697         ** instruction.  Pop this record from the stack and invoke the
  2694   2698         ** callback on it.
  2695   2699         */
  2696   2700         case OP_SortCallback: {
  2697   2701           int i = p->tos;
  2698   2702           VERIFY( if( i<0 ) goto not_enough_stack; )
  2699   2703           if( xCallback!=0 ){
  2700         -          if( xCallback(pArg, pOp->p1, (char**)p->zStack[i], p->azColName) ){
         2704  +          if( xCallback(pArg, pOp->p1, (char**)zStack[i], p->azColName) ){
  2701   2705               rc = SQLITE_ABORT;
  2702   2706             }
  2703   2707           }
  2704   2708           PopStack(p, 1);
  2705   2709           break;
  2706   2710         }
  2707   2711   
................................................................................
  2873   2877           if( VERIFY( i>=0 && i<p->nField && ) p->azField ){
  2874   2878             z = p->azField[i];
  2875   2879           }else{
  2876   2880             z = 0;
  2877   2881           }
  2878   2882           if( z==0 ) z = "";
  2879   2883           p->tos++;
  2880         -        p->aStack[p->tos].n = strlen(z) + 1;
  2881         -        p->zStack[p->tos] = z;
  2882         -        p->aStack[p->tos].flags = STK_Str;
         2884  +        aStack[p->tos].n = strlen(z) + 1;
         2885  +        zStack[p->tos] = z;
         2886  +        aStack[p->tos].flags = STK_Str;
  2883   2887           break;
  2884   2888         }
  2885   2889   
  2886   2890         /* Opcode: MemStore P1 * *
  2887   2891         **
  2888   2892         ** Pop a single value of the stack and store that value into memory
  2889   2893         ** location P1.  P1 should be a small integer since space is allocated
................................................................................
  2906   2910           }
  2907   2911           pMem = &p->aMem[i];
  2908   2912           if( pMem->s.flags & STK_Dyn ){
  2909   2913             zOld = pMem->z;
  2910   2914           }else{
  2911   2915             zOld = 0;
  2912   2916           }
  2913         -        pMem->s = p->aStack[tos];
         2917  +        pMem->s = aStack[tos];
  2914   2918           if( pMem->s.flags & STK_Str ){
  2915         -          pMem->z = sqliteStrNDup(p->zStack[tos], pMem->s.n);
         2919  +          pMem->z = sqliteStrNDup(zStack[tos], pMem->s.n);
  2916   2920             pMem->s.flags |= STK_Dyn;
  2917   2921           }
  2918   2922           if( zOld ) sqliteFree(zOld);
  2919   2923           PopStack(p, 1);
  2920   2924           break;
  2921   2925         }
  2922   2926   
................................................................................
  2925   2929         ** Push a copy of the value in memory location P1 onto the stack.
  2926   2930         */
  2927   2931         case OP_MemLoad: {
  2928   2932           int tos = ++p->tos;
  2929   2933           int i = pOp->p1;
  2930   2934           VERIFY( if( NeedStack(p, tos) ) goto no_mem; )
  2931   2935           if( i<0 || i>=p->nMem ){
  2932         -          p->aStack[tos].flags = STK_Null;
  2933         -          p->zStack[tos] = 0;
         2936  +          aStack[tos].flags = STK_Null;
         2937  +          zStack[tos] = 0;
  2934   2938           }else{
  2935         -          p->aStack[tos] = p->aMem[i].s;
  2936         -          if( p->aStack[tos].flags & STK_Str ){
  2937         -            char *z = sqliteMalloc(p->aStack[tos].n);
         2939  +          aStack[tos] = p->aMem[i].s;
         2940  +          if( aStack[tos].flags & STK_Str ){
         2941  +            char *z = sqliteMalloc(aStack[tos].n);
  2938   2942               if( z==0 ) goto no_mem;
  2939         -            memcpy(z, p->aMem[i].z, p->aStack[tos].n);
  2940         -            p->zStack[tos] = z;
  2941         -            p->aStack[tos].flags |= STK_Dyn;
         2943  +            memcpy(z, p->aMem[i].z, aStack[tos].n);
         2944  +            zStack[tos] = z;
         2945  +            aStack[tos].flags |= STK_Dyn;
  2942   2946             }
  2943   2947           }
  2944   2948           break;
  2945   2949         }
  2946   2950   
  2947   2951         /* Opcode: AggReset * P2 *
  2948   2952         **
................................................................................
  2973   2977           int tos = p->tos;
  2974   2978           AggElem *pElem;
  2975   2979           char *zKey;
  2976   2980           int nKey;
  2977   2981   
  2978   2982           VERIFY( if( tos<0 ) goto not_enough_stack; )
  2979   2983           Stringify(p, tos);
  2980         -        zKey = p->zStack[tos]; 
  2981         -        nKey = p->aStack[tos].n;
         2984  +        zKey = zStack[tos]; 
         2985  +        nKey = aStack[tos].n;
  2982   2986           if( p->agg.nHash<=0 ){
  2983   2987             pElem = 0;
  2984   2988           }else{
  2985   2989             int h = sqliteHashNoCase(zKey, nKey-1) % p->agg.nHash;
  2986   2990             for(pElem=p->agg.apHash[h]; pElem; pElem=pElem->pHash){
  2987   2991               if( strcmp(pElem->zKey, zKey)==0 ) break;
  2988   2992             }
................................................................................
  3042   3046             Mem *pMem = &pFocus->aMem[i];
  3043   3047             char *zOld;
  3044   3048             if( pMem->s.flags & STK_Dyn ){
  3045   3049               zOld = pMem->z;
  3046   3050             }else{
  3047   3051               zOld = 0;
  3048   3052             }
  3049         -          pMem->s = p->aStack[tos];
         3053  +          pMem->s = aStack[tos];
  3050   3054             if( pMem->s.flags & STK_Str ){
  3051         -            pMem->z = sqliteMalloc( p->aStack[tos].n );
         3055  +            pMem->z = sqliteMalloc( aStack[tos].n );
  3052   3056               if( pMem->z==0 ) goto no_mem;
  3053         -            memcpy(pMem->z, p->zStack[tos], pMem->s.n);
         3057  +            memcpy(pMem->z, zStack[tos], pMem->s.n);
  3054   3058               pMem->s.flags |= STK_Str|STK_Dyn;
  3055   3059             }
  3056   3060             if( zOld ) sqliteFree(zOld);
  3057   3061           }
  3058   3062           PopStack(p, 1);
  3059   3063           break;
  3060   3064         }
................................................................................
  3069   3073           AggElem *pFocus = AggInFocus(p->agg);
  3070   3074           int i = pOp->p2;
  3071   3075           int tos = ++p->tos;
  3072   3076           VERIFY( if( NeedStack(p, tos) ) goto no_mem; )
  3073   3077           if( pFocus==0 ) goto no_mem;
  3074   3078           if( VERIFY( i>=0 && ) i<p->agg.nMem ){
  3075   3079             Mem *pMem = &pFocus->aMem[i];
  3076         -          p->aStack[tos] = pMem->s;
  3077         -          p->zStack[tos] = pMem->z;
  3078         -          p->aStack[tos].flags &= ~STK_Dyn;
         3080  +          aStack[tos] = pMem->s;
         3081  +          zStack[tos] = pMem->z;
         3082  +          aStack[tos].flags &= ~STK_Dyn;
  3079   3083           }
  3080   3084           break;
  3081   3085         }
  3082   3086   
  3083   3087         /* Opcode: AggNext * P2 *
  3084   3088         **
  3085   3089         ** Make the next aggregate value the current aggregate.  The prior
................................................................................
  3144   3148           }
  3145   3149           if( pOp->p3 ){
  3146   3150             SetInsert(&p->aSet[i], pOp->p3);
  3147   3151           }else{
  3148   3152             int tos = p->tos;
  3149   3153             if( tos<0 ) goto not_enough_stack;
  3150   3154             Stringify(p, tos);
  3151         -          SetInsert(&p->aSet[i], p->zStack[tos]);
         3155  +          SetInsert(&p->aSet[i], zStack[tos]);
  3152   3156             PopStack(p, 1);
  3153   3157           }
  3154   3158           break;
  3155   3159         }
  3156   3160   
  3157   3161         /* Opcode: SetFound P1 P2 *
  3158   3162         **
................................................................................
  3161   3165         ** then jump to P2.  Otherwise fall through.
  3162   3166         */
  3163   3167         case OP_SetFound: {
  3164   3168           int i = pOp->p1;
  3165   3169           int tos = p->tos;
  3166   3170           VERIFY( if( tos<0 ) goto not_enough_stack; )
  3167   3171           Stringify(p, tos);
  3168         -        if( VERIFY( i>=0 && i<p->nSet &&) SetTest(&p->aSet[i], p->zStack[tos])){
         3172  +        if( VERIFY( i>=0 && i<p->nSet &&) SetTest(&p->aSet[i], zStack[tos])){
  3169   3173             pc = pOp->p2 - 1;
  3170   3174           }
  3171   3175           PopStack(p, 1);
  3172   3176           break;
  3173   3177         }
  3174   3178   
  3175   3179         /* Opcode: SetNotFound P1 P2 *
................................................................................
  3179   3183         ** set P1, then jump to P2.  Otherwise fall through.
  3180   3184         */
  3181   3185         case OP_SetNotFound: {
  3182   3186           int i = pOp->p1;
  3183   3187           int tos = p->tos;
  3184   3188           VERIFY( if( tos<0 ) goto not_enough_stack; )
  3185   3189           Stringify(p, tos);
  3186         -        if(VERIFY( i>=0 && i<p->nSet &&) !SetTest(&p->aSet[i], p->zStack[tos])){
         3190  +        if(VERIFY( i>=0 && i<p->nSet &&) !SetTest(&p->aSet[i], zStack[tos])){
  3187   3191             pc = pOp->p2 - 1;
  3188   3192           }
  3189   3193           PopStack(p, 1);
  3190   3194           break;
  3191   3195         }
  3192   3196   
  3193   3197         /* Opcode: Length * * *
................................................................................
  3196   3200         ** stack with an integer which is the length of the string.
  3197   3201         */
  3198   3202         case OP_Strlen: {
  3199   3203           int tos = p->tos;
  3200   3204           int len;
  3201   3205           VERIFY( if( tos<0 ) goto not_enough_stack; )
  3202   3206           Stringify(p, tos);
  3203         -        len = p->aStack[tos].n-1;
         3207  +        len = aStack[tos].n-1;
  3204   3208           PopStack(p, 1);
  3205   3209           p->tos++;
  3206         -        p->aStack[tos].i = len;
  3207         -        p->aStack[tos].flags = STK_Int;
         3210  +        aStack[tos].i = len;
         3211  +        aStack[tos].flags = STK_Int;
  3208   3212           break;
  3209   3213         }
  3210   3214   
  3211   3215         /* Opcode: Substr P1 P2 *
  3212   3216         **
  3213   3217         ** This operation pops between 1 and 3 elements from the stack and
  3214   3218         ** pushes back a single element.  The bottom-most element popped from
................................................................................
  3232   3236           int start;
  3233   3237           int n;
  3234   3238           char *z;
  3235   3239   
  3236   3240           if( pOp->p2==0 ){
  3237   3241             VERIFY( if( p->tos<0 ) goto not_enough_stack; )
  3238   3242             Integerify(p, p->tos);
  3239         -          cnt = p->aStack[p->tos].i;
         3243  +          cnt = aStack[p->tos].i;
  3240   3244             PopStack(p, 1);
  3241   3245           }else{
  3242   3246             cnt = pOp->p2;
  3243   3247           }
  3244   3248           if( pOp->p1==0 ){
  3245   3249             VERIFY( if( p->tos<0 ) goto not_enough_stack; )
  3246   3250             Integerify(p, p->tos);
  3247         -          start = p->aStack[p->tos].i - 1;
         3251  +          start = aStack[p->tos].i - 1;
  3248   3252             PopStack(p, 1);
  3249   3253           }else{
  3250   3254             start = pOp->p1 - 1;
  3251   3255           }
  3252   3256           VERIFY( if( p->tos<0 ) goto not_enough_stack; )
  3253   3257           Stringify(p, p->tos);
  3254         -        n = p->aStack[p->tos].n - 1;
         3258  +        n = aStack[p->tos].n - 1;
  3255   3259           if( start<0 ){
  3256   3260             start += n + 1;
  3257   3261             if( start<0 ){
  3258   3262               cnt += start;
  3259   3263               start = 0;
  3260   3264             }
  3261   3265           }
................................................................................
  3264   3268           }
  3265   3269           if( cnt<0 ) cnt = 0;
  3266   3270           if( cnt > n ){
  3267   3271             cnt = n;
  3268   3272           }
  3269   3273           z = sqliteMalloc( cnt+1 );
  3270   3274           if( z==0 ) goto no_mem;
  3271         -        strncpy(z, &p->zStack[p->tos][start], cnt);
         3275  +        strncpy(z, &zStack[p->tos][start], cnt);
  3272   3276           z[cnt] = 0;
  3273   3277           PopStack(p, 1);
  3274   3278           p->tos++;
  3275         -        p->zStack[p->tos] = z;
  3276         -        p->aStack[p->tos].n = cnt + 1;
  3277         -        p->aStack[p->tos].flags = STK_Str|STK_Dyn;
         3279  +        zStack[p->tos] = z;
         3280  +        aStack[p->tos].n = cnt + 1;
         3281  +        aStack[p->tos].flags = STK_Str|STK_Dyn;
  3278   3282           break;
  3279   3283         }
  3280   3284   
  3281   3285         /* An other opcode is illegal...
  3282   3286         */
  3283   3287         default: {
  3284   3288           sprintf(zBuf,"%d",pOp->opcode);
................................................................................
  3298   3302         sqliteSetString(pzErrMsg, "jump destination out of range", 0);
  3299   3303         rc = SQLITE_INTERNAL;
  3300   3304       }
  3301   3305       if( p->trace && p->tos>=0 ){
  3302   3306         int i;
  3303   3307         fprintf(p->trace, "Stack:");
  3304   3308         for(i=p->tos; i>=0 && i>p->tos-5; i--){
  3305         -        if( p->aStack[i].flags & STK_Null ){
         3309  +        if( aStack[i].flags & STK_Null ){
  3306   3310             fprintf(p->trace, " NULL");
  3307         -        }else if( p->aStack[i].flags & STK_Int ){
  3308         -          fprintf(p->trace, " i:%d", p->aStack[i].i);
  3309         -        }else if( p->aStack[i].flags & STK_Real ){
  3310         -          fprintf(p->trace, " r:%g", p->aStack[i].r);
  3311         -        }else if( p->aStack[i].flags & STK_Str ){
  3312         -          if( p->aStack[i].flags & STK_Dyn ){
  3313         -            fprintf(p->trace, " z:[%.11s]", p->zStack[i]);
         3311  +        }else if( aStack[i].flags & STK_Int ){
         3312  +          fprintf(p->trace, " i:%d", aStack[i].i);
         3313  +        }else if( aStack[i].flags & STK_Real ){
         3314  +          fprintf(p->trace, " r:%g", aStack[i].r);
         3315  +        }else if( aStack[i].flags & STK_Str ){
         3316  +          if( aStack[i].flags & STK_Dyn ){
         3317  +            fprintf(p->trace, " z:[%.11s]", zStack[i]);
  3314   3318             }else{
  3315         -            fprintf(p->trace, " s:[%.11s]", p->zStack[i]);
         3319  +            fprintf(p->trace, " s:[%.11s]", zStack[i]);
  3316   3320             }
  3317   3321           }else{
  3318   3322             fprintf(p->trace, " ???");
  3319   3323           }
  3320   3324         }
  3321   3325         fprintf(p->trace,"\n");
  3322   3326       }

Changes to www/c_interface.tcl.

     1      1   #
     2      2   # Run this Tcl script to generate the sqlite.html file.
     3      3   #
     4         -set rcsid {$Id: c_interface.tcl,v 1.11 2000/10/16 22:06:43 drh Exp $}
            4  +set rcsid {$Id: c_interface.tcl,v 1.12 2000/10/23 13:16:33 drh Exp $}
     5      5   
     6      6   puts {<html>
     7      7   <head>
     8      8     <title>The C language interface to the SQLite library</title>
     9      9   </head>
    10     10   <body bgcolor=white>
    11     11   <h1 align=center>
................................................................................
    25     25   <p>The interface to the SQLite library consists of three core functions,
    26     26   one opaque data structure, and some constants used as return values.
    27     27   The core interface is as follows:</p>
    28     28   
    29     29   <blockquote><pre>
    30     30   typedef struct sqlite sqlite;
    31     31   
    32         -sqlite *sqlite_open(const char *filename, int mode, char **errmsg);
           32  +sqlite *sqlite_open(const char *dbname, int mode, char **errmsg);
    33     33   
    34     34   void sqlite_close(sqlite*);
    35     35   
    36     36   int sqlite_exec(
    37     37     sqlite*,
    38     38     char *sql,
    39     39     int (*)(void*,int,char**,char**),
................................................................................
   130    130   database read only.  The third argument is a pointer to a string
   131    131   pointer.  If the third argument is not NULL and an error occurs
   132    132   while trying to open the database, then an error message will be
   133    133   written to memory obtained from malloc() and *errmsg will be made
   134    134   to point to this error message.  The calling function is responsible
   135    135   for freeing the memory when it has finished with it.</p>
   136    136   
   137         -<p>An SQLite database is just a directory containing a collection of
   138         -GDBM files.  There is one GDBM file for each table and index in the
          137  +<p>The name of an SQLite database is normally the name of a directory
          138  +that contains a collection of GDBM files that comprise the database.
          139  +There is one GDBM file for each table and index in the
   139    140   database.  All GDBM files end with the ".tbl" suffix.  Every SQLite
   140    141   database also contains a special database table named <b>sqlite_master</b>
   141    142   stored in its own GDBM file.  This special table records the database
   142    143   schema.</p>
   143    144   
   144    145   <p>To create a new SQLite database, all you have to do is call
   145    146   <b>sqlite_open()</b> with the first parameter set to the name of
   146         -an empty directory and the second parameter set to 0666.</p>
          147  +an empty directory and the second parameter set to 0666.  The
          148  +directory is created automatically if it does not already exist.</p>
          149  +
          150  +<p>Beginning with SQLite version 1.0.14, SQLite supports database
          151  +backends other than GDBM.  The only backends currently supported 
          152  +are the default GDBM driver and an in-memory hash table database.
          153  +You may anticipate additional backends in future versions of SQLite.</p>
          154  +
          155  +<p>An alternative database backend is specified by prepending the
          156  +backend name and a colon to the database name argument of the
          157  +<b>sqlite_open()</b> function.  For the GDBM backend, you can
          158  +prepend "<b>gdbm:</b>" to the directory name.  To select the in-memory
          159  +hash table backend, prepend "<b>memory:</b>" to the database name.
          160  +Future database drivers will be selected by a similar mechanism.</p>
   147    161   
   148    162   <p>The return value of the <b>sqlite_open()</b> function is a
   149    163   pointer to an opaque <b>sqlite</b> structure.  This pointer will
   150    164   be the first argument to all subsequent SQLite function calls that
   151    165   deal with the same database.  NULL is returned if the open fails
   152    166   for any reason.</p>
   153    167   

Changes to www/changes.tcl.

    12     12   }
    13     13   
    14     14   
    15     15   proc chng {date desc} {
    16     16     puts "<DT><B>$date</B></DT>"
    17     17     puts "<DD><P><UL>$desc</UL></P></DD>"
    18     18   }
           19  +
           20  +chng {2000 Oct 23 (1.0.15)} {
           21  +<li>Documentation updates</li>
           22  +<li>Some sanity checking code was removed from the inner loop of vdbe.c
           23  +    to help the library to run a little faster.  The code is only
           24  +    removed if you compile with -DNDEBUG.</li>
           25  +}
    19     26   
    20     27   chng {2000 Oct 19 (1.0.14)} {
    21     28   <li>Added a "memory:" backend driver that stores its database in an
    22     29       in-memory hash table.</li>
    23     30   }
    24     31   
    25     32   chng {2000 Oct 18 (1.0.13)} {

Changes to www/tclsqlite.tcl.

     1      1   #
     2      2   # Run this Tcl script to generate the tclsqlite.html file.
     3      3   #
     4         -set rcsid {$Id: tclsqlite.tcl,v 1.2 2000/10/08 22:20:58 drh Exp $}
            4  +set rcsid {$Id: tclsqlite.tcl,v 1.3 2000/10/23 13:16:33 drh Exp $}
     5      5   
     6      6   puts {<html>
     7      7   <head>
     8      8     <title>The Tcl interface to the SQLite library</title>
     9      9   </head>
    10     10   <body bgcolor=white>
    11     11   <h1 align=center>
................................................................................
    26     26   tcl command named <b>sqlite</b>.  Because there is only this
    27     27   one interface command, the interface is not placed in a separate
    28     28   namespace.</p>
    29     29   
    30     30   <p>The <b>sqlite</b> command is used as follows:</p>
    31     31   
    32     32   <blockquote>
    33         -<b>sqlite</b>&nbsp;&nbsp;<i>dbcmd&nbsp;&nbsp;database-directory-name</i>
           33  +<b>sqlite</b>&nbsp;&nbsp;<i>dbcmd&nbsp;&nbsp;database-name</i>
    34     34   </blockquote>
    35     35   
    36     36   <p>
    37         -The <b>sqlite</b> command opens the SQLite database located in the
    38         -directory named by the second argument.  If the database or directory
    39         -does not exist, it is created.  The <b>sqlite</b> command 
    40         -also creates a new Tcl
           37  +The <b>sqlite</b> command opens the database named in the second
           38  +argument.  If the database does not already exist, it is
           39  +automatically created.
           40  +The <b>sqlite</b> command also creates a new Tcl
    41     41   command to control the database.  The name of the new Tcl command
    42     42   is given by the first argument.  This approach is similar to the
    43     43   way widgets are created in Tk.
    44     44   </p>
    45     45   
           46  +<p>
           47  +The name of the database is usually either the name of a directory
           48  +that will contain the GDBM files that comprise the database, or it is the
           49  +name of the directory prefaced by "<b>gdbm:</b>".  The second form
           50  +of the name is a new feature beginning in SQLite version 1.0.14 that
           51  +allows you to select alternative database backends.  The default
           52  +backend is GDBM.  But you can also select to store the database in
           53  +a hash table in memory by using the prefix "<b>memory:</b>". 
           54  +Other backends may be added in the future.
           55  +</p>
           56  +
           57  +<p>
           58  +Every time you open an SQLite database with the <b>memory:</b> prefix
           59  +on the database name, you get a new in-memory database.  This is true
           60  +even if you open two databases with the same name.  Furthermore,
           61  +an in-memory database is automatically deleted when the database is
           62  +closed and so is not useful for persistant storage like a normal
           63  +database.  But the use of an in-memory SQL database does give Tcl/Tk
           64  +a powerful new data storage mechanism that can do things that are
           65  +difficult to do with only Tcl array variables.  In fact, the
           66  +hash-table backend for SQLite was created for the sole purpose of
           67  +providing better data structure support to the Tcl language.
           68  +</p>
           69  +
    46     70   <p>
    47     71   Once an SQLite database is open, it can be controlled using 
    48     72   methods of the <i>dbcmd</i>.  There are currently 5 methods
    49     73   defined:</p>
    50     74   
    51     75   <p>
    52     76   <ul>
................................................................................
   201    225   <h2>The "timeout" method</h2>
   202    226   
   203    227   <p>The "timeout" method is used to control how long the SQLite library
   204    228   will wait for locks to clear before giving up on a database transaction.
   205    229   The default timeout is 0 millisecond.  (In other words, the default behavior
   206    230   is not to wait at all.)</p>
   207    231   
   208         -<p>The GDBM library the underlies SQLite allows multiple simultaneous
          232  +<p>The GDBM backend allows multiple simultaneous
   209    233   readers or a single writer but not both.  If any process is writing to
   210    234   the database no other process is allows to read or write.  If any process
   211    235   is reading the database other processes are allowed to read but not write.
   212    236   Each GDBM file is locked separately.  Because each SQL table is stored as
   213    237   a separate file, it is possible for different processes to write to different
   214    238   database tables at the same time, just not the same table.</p>
   215    239