/ Check-in [9b837b05]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Merge in the latest changes from trunk. Simplify the implementation of the tointeger() and toreal() functions. Fix test cases and put unambiguous labels on all testcase names.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | toTypeFuncs
Files: files | file ages | folders
SHA1: 9b837b0508fbfb395f0a0d8e4bd127730c80ffc5
User & Date: drh 2013-06-21 19:29:33
Context
2013-07-20
00:39
Merge updates from trunk. check-in: dd4b77c8 user: mistachkin tags: toTypeFuncs
2013-06-21
19:29
Merge in the latest changes from trunk. Simplify the implementation of the tointeger() and toreal() functions. Fix test cases and put unambiguous labels on all testcase names. check-in: 9b837b05 user: drh tags: toTypeFuncs
18:36
Remove an unused function declaration from the FTS3 source code. check-in: 096ae1d8 user: drh tags: trunk
18:32
Merge updates from trunk. check-in: fa2a91e6 user: mistachkin tags: toTypeFuncs
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

1077
1078
1079
1080
1081
1082
1083


1084
1085
1086
1087
1088
1089
1090
1091
1092

1093








1094
1095


1096
1097
1098
1099
1100
1101
1102
....
1127
1128
1129
1130
1131
1132
1133
1134

1135
1136
1137
1138
1139
1140
1141
....
1193
1194
1195
1196
1197
1198
1199





1200
1201
1202
1203
1204
1205
1206
....
1264
1265
1266
1267
1268
1269
1270

1271
1272
1273
1274
1275
1276
1277
....
1297
1298
1299
1300
1301
1302
1303

1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
....
1320
1321
1322
1323
1324
1325
1326



















1327
1328
1329
1330
1331
1332
1333
1334
....
1361
1362
1363
1364
1365
1366
1367

1368

1369
1370
1371
1372
1373
1374
1375
  int bNoDocsize = 0;             /* True to omit %_docsize table */
  int bDescIdx = 0;               /* True to store descending indexes */
  char *zPrefix = 0;              /* Prefix parameter value (or NULL) */
  char *zCompress = 0;            /* compress=? parameter (or NULL) */
  char *zUncompress = 0;          /* uncompress=? parameter (or NULL) */
  char *zContent = 0;             /* content=? parameter (or NULL) */
  char *zLanguageid = 0;          /* languageid=? parameter (or NULL) */



  assert( strlen(argv[0])==4 );
  assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
       || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
  );

  nDb = (int)strlen(argv[1]) + 1;
  nName = (int)strlen(argv[2]) + 1;


  aCol = (const char **)sqlite3_malloc(sizeof(const char *) * (argc-2) );








  if( !aCol ) return SQLITE_NOMEM;
  memset((void *)aCol, 0, sizeof(const char *) * (argc-2));



  /* Loop through all of the arguments passed by the user to the FTS3/4
  ** module (i.e. all the column names and special arguments). This loop
  ** does the following:
  **
  **   + Figures out the number of columns the FTSX table will have, and
  **     the number of bytes of space that must be allocated to store copies
................................................................................
      } aFts4Opt[] = {
        { "matchinfo",   9 },     /* 0 -> MATCHINFO */
        { "prefix",      6 },     /* 1 -> PREFIX */
        { "compress",    8 },     /* 2 -> COMPRESS */
        { "uncompress", 10 },     /* 3 -> UNCOMPRESS */
        { "order",       5 },     /* 4 -> ORDER */
        { "content",     7 },     /* 5 -> CONTENT */
        { "languageid", 10 }      /* 6 -> LANGUAGEID */

      };

      int iOpt;
      if( !zVal ){
        rc = SQLITE_NOMEM;
      }else{
        for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
................................................................................

            case 6:              /* LANGUAGEID */
              assert( iOpt==6 );
              sqlite3_free(zLanguageid);
              zLanguageid = zVal;
              zVal = 0;
              break;





          }
        }
        sqlite3_free(zVal);
      }
    }

    /* Otherwise, the argument is a column name. */
................................................................................
  }
  if( rc!=SQLITE_OK ) goto fts3_init_out;

  /* Allocate and populate the Fts3Table structure. */
  nByte = sizeof(Fts3Table) +                  /* Fts3Table */
          nCol * sizeof(char *) +              /* azColumn */
          nIndex * sizeof(struct Fts3Index) +  /* aIndex */

          nName +                              /* zName */
          nDb +                                /* zDb */
          nString;                             /* Space for azColumn strings */
  p = (Fts3Table*)sqlite3_malloc(nByte);
  if( p==0 ){
    rc = SQLITE_NOMEM;
    goto fts3_init_out;
................................................................................

  p->aIndex = (struct Fts3Index *)&p->azColumn[nCol];
  memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex);
  p->nIndex = nIndex;
  for(i=0; i<nIndex; i++){
    fts3HashInit(&p->aIndex[i].hPending, FTS3_HASH_STRING, 1);
  }


  /* Fill in the zName and zDb fields of the vtab structure. */
  zCsr = (char *)&p->aIndex[nIndex];
  p->zName = zCsr;
  memcpy(zCsr, argv[2], nName);
  zCsr += nName;
  p->zDb = zCsr;
  memcpy(zCsr, argv[1], nDb);
  zCsr += nDb;

................................................................................
    zCsr[n] = '\0';
    sqlite3Fts3Dequote(zCsr);
    p->azColumn[iCol] = zCsr;
    zCsr += n+1;
    assert( zCsr <= &((char *)p)[nByte] );
  }




















  if( (zCompress==0)!=(zUncompress==0) ){
    char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
    rc = SQLITE_ERROR;
    *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
  }
  p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
  p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
  if( rc!=SQLITE_OK ) goto fts3_init_out;
................................................................................
fts3_init_out:
  sqlite3_free(zPrefix);
  sqlite3_free(aIndex);
  sqlite3_free(zCompress);
  sqlite3_free(zUncompress);
  sqlite3_free(zContent);
  sqlite3_free(zLanguageid);

  sqlite3_free((void *)aCol);

  if( rc!=SQLITE_OK ){
    if( p ){
      fts3DisconnectMethod((sqlite3_vtab *)p);
    }else if( pTokenizer ){
      pTokenizer->pModule->xDestroy(pTokenizer);
    }
  }else{







>
>









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







 







|
>







 







>
>
>
>
>







 







>







 







>


|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







 







>

>







1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105

1106
1107
1108
1109
1110
1111
1112
1113
1114
....
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
....
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
....
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
....
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
....
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
....
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
  int bNoDocsize = 0;             /* True to omit %_docsize table */
  int bDescIdx = 0;               /* True to store descending indexes */
  char *zPrefix = 0;              /* Prefix parameter value (or NULL) */
  char *zCompress = 0;            /* compress=? parameter (or NULL) */
  char *zUncompress = 0;          /* uncompress=? parameter (or NULL) */
  char *zContent = 0;             /* content=? parameter (or NULL) */
  char *zLanguageid = 0;          /* languageid=? parameter (or NULL) */
  char **azNotindexed = 0;        /* The set of notindexed= columns */
  int nNotindexed = 0;            /* Size of azNotindexed[] array */

  assert( strlen(argv[0])==4 );
  assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
       || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
  );

  nDb = (int)strlen(argv[1]) + 1;
  nName = (int)strlen(argv[2]) + 1;

  nByte = sizeof(const char *) * (argc-2);
  aCol = (const char **)sqlite3_malloc(nByte);
  if( aCol ){
    memset(aCol, 0, nByte);
    azNotindexed = (char **)sqlite3_malloc(nByte);
  }
  if( azNotindexed ){
    memset(azNotindexed, 0, nByte);
  }
  if( !aCol || !azNotindexed ){
    rc = SQLITE_NOMEM;

    goto fts3_init_out;
  }

  /* Loop through all of the arguments passed by the user to the FTS3/4
  ** module (i.e. all the column names and special arguments). This loop
  ** does the following:
  **
  **   + Figures out the number of columns the FTSX table will have, and
  **     the number of bytes of space that must be allocated to store copies
................................................................................
      } aFts4Opt[] = {
        { "matchinfo",   9 },     /* 0 -> MATCHINFO */
        { "prefix",      6 },     /* 1 -> PREFIX */
        { "compress",    8 },     /* 2 -> COMPRESS */
        { "uncompress", 10 },     /* 3 -> UNCOMPRESS */
        { "order",       5 },     /* 4 -> ORDER */
        { "content",     7 },     /* 5 -> CONTENT */
        { "languageid", 10 },     /* 6 -> LANGUAGEID */
        { "notindexed", 10 }      /* 7 -> NOTINDEXED */
      };

      int iOpt;
      if( !zVal ){
        rc = SQLITE_NOMEM;
      }else{
        for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
................................................................................

            case 6:              /* LANGUAGEID */
              assert( iOpt==6 );
              sqlite3_free(zLanguageid);
              zLanguageid = zVal;
              zVal = 0;
              break;

            case 7:              /* NOTINDEXED */
              azNotindexed[nNotindexed++] = zVal;
              zVal = 0;
              break;
          }
        }
        sqlite3_free(zVal);
      }
    }

    /* Otherwise, the argument is a column name. */
