Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | added the fcnt() function for testing (CVS 92) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
0f93c27cddb4254f72305ca3a64b77c2 |
User & Date: | drh 2000-06-11 23:50:13.000 |
Context
2000-06-12
| ||
12:20 | :-) (CVS 93) (check-in: 3c0540e6fb user: drh tags: trunk) | |
2000-06-11
| ||
23:50 | added the fcnt() function for testing (CVS 92) (check-in: 0f93c27cdd user: drh tags: trunk) | |
2000-06-09
| ||
14:14 | :-) (CVS 91) (check-in: d573b431ed user: drh tags: trunk) | |
Changes
Changes to src/expr.c.
︙ | ︙ | |||
19 20 21 22 23 24 25 | ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** This file contains C code routines used for processing expressions ** | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** This file contains C code routines used for processing expressions ** ** $Id: expr.c,v 1.15 2000/06/11 23:50:13 drh Exp $ */ #include "sqliteInt.h" /* ** Walk an expression tree. Return 1 if the expression is constant ** and 0 if it involves variables. */ |
︙ | ︙ | |||
317 318 319 320 321 322 323 324 325 326 327 328 329 330 | int id; } aFunc[] = { { "count", 5, FN_Count }, { "min", 3, FN_Min }, { "max", 3, FN_Max }, { "sum", 3, FN_Sum }, { "avg", 3, FN_Avg }, }; int i; for(i=0; i<ArraySize(aFunc); i++){ if( aFunc[i].len==pToken->n && sqliteStrNICmp(pToken->z, aFunc[i].zName, aFunc[i].len)==0 ){ return aFunc[i].id; } | > | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | int id; } aFunc[] = { { "count", 5, FN_Count }, { "min", 3, FN_Min }, { "max", 3, FN_Max }, { "sum", 3, FN_Sum }, { "avg", 3, FN_Avg }, { "fcnt", 4, FN_Fcnt }, /* Used for testing only */ }; int i; for(i=0; i<ArraySize(aFunc); i++){ if( aFunc[i].len==pToken->n && sqliteStrNICmp(pToken->z, aFunc[i].zName, aFunc[i].len)==0 ){ return aFunc[i].id; } |
︙ | ︙ | |||
374 375 376 377 378 379 380 381 382 383 384 385 386 387 | case FN_Avg: case FN_Sum: { no_such_func = !allowAgg; too_many_args = n>1; too_few_args = n<1; is_agg = 1; break; } default: break; } if( no_such_func ){ sqliteSetNString(&pParse->zErrMsg, "no such function: ", -1, pExpr->token.z, pExpr->token.n, 0); pParse->nErr++; | > > > > > > > > > > > | 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | case FN_Avg: case FN_Sum: { no_such_func = !allowAgg; too_many_args = n>1; too_few_args = n<1; is_agg = 1; break; } /* The "fcnt(*)" function always returns the number of fetch ** operations that have occurred so far while processing the ** SQL statement. This information can be used by test procedures ** to verify that indices are being used properly to minimize ** searching. All arguments to fcnt() are ignored. fcnt() has ** no use (other than testing) that we are aware of. */ case FN_Fcnt: { n = 0; break; } default: break; } if( no_such_func ){ sqliteSetNString(&pParse->zErrMsg, "no such function: ", -1, pExpr->token.z, pExpr->token.n, 0); pParse->nErr++; |
︙ | ︙ | |||
551 552 553 554 555 556 557 558 559 560 561 562 563 564 | break; } case TK_FUNCTION: { int id = pExpr->iField; int op; int i; ExprList *pList = pExpr->pList; op = id==FN_Min ? OP_Min : OP_Max; for(i=0; i<pList->nExpr; i++){ sqliteExprCode(pParse, pList->a[i].pExpr); if( i>0 ){ sqliteVdbeAddOp(v, op, 0, 0, 0, 0); } } | > > > > | 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | break; } case TK_FUNCTION: { int id = pExpr->iField; int op; int i; ExprList *pList = pExpr->pList; if( id==FN_Fcnt ){ sqliteVdbeAddOp(v, OP_Fcnt, 0, 0, 0, 0); break; } op = id==FN_Min ? OP_Min : OP_Max; for(i=0; i<pList->nExpr; i++){ sqliteExprCode(pParse, pList->a[i].pExpr); if( i>0 ){ sqliteVdbeAddOp(v, op, 0, 0, 0, 0); } } |
︙ | ︙ |
Changes to src/sqliteInt.h.
︙ | ︙ | |||
19 20 21 22 23 24 25 | ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** Internal interface definitions for SQLite. ** | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ** Author contact information: ** drh@hwaci.com ** http://www.hwaci.com/drh/ ** ************************************************************************* ** Internal interface definitions for SQLite. ** ** @(#) $Id: sqliteInt.h,v 1.24 2000/06/11 23:50:13 drh Exp $ */ #include "sqlite.h" #include "dbbe.h" #include "vdbe.h" #include "parse.h" #include <gdbm.h> #include <stdio.h> |
︙ | ︙ | |||
81 82 83 84 85 86 87 88 89 90 91 92 93 94 | */ #define FN_Unknown 0 #define FN_Count 1 #define FN_Min 2 #define FN_Max 3 #define FN_Sum 4 #define FN_Avg 5 /* ** Forward references to structures */ typedef struct Column Column; typedef struct Table Table; typedef struct Index Index; | > | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | */ #define FN_Unknown 0 #define FN_Count 1 #define FN_Min 2 #define FN_Max 3 #define FN_Sum 4 #define FN_Avg 5 #define FN_Fcnt 6 /* ** Forward references to structures */ typedef struct Column Column; typedef struct Table Table; typedef struct Index Index; |
︙ | ︙ |
Changes to src/vdbe.c.
︙ | ︙ | |||
37 38 39 40 41 42 43 | ** inplicit conversion from one type to the other occurs as necessary. ** ** Most of the code in this file is taken up by the sqliteVdbeExec() ** function which does the work of interpreting a VDBE program. ** But other routines are also provided to help in building up ** a program instruction by instruction. ** | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | ** inplicit conversion from one type to the other occurs as necessary. ** ** Most of the code in this file is taken up by the sqliteVdbeExec() ** function which does the work of interpreting a VDBE program. ** But other routines are also provided to help in building up ** a program instruction by instruction. ** ** $Id: vdbe.c,v 1.33 2000/06/11 23:50:13 drh Exp $ */ #include "sqliteInt.h" #include <unistd.h> /* ** SQL is translated into a sequence of instructions to be ** executed by a virtual machine. Each instruction is an instance |
︙ | ︙ | |||
187 188 189 190 191 192 193 194 195 196 197 198 199 200 | char *zLine; /* A single line from the input file */ int nLineAlloc; /* Number of spaces allocated for zLine */ int nMem; /* Number of memory locations currently allocated */ Mem *aMem; /* The memory locations */ Agg agg; /* Aggregate information */ int nSet; /* Number of sets allocated */ Set *aSet; /* An array of sets */ }; /* ** Create a new virtual database engine. */ Vdbe *sqliteVdbeCreate(Dbbe *pBe){ Vdbe *p; | > | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | char *zLine; /* A single line from the input file */ int nLineAlloc; /* Number of spaces allocated for zLine */ int nMem; /* Number of memory locations currently allocated */ Mem *aMem; /* The memory locations */ Agg agg; /* Aggregate information */ int nSet; /* Number of sets allocated */ Set *aSet; /* An array of sets */ int nFetch; /* Number of OP_Fetch instructions executed */ }; /* ** Create a new virtual database engine. */ Vdbe *sqliteVdbeCreate(Dbbe *pBe){ Vdbe *p; |
︙ | ︙ | |||
729 730 731 732 733 734 735 | ** ** If any of the numeric OP_ values for opcodes defined in sqliteVdbe.h ** change, be sure to change this array to match. You can use the ** "opNames.awk" awk script which is part of the source tree to regenerate ** this array, then copy and paste it into this file, if you want. */ static char *zOpName[] = { 0, | | | | | | | | | | | | | | | | | | | | | | | | 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | ** ** If any of the numeric OP_ values for opcodes defined in sqliteVdbe.h ** change, be sure to change this array to match. You can use the ** "opNames.awk" awk script which is part of the source tree to regenerate ** this array, then copy and paste it into this file, if you want. */ static char *zOpName[] = { 0, "Open", "Close", "Fetch", "Fcnt", "New", "Put", "Distinct", "Found", "NotFound", "Delete", "Field", "KeyAsData", "Key", "Rewind", "Next", "Destroy", "Reorganize", "ResetIdx", "NextIdx", "PutIdx", "DeleteIdx", "MemLoad", "MemStore", "ListOpen", "ListWrite", "ListRewind", "ListRead", "ListClose", "SortOpen", "SortPut", "SortMakeRec", "SortMakeKey", "Sort", "SortNext", "SortKey", "SortCallback", "SortClose", "FileOpen", "FileRead", "FileField", "FileClose", "AggReset", "AggFocus", "AggIncr", "AggNext", "AggSet", "AggGet", "SetInsert", "SetFound", "SetNotFound", "SetClear", "MakeRecord", "MakeKey", "Goto", "If", "Halt", "ColumnCount", "ColumnName", "Callback", "Integer", "String", "Null", "Pop", "Dup", "Pull", "Add", "AddImm", "Subtract", "Multiply", "Divide", "Min", "Max", "Like", "Glob", "Eq", "Ne", "Lt", "Le", "Gt", "Ge", "IsNull", "NotNull", "Negative", "And", "Or", "Not", "Concat", "Noop", }; /* ** Given the name of an opcode, return its number. Return 0 if ** there is no match. ** ** This routine is used for testing and debugging. |
︙ | ︙ | |||
1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 | sqliteDbbeFetch(p->aTab[i].pTable, sizeof(int), (char*)&p->aStack[tos].i); }else{ if( Stringify(p, tos) ) goto no_mem; sqliteDbbeFetch(p->aTab[i].pTable, p->aStack[tos].n, p->zStack[tos]); } } PopStack(p, 1); break; } /* Opcode: Distinct P1 P2 * ** ** Use the top of the stack as a key. If a record with that key ** does not exist in table P1, then jump to P2. If the record ** does already exist, then fall thru. The record is not retrieved. ** The key is not popped from the stack. | > > > > > > > > > > > > > > > > > > | 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 | sqliteDbbeFetch(p->aTab[i].pTable, sizeof(int), (char*)&p->aStack[tos].i); }else{ if( Stringify(p, tos) ) goto no_mem; sqliteDbbeFetch(p->aTab[i].pTable, p->aStack[tos].n, p->zStack[tos]); } p->nFetch++; } PopStack(p, 1); break; } /* Opcode: Fcnt * * * ** ** Push an integer onto the stack which is the total number of ** OP_Fetch opcodes that have been executed by this virtual machine. ** ** This instruction is used to implement the special fcnt() function ** in the SQL dialect that SQLite understands. fcnt() is used for ** testing purposes. */ case OP_Fcnt: { int i = ++p->tos; if( NeedStack(p, p->tos) ) goto no_mem; p->aStack[i].i = p->nFetch; p->aStack[i].flags = STK_Int; break; } /* Opcode: Distinct P1 P2 * ** ** Use the top of the stack as a key. If a record with that key ** does not exist in table P1, then jump to P2. If the record ** does already exist, then fall thru. The record is not retrieved. ** The key is not popped from the stack. |
︙ | ︙ | |||
2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 | ** more entries, rewind P1 and jump to location P2. */ case OP_Next: { int i = pOp->p1; if( i>=0 && i<p->nTable && p->aTab[i].pTable!=0 ){ if( sqliteDbbeNextKey(p->aTab[i].pTable)==0 ){ pc = pOp->p2 - 1; } } break; } /* Opcode: ResetIdx P1 * * ** | > > | 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 | ** more entries, rewind P1 and jump to location P2. */ case OP_Next: { int i = pOp->p1; if( i>=0 && i<p->nTable && p->aTab[i].pTable!=0 ){ if( sqliteDbbeNextKey(p->aTab[i].pTable)==0 ){ pc = pOp->p2 - 1; }else{ p->nFetch++; } } break; } /* Opcode: ResetIdx P1 * * ** |
︙ | ︙ |
Changes to src/vdbe.h.
︙ | ︙ | |||
23 24 25 26 27 28 29 | ************************************************************************* ** Header file for the Virtual DataBase Engine (VDBE) ** ** This header defines the interface to the virtual database engine ** or VDBE. The VDBE implements an abstract machine that runs a ** simple program to access and modify the underlying database. ** | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ************************************************************************* ** Header file for the Virtual DataBase Engine (VDBE) ** ** This header defines the interface to the virtual database engine ** or VDBE. The VDBE implements an abstract machine that runs a ** simple program to access and modify the underlying database. ** ** $Id: vdbe.h,v 1.10 2000/06/11 23:50:13 drh Exp $ */ #ifndef _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_ #include <stdio.h> /* ** A single VDBE is an opaque structure named "Vdbe". Only routines |
︙ | ︙ | |||
70 71 72 73 74 75 76 | ** ** The source tree contains an AWK script named renumberOps.awk that ** can be used to renumber these opcodes when new opcodes are inserted. */ #define OP_Open 1 #define OP_Close 2 #define OP_Fetch 3 | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | ** ** The source tree contains an AWK script named renumberOps.awk that ** can be used to renumber these opcodes when new opcodes are inserted. */ #define OP_Open 1 #define OP_Close 2 #define OP_Fetch 3 #define OP_Fcnt 4 #define OP_New 5 #define OP_Put 6 #define OP_Distinct 7 #define OP_Found 8 #define OP_NotFound 9 #define OP_Delete 10 #define OP_Field 11 #define OP_KeyAsData 12 #define OP_Key 13 #define OP_Rewind 14 #define OP_Next 15 #define OP_Destroy 16 #define OP_Reorganize 17 #define OP_ResetIdx 18 #define OP_NextIdx 19 #define OP_PutIdx 20 #define OP_DeleteIdx 21 #define OP_MemLoad 22 #define OP_MemStore 23 #define OP_ListOpen 24 #define OP_ListWrite 25 #define OP_ListRewind 26 #define OP_ListRead 27 #define OP_ListClose 28 #define OP_SortOpen 29 #define OP_SortPut 30 #define OP_SortMakeRec 31 #define OP_SortMakeKey 32 #define OP_Sort 33 #define OP_SortNext 34 #define OP_SortKey 35 #define OP_SortCallback 36 #define OP_SortClose 37 #define OP_FileOpen 38 #define OP_FileRead 39 #define OP_FileField 40 #define OP_FileClose 41 #define OP_AggReset 42 #define OP_AggFocus 43 #define OP_AggIncr 44 #define OP_AggNext 45 #define OP_AggSet 46 #define OP_AggGet 47 #define OP_SetInsert 48 #define OP_SetFound 49 #define OP_SetNotFound 50 #define OP_SetClear 51 #define OP_MakeRecord 52 #define OP_MakeKey 53 #define OP_Goto 54 #define OP_If 55 #define OP_Halt 56 #define OP_ColumnCount 57 #define OP_ColumnName 58 #define OP_Callback 59 #define OP_Integer 60 #define OP_String 61 #define OP_Null 62 #define OP_Pop 63 #define OP_Dup 64 #define OP_Pull 65 #define OP_Add 66 #define OP_AddImm 67 #define OP_Subtract 68 #define OP_Multiply 69 #define OP_Divide 70 #define OP_Min 71 #define OP_Max 72 #define OP_Like 73 #define OP_Glob 74 #define OP_Eq 75 #define OP_Ne 76 #define OP_Lt 77 #define OP_Le 78 #define OP_Gt 79 #define OP_Ge 80 #define OP_IsNull 81 #define OP_NotNull 82 #define OP_Negative 83 #define OP_And 84 #define OP_Or 85 #define OP_Not 86 #define OP_Concat 87 #define OP_Noop 88 #define OP_MAX 88 /* ** Prototypes for the VDBE interface. See comments on the implementation ** for a description of what each of these routines does. */ Vdbe *sqliteVdbeCreate(Dbbe*); int sqliteVdbeAddOp(Vdbe*,int,int,int,const char*,int); |
︙ | ︙ |