/ Check-in [cd1be815]
Login

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

Overview
Comment:Add definitions of the CollSeq and KeyInfo structures. (CVS 1399)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:cd1be81569aa6d5a365eb27b7d067a153079ce45
User & Date: drh 2004-05-18 23:21:36
Context
2004-05-19
10:34
Tests for text encoding conversion functions. Also new sqlite3_bindXX APIs. (CVS 1400) check-in: 4e602bb4 user: danielk1977 tags: trunk
2004-05-18
23:21
Add definitions of the CollSeq and KeyInfo structures. (CVS 1399) check-in: cd1be815 user: drh tags: trunk
22:38
Remove dead code from vdbeaux.c. Add comments describing desired changes to OP_Sort processing in select.c (CVS 1398) check-in: ae37e8a0 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.236 2004/05/18 10:06:26 danielk1977 Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.237 2004/05/18 23:21:36 drh Exp $
    15     15   */
    16     16   #include "config.h"
    17     17   #include "sqlite.h"
    18     18   #include "hash.h"
    19     19   #include "parse.h"
    20     20   #include <stdio.h>
    21     21   #include <stdlib.h>
................................................................................
   255    255   typedef struct Trigger Trigger;
   256    256   typedef struct TriggerStep TriggerStep;
   257    257   typedef struct TriggerStack TriggerStack;
   258    258   typedef struct FKey FKey;
   259    259   typedef struct Db Db;
   260    260   typedef struct AuthContext AuthContext;
   261    261   typedef struct KeyClass KeyClass;
          262  +typedef struct CollSeq CollSeq;
   262    263   
   263    264   /*
   264    265   ** Each database file to be accessed by the system is an instance
   265    266   ** of the following structure.  There are normally two of these structures
   266    267   ** in the sqlite.aDb[] array.  aDb[0] is the main database file and
   267    268   ** aDb[1] is the database file used to hold temporary tables.  Additional
   268    269   ** databases may be attached.
................................................................................
   365    366     int cache_size;               /* Number of pages to use in the cache */
   366    367     int nTable;                   /* Number of tables in the database */
   367    368     void *pBusyArg;               /* 1st Argument to the busy callback */
   368    369     int (*xBusyCallback)(void *,const char*,int);  /* The busy callback */
   369    370     void *pCommitArg;             /* Argument to xCommitCallback() */   
   370    371     int (*xCommitCallback)(void*);/* Invoked at every commit. */
   371    372     Hash aFunc;                   /* All functions that can be in SQL exprs */
          373  +  Hash aCollSeq;                /* All collating sequences */
          374  +  CollSeq *pDfltColl;           /* The default collating sequence (memcmp) */
   372    375     i64 lastRowid;                /* ROWID of most recent insert (see above) */
   373    376     i64 priorNewRowid;            /* Last randomly generated ROWID */
   374    377     int magic;                    /* Magic number for detect library misuse */
   375    378     int nChange;                  /* Number of rows changed (see above) */
   376    379     int lsChange;                 /* Last statement change count (see above) */
   377    380     int csChange;                 /* Current statement change count (see above) */
   378    381     struct sqlite3InitInfo {       /* Information used during initialization */
................................................................................
   451    454   ** information about each column of an SQL table is held in an instance
   452    455   ** of this structure.
   453    456   */
   454    457   struct Column {
   455    458     char *zName;     /* Name of this column */
   456    459     char *zDflt;     /* Default value of this column */
   457    460     char *zType;     /* Data type for this column */
          461  +  CollSeq *pColl;  /* Collating sequence.  If NULL, use the default */
   458    462     u8 notNull;      /* True if there is a NOT NULL constraint */
   459    463     u8 isPrimKey;    /* True if this column is part of the PRIMARY KEY */
   460         -//  u8 sortOrder;    /* Some combination of SQLITE_SO_... values */ 
   461    464     char affinity;   /* One of the SQLITE_AFF_... values */
   462    465     u8 dottedName;   /* True if zName contains a "." character */
   463    466   };
          467  +
          468  +/*
          469  +** A "Collating Sequence" is defined by an instance of the following
          470  +** structure.  Every collating sequence has a name and a comparison
          471  +** function that defines the order of text for that sequence.  The
          472  +** CollSeq.pUser parameter is an extra parameter that passed in as
          473  +** the first argument to the comparison function.
          474  +**
          475  +** If CollSeq.xCmp is NULL, it means that the collating sequence is
          476  +** undefined.  Indices built on an undefined collating sequence may
          477  +** not be read or written.
          478  +*/
          479  +struct CollSeq {
          480  +  char *zName;         /* Name of the collating sequence */
          481  +  void *pUser;         /* First argument to xCmp() */
          482  +  int (*xCmp)(void*,int,const void*,int,const void*); /* Comparison function */
          483  +};
   464    484   
   465    485   /*
   466    486   ** The allowed sort orders.
   467    487   **
   468    488   ** The TEXT and NUM values use bits that do not overlap with DESC and ASC.
   469    489   ** That way the two can be combined into a single number.
   470    490   */
................................................................................
   701    721   ** be the right operand of an IN operator.  Or, if a scalar SELECT appears
   702    722   ** in an expression the opcode is TK_SELECT and Expr.pSelect is the only
   703    723   ** operand.
   704    724   */
   705    725   struct Expr {
   706    726     u8 op;                 /* Operation performed by this node */
   707    727     u8 dataType;           /* Either SQLITE_SO_TEXT or SQLITE_SO_NUM */
          728  +  char affinity;         /* The affinity of the column or 0 if not a column */
   708    729     u8 iDb;                /* Database referenced by this expression */
   709    730     u8 flags;              /* Various flags.  See below */
   710    731     Expr *pLeft, *pRight;  /* Left and right subnodes */
   711    732     ExprList *pList;       /* A list of expressions used as function arguments
   712    733                            ** or in "<expr> IN (<expr-list)" */
   713    734     Token token;           /* An operand token */
   714    735     Token span;            /* Complete text of the expression */
   715    736     int iTable, iColumn;   /* When op==TK_COLUMN, then this expr node means the
   716    737                            ** iColumn-th field of the iTable-th table. */
   717    738     int iAgg;              /* When op==TK_COLUMN and pParse->useAgg==TRUE, pull
   718    739                            ** result from the iAgg-th element of the aggregator */
   719    740     Select *pSelect;       /* When the expression is a sub-select.  Also the
   720    741                            ** right side of "<expr> IN (<select>)" */
   721         -  char affinity;         /* The affinity of the column or 0 if not a column */
   722    742   };
   723    743   
   724    744   /*
   725    745   ** The following are the meanings of bits in the Expr.flags field.
   726    746   */
   727    747   #define EP_FromJoin     0x0001  /* Originated in ON or USING clause of a join */
   728    748   

Changes to src/vdbe.h.

    11     11   *************************************************************************
    12     12   ** Header file for the Virtual DataBase Engine (VDBE)
    13     13   **
    14     14   ** This header defines the interface to the virtual database engine
    15     15   ** or VDBE.  The VDBE implements an abstract machine that runs a
    16     16   ** simple program to access and modify the underlying database.
    17     17   **
    18         -** $Id: vdbe.h,v 1.76 2004/05/18 10:06:26 danielk1977 Exp $
           18  +** $Id: vdbe.h,v 1.77 2004/05/18 23:21:36 drh Exp $
    19     19   */
    20     20   #ifndef _SQLITE_VDBE_H_
    21     21   #define _SQLITE_VDBE_H_
    22     22   #include <stdio.h>
    23     23   
    24     24   /*
    25     25   ** A single VDBE is an opaque structure named "Vdbe".  Only routines
................................................................................
    75     75   #define ADDR(X)  (-1-(X))
    76     76   
    77     77   /*
    78     78   ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
    79     79   ** header file that defines a number for each opcode used by the VDBE.
    80     80   */
    81     81   #include "opcodes.h"
           82  +
           83  +/*
           84  +** An instance of the following structure is passed as the first
           85  +** argument to sqlite3VdbeKeyCompare and is used to control the 
           86  +** comparison of the two keys.
           87  +**
           88  +** If the KeyInfo.incrKey value is true and the comparison would
           89  +** otherwise be equal, then return a result as if the second key larger.
           90  +*/
           91  +typedef struct KeyInfo KeyInfo;
           92  +struct KeyInfo {
           93  +  u8 incrKey;           /* Increase value of 2nd key by epsilon */
           94  +  u8 reverseOrder;      /* If true, reverse the comparison order */
           95  +  int nField;           /* Number of entries in aColl[] */
           96  +  struct CollSeq *aColl[1];  /* Collating sequence for each term of the key */
           97  +};
    82     98   
    83     99   /*
    84    100   ** Prototypes for the VDBE interface.  See comments on the implementation
    85    101   ** for a description of what each of these routines does.
    86    102   */
    87    103   Vdbe *sqlite3VdbeCreate(sqlite*);
    88    104   void sqlite3VdbeCreateCallback(Vdbe*, int*);

Changes to src/vdbeaux.c.

  1040   1040       sqlite3_search_count++;
  1041   1041       p->deferredMoveto = 0;
  1042   1042       p->cacheValid = 0;
  1043   1043     }
  1044   1044     return SQLITE_OK;
  1045   1045   }
  1046   1046   
  1047         -#if 0
  1048         -/*
  1049         -** FIX ME
  1050         -**
  1051         -** This function is included temporarily so that regression tests have
  1052         -** a chance of passing. It always uses memcmp().
  1053         -*/
  1054         -int sqlite2BtreeKeyCompare(
  1055         -  BtCursor *pCur,       /* Pointer to entry to compare against */
  1056         -  const void *pKey,     /* Key to compare against entry that pCur points to */
  1057         -  int nKey,             /* Number of bytes in pKey */
  1058         -  int nIgnore,          /* Ignore this many bytes at the end of pCur */
  1059         -  int *pResult          /* Write the result here */
  1060         -){
  1061         -  const void *pCellKey;
  1062         -  void *pMallocedKey;
  1063         -  u64 nCellKey;
  1064         -  int rc;
  1065         -
  1066         -  sqlite3BtreeKeySize(pCur, &nCellKey);
  1067         -  nCellKey = nCellKey - nIgnore;
  1068         -  if( nCellKey<=0 ){
  1069         -    *pResult = 0;
  1070         -    return SQLITE_OK;
  1071         -  }
  1072         -
  1073         -  pCellKey = sqlite3BtreeKeyFetch(pCur, nCellKey);
  1074         -  if( pCellKey ){
  1075         -    *pResult = memcmp(pCellKey, pKey, nKey>nCellKey?nCellKey:nKey);
  1076         -    return SQLITE_OK;
  1077         -  }
  1078         -
  1079         -  pMallocedKey = sqliteMalloc( nCellKey );
  1080         -  if( pMallocedKey==0 ) return SQLITE_NOMEM;
  1081         -
  1082         -  rc = sqlite3BtreeKey(pCur, 0, nCellKey, pMallocedKey);
  1083         -  *pResult = memcmp(pMallocedKey, pKey, nKey>nCellKey?nCellKey:nKey);
  1084         -  sqliteFree(pMallocedKey);
  1085         -
  1086         -  return rc;
  1087         -}
  1088         -#endif
  1089         -
  1090   1047   /*
  1091   1048   ** The following functions:
  1092   1049   **
  1093   1050   ** sqlite3VdbeSerialType()
  1094   1051   ** sqlite3VdbeSerialTypeLen()
  1095   1052   ** sqlite3VdbeSerialRead()
  1096   1053   ** sqlite3VdbeSerialLen()