................................................................................
  }
  if( rc!=SQLITE_OK ) goto fts3_init_out;

  /* Allocate and populate the Fts3Table structure. */
  nByte = sizeof(Fts3Table) +                  /* Fts3Table */
          nCol * sizeof(char *) +              /* azColumn */
          nIndex * sizeof(struct Fts3Index) +  /* aIndex */
          nCol * sizeof(u8) +                  /* abNotindexed */
          nName +                              /* zName */
          nDb +                                /* zDb */
          nString;                             /* Space for azColumn strings */
  p = (Fts3Table*)sqlite3_malloc(nByte);
  if( p==0 ){
    rc = SQLITE_NOMEM;
    goto fts3_init_out;
................................................................................

  p->aIndex = (struct Fts3Index *)&p->azColumn[nCol];
  memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex);
  p->nIndex = nIndex;
  for(i=0; i<nIndex; i++){
    fts3HashInit(&p->aIndex[i].hPending, FTS3_HASH_STRING, 1);
  }
  p->abNotindexed = (u8 *)&p->aIndex[nIndex];

  /* Fill in the zName and zDb fields of the vtab structure. */
  zCsr = (char *)&p->abNotindexed[nCol];
  p->zName = zCsr;
  memcpy(zCsr, argv[2], nName);
  zCsr += nName;
  p->zDb = zCsr;
  memcpy(zCsr, argv[1], nDb);
  zCsr += nDb;

................................................................................
    zCsr[n] = '\0';
    sqlite3Fts3Dequote(zCsr);
    p->azColumn[iCol] = zCsr;
    zCsr += n+1;
    assert( zCsr <= &((char *)p)[nByte] );
  }

  /* Fill in the abNotindexed array */
  for(iCol=0; iCol<nCol; iCol++){
    int n = strlen(p->azColumn[iCol]);
    for(i=0; i<nNotindexed; i++){
      char *zNot = azNotindexed[i];
      if( zNot && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n) ){
        p->abNotindexed[iCol] = 1;
        sqlite3_free(zNot);
        azNotindexed[i] = 0;
      }
    }
  }
  for(i=0; i<nNotindexed; i++){
    if( azNotindexed[i] ){
      *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
      rc = SQLITE_ERROR;
    }
  }

  if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
    char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
    rc = SQLITE_ERROR;
    *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
  }
  p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
  p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc);
  if( rc!=SQLITE_OK ) goto fts3_init_out;
................................................................................
fts3_init_out:
  sqlite3_free(zPrefix);
  sqlite3_free(aIndex);
  sqlite3_free(zCompress);
  sqlite3_free(zUncompress);
  sqlite3_free(zContent);
  sqlite3_free(zLanguageid);
  for(i=0; i<nNotindexed; i++) sqlite3_free(azNotindexed[i]);
  sqlite3_free((void *)aCol);
  sqlite3_free((void *)azNotindexed);
  if( rc!=SQLITE_OK ){
    if( p ){
      fts3DisconnectMethod((sqlite3_vtab *)p);
    }else if( pTokenizer ){
      pTokenizer->pModule->xDestroy(pTokenizer);
    }
  }else{

Changes to ext/fts3/fts3Int.h.

202
203
204
205
206
207
208

209
210
211
212
213
214
215
...
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
struct Fts3Table {
  sqlite3_vtab base;              /* Base class used by SQLite core */
  sqlite3 *db;                    /* The database connection */
  const char *zDb;                /* logical database name */
  const char *zName;              /* virtual table name */
  int nColumn;                    /* number of named columns in virtual table */
  char **azColumn;                /* column names.  malloced */

  sqlite3_tokenizer *pTokenizer;  /* tokenizer for inserts and queries */
  char *zContentTbl;              /* content=xxx option, or NULL */
  char *zLanguageid;              /* languageid=xxx option, or NULL */
  u8 bAutoincrmerge;              /* True if automerge=1 */
  u32 nLeafAdd;                   /* Number of leaf blocks added this trans */

  /* Precompiled statements used by the implementation. Each of these 
................................................................................
int sqlite3Fts3Optimize(Fts3Table *);
int sqlite3Fts3SegReaderNew(int, int, sqlite3_int64,
  sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
int sqlite3Fts3SegReaderPending(
  Fts3Table*,int,const char*,int,int,Fts3SegReader**);
void sqlite3Fts3SegReaderFree(Fts3SegReader *);
int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);
int sqlite3Fts3ReadLock(Fts3Table *);
int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);

int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);

#ifndef SQLITE_DISABLE_FTS4_DEFERRED
void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *);







>







 







<







202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
430
431
432
433
434
435
436

437
438
439
440
441
442
443
struct Fts3Table {
  sqlite3_vtab base;              /* Base class used by SQLite core */
  sqlite3 *db;                    /* The database connection */
  const char *zDb;                /* logical database name */
  const char *zName;              /* virtual table name */
  int nColumn;                    /* number of named columns in virtual table */
  char **azColumn;                /* column names.  malloced */
  u8 *abNotindexed;               /* True for 'notindexed' columns */
  sqlite3_tokenizer *pTokenizer;  /* tokenizer for inserts and queries */
  char *zContentTbl;              /* content=xxx option, or NULL */
  char *zLanguageid;              /* languageid=xxx option, or NULL */
  u8 bAutoincrmerge;              /* True if automerge=1 */
  u32 nLeafAdd;                   /* Number of leaf blocks added this trans */

  /* Precompiled statements used by the implementation. Each of these 
................................................................................
int sqlite3Fts3Optimize(Fts3Table *);
int sqlite3Fts3SegReaderNew(int, int, sqlite3_int64,
  sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
int sqlite3Fts3SegReaderPending(
  Fts3Table*,int,const char*,int,int,Fts3SegReader**);
void sqlite3Fts3SegReaderFree(Fts3SegReader *);
int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);

int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);

int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);

#ifndef SQLITE_DISABLE_FTS4_DEFERRED
void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *);

Changes to ext/fts3/fts3_write.c.

896
897
898
899
900
901
902


903
904
905
906
907
908

909
910
911
912
913
914
915
....
1048
1049
1050
1051
1052
1053
1054


1055
1056
1057

1058
1059
1060
1061
1062
1063
1064
....
3292
3293
3294
3295
3296
3297
3298

3299
3300
3301

3302
3303
3304
3305
3306
3307
3308
....
5097
5098
5099
5100
5101
5102
5103

5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132

5133
5134
5135
5136
5137
5138
5139
  Fts3Table *p, 
  int iLangid, 
  sqlite3_value **apVal, 
  u32 *aSz
){
  int i;                          /* Iterator variable */
  for(i=2; i<p->nColumn+2; i++){


    const char *zText = (const char *)sqlite3_value_text(apVal[i]);
    int rc = fts3PendingTermsAdd(p, iLangid, zText, i-2, &aSz[i-2]);
    if( rc!=SQLITE_OK ){
      return rc;
    }
    aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);

  }
  return SQLITE_OK;
}

