/ Check-in [167644f3]
Login

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

Overview
Comment:Set the "type" correctly of built-in BINARY collating sequences for UTF16.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 167644f33c949b532655c2297aedf13f93876396
User & Date: drh 2009-08-20 02:49:31
Context
2009-08-20
13:45
Incremental code and comment cleanup in where.c. There is more to be done. check-in: 4a5d9550 user: drh tags: trunk
02:49
Set the "type" correctly of built-in BINARY collating sequences for UTF16. check-in: 167644f3 user: drh tags: trunk
02:34
All the sqlite3GetCollSeq() function to specify an arbitrary text encoding. check-in: 4ee44322 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

  1353   1353   }
  1354   1354   
  1355   1355   /*
  1356   1356   ** Create a new collating function for database "db".  The name is zName
  1357   1357   ** and the encoding is enc.
  1358   1358   */
  1359   1359   static int createCollation(
  1360         -  sqlite3* db, 
         1360  +  sqlite3* db,
  1361   1361     const char *zName, 
  1362         -  int enc, 
         1362  +  int enc,
         1363  +  int collType,
  1363   1364     void* pCtx,
  1364   1365     int(*xCompare)(void*,int,const void*,int,const void*),
  1365   1366     void(*xDel)(void*)
  1366   1367   ){
  1367   1368     CollSeq *pColl;
  1368   1369     int enc2;
  1369   1370     int nName = sqlite3Strlen30(zName);
................................................................................
  1420   1421   
  1421   1422     pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
  1422   1423     if( pColl ){
  1423   1424       pColl->xCmp = xCompare;
  1424   1425       pColl->pUser = pCtx;
  1425   1426       pColl->xDel = xDel;
  1426   1427       pColl->enc = (u8)(enc2 | (enc & SQLITE_UTF16_ALIGNED));
         1428  +    pColl->type = collType;
  1427   1429     }
  1428   1430     sqlite3Error(db, SQLITE_OK, 0);
  1429   1431     return SQLITE_OK;
  1430   1432   }
  1431   1433   
  1432   1434   
  1433   1435   /*
................................................................................
  1517   1519     const char *zFilename, /* Database filename UTF-8 encoded */
  1518   1520     sqlite3 **ppDb,        /* OUT: Returned database handle */
  1519   1521     unsigned flags,        /* Operational flags */
  1520   1522     const char *zVfs       /* Name of the VFS to use */
  1521   1523   ){
  1522   1524     sqlite3 *db;
  1523   1525     int rc;
  1524         -  CollSeq *pColl;
  1525   1526     int isThreadsafe;
  1526   1527   
  1527   1528     *ppDb = 0;
  1528   1529   #ifndef SQLITE_OMIT_AUTOINIT
  1529   1530     rc = sqlite3_initialize();
  1530   1531     if( rc ) return rc;
  1531   1532   #endif
................................................................................
  1603   1604       goto opendb_out;
  1604   1605     }
  1605   1606   
  1606   1607     /* Add the default collation sequence BINARY. BINARY works for both UTF-8
  1607   1608     ** and UTF-16, so add a version for each to avoid any unnecessary
  1608   1609     ** conversions. The only error that can occur here is a malloc() failure.
  1609   1610     */
  1610         -  createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
  1611         -  createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
  1612         -  createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
  1613         -  createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
         1611  +  createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0,
         1612  +                  binCollFunc, 0);
         1613  +  createCollation(db, "BINARY", SQLITE_UTF16BE, SQLITE_COLL_BINARY, 0,
         1614  +                  binCollFunc, 0);
         1615  +  createCollation(db, "BINARY", SQLITE_UTF16LE, SQLITE_COLL_BINARY, 0,
         1616  +                  binCollFunc, 0);
         1617  +  createCollation(db, "RTRIM", SQLITE_UTF8, SQLITE_COLL_USER, (void*)1,
         1618  +                  binCollFunc, 0);
  1614   1619     if( db->mallocFailed ){
  1615   1620       goto opendb_out;
  1616   1621     }
  1617   1622     db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
  1618   1623     assert( db->pDfltColl!=0 );
  1619   1624   
  1620   1625     /* Also add a UTF-8 case-insensitive collation sequence. */
  1621         -  createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
  1622         -
  1623         -  /* Set flags on the built-in collating sequences */
  1624         -  db->pDfltColl->type = SQLITE_COLL_BINARY;
  1625         -  pColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "NOCASE", 0);
  1626         -  if( pColl ){
  1627         -    pColl->type = SQLITE_COLL_NOCASE;
  1628         -  }
         1626  +  createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
         1627  +                  nocaseCollatingFunc, 0);
  1629   1628   
  1630   1629     /* Open the backend database driver */
  1631   1630     db->openFlags = flags;
  1632   1631     rc = sqlite3BtreeFactory(db, zFilename, 0, SQLITE_DEFAULT_CACHE_SIZE, 
  1633   1632                              flags | SQLITE_OPEN_MAIN_DB,
  1634   1633                              &db->aDb[0].pBt);
  1635   1634     if( rc!=SQLITE_OK ){
................................................................................
  1802   1801     int enc, 
  1803   1802     void* pCtx,
  1804   1803     int(*xCompare)(void*,int,const void*,int,const void*)
  1805   1804   ){
  1806   1805     int rc;
  1807   1806     sqlite3_mutex_enter(db->mutex);
  1808   1807     assert( !db->mallocFailed );
  1809         -  rc = createCollation(db, zName, enc, pCtx, xCompare, 0);
         1808  +  rc = createCollation(db, zName, enc, SQLITE_COLL_USER, pCtx, xCompare, 0);
  1810   1809     rc = sqlite3ApiExit(db, rc);
  1811   1810     sqlite3_mutex_leave(db->mutex);
  1812   1811     return rc;
  1813   1812   }
  1814   1813   
  1815   1814   /*
  1816   1815   ** Register a new collation sequence with the database handle db.
................................................................................
  1822   1821     void* pCtx,
  1823   1822     int(*xCompare)(void*,int,const void*,int,const void*),
  1824   1823     void(*xDel)(void*)
  1825   1824   ){
  1826   1825     int rc;
  1827   1826     sqlite3_mutex_enter(db->mutex);
  1828   1827     assert( !db->mallocFailed );
  1829         -  rc = createCollation(db, zName, enc, pCtx, xCompare, xDel);
         1828  +  rc = createCollation(db, zName, enc, SQLITE_COLL_USER, pCtx, xCompare, xDel);
  1830   1829     rc = sqlite3ApiExit(db, rc);
  1831   1830     sqlite3_mutex_leave(db->mutex);
  1832   1831     return rc;
  1833   1832   }
  1834   1833   
  1835   1834   #ifndef SQLITE_OMIT_UTF16
  1836   1835   /*
................................................................................
  1845   1844   ){
  1846   1845     int rc = SQLITE_OK;
  1847   1846     char *zName8;
  1848   1847     sqlite3_mutex_enter(db->mutex);
  1849   1848     assert( !db->mallocFailed );
  1850   1849     zName8 = sqlite3Utf16to8(db, zName, -1);
  1851   1850     if( zName8 ){
  1852         -    rc = createCollation(db, zName8, enc, pCtx, xCompare, 0);
         1851  +    rc = createCollation(db, zName8, enc, SQLITE_COLL_USER, pCtx, xCompare, 0);
  1853   1852       sqlite3DbFree(db, zName8);
  1854   1853     }
  1855   1854     rc = sqlite3ApiExit(db, rc);
  1856   1855     sqlite3_mutex_leave(db->mutex);
  1857   1856     return rc;
  1858   1857   }
  1859   1858   #endif /* SQLITE_OMIT_UTF16 */