1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Comment updates most. Also some small changes to the VDBE. (CVS 339)

FossilOrigin-Name: 9b0be4fcc1cbca69f5fee906f86dfb36a323fe84
This commit is contained in:
drh
2002-01-06 17:07:40 +00:00
parent c6b52df32d
commit aacc543e23
12 changed files with 99 additions and 74 deletions

View File

@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.36 2002/01/04 03:09:30 drh Exp $
** $Id: expr.c,v 1.37 2002/01/06 17:07:40 drh Exp $
*/
#include "sqliteInt.h"
@ -49,7 +49,9 @@ static int isConstant(Expr *p){
** These operators have to be processed before column names are
** resolved because each such operator increments pParse->nTab
** to reserve cursor numbers for its own use. But pParse->nTab
** needs to be constant once we begin resolving column names.
** needs to be constant once we begin resolving column names. For
** that reason, this procedure needs to be called on every expression
** before sqliteExprResolveIds() is called on any expression.
**
** Actually, the processing of IN-SELECT is only started by this
** routine. This routine allocates a cursor number to the IN-SELECT
@ -86,11 +88,15 @@ static int sqliteIsRowid(const char *z){
/*
** This routine walks an expression tree and resolves references to
** table columns. Nodes of the form ID.ID or ID resolve into an
** index to the table in the table list and a column offset. The opcode
** for such nodes is changed to TK_COLUMN. The iTable value is changed
** to the index of the referenced table in pTabList plus the pParse->nTab
** value. The iColumn value is changed to the index of the column of the
** referenced table.
** index to the table in the table list and a column offset. The
** Expr.opcode for such nodes is changed to TK_COLUMN. The Expr.iTable
** value is changed to the index of the referenced table in pTabList
** plus the pParse->nTab value. This value will ultimately become the
** VDBE cursor number for a cursor that is pointing into the referenced
** table. The Expr.iColumn value is changed to the index of the column
** of the referenced table. The Expr.iColumn value for the special
** ROWID column is -1. Any INTEGER PRIMARY KEY column is tried as an
** alias for ROWID.
**
** We also check for instances of the IN operator. IN comes in two
** forms:

View File

@ -12,13 +12,22 @@
** This is the implementation of generic hash-tables
** used in SQLite.
**
** $Id: hash.c,v 1.4 2001/11/21 02:21:12 drh Exp $
** $Id: hash.c,v 1.5 2002/01/06 17:07:40 drh Exp $
*/
#include "sqliteInt.h"
#include <assert.h>
/* Turn bulk memory into a hash table object by initializing the
** fields of the Hash structure.
**
** "new" is a pointer to the hash table that is to be initialized.
** keyClass is one of the constants SQLITE_HASH_INT, SQLITE_HASH_POINTER,
** SQLITE_HASH_BINARY, or SQLITE_HASH_STRING. The value of keyClass
** determines what kind of key the hash table will use. "copyKey" is
** true if the hash table should make its own private copy of keys and
** false if it should just use the supplied pointer. CopyKey only makes
** sense for SQLITE_HASH_STRING and SQLITE_HASH_BINARY and is ignored
** for other key classes.
*/
void sqliteHashInit(Hash *new, int keyClass, int copyKey){
assert( new!=0 );
@ -33,6 +42,8 @@ void sqliteHashInit(Hash *new, int keyClass, int copyKey){
}
/* Remove all entries from a hash table. Reclaim all memory.
** Call this routine to delete a hash table or to reset a hash table
** to the empty state.
*/
void sqliteHashClear(Hash *pH){
HashElem *elem; /* For looping over all elements of the table */
@ -107,6 +118,15 @@ static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2){
/*
** Return a pointer to the appropriate hash function given the key class.
**
** The C syntax in this function definition may be unfamilar to some
** programmers, so we provide the following additional explanation:
**
** The name of the function is "hashFunction". The function takes a
** single parameter "keyClass". The return value of hashFunction()
** is a pointer to another function. Specifically, the return value
** of hashFunction() is a pointer to a function that takes two parameters
** with types "const void*" and "int" and returns an "int".
*/
static int (*hashFunction(int keyClass))(const void*,int){
switch( keyClass ){
@ -121,6 +141,9 @@ static int (*hashFunction(int keyClass))(const void*,int){
/*
** Return a pointer to the appropriate hash function given the key class.
**
** For help in interpreted the obscure C code in the function definition,
** see the header comment on the previous function.
*/
static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
switch( keyClass ){
@ -134,8 +157,9 @@ static int (*compareFunction(int keyClass))(const void*,int,const void*,int){
}
/* Resize the hash table. new_size must be a power of 2.
** The hash table might fail to resize if sqliteMalloc() fails.
/* Resize the hash table so that it cantains "new_size" buckets.
** "new_size" must be a power of 2. The hash table might fail
** to resize if sqliteMalloc() fails.
*/
static void rehash(Hash *pH, int new_size){
struct _ht *new_ht; /* The new hash table */
@ -172,8 +196,8 @@ static void rehash(Hash *pH, int new_size){
}
/* This function (for internal use only) locates an element in an
** pH that matches the given key. The hash for this key has
** already been computed and is passed as the 3rd parameter.
** hash table that matches the given key. The hash for this key has
** already been computed and is passed as the 4th parameter.
*/
static HashElem *findElementGivenHash(
const Hash *pH, /* The pH to be searched */
@ -205,7 +229,7 @@ static HashElem *findElementGivenHash(
static void removeElementGivenHash(
Hash *pH, /* The pH containing "elem" */
HashElem* elem, /* The element to be removed from the pH */
int h /* Hash value for the element */
int h /* Hash value for the element */
){
if( elem->prev ){
elem->prev->next = elem->next;
@ -229,9 +253,9 @@ static void removeElementGivenHash(
pH->count--;
}
/* Attempt to locate an element of the associative pH with a key
/* Attempt to locate an element of the hash table pH with a key
** that matches pKey,nKey. Return the data for this element if it is
** found, or NULL if no match is found.
** found, or NULL if there is no match.
*/
void *sqliteHashFind(const Hash *pH, const void *pKey, int nKey){
int h; /* A hash on key */
@ -257,7 +281,7 @@ void *sqliteHashFind(const Hash *pH, const void *pKey, int nKey){
** If another element already exists with the same key, then the
** new data replaces the old data and the old data is returned.
** The key is not copied in this instance. If a malloc fails, then
** new data is returned.
** the new data is returned and the hash table is unchanged.
**
** If the "data" parameter to this function is NULL, then the
** element corresponding to "key" is removed from the hash table.

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.31 2002/01/04 03:09:30 drh Exp $
** $Id: insert.c,v 1.32 2002/01/06 17:07:40 drh Exp $
*/
#include "sqliteInt.h"
@ -163,7 +163,7 @@ void sqliteInsert(
}
}
/* If there is not IDLIST term but the table has an integer primary
/* If there is no IDLIST term but the table has an integer primary
** key, the set the keyColumn variable to the primary key column index
** in the original table definition.
*/
@ -220,15 +220,15 @@ void sqliteInsert(
sqliteVdbeAddOp(v, OP_Dup, 0, 0);
}
/* Push onto the stack data for all columns of the new entry, beginning
/* Push onto the stack, data for all columns of the new entry, beginning
** with the first column.
*/
for(i=0; i<pTab->nCol; i++){
if( i==pTab->iPKey ){
/* The value of the INTEGER PRIMARY KEY column is always a NULL.
** Whenever this column is used, the record number will be substituted
** in its place, so there is no point in it taking up space in
** the data record. */
** Whenever this column is read, the record number will be substituted
** in its place. So will fill this column with a NULL to avoid
** taking up data space with information that will never be used. */
sqliteVdbeAddOp(v, OP_String, 0, 0);
continue;
}

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.52 2001/12/21 14:30:43 drh Exp $
** $Id: main.c,v 1.53 2002/01/06 17:07:40 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -67,9 +67,9 @@ static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){
}else{
/* If the SQL column is blank it means this is an index that
** was created to be the PRIMARY KEY or to fulfill a UNIQUE
** constraint or a CREATE TABLE. The index should have already
** constraint for a CREATE TABLE. The index should have already
** been created when we processed the CREATE TABLE. All we have
** to do here is record the root page.
** to do here is record the root page number for that index.
*/
Index *pIndex = sqliteFindIndex(db, argv[1]);
if( pIndex==0 || pIndex->tnum!=0 ){
@ -118,7 +118,7 @@ static int sqliteInit(sqlite *db, char **pzErrMsg){
")"
;
/* The following program is used to initialize the internal
/* The following VDBE program is used to initialize the internal
** structure holding the tables and indexes of the database.
** The database contains a special table named "sqlite_master"
** defined as follows:
@ -210,6 +210,11 @@ static int sqliteInit(sqlite *db, char **pzErrMsg){
sqliteSetString(pzErrMsg, "unsupported file format", 0);
rc = SQLITE_ERROR;
}
/* The schema for the SQLITE_MASTER table is not stored in the
** database itself. We have to invoke the callback one extra
** time to get it to process the SQLITE_MASTER table defintion.
*/
if( rc==SQLITE_OK ){
Table *pTab;
char *azArg[6];
@ -270,9 +275,7 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){
if( rc!=SQLITE_OK ){
switch( rc ){
default: {
if( pzErrMsg ){
sqliteSetString(pzErrMsg, "unable to open database: ", zFilename, 0);
}
sqliteSetString(pzErrMsg, "unable to open database: ", zFilename, 0);
}
}
sqliteFree(db);
@ -289,7 +292,7 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){
sqlite_close(db);
sqliteStrRealloc(pzErrMsg);
return 0;
}else /* if( pzErrMsg ) */{
}else if( pzErrMsg ){
sqliteFree(*pzErrMsg);
*pzErrMsg = 0;
}
@ -304,7 +307,7 @@ no_mem_on_open:
/*
** Erase all schema information from the schema hash table. Except
** tables that are created using CREATE TEMPORARY TABLE are preserved
** if the preserverTemps flag is true.
** if the preserveTemps flag is true.
**
** The database schema is normally read in once when the database
** is first opened and stored in a hash table in the sqlite structure.

View File

@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.34 2001/12/15 14:22:19 drh Exp $
** @(#) $Id: pager.c,v 1.35 2002/01/06 17:07:40 drh Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
@ -993,7 +993,7 @@ int sqlitepager_write(void *pData){
}
/*
** Return TRUE if the page given in the argument was previous passed
** Return TRUE if the page given in the argument was previously passed
** to sqlitepager_write(). In other words, return TRUE if it is ok
** to change the content of the page.
*/

View File

@ -14,7 +14,7 @@
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.41 2001/12/22 14:49:25 drh Exp $
** @(#) $Id: parse.y,v 1.42 2002/01/06 17:07:40 drh Exp $
*/
%token_prefix TK_
%token_type {Token}
@ -102,6 +102,7 @@ id(A) ::= CLUSTER(X). {A = X;}
id(A) ::= ID(X). {A = X;}
id(A) ::= TEMP(X). {A = X;}
id(A) ::= OFFSET(X). {A = X;}
id(A) ::= KEY(X). {A = X;}
// And "ids" is an identifer-or-string.
//

View File

@ -12,7 +12,7 @@
** This file contains code to implement the "sqlite" command line
** utility for accessing SQLite databases.
**
** $Id: shell.c,v 1.40 2001/11/25 13:18:24 drh Exp $
** $Id: shell.c,v 1.41 2002/01/06 17:07:40 drh Exp $
*/
#include <stdlib.h>
#include <string.h>
@ -92,7 +92,7 @@ static char *getline(char *zPrompt, FILE *in){
** Retrieve a single line of input text. "isatty" is true if text
** is coming from a terminal. In that case, we issue a prompt and
** attempt to use "readline" for command-line editing. If "isatty"
** is false, use "getline" instead of "readline" and issue to prompt.
** is false, use "getline" instead of "readline" and issue no prompt.
**
** zPrior is a string of prior text retrieved. If not the empty
** string, then issue a continuation prompt.

View File

@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.74 2001/12/31 02:48:51 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.75 2002/01/06 17:07:40 drh Exp $
*/
#include "sqlite.h"
#include "hash.h"
@ -119,13 +119,6 @@ extern int sqlite_nFree; /* Number of sqliteFree() calls */
extern int sqlite_iMallocFail; /* Fail sqliteMalloc() after this many calls */
#endif
/*
** The number of entries in the in-memory hash array holding the
** database schema. (Collision resolution is by chaining, so the
** table will hold more than this many entries.)
*/
#define N_HASH 51
/*
** Name of the master database table. The master database table
** is a special table that holds the names and attributes of all

View File

@ -30,7 +30,7 @@
** But other routines are also provided to help in building up
** a program instruction by instruction.
**
** $Id: vdbe.c,v 1.104 2002/01/04 03:09:30 drh Exp $
** $Id: vdbe.c,v 1.105 2002/01/06 17:07:41 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -456,11 +456,12 @@ void sqliteVdbeCompressSpace(Vdbe *p, int addr){
Op *pOp;
if( p->aOp==0 || addr<0 || addr>=p->nOp ) return;
pOp = &p->aOp[addr];
if( pOp->p3type==P3_POINTER ){
return;
}
if( pOp->p3type!=P3_DYNAMIC ){
pOp->p3 = sqliteStrDup(pOp->p3);
pOp->p3type = P3_DYNAMIC;
}else if( pOp->p3type!=P3_STATIC ){
return;
}
z = pOp->p3;
if( z==0 ) return;
@ -474,10 +475,8 @@ void sqliteVdbeCompressSpace(Vdbe *p, int addr){
z[j++] = z[i++];
}
}
while( i>0 && isspace(z[i-1]) ){
z[i-1] = 0;
i--;
}
while( j>0 && isspace(z[j-1]) ){ j--; }
z[j] = 0;
}
/*
@ -922,7 +921,6 @@ int sqliteVdbeList(
azValue[3] = zP2;
azValue[5] = 0;
rc = SQLITE_OK;
/* if( pzErrMsg ){ *pzErrMsg = 0; } */
for(i=0; rc==SQLITE_OK && i<p->nOp; i++){
if( p->db->flags & SQLITE_Interrupt ){
p->db->flags &= ~SQLITE_Interrupt;
@ -1028,8 +1026,9 @@ static int byteSwap(int x){
** from sqliteMalloc() and *pzErrMsg is made to point to that memory.
** The return parameter is the number of errors.
**
** If the callback every returns non-zero, then the program exits
** immediately. No error message but the function does return SQLITE_ABORT.
** If the callback ever returns non-zero, then the program exits
** immediately. There will be no error message but the function
** does return SQLITE_ABORT.
**
** A memory allocation error causes this routine to return SQLITE_NOMEM
** and abandon furture processing.
@ -1089,7 +1088,6 @@ int sqliteVdbeExec(
p->trace = stdout;
}
#endif
/* if( pzErrMsg ){ *pzErrMsg = 0; } */
if( sqlite_malloc_failed ) goto no_mem;
for(pc=0; !sqlite_malloc_failed && rc==SQLITE_OK && pc<p->nOp
VERIFY(&& pc>=0); pc++){

View File

@ -13,7 +13,7 @@
** the WHERE clause of SQL statements. Also found here are subroutines
** to generate VDBE code to evaluate expressions.
**
** $Id: where.c,v 1.30 2002/01/04 03:09:30 drh Exp $
** $Id: where.c,v 1.31 2002/01/06 17:07:41 drh Exp $
*/
#include "sqliteInt.h"
@ -572,8 +572,8 @@ WhereInfo *sqliteWhereBegin(
pLevel->p2 = start;
haveKey = 0;
}else{
/* Case 5: The contraints on the right-most index field are
** inequalities.
/* Case 5: The contraint on the right-most index field is
** an inequality.
*/
int score = pLevel->score;
int nEqColumn = score/4;