/*
** This function is called by the xUpdate() method for an INSERT operation.
** The apVal parameter is passed a copy of the apVal argument passed by
................................................................................
  rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, &pRowid);
  if( rc==SQLITE_OK ){
    if( SQLITE_ROW==sqlite3_step(pSelect) ){
      int i;
      int iLangid = langidFromSelect(p, pSelect);
      rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0));
      for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){


        const char *zText = (const char *)sqlite3_column_text(pSelect, i);
        rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[i-1]);
        aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);

      }
      if( rc!=SQLITE_OK ){
        sqlite3_reset(pSelect);
        *pRC = rc;
        return;
      }
      *pbFound = 1;
................................................................................

    while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
      int iCol;
      int iLangid = langidFromSelect(p, pStmt);
      rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0));
      memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
      for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){

        const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
        rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
        aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);

      }
      if( p->bHasDocsize ){
        fts3InsertDocsize(&rc, p, aSz);
      }
      if( rc!=SQLITE_OK ){
        sqlite3_finalize(pStmt);
        pStmt = 0;
................................................................................
    sqlite3_tokenizer *pT = p->pTokenizer;
    sqlite3_tokenizer_module const *pModule = pT->pModule;
   
    assert( pCsr->isRequireSeek==0 );
    iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
  
    for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){

      const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
      sqlite3_tokenizer_cursor *pTC = 0;
  
      rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
      while( rc==SQLITE_OK ){
        char const *zToken;       /* Buffer containing token */
        int nToken = 0;           /* Number of bytes in token */
        int iDum1 = 0, iDum2 = 0; /* Dummy variables */
        int iPos = 0;             /* Position of token in zText */
  
        rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
        for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
          Fts3PhraseToken *pPT = pDef->pToken;
          if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
           && (pPT->bFirst==0 || iPos==0)
           && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
           && (0==memcmp(zToken, pPT->z, pPT->n))
          ){
            fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
          }
        }
      }
      if( pTC ) pModule->xClose(pTC);
      if( rc==SQLITE_DONE ) rc = SQLITE_OK;
    }
  
    for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
      if( pDef->pList ){
        rc = fts3PendingListAppendVarint(&pDef->pList, 0);

      }
    }
  }

  return rc;
}








>
>
|
|
|
|
|
|
>







 







>
>
|
|
|
>







 







>
|
|
|
>







 







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
....
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
....
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
....
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
  Fts3Table *p, 
  int iLangid, 
  sqlite3_value **apVal, 
  u32 *aSz
){
  int i;                          /* Iterator variable */
  for(i=2; i<p->nColumn+2; i++){
    int iCol = i-2;
    if( p->abNotindexed[iCol]==0 ){
      const char *zText = (const char *)sqlite3_value_text(apVal[i]);
      int rc = fts3PendingTermsAdd(p, iLangid, zText, iCol, &aSz[iCol]);
      if( rc!=SQLITE_OK ){
        return rc;
      }
      aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
    }
  }
  return SQLITE_OK;
}

/*
** This function is called by the xUpdate() method for an INSERT operation.
** The apVal parameter is passed a copy of the apVal argument passed by
................................................................................
  rc = fts3SqlStmt(p, SQL_SELECT_CONTENT_BY_ROWID, &pSelect, &pRowid);
  if( rc==SQLITE_OK ){
    if( SQLITE_ROW==sqlite3_step(pSelect) ){
      int i;
      int iLangid = langidFromSelect(p, pSelect);
      rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0));
      for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){
        int iCol = i-1;
        if( p->abNotindexed[iCol]==0 ){
          const char *zText = (const char *)sqlite3_column_text(pSelect, i);
          rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[iCol]);
          aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
        }
      }
      if( rc!=SQLITE_OK ){
        sqlite3_reset(pSelect);
        *pRC = rc;
        return;
      }
      *pbFound = 1;
................................................................................

    while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
      int iCol;
      int iLangid = langidFromSelect(p, pStmt);
      rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0));
      memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
      for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
        if( p->abNotindexed[iCol]==0 ){
          const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
          rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
          aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
        }
      }
      if( p->bHasDocsize ){
        fts3InsertDocsize(&rc, p, aSz);
      }
      if( rc!=SQLITE_OK ){
        sqlite3_finalize(pStmt);
        pStmt = 0;
................................................................................
    sqlite3_tokenizer *pT = p->pTokenizer;
    sqlite3_tokenizer_module const *pModule = pT->pModule;
   
    assert( pCsr->isRequireSeek==0 );
    iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
  
    for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
      if( p->abNotindexed[i]==0 ){
        const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
        sqlite3_tokenizer_cursor *pTC = 0;

        rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
        while( rc==SQLITE_OK ){
          char const *zToken;       /* Buffer containing token */
          int nToken = 0;           /* Number of bytes in token */
          int iDum1 = 0, iDum2 = 0; /* Dummy variables */
          int iPos = 0;             /* Position of token in zText */

          rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
          for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
            Fts3PhraseToken *pPT = pDef->pToken;
            if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
                && (pPT->bFirst==0 || iPos==0)
                && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
                && (0==memcmp(zToken, pPT->z, pPT->n))
              ){
              fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
            }
          }
        }
        if( pTC ) pModule->xClose(pTC);
        if( rc==SQLITE_DONE ) rc = SQLITE_OK;
      }

      for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
        if( pDef->pList ){
          rc = fts3PendingListAppendVarint(&pDef->pList, 0);
        }
      }
    }
  }

  return rc;
}

Changes to src/func.c.

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
...
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998

999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049

1050
1051
1052
1053
1054
1055
1056
1057
1058
....
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
....
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
....
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
*/
#include "sqliteInt.h"
#include <stdlib.h>
#include <assert.h>
#ifndef SQLITE_OMIT_FLOATING_POINT
# include <math.h>
#endif
#include "vdbeInt.h"

/*
** Return the collating function associated with a function.
*/
static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
  return context->pColl;
................................................................................
      sqlite3_result_text(context, "NULL", 4, SQLITE_STATIC);
      break;
    }
  }
}

/*
** EXPERIMENTAL - This is not an official function.  The interface may
** change.  This function may disappear.  Do not write code that depends
** on this function.
**
** Implementation of the tointeger() function.  This function takes a
** single argument.  If the argument is an integer or is a double that
** can be losslessly converted to an integer, the return value is the
** same as the argument.  If the argument is a double that cannot be
** losslessly represented as an integer, the return value is NULL.
** If the argument is NULL, the return value is NULL.  Otherwise, an
** attempt is made to convert the argument to an integer.  If the
** conversion is successful, the integer value is returned; otherwise,
** NULL is returned.
*/
static void tointegerFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_FLOAT:
#ifndef SQLITE_OMIT_FLOATING_POINT
    {
      double rVal = sqlite3_value_double(argv[0]);
      double rIntVal = 0.0;

      if( !sqlite3IsNaN(rVal) && modf(rVal, &rIntVal)==0.0 &&
          rIntVal>=SMALLEST_INT64 && rIntVal<=LARGEST_INT64 ){
        sqlite3_result_int64(context, (i64)rIntVal);
        return;
      }
      sqlite3_result_null(context);
      break;
    }
#endif
    case SQLITE_INTEGER: {
      sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
      break;
    }
    case SQLITE_BLOB:
    case SQLITE_TEXT: {
      const unsigned char *zStr = sqlite3_value_text(argv[0]);
      if( zStr ){
        int nStr = sqlite3_value_bytes(argv[0]);
        if( nStr ){
          i64 iVal;
          if( !sqlite3Atoi64(zStr, &iVal, nStr, SQLITE_UTF8) ){
            sqlite3_result_int64(context, iVal);
            return;
          }
        }
      }
      sqlite3_result_null(context);
      break;
    }
    default: {
      assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
      sqlite3_result_null(context);
      break;
    }
  }
}

