/ Check-in [9ff80a9b]
Login

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

Overview
Comment:Move the sqlite3LocateCollSeq(), sqlite3FindCollSeq(), and sqlite3GetCollSeq() routines so that they are all beside one another in the callback.c source file. No logic changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9ff80a9bf8fee776e2f282d0597215b77d48093ebc71d047ad1457da0582ddbc
User & Date: drh 2019-10-22 01:00:16
Context
2019-10-22
11:29
Previous check-in to fix [b47e3627ecaadbde] was incomplete. This check-in completes the fix and adds a test cases. check-in: c7da1c01 user: drh tags: trunk
01:00
Move the sqlite3LocateCollSeq(), sqlite3FindCollSeq(), and sqlite3GetCollSeq() routines so that they are all beside one another in the callback.c source file. No logic changes. check-in: 9ff80a9b user: drh tags: trunk
00:03
When flipping ("commuting") a comparison operator, set the new EP_Commuted bit rather than adding extra EP_Collate bits, to single later processing that the order of precedence for COLLATE operators is inverted. Fix for ticket [b47e3627ecaadbde] check-in: 90f7c477 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  1515   1515           pIdx->azColl[0] = p->aCol[i].zColl;
  1516   1516         }
  1517   1517       }
  1518   1518     }else{
  1519   1519       sqlite3DbFree(db, zColl);
  1520   1520     }
  1521   1521   }
  1522         -
  1523         -/*
  1524         -** This function returns the collation sequence for database native text
  1525         -** encoding identified by the string zName, length nName.
  1526         -**
  1527         -** If the requested collation sequence is not available, or not available
  1528         -** in the database native encoding, the collation factory is invoked to
  1529         -** request it. If the collation factory does not supply such a sequence,
  1530         -** and the sequence is available in another text encoding, then that is
  1531         -** returned instead.
  1532         -**
  1533         -** If no versions of the requested collations sequence are available, or
  1534         -** another error occurs, NULL is returned and an error message written into
  1535         -** pParse.
  1536         -**
  1537         -** This routine is a wrapper around sqlite3FindCollSeq().  This routine
  1538         -** invokes the collation factory if the named collation cannot be found
  1539         -** and generates an error message.
  1540         -**
  1541         -** See also: sqlite3FindCollSeq(), sqlite3GetCollSeq()
  1542         -*/
  1543         -CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName){
  1544         -  sqlite3 *db = pParse->db;
  1545         -  u8 enc = ENC(db);
  1546         -  u8 initbusy = db->init.busy;
  1547         -  CollSeq *pColl;
  1548         -
  1549         -  pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);
  1550         -  if( !initbusy && (!pColl || !pColl->xCmp) ){
  1551         -    pColl = sqlite3GetCollSeq(pParse, enc, pColl, zName);
  1552         -  }
  1553         -
  1554         -  return pColl;
  1555         -}
  1556         -
  1557   1522   
  1558   1523   /*
  1559   1524   ** Generate code that will increment the schema cookie.
  1560   1525   **
  1561   1526   ** The schema cookie is used to determine when the schema for the
  1562   1527   ** database changes.  After each schema change, the cookie value
  1563   1528   ** changes.  When a process first reads the schema it records the

Changes to src/callback.c.

    61     61         pColl->xDel = 0;         /* Do not copy the destructor */
    62     62         return SQLITE_OK;
    63     63       }
    64     64     }
    65     65     return SQLITE_ERROR;
    66     66   }
    67     67   
    68         -/*
    69         -** This function is responsible for invoking the collation factory callback
    70         -** or substituting a collation sequence of a different encoding when the
    71         -** requested collation sequence is not available in the desired encoding.
    72         -** 
    73         -** If it is not NULL, then pColl must point to the database native encoding 
    74         -** collation sequence with name zName, length nName.
    75         -**
    76         -** The return value is either the collation sequence to be used in database
    77         -** db for collation type name zName, length nName, or NULL, if no collation
    78         -** sequence can be found.  If no collation is found, leave an error message.
    79         -**
    80         -** See also: sqlite3LocateCollSeq(), sqlite3FindCollSeq()
    81         -*/
    82         -CollSeq *sqlite3GetCollSeq(
    83         -  Parse *pParse,        /* Parsing context */
    84         -  u8 enc,               /* The desired encoding for the collating sequence */
    85         -  CollSeq *pColl,       /* Collating sequence with native encoding, or NULL */
    86         -  const char *zName     /* Collating sequence name */
    87         -){
    88         -  CollSeq *p;
    89         -  sqlite3 *db = pParse->db;
    90         -
    91         -  p = pColl;
    92         -  if( !p ){
    93         -    p = sqlite3FindCollSeq(db, enc, zName, 0);
    94         -  }
    95         -  if( !p || !p->xCmp ){
    96         -    /* No collation sequence of this type for this encoding is registered.
    97         -    ** Call the collation factory to see if it can supply us with one.
    98         -    */
    99         -    callCollNeeded(db, enc, zName);
   100         -    p = sqlite3FindCollSeq(db, enc, zName, 0);
   101         -  }
   102         -  if( p && !p->xCmp && synthCollSeq(db, p) ){
   103         -    p = 0;
   104         -  }
   105         -  assert( !p || p->xCmp );
   106         -  if( p==0 ){
   107         -    sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName);
   108         -    pParse->rc = SQLITE_ERROR_MISSING_COLLSEQ;
   109         -  }
   110         -  return p;
   111         -}
   112         -
   113     68   /*
   114     69   ** This routine is called on a collation sequence before it is used to
   115     70   ** check that it is defined. An undefined collation sequence exists when
   116     71   ** a database is loaded that contains references to collation sequences
   117     72   ** that have not been defined by sqlite3_create_collation() etc.
   118     73   **
   119     74   ** If required, this routine calls the 'collation needed' callback to
................................................................................
   198    153   ** this routine.  sqlite3LocateCollSeq() invokes the collation factory
   199    154   ** if necessary and generates an error message if the collating sequence
   200    155   ** cannot be found.
   201    156   **
   202    157   ** See also: sqlite3LocateCollSeq(), sqlite3GetCollSeq()
   203    158   */
   204    159   CollSeq *sqlite3FindCollSeq(
   205         -  sqlite3 *db,
   206         -  u8 enc,
   207         -  const char *zName,
   208         -  int create
          160  +  sqlite3 *db,          /* Database connection to search */
          161  +  u8 enc,               /* Desired text encoding */
          162  +  const char *zName,    /* Name of the collating sequence.  Might be NULL */
          163  +  int create            /* True to create CollSeq if doesn't already exist */
   209    164   ){
   210    165     CollSeq *pColl;
   211    166     if( zName ){
   212    167       pColl = findCollSeqEntry(db, zName, create);
   213    168     }else{
   214    169       pColl = db->pDfltColl;
   215    170     }
   216    171     assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
   217    172     assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
   218    173     if( pColl ) pColl += enc-1;
          174  +  return pColl;
          175  +}
          176  +
          177  +/*
          178  +** This function is responsible for invoking the collation factory callback
          179  +** or substituting a collation sequence of a different encoding when the
          180  +** requested collation sequence is not available in the desired encoding.
          181  +** 
          182  +** If it is not NULL, then pColl must point to the database native encoding 
          183  +** collation sequence with name zName, length nName.
          184  +**
          185  +** The return value is either the collation sequence to be used in database
          186  +** db for collation type name zName, length nName, or NULL, if no collation
          187  +** sequence can be found.  If no collation is found, leave an error message.
          188  +**
          189  +** See also: sqlite3LocateCollSeq(), sqlite3FindCollSeq()
          190  +*/
          191  +CollSeq *sqlite3GetCollSeq(
          192  +  Parse *pParse,        /* Parsing context */
          193  +  u8 enc,               /* The desired encoding for the collating sequence */
          194  +  CollSeq *pColl,       /* Collating sequence with native encoding, or NULL */
          195  +  const char *zName     /* Collating sequence name */
          196  +){
          197  +  CollSeq *p;
          198  +  sqlite3 *db = pParse->db;
          199  +
          200  +  p = pColl;
          201  +  if( !p ){
          202  +    p = sqlite3FindCollSeq(db, enc, zName, 0);
          203  +  }
          204  +  if( !p || !p->xCmp ){
          205  +    /* No collation sequence of this type for this encoding is registered.
          206  +    ** Call the collation factory to see if it can supply us with one.
          207  +    */
          208  +    callCollNeeded(db, enc, zName);
          209  +    p = sqlite3FindCollSeq(db, enc, zName, 0);
          210  +  }
          211  +  if( p && !p->xCmp && synthCollSeq(db, p) ){
          212  +    p = 0;
          213  +  }
          214  +  assert( !p || p->xCmp );
          215  +  if( p==0 ){
          216  +    sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName);
          217  +    pParse->rc = SQLITE_ERROR_MISSING_COLLSEQ;
          218  +  }
          219  +  return p;
          220  +}
          221  +
          222  +/*
          223  +** This function returns the collation sequence for database native text
          224  +** encoding identified by the string zName.
          225  +**
          226  +** If the requested collation sequence is not available, or not available
          227  +** in the database native encoding, the collation factory is invoked to
          228  +** request it. If the collation factory does not supply such a sequence,
          229  +** and the sequence is available in another text encoding, then that is
          230  +** returned instead.
          231  +**
          232  +** If no versions of the requested collations sequence are available, or
          233  +** another error occurs, NULL is returned and an error message written into
          234  +** pParse.
          235  +**
          236  +** This routine is a wrapper around sqlite3FindCollSeq().  This routine
          237  +** invokes the collation factory if the named collation cannot be found
          238  +** and generates an error message.
          239  +**
          240  +** See also: sqlite3FindCollSeq(), sqlite3GetCollSeq()
          241  +*/
          242  +CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName){
          243  +  sqlite3 *db = pParse->db;
          244  +  u8 enc = ENC(db);
          245  +  u8 initbusy = db->init.busy;
          246  +  CollSeq *pColl;
          247  +
          248  +  pColl = sqlite3FindCollSeq(db, enc, zName, initbusy);
          249  +  if( !initbusy && (!pColl || !pColl->xCmp) ){
          250  +    pColl = sqlite3GetCollSeq(pParse, enc, pColl, zName);
          251  +  }
          252  +
   219    253     return pColl;
   220    254   }
   221    255   
   222    256   /* During the search for the best function definition, this procedure
   223    257   ** is called to test how well the function passed as the first argument
   224    258   ** matches the request for a function with nArg arguments in a system
   225    259   ** that uses encoding enc. The value returned indicates how well the