SQLite

Check-in [abe9f5e81f]
Login

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

Overview
Comment:Replace sqlite3AffinityType() with a slightly faster version. (CVS 2296)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: abe9f5e81f1196f28eec628e898b2a994c4d659d
User & Date: danielk1977 2005-02-01 01:21:55.000
Context
2005-02-01
01:40
Tweaks to the keyword hash generator. Tried to make it a little faster. If nothing else, the keyword hash table is now a little smaller. (CVS 2297) (check-in: 4eca6c05ab user: drh tags: trunk)
01:21
Replace sqlite3AffinityType() with a slightly faster version. (CVS 2296) (check-in: abe9f5e81f user: danielk1977 tags: trunk)
2005-01-31
23:45
Performance tweaks for sqlite3AffinityType. (CVS 2295) (check-in: 32b926154a user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/build.c.
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.304 2005/01/31 23:45:56 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Initialize the pParse structure as needed.







|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.305 2005/02/01 01:21:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Initialize the pParse structure as needed.
853
854
855
856
857
858
859


















860
861
862

863
864
865
866

867

868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
  i = p->nCol-1;
  if( i>=0 ) p->aCol[i].notNull = onError;
}

/*
** Scan the column type name zType (length nType) and return the
** associated affinity type.


















*/
static char sqlite3AffinityType(const char *zType, int nType){
  int n, i;

  static const struct {
    const char *zSub;  /* Keywords substring to search for */
    char nSub;         /* length of zSub */
    char affinity;     /* Affinity to return if it matches */

  } substrings[] = {

    {"INT",  3, SQLITE_AFF_INTEGER},
    {"CHAR", 4, SQLITE_AFF_TEXT},
    {"CLOB", 4, SQLITE_AFF_TEXT},
    {"TEXT", 4, SQLITE_AFF_TEXT},
    {"BLOB", 4, SQLITE_AFF_NONE},
  };

  if( nType==0 ){
    return SQLITE_AFF_NONE;
  }
  for(i=0; i<sizeof(substrings)/sizeof(substrings[0]); i++){
    const char *zSub = substrings[i].zSub;
    int c1 = tolower(zSub[0]);
    int len = substrings[i].nSub;
    int limit = nType - len;
    const char *z = zType;
    for(n=0; n<=limit; n++, z++){
      if( tolower(z[0])==c1 && 0==sqlite3StrNICmp(z, zSub, len) ){
        return substrings[i].affinity;
      }
    }
  }
  return SQLITE_AFF_NUMERIC;
}

/*
** This routine is called by the parser while in the middle of
** parsing a CREATE TABLE statement.  The pFirst token is the first
** token in the sequence of tokens that describe the type of the
** column currently under construction.   pLast is the last token







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|
>
|
<
|
|
>
|
>
|
|
|
|
|
<
|
<
|
<
<
<
<
<
<
<
<
<
|
|
|
|
|







853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882

883
884
885
886
887
888
889
890
891
892

893

894









895
896
897
898
899
900
901
902
903
904
905
906
  i = p->nCol-1;
  if( i>=0 ) p->aCol[i].notNull = onError;
}

/*
** Scan the column type name zType (length nType) and return the
** associated affinity type.
**
** This routine does a case-independent search of zType for the 
** substrings in the following table. If one of the substrings is
** found, the corresponding affinity is returned. If zType contains
** more than one of the substrings, entries toward the top of 
** the table take priority. For example, if zType is 'BLOBINT', 
** SQLITE_AFF_INTEGER is returned.
**
** Substring     | Affinity
** --------------------------------
** 'INT'         | SQLITE_AFF_INTEGER
** 'CHAR'        | SQLITE_AFF_TEXT
** 'CLOB'        | SQLITE_AFF_TEXT
** 'TEXT'        | SQLITE_AFF_TEXT
** 'BLOB'        | SQLITE_AFF_NONE
**
** If none of the substrings in the above table are found,
** SQLITE_AFF_NUMERIC is returned.
*/
static char sqlite3AffinityType(const char *zType, int nType){
  u32 h = 0;
  char aff = SQLITE_AFF_NUMERIC;
  const unsigned char *zIn = zType;

  const unsigned char *zEnd = (zIn+nType);

  while( zIn!=zEnd ){
    h = (h<<8) + sqlite3UpperToLower[*zIn];
    zIn++;
    if     ( h==0x63686172 ) aff = SQLITE_AFF_TEXT;           /* CHAR */
    else if( h==0x636C6F62 ) aff = SQLITE_AFF_TEXT;           /* CLOB */
    else if( h==0x74657874 ) aff = SQLITE_AFF_TEXT;           /* TEXT */
    else if( h==0x626C6F62 && aff==SQLITE_AFF_NUMERIC ){      /* BLOB */
      aff = SQLITE_AFF_NONE;

    }else if( (h&0x00FFFFFF)==0x00696E74 ){                   /* INT */

      aff = SQLITE_AFF_INTEGER; 









      break;
    }
  }

  return aff;
}

/*
** This routine is called by the parser while in the middle of
** parsing a CREATE TABLE statement.  The pFirst token is the first
** token in the sequence of tokens that describe the type of the
** column currently under construction.   pLast is the last token