/*
** EXPERIMENTAL - This is not an official function.  The interface may
** change.  This function may disappear.  Do not write code that depends
** on this function.
**
** Implementation of the toreal() function.  This function takes a
** single argument.  If the argument is a double or is an integer that
** can be losslessly converted to a double, the return value is the
** same as the argument.  If the argument is an integer that cannot be
** losslessly represented as a double, the return value is NULL.
** If the argument is NULL, the return value is NULL.  Otherwise, an
** attempt is made to convert the argument to a double.  If the
** conversion is successful, the double value is returned; otherwise,
** NULL is returned.

*/
#ifndef SQLITE_OMIT_FLOATING_POINT
static void torealFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
................................................................................
      break;
    }
    case SQLITE_INTEGER: {
      i64 iVal = sqlite3_value_int64(argv[0]);
      double rVal = (double)iVal;
      if( iVal==rVal ){
        sqlite3_result_double(context, rVal);
        return;
      }
      sqlite3_result_null(context);
      break;
    }
    case SQLITE_BLOB:
    case SQLITE_TEXT: {
      const unsigned char *zStr = sqlite3_value_text(argv[0]);
      if( zStr ){
        int nStr = sqlite3_value_bytes(argv[0]);
................................................................................
          double rVal;
          if( sqlite3AtoF(zStr, &rVal, nStr, SQLITE_UTF8) ){
            sqlite3_result_double(context, rVal);
            return;
          }
        }
      }
      sqlite3_result_null(context);
      break;
    }
    default: {
      assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
      sqlite3_result_null(context);
      break;
    }
  }
}
#endif

/*
** The unicode() function.  Return the integer unicode code-point value
** for the first character of the input string. 
*/
static void unicodeFunc(
  sqlite3_context *context,
................................................................................
    FUNCTION(sqlite_log,         2, 0, 0, errlogFunc       ),
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
    FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc  ),
    FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc  ),
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
    FUNCTION(quote,              1, 0, 0, quoteFunc        ),
    FUNCTION(tointeger,          1, 0, 0, tointegerFunc    ),
#ifndef SQLITE_OMIT_FLOATING_POINT
    FUNCTION(toreal,             1, 0, 0, torealFunc       ),
#endif
    FUNCTION(last_insert_rowid,  0, 0, 0, last_insert_rowid),
    FUNCTION(changes,            0, 0, 0, changes          ),
    FUNCTION(total_changes,      0, 0, 0, total_changes    ),
    FUNCTION(replace,            3, 0, 0, replaceFunc      ),
    FUNCTION(zeroblob,           1, 0, 0, zeroblobFunc     ),
  #ifdef SQLITE_SOUNDEX
    FUNCTION(soundex,            1, 0, 0, soundexFunc      ),







<
<
<







 







|
|
|
<
<
<
<
<
<
<
<
<
<









|
<
<

<
>
|
<
|
<

<


<













<



<




<






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

<







 







<

<







 







<




<




<







 







<

<







15
16
17
18
19
20
21



22
23
24
25
26
27
28
...
962
963
964
965
966
967
968
969
970
971










972
973
974
975
976
977
978
979
980
981


982

983
984

985

986

987
988

989
990
991
992
993
994
995
996
997
998
999
1000
1001

1002
1003
1004

1005
1006
1007
1008

1009
1010
1011
1012
1013
1014






1015






1016
1017

1018
1019
1020
1021
1022
1023
1024
....
1028
1029
1030
1031
1032
1033
1034

1035

1036
1037
1038
1039
1040
1041
1042
....
1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054

1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
....
1762
1763
1764
1765
1766
1767
1768

1769

1770
1771
1772
1773
1774
1775
1776
** There is only one exported symbol in this file - the function
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
*/
#include "sqliteInt.h"
#include <stdlib.h>
#include <assert.h>



#include "vdbeInt.h"

/*
** Return the collating function associated with a function.
*/
static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
  return context->pColl;
................................................................................
      sqlite3_result_text(context, "NULL", 4, SQLITE_STATIC);
      break;
    }
  }
}

/*
** tointeger(X):  If X is any value (integer, double, or string) that can
** be losslessly converted into an integer, then make the conversion and
** return the result.  Otherwise, return NULL.










*/
static void tointegerFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_FLOAT: {


      double rVal = sqlite3_value_double(argv[0]);

      i64 iVal = (i64)rVal;
      if( !sqlite3IsNaN(rVal) && rVal==(double)iVal ){

        sqlite3_result_int64(context, iVal);

      }

      break;
    }

    case SQLITE_INTEGER: {
      sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
      break;
    }
    case SQLITE_BLOB:
    case SQLITE_TEXT: {
      const unsigned char *zStr = sqlite3_value_text(argv[0]);
      if( zStr ){
        int nStr = sqlite3_value_bytes(argv[0]);
        if( nStr ){
          i64 iVal;
          if( !sqlite3Atoi64(zStr, &iVal, nStr, SQLITE_UTF8) ){
            sqlite3_result_int64(context, iVal);

          }
        }
      }

      break;
    }
    default: {
      assert( sqlite3_value_type(argv[0])==SQLITE_NULL );

      break;
    }
  }
}

/*






** toreal(X):  If X can be losslessly converted into a real number, then






** do so and return that real number.  Otherwise return NULL.
*/

static void torealFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
................................................................................
      break;
    }
    case SQLITE_INTEGER: {
      i64 iVal = sqlite3_value_int64(argv[0]);
      double rVal = (double)iVal;
      if( iVal==rVal ){
        sqlite3_result_double(context, rVal);

      }

      break;
    }
    case SQLITE_BLOB:
    case SQLITE_TEXT: {
      const unsigned char *zStr = sqlite3_value_text(argv[0]);
      if( zStr ){
        int nStr = sqlite3_value_bytes(argv[0]);
................................................................................
          double rVal;
          if( sqlite3AtoF(zStr, &rVal, nStr, SQLITE_UTF8) ){
            sqlite3_result_double(context, rVal);
            return;
          }
        }
      }

      break;
    }
    default: {
      assert( sqlite3_value_type(argv[0])==SQLITE_NULL );

      break;
    }
  }
}


/*
** The unicode() function.  Return the integer unicode code-point value
** for the first character of the input string. 
*/
static void unicodeFunc(
  sqlite3_context *context,
................................................................................
    FUNCTION(sqlite_log,         2, 0, 0, errlogFunc       ),
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
    FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc  ),
    FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc  ),
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
    FUNCTION(quote,              1, 0, 0, quoteFunc        ),
    FUNCTION(tointeger,          1, 0, 0, tointegerFunc    ),

    FUNCTION(toreal,             1, 0, 0, torealFunc       ),

    FUNCTION(last_insert_rowid,  0, 0, 0, last_insert_rowid),
    FUNCTION(changes,            0, 0, 0, changes          ),
    FUNCTION(total_changes,      0, 0, 0, total_changes    ),
    FUNCTION(replace,            3, 0, 0, replaceFunc      ),
    FUNCTION(zeroblob,           1, 0, 0, zeroblobFunc     ),
  #ifdef SQLITE_SOUNDEX
    FUNCTION(soundex,            1, 0, 0, soundexFunc      ),

Changes to src/sqliteInt.h.

339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# ifndef SQLITE_BIG_DBL
#   define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
# endif
# define SQLITE_OMIT_DATETIME_FUNCS 1
# define SQLITE_OMIT_TRACE 1
# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
# undef SQLITE_HAVE_ISNAN
#else
# include <math.h>
#endif
#ifndef SQLITE_BIG_DBL
# define SQLITE_BIG_DBL (1e99)
#endif

/*
** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0







<
<







339
340
341
342
343
344
345


346
347
348
349
350
351
352
# ifndef SQLITE_BIG_DBL
#   define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50)
# endif
# define SQLITE_OMIT_DATETIME_FUNCS 1
# define SQLITE_OMIT_TRACE 1
# undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
# undef SQLITE_HAVE_ISNAN


#endif
#ifndef SQLITE_BIG_DBL
# define SQLITE_BIG_DBL (1e99)
#endif

/*
** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0

Changes to test/fts3malloc.test.

58
59
60
61
62
63
64



65
66
67
68
69
70
71
..
77
78
79
80
81
82
83

84
85
86
87
88
89
90
}
do_error_test fts3_malloc-1.5 {
  CREATE VIRTUAL TABLE ft5 USING fts3(a, b, tokenize unknown)
} {unknown tokenizer: unknown}
do_write_test fts3_malloc-1.6 sqlite_master {
  CREATE VIRTUAL TABLE ft6 USING fts3(a, b, tokenize porter)
}




# Test the xConnect/xDisconnect methods:
#db eval { ATTACH 'test2.db' AS aux }
#do_write_test fts3_malloc-1.6 aux.sqlite_master {
#  CREATE VIRTUAL TABLE aux.ft7 USING fts3(a, b, c);
#}
#do_write_test fts3_malloc-1.6 aux.sqlite_master {
................................................................................
do_test fts3_malloc-2.0 {
  execsql { 
    DROP TABLE ft1;
    DROP TABLE ft2;
    DROP TABLE ft3;
    DROP TABLE ft4;
    DROP TABLE ft6;

  }
  execsql { CREATE VIRTUAL TABLE ft USING fts3(a, b) }
  for {set ii 1} {$ii < 32} {incr ii} {
    set a [list]
    set b [list]
    if {$ii & 0x01} {lappend a one   ; lappend b neung}
    if {$ii & 0x02} {lappend a two   ; lappend b song }







>
>
>







 







>







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
}
do_error_test fts3_malloc-1.5 {
  CREATE VIRTUAL TABLE ft5 USING fts3(a, b, tokenize unknown)
} {unknown tokenizer: unknown}
do_write_test fts3_malloc-1.6 sqlite_master {
  CREATE VIRTUAL TABLE ft6 USING fts3(a, b, tokenize porter)
}
do_write_test fts3_malloc-1.7 sqlite_master {
  CREATE VIRTUAL TABLE ft7 USING fts4(a, b, notindexed=b)
}

# Test the xConnect/xDisconnect methods:
#db eval { ATTACH 'test2.db' AS aux }
#do_write_test fts3_malloc-1.6 aux.sqlite_master {
#  CREATE VIRTUAL TABLE aux.ft7 USING fts3(a, b, c);
#}
#do_write_test fts3_malloc-1.6 aux.sqlite_master {
................................................................................
do_test fts3_malloc-2.0 {
  execsql { 
    DROP TABLE ft1;
    DROP TABLE ft2;
    DROP TABLE ft3;
    DROP TABLE ft4;
    DROP TABLE ft6;
    DROP TABLE ft7;
  }
  execsql { CREATE VIRTUAL TABLE ft USING fts3(a, b) }
  for {set ii 1} {$ii < 32} {incr ii} {
    set a [list]
    set b [list]
    if {$ii & 0x01} {lappend a one   ; lappend b neung}
    if {$ii & 0x02} {lappend a two   ; lappend b song }

Added test/fts4noti.test.























































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
# 2013 June 21
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the notindexed=xxx FTS4 option.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set ::testprefix fts4noti

# If SQLITE_ENABLE_FTS3 is defined, omit this file.
ifcapable !fts3 {
  finish_test
  return
}


#-------------------------------------------------------------------------
# Test that typos in "notindexed=" column names are detected.
#
do_execsql_test 1.0 {
  CREATE TABLE cc(a, b, c);
}
foreach {tn arg res} {
  1 "(b, c, notindexed=a)"                  {1 {no such column: a}}
  2 "(a, b, notindexed=a)"                                   {0 {}}
  3 "(a, b, notindexed=a, notindexed=a)"                     {0 {}}
  4 "(notindexed=a, a, b)"                                   {0 {}}
  5 "(notindexed=a, notindexed=b, notindexed=c, a, b, c, d)" {0 {}}
  6 "(notindexed=a, notindexed=B, notindexed=c, a, b, c, d)" {0 {}}
  7 "(notindexed=a, notindexed=b, notindexed=c, a, B, c, d)" {0 {}}
  8 "(notindexed=d, content=cc)" {1 {no such column: d}}
  9 "(notindexed=a, content=cc)" {0 {}}
  10 "(notindexed=a, notindexed=b, a)" {1 {no such column: b}}
  11 "(notindexed=a, notindexed=b, b)" {1 {no such column: a}}
} {
  do_catchsql_test 1.$tn "CREATE VIRTUAL TABLE t1 USING fts4 $arg" $res
  if {[lindex $res 0]==0} { execsql "DROP TABLE t1" }
}

do_execsql_test 1.x { SELECT name FROM sqlite_master } {cc}


#-------------------------------------------------------------------------
# Test that notindexed columns are not indexed.
#
foreach {tn schema} {
  1 { 
    CREATE VIRTUAL TABLE t1 USING fts4(a, b, c, notindexed=b); 
  }
  2 { 
    CREATE TABLE c1(a, b, c);
    INSERT INTO c1 VALUES('one two', 'three four', 'five six');
    INSERT INTO c1 VALUES('three four', 'five six', 'one two');
    CREATE VIRTUAL TABLE t1 USING fts4(content=c1, notindexed=b); 
  }
  3 { 
    CREATE VIRTUAL TABLE t1 USING fts4(content="", a, b, c, notindexed=b); 
  }
} {
  execsql $schema

  do_execsql_test 2.$tn.1 {
    INSERT INTO t1(docid,a,b,c) VALUES(1, 'one two', 'three four', 'five six');
    INSERT INTO t1(docid,a,b,c) VALUES(2, 'three four', 'five six', 'one two');
  }

  do_execsql_test 2.$tn.2 { SELECT docid FROM t1 WHERE t1 MATCH 'one' } {1 2}
  do_execsql_test 2.$tn.3 { SELECT docid FROM t1 WHERE t1 MATCH 'three' } {2}
  do_execsql_test 2.$tn.4 { SELECT docid FROM t1 WHERE t1 MATCH 'five' } {1}

  do_execsql_test 2.$tn.5 { INSERT INTO t1(t1) VALUES('optimize') }

  do_execsql_test 2.$tn.6 { SELECT docid FROM t1 WHERE t1 MATCH 'one' } {1 2}
  do_execsql_test 2.$tn.7 { SELECT docid FROM t1 WHERE t1 MATCH 'three' } {2}
  do_execsql_test 2.$tn.8 { SELECT docid FROM t1 WHERE t1 MATCH 'five' } {1}

  if {$tn!=3} {
    do_execsql_test 2.$tn.9 { INSERT INTO t1(t1) VALUES('rebuild') }
  
    do_execsql_test 2.$tn.10 { SELECT docid FROM t1 WHERE t1 MATCH 'one' } {1 2}
    do_execsql_test 2.$tn.11 { SELECT docid FROM t1 WHERE t1 MATCH 'three' } {2}
    do_execsql_test 2.$tn.12 { SELECT docid FROM t1 WHERE t1 MATCH 'five' } {1}
  
    do_execsql_test 2.$tn.13 { 
      SELECT a,b,c FROM t1 WHERE docid=1
    } {{one two} {three four} {five six}}
    do_execsql_test 2.$tn.14 { 
      SELECT a,b,c FROM t1 WHERE docid=2
    } {{three four} {five six} {one two}}
  }

  do_execsql_test 2.x { DROP TABLE t1 }
}

#-------------------------------------------------------------------------
# Test that notindexed columns are not scanned for deferred tokens.
#

do_execsql_test 3.1 {
  CREATE VIRTUAL TABLE t2 USING fts4(x, y, notindexed=x);
}
do_test 3.2 {
  set v [string repeat " 1" 50000]
  set v1 "x $v"
  set v2 "y $v"
  execsql { 
    INSERT INTO t2 VALUES(1, 'x y z');
    INSERT INTO t2 VALUES(2, $v1);
    INSERT INTO t2 VALUES(3, $v2);
    INSERT INTO t2 VALUES(4, $v2);
    INSERT INTO t2 VALUES(5, $v2);
    INSERT INTO t2 VALUES(6, $v2);
  }
} {}

do_execsql_test 3.3 { SELECT x FROM t2 WHERE t2 MATCH '2' } {}
do_execsql_test 3.4 { SELECT x FROM t2 WHERE t2 MATCH '1' } {2 3 4 5 6}
do_execsql_test 3.5 { SELECT x FROM t2 WHERE t2 MATCH 'x' } {1 2}
do_execsql_test 3.6 { SELECT x FROM t2 WHERE t2 MATCH 'x 1' } {2}

do_execsql_test 3.x { DROP TABLE t2 }
  
#-------------------------------------------------------------------------
# Test that the types of notindexed columns are not modified.
#
do_execsql_test 4.1 {
  CREATE VIRTUAL TABLE t2 USING fts4(poi, addr, notindexed=poi);
  INSERT INTO t2 VALUES(114, 'x x x');
  INSERT INTO t2 VALUES(X'1234', 'y y y');
  INSERT INTO t2 VALUES(NULL, 'z z z');
  INSERT INTO t2 VALUES(113.2, 'w w w');
  INSERT INTO t2 VALUES('poi', 'v v v');
}
do_execsql_test 4.2 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'x' } {integer}
do_execsql_test 4.3 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'y' } {blob}
do_execsql_test 4.4 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'z' } {null}
do_execsql_test 4.5 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'w' } {real}
do_execsql_test 4.6 { SELECT typeof(poi) FROM t2 WHERE t2 MATCH 'v' } {text}

do_execsql_test 4.x { DROP TABLE t2 }

#-------------------------------------------------------------------------
# Test that multiple notindexed options on a single table work as expected.
#
do_execsql_test 5.1 {
  CREATE VIRTUAL TABLE t2 USING fts4(
      notindexed="three", one, two, three, notindexed="one",
  );
  INSERT INTO t2 VALUES('a', 'b', 'c');
  INSERT INTO t2 VALUES('c', 'a', 'b');
  INSERT INTO t2 VALUES('b', 'c', 'a');
}
do_execsql_test 5.2 { SELECT docid FROM t2 WHERE t2 MATCH 'a' } {2}
do_execsql_test 5.3 { SELECT docid FROM t2 WHERE t2 MATCH 'b' } {1}
do_execsql_test 5.4 { SELECT docid FROM t2 WHERE t2 MATCH 'c' } {3}

do_execsql_test 5.x { DROP TABLE t2 }

finish_test



Changes to test/func4.test.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# This file implements regression tests for SQLite library. The
# focus of this file is testing the tointeger() and toreal()
# functions.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl

set i 0
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(NULL);
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('   ');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('1234');
} {1234}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('   1234');
} {1234}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('bad');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('0xBAD');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('123BAD');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('0x123BAD');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('123NO');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('0x123NO');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('-0x1');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('-0x0');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('0x0');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger('0x1');
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-1);
} {-1}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-0);
} {0}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(0);
} {0}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(1);
} {1}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-1.79769313486232e308 - 1);
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-1.79769313486232e308);
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-1.79769313486232e308 + 1);
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-9223372036854775808 - 1);
} {-9223372036854775808}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-9223372036854775808);
} {-9223372036854775808}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-9223372036854775808 + 1);
} {-9223372036854775807}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-2147483648 - 1);
} {-2147483649}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-2147483648);
} {-2147483648}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(-2147483648 + 1);
} {-2147483647}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(2147483647 - 1);
} {2147483646}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(2147483647);
} {2147483647}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(2147483647 + 1);
} {2147483648}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(9223372036854775807 - 1);
} {9223372036854775806}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(9223372036854775807);
} {9223372036854775807}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(9223372036854775807 + 1);
} {-9223372036854775808}

do_execsql_test func4-1.[incr i] {
  SELECT tointeger(1.79769313486232e308 - 1);
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(1.79769313486232e308);
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(1.79769313486232e308 + 1);
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(4503599627370496 - 1);
} {4503599627370495}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(4503599627370496);
} {4503599627370496}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(4503599627370496 + 1);
} {4503599627370497}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(9007199254740992 - 1);
} {9007199254740991}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(9007199254740992);
} {9007199254740992}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(9007199254740992 + 1);
} {9007199254740993}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(9223372036854775808 - 1);
} {-9223372036854775808}

do_execsql_test func4-1.[incr i] {
  SELECT tointeger(9223372036854775808);
} {-9223372036854775808}

do_execsql_test func4-1.[incr i] {
  SELECT tointeger(9223372036854775808 + 1);
} {-9223372036854775808}

do_execsql_test func4-1.[incr i] {
  SELECT tointeger(18446744073709551616 - 1);
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(18446744073709551616);
} {{}}
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(18446744073709551616 + 1);
} {{}}

ifcapable floatingpoint {
  set i 0
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(NULL);
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('   ');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('1234');
  } {1234.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('   1234');
  } {1234.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('bad');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0xBAD');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('123BAD');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0x123BAD');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('123NO');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0x123NO');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('-0x1');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('-0x0');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0x0');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0x1');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-1);
  } {-1.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-0);
  } {0.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(0);
  } {0.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(1);
  } {1.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-1.79769313486232e308 - 1);
  } {-Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-1.79769313486232e308);
  } {-Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-1.79769313486232e308 + 1);
  } {-Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-9223372036854775808 - 1);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-9223372036854775808);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-9223372036854775808 + 1);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-2147483648 - 1);
  } {-2147483649.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-2147483648);
  } {-2147483648.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-2147483648 + 1);
  } {-2147483647.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(2147483647 - 1);
  } {2147483646.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(2147483647);
  } {2147483647.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(2147483647 + 1);
  } {2147483648.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775807 - 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775807);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775807 + 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(1.79769313486232e308 - 1);
  } {Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(1.79769313486232e308);
  } {Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(1.79769313486232e308 + 1);
  } {Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(4503599627370496 - 1);
  } {4503599627370500.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(4503599627370496);
  } {4503599627370500.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(4503599627370496 + 1);
  } {4503599627370500.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9007199254740992 - 1);
  } {9007199254740990.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9007199254740992);
  } {9007199254740990.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9007199254740992 + 1);
  } {9007199254740990.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775808 - 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775808);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775808 + 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(18446744073709551616 - 1);
  } {1.84467440737096e+19}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(18446744073709551616);
  } {1.84467440737096e+19}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(18446744073709551616 + 1);
  } {1.84467440737096e+19}
}

ifcapable check {
  set i 0
  do_execsql_test func4-3.[incr i] {
    CREATE TABLE t1(
      x INTEGER CHECK(tointeger(x) IS NOT NULL AND x = CAST(x AS INTEGER))
    );
  } {}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES (NULL);
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES (NULL);
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES ('');
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES ('bad');
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES ('1234bad');
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES ('1234.56bad');
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES (1234);
    }
  } {0 {}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES (1234.56);
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES ('1234');
    }
  } {0 {}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES ('1234.56');
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES (ZEROBLOB(4));
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES (X'');
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES (X'1234');
    }
  } {1 {constraint failed}}
  do_test func4-3.[incr i] {
    catchsql {
      INSERT INTO t1 (x) VALUES (X'12345678');
    }
  } {1 {constraint failed}}
  do_execsql_test func4-3.[incr i] {
    SELECT x FROM t1 ORDER BY x;
  } {1234 1234}

  ifcapable floatingpoint {
    set i 0
    do_execsql_test func4-4.[incr i] {
      CREATE TABLE t2(
        x REAL CHECK(toreal(x) IS NOT NULL)
      );
    } {}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (NULL);
      }
    } {1 {constraint failed}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (NULL);
      }
    } {1 {constraint failed}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES ('');
      }
    } {1 {constraint failed}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES ('bad');
      }
    } {1 {constraint failed}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES ('1234bad');
      }
    } {1 {constraint failed}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES ('1234.56bad');
      }
    } {1 {constraint failed}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (1234);
      }
    } {0 {}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (1234.56);
      }
    } {0 {}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES ('1234');
      }
    } {0 {}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES ('1234.56');
      }
    } {0 {}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (ZEROBLOB(4));
      }
    } {1 {constraint failed}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (X'');
      }
    } {1 {constraint failed}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (X'1234');
      }
    } {1 {constraint failed}}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (X'12345678');
      }
    } {1 {constraint failed}}
    do_execsql_test func4-4.[incr i] {
      SELECT x FROM t2 ORDER BY x;
    } {1234.0 1234.0 1234.56 1234.56}
  }
}

finish_test







<
|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|

<
>
|


|


|


|


|


|


|


|


|


|

<
>
|

<
>
|

<
>
|


|


|





|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|






|




|




|




|




|




|




|




|




|




|




|




|




|




|




|




|





|




|




|




|




|




|




|




|




|




|




|




|




|




|




|




|






11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# This file implements regression tests for SQLite library. The
# focus of this file is testing the tointeger() and toreal()
# functions.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl


do_execsql_test func4-1.1 {
  SELECT tointeger(NULL);
} {{}}
do_execsql_test func4-1.2 {
  SELECT tointeger('');
} {{}}
do_execsql_test func4-1.3 {
  SELECT tointeger('   ');
} {{}}
do_execsql_test func4-1.4 {
  SELECT tointeger('1234');
} {1234}
do_execsql_test func4-1.5 {
  SELECT tointeger('   1234');
} {1234}
do_execsql_test func4-1.6 {
  SELECT tointeger('bad');
} {{}}
do_execsql_test func4-1.7 {
  SELECT tointeger('0xBAD');
} {{}}
do_execsql_test func4-1.8 {
  SELECT tointeger('123BAD');
} {{}}
do_execsql_test func4-1.9 {
  SELECT tointeger('0x123BAD');
} {{}}
do_execsql_test func4-1.10 {
  SELECT tointeger('123NO');
} {{}}
do_execsql_test func4-1.11 {
  SELECT tointeger('0x123NO');
} {{}}
do_execsql_test func4-1.12 {
  SELECT tointeger('-0x1');
} {{}}
do_execsql_test func4-1.13 {
  SELECT tointeger('-0x0');
} {{}}
do_execsql_test func4-1.14 {
  SELECT tointeger('0x0');
} {{}}
do_execsql_test func4-1.15 {
  SELECT tointeger('0x1');
} {{}}
do_execsql_test func4-1.16 {
  SELECT tointeger(-1);
} {-1}
do_execsql_test func4-1.17 {
  SELECT tointeger(-0);
} {0}
do_execsql_test func4-1.18 {
  SELECT tointeger(0);
} {0}
do_execsql_test func4-1.19 {
  SELECT tointeger(1);
} {1}
do_execsql_test func4-1.20 {
  SELECT tointeger(-1.79769313486232e308 - 1);
} {{}}
do_execsql_test func4-1.21 {
  SELECT tointeger(-1.79769313486232e308);
} {{}}
do_execsql_test func4-1.22 {
  SELECT tointeger(-1.79769313486232e308 + 1);
} {{}}
do_execsql_test func4-1.23 {
  SELECT tointeger(-9223372036854775808 - 1);
} {-9223372036854775808}
do_execsql_test func4-1.24 {
  SELECT tointeger(-9223372036854775808);
} {-9223372036854775808}
do_execsql_test func4-1.25 {
  SELECT tointeger(-9223372036854775808 + 1);
} {-9223372036854775807}
do_execsql_test func4-1.26 {
  SELECT tointeger(-2147483648 - 1);
} {-2147483649}
do_execsql_test func4-1.27 {
  SELECT tointeger(-2147483648);
} {-2147483648}
do_execsql_test func4-1.28 {
  SELECT tointeger(-2147483648 + 1);
} {-2147483647}
do_execsql_test func4-1.29 {
  SELECT tointeger(2147483647 - 1);
} {2147483646}
do_execsql_test func4-1.30 {
  SELECT tointeger(2147483647);
} {2147483647}
do_execsql_test func4-1.31 {
  SELECT tointeger(2147483647 + 1);
} {2147483648}
do_execsql_test func4-1.32 {
  SELECT tointeger(9223372036854775807 - 1);
} {9223372036854775806}
do_execsql_test func4-1.33 {
  SELECT tointeger(9223372036854775807);
} {9223372036854775807}
do_execsql_test func4-1.34 {
  SELECT tointeger(9223372036854775807 + 1);

} {{}}
do_execsql_test func4-1.35 {
  SELECT tointeger(1.79769313486232e308 - 1);
} {{}}
do_execsql_test func4-1.36 {
  SELECT tointeger(1.79769313486232e308);
} {{}}
do_execsql_test func4-1.37 {
  SELECT tointeger(1.79769313486232e308 + 1);
} {{}}
do_execsql_test func4-1.38 {
  SELECT tointeger(4503599627370496 - 1);
} {4503599627370495}
do_execsql_test func4-1.39 {
  SELECT tointeger(4503599627370496);
} {4503599627370496}
do_execsql_test func4-1.40 {
  SELECT tointeger(4503599627370496 + 1);
} {4503599627370497}
do_execsql_test func4-1.41 {
  SELECT tointeger(9007199254740992 - 1);
} {9007199254740991}
do_execsql_test func4-1.42 {
  SELECT tointeger(9007199254740992);
} {9007199254740992}
do_execsql_test func4-1.43 {
  SELECT tointeger(9007199254740992 + 1);
} {9007199254740993}
do_execsql_test func4-1.44 {
  SELECT tointeger(9223372036854775808 - 1);

} {{}}
do_execsql_test func4-1.45 {
  SELECT tointeger(9223372036854775808);

} {{}}
do_execsql_test func4-1.46 {
  SELECT tointeger(9223372036854775808 + 1);

} {{}}
do_execsql_test func4-1.47 {
  SELECT tointeger(18446744073709551616 - 1);
} {{}}
do_execsql_test func4-1.48 {
  SELECT tointeger(18446744073709551616);
} {{}}
do_execsql_test func4-1.49 {
  SELECT tointeger(18446744073709551616 + 1);
} {{}}

ifcapable floatingpoint {
  set i 0
  do_execsql_test func4-2.1 {
    SELECT toreal(NULL);
  } {{}}
  do_execsql_test func4-2.2 {
    SELECT toreal('');
  } {{}}
  do_execsql_test func4-2.3 {
    SELECT toreal('   ');
  } {{}}
  do_execsql_test func4-2.4 {
    SELECT toreal('1234');
  } {1234.0}
  do_execsql_test func4-2.5 {
    SELECT toreal('   1234');
  } {1234.0}
  do_execsql_test func4-2.6 {
    SELECT toreal('bad');
  } {{}}
  do_execsql_test func4-2.7 {
    SELECT toreal('0xBAD');
  } {{}}
  do_execsql_test func4-2.8 {
    SELECT toreal('123BAD');
  } {{}}
  do_execsql_test func4-2.9 {
    SELECT toreal('0x123BAD');
  } {{}}
  do_execsql_test func4-2.10 {
    SELECT toreal('123NO');
  } {{}}
  do_execsql_test func4-2.11 {
    SELECT toreal('0x123NO');
  } {{}}
  do_execsql_test func4-2.12 {
    SELECT toreal('-0x1');
  } {{}}
  do_execsql_test func4-2.13 {
    SELECT toreal('-0x0');
  } {{}}
  do_execsql_test func4-2.14 {
    SELECT toreal('0x0');
  } {{}}
  do_execsql_test func4-2.15 {
    SELECT toreal('0x1');
  } {{}}
  do_execsql_test func4-2.16 {
    SELECT toreal(-1);
  } {-1.0}
  do_execsql_test func4-2.17 {
    SELECT toreal(-0);
  } {0.0}
  do_execsql_test func4-2.18 {
    SELECT toreal(0);
  } {0.0}
  do_execsql_test func4-2.19 {
    SELECT toreal(1);
  } {1.0}
  do_execsql_test func4-2.20 {
    SELECT toreal(-1.79769313486232e308 - 1);
  } {-Inf}
  do_execsql_test func4-2.21 {
    SELECT toreal(-1.79769313486232e308);
  } {-Inf}
  do_execsql_test func4-2.22 {
    SELECT toreal(-1.79769313486232e308 + 1);
  } {-Inf}
  do_execsql_test func4-2.23 {
    SELECT toreal(-9223372036854775808 - 1);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.24 {
    SELECT toreal(-9223372036854775808);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.25 {
    SELECT toreal(-9223372036854775808 + 1);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.26 {
    SELECT toreal(-2147483648 - 1);
  } {-2147483649.0}
  do_execsql_test func4-2.27 {
    SELECT toreal(-2147483648);
  } {-2147483648.0}
  do_execsql_test func4-2.28 {
    SELECT toreal(-2147483648 + 1);
  } {-2147483647.0}
  do_execsql_test func4-2.29 {
    SELECT toreal(2147483647 - 1);
  } {2147483646.0}
  do_execsql_test func4-2.30 {
    SELECT toreal(2147483647);
  } {2147483647.0}
  do_execsql_test func4-2.31 {
    SELECT toreal(2147483647 + 1);
  } {2147483648.0}
  do_execsql_test func4-2.32 {
    SELECT toreal(9223372036854775807 - 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.33 {
    SELECT toreal(9223372036854775807);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.34 {
    SELECT toreal(9223372036854775807 + 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.35 {
    SELECT toreal(1.79769313486232e308 - 1);
  } {Inf}
  do_execsql_test func4-2.36 {
    SELECT toreal(1.79769313486232e308);
  } {Inf}
  do_execsql_test func4-2.37 {
    SELECT toreal(1.79769313486232e308 + 1);
  } {Inf}
  do_execsql_test func4-2.38 {
    SELECT toreal(4503599627370496 - 1);
  } {4503599627370500.0}
  do_execsql_test func4-2.39 {
    SELECT toreal(4503599627370496);
  } {4503599627370500.0}
  do_execsql_test func4-2.40 {
    SELECT toreal(4503599627370496 + 1);
  } {4503599627370500.0}
  do_execsql_test func4-2.41 {
    SELECT toreal(9007199254740992 - 1);
  } {9007199254740990.0}
  do_execsql_test func4-2.42 {
    SELECT toreal(9007199254740992);
  } {9007199254740990.0}
  do_execsql_test func4-2.43 {
    SELECT toreal(9007199254740992 + 1);
  } {9007199254740990.0}
  do_execsql_test func4-2.44 {
    SELECT toreal(9223372036854775808 - 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.45 {
    SELECT toreal(9223372036854775808);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.46 {
    SELECT toreal(9223372036854775808 + 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.47 {
    SELECT toreal(18446744073709551616 - 1);
  } {1.84467440737096e+19}
  do_execsql_test func4-2.48 {
    SELECT toreal(18446744073709551616);
  } {1.84467440737096e+19}
  do_execsql_test func4-2.49 {
    SELECT toreal(18446744073709551616 + 1);
  } {1.84467440737096e+19}
}

ifcapable check {
  set i 0
  do_execsql_test func4-3.1 {
    CREATE TABLE t1(
      x INTEGER CHECK(tointeger(x) IS NOT NULL AND x = CAST(x AS INTEGER))
    );
  } {}
  do_test func4-3.2 {
    catchsql {
      INSERT INTO t1 (x) VALUES (NULL);
    }
  } {1 {constraint failed}}
  do_test func4-3.3 {
    catchsql {
      INSERT INTO t1 (x) VALUES (NULL);
    }
  } {1 {constraint failed}}
  do_test func4-3.4 {
    catchsql {
      INSERT INTO t1 (x) VALUES ('');
    }
  } {1 {constraint failed}}
  do_test func4-3.5 {
    catchsql {
      INSERT INTO t1 (x) VALUES ('bad');
    }
  } {1 {constraint failed}}
  do_test func4-3.6 {
    catchsql {
      INSERT INTO t1 (x) VALUES ('1234bad');
    }
  } {1 {constraint failed}}
  do_test func4-3.7 {
    catchsql {
      INSERT INTO t1 (x) VALUES ('1234.56bad');
    }
  } {1 {constraint failed}}
  do_test func4-3.8 {
    catchsql {
      INSERT INTO t1 (x) VALUES (1234);
    }
  } {0 {}}
  do_test func4-3.9 {
    catchsql {
      INSERT INTO t1 (x) VALUES (1234.56);
    }
  } {1 {constraint failed}}
  do_test func4-3.10 {
    catchsql {
      INSERT INTO t1 (x) VALUES ('1234');
    }
  } {0 {}}
  do_test func4-3.11 {
    catchsql {
      INSERT INTO t1 (x) VALUES ('1234.56');
    }
  } {1 {constraint failed}}
  do_test func4-3.12 {
    catchsql {
      INSERT INTO t1 (x) VALUES (ZEROBLOB(4));
    }
  } {1 {constraint failed}}
  do_test func4-3.13 {
    catchsql {
      INSERT INTO t1 (x) VALUES (X'');
    }
  } {1 {constraint failed}}
  do_test func4-3.14 {
    catchsql {
      INSERT INTO t1 (x) VALUES (X'1234');
    }
  } {1 {constraint failed}}
  do_test func4-3.15 {
    catchsql {
      INSERT INTO t1 (x) VALUES (X'12345678');
    }
  } {1 {constraint failed}}
  do_execsql_test func4-3.16 {
    SELECT x FROM t1 ORDER BY x;
  } {1234 1234}

  ifcapable floatingpoint {
    set i 0
    do_execsql_test func4-4.1 {
      CREATE TABLE t2(
        x REAL CHECK(toreal(x) IS NOT NULL)
      );
    } {}
    do_test func4-4.2 {
      catchsql {
        INSERT INTO t2 (x) VALUES (NULL);
      }
    } {1 {constraint failed}}
    do_test func4-4.3 {
      catchsql {
        INSERT INTO t2 (x) VALUES (NULL);
      }
    } {1 {constraint failed}}
    do_test func4-4.4 {
      catchsql {
        INSERT INTO t2 (x) VALUES ('');
      }
    } {1 {constraint failed}}
    do_test func4-4.5 {
      catchsql {
        INSERT INTO t2 (x) VALUES ('bad');
      }
    } {1 {constraint failed}}
    do_test func4-4.6 {
      catchsql {
        INSERT INTO t2 (x) VALUES ('1234bad');
      }
    } {1 {constraint failed}}
    do_test func4-4.7 {
      catchsql {
        INSERT INTO t2 (x) VALUES ('1234.56bad');
      }
    } {1 {constraint failed}}
    do_test func4-4.8 {
      catchsql {
        INSERT INTO t2 (x) VALUES (1234);
      }
    } {0 {}}
    do_test func4-4.9 {
      catchsql {
        INSERT INTO t2 (x) VALUES (1234.56);
      }
    } {0 {}}
    do_test func4-4.10 {
      catchsql {
        INSERT INTO t2 (x) VALUES ('1234');
      }
    } {0 {}}
    do_test func4-4.11 {
      catchsql {
        INSERT INTO t2 (x) VALUES ('1234.56');
      }
    } {0 {}}
    do_test func4-4.12 {
      catchsql {
        INSERT INTO t2 (x) VALUES (ZEROBLOB(4));
      }
    } {1 {constraint failed}}
    do_test func4-4.13 {
      catchsql {
        INSERT INTO t2 (x) VALUES (X'');
      }
    } {1 {constraint failed}}
    do_test func4-4.14 {
      catchsql {
        INSERT INTO t2 (x) VALUES (X'1234');
      }
    } {1 {constraint failed}}
    do_test func4-4.15 {
      catchsql {
        INSERT INTO t2 (x) VALUES (X'12345678');
      }
    } {1 {constraint failed}}
    do_execsql_test func4-4.16 {
      SELECT x FROM t2 ORDER BY x;
    } {1234.0 1234.0 1234.56 1234.56}
  }
}

finish_test

Changes to test/permutations.test.

190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  fts3near.test fts3query.test fts3shared.test fts3snippet.test 
  fts3sort.test
  fts3fault.test fts3malloc.test fts3matchinfo.test
  fts3aux1.test fts3comp1.test fts3auto.test
  fts4aa.test fts4content.test
  fts3conf.test fts3prefix.test fts3fault2.test fts3corrupt.test
  fts3corrupt2.test fts3first.test fts4langid.test fts4merge.test
  fts4check.test fts4unicode.test
}

test_suite "nofaultsim" -prefix "" -description {
  "Very" quick test suite. Runs in less than 5 minutes on a workstation. 
  This test suite is the same as the "quick" tests, except that some files
  that test malloc and IO errors are omitted.
} -files [







|







190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  fts3near.test fts3query.test fts3shared.test fts3snippet.test 
  fts3sort.test
  fts3fault.test fts3malloc.test fts3matchinfo.test
  fts3aux1.test fts3comp1.test fts3auto.test
  fts4aa.test fts4content.test
  fts3conf.test fts3prefix.test fts3fault2.test fts3corrupt.test
  fts3corrupt2.test fts3first.test fts4langid.test fts4merge.test
  fts4check.test fts4unicode.test fts4noti.test
}

test_suite "nofaultsim" -prefix "" -description {
  "Very" quick test suite. Runs in less than 5 minutes on a workstation. 
  This test suite is the same as the "quick" tests, except that some files
  that test malloc and IO errors are omitted.
} -files [