Merge latest trunk changes with this branch.

FossilOrigin-Name: 47dd65a890955f333d431e275f3f4d95d34a5ba5
This commit is contained in:
dan 2013-05-15 15:42:14 +00:00
commit 91cf9ba339
5 changed files with 219 additions and 20 deletions

114
ext/misc/rot13.c Normal file
View File

@ -0,0 +1,114 @@
/*
** 2013-05-15
**
** 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 SQLite extension implements a rot13() function and a rot13
** collating sequence.
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
#include <assert.h>
#include <string.h>
/*
** Perform rot13 encoding on a single ASCII character.
*/
static unsigned char rot13(unsigned char c){
if( c>='a' && c<='z' ){
c += 13;
if( c>'z' ) c -= 26;
}else if( c>='A' && c<='Z' ){
c += 13;
if( c>'Z' ) c -= 26;
}
return c;
}
/*
** Implementation of the rot13() function.
**
** Rotate ASCII alphabetic characters by 13 character positions.
** Non-ASCII characters are unchanged. rot13(rot13(X)) should always
** equal X.
*/
static void rot13func(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
const unsigned char *zIn;
int nIn;
unsigned char *zOut;
char *zToFree = 0;
int i;
char zTemp[100];
assert( argc==1 );
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
zIn = (const unsigned char*)sqlite3_value_text(argv[0]);
nIn = sqlite3_value_bytes(argv[0]);
if( nIn<sizeof(zTemp)-1 ){
zOut = zTemp;
}else{
zOut = zToFree = sqlite3_malloc( nIn+1 );
if( zOut==0 ){
sqlite3_result_error_nomem(context);
return;
}
}
for(i=0; i<nIn; i++) zOut[i] = rot13(zIn[i]);
zOut[i] = 0;
sqlite3_result_text(context, (char*)zOut, i, SQLITE_TRANSIENT);
sqlite3_free(zToFree);
}
/*
** Implement the rot13 collating sequence so that if
**
** x=y COLLATE rot13
**
** Then
**
** rot13(x)=rot13(y) COLLATE binary
*/
static int rot13CollFunc(
void *notUsed,
int nKey1, const void *pKey1,
int nKey2, const void *pKey2
){
const char *zA = (const char*)pKey1;
const char *zB = (const char*)pKey2;
int i, x;
for(i=0; i<nKey1 && i<nKey2; i++){
x = (int)rot13(zA[i]) - (int)rot13(zB[i]);
if( x!=0 ) return x;
}
return nKey1 - nKey2;
}
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_rot_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
(void)pzErrMsg; /* Unused parameter */
rc = sqlite3_create_function(db, "rot13", 1, SQLITE_UTF8, 0,
rot13func, 0, 0);
if( rc==SQLITE_OK ){
rc = sqlite3_create_collation(db, "rot13", SQLITE_UTF8, 0, rot13CollFunc);
}
return rc;
}

View File

@ -1,5 +1,5 @@
C When\sclosing\sa\sconnection,\savoid\stripping\sactive\scursors\sbelonging\sto\sa\sdifferent\sshared-cache\sclient.\sAlso,\sif\ssqlite3_close()\sis\scalled\swhile\sthere\sare\sstill\sactive\sstatements\sbelonging\sto\sthe\sconnection,\sreturn\sSQLITE_BUSY\sand\sdo\snot\sroll\sback\sany\sactive\stransaction.
D 2013-05-15T10:21:50.290
C Merge\slatest\strunk\schanges\swith\sthis\sbranch.
D 2013-05-15T15:42:14.167
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in ce81671efd6223d19d4c8c6b88ac2c4134427111
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -89,6 +89,7 @@ F ext/misc/fuzzer.c fb64a15af978ae73fa9075b9b1dfbe82b8defc6f
F ext/misc/ieee754.c 2565ce373d842977efe0922dc50b8a41b3289556
F ext/misc/nextchar.c 1131e2b36116ffc6fe6b2e3464bfdace27978b1e
F ext/misc/regexp.c c25c65fe775f5d9801fb8573e36ebe73f2c0c2e0
F ext/misc/rot13.c 1ac6f95f99b575907b9b09c81a349114cf9be45a
F ext/misc/spellfix.c f9d24a2b2617cee143b7841b453e4e1fd8f189cc
F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
@ -140,7 +141,7 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
F src/btree.c fcfbe61a311e54224b23527bbf7586ce320e7b40
F src/btree.h 6fa8a3ff2483d0bb64a9f0105a8cedeac9e00cca
F src/btreeInt.h eecc84f02375b2bb7a44abbcbbe3747dde73edb2
F src/build.c 083da8466fd7e481cb8bd5264398f537507f6176
F src/build.c 92ef9483189389828966153c5950f2e5a49c1182
F src/callback.c d7e46f40c3cf53c43550b7da7a1d0479910b62cc
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 4262c227bc91cecc61ae37ed3a40f08069cfa267
@ -341,7 +342,7 @@ F test/closure01.test 6194a899cdbba561d0439c0d6cc7bcdf4fc413e7
F test/coalesce.test cee0dccb9fbd2d494b77234bccf9dc6c6786eb91
F test/collate1.test fd02c4d8afc71879c4bb952586389961a21fb0ce
F test/collate2.test 04cebe4a033be319d6ddbb3bbc69464e01700b49
F test/collate3.test d28d2cfab2c3a3d4628ae4b2b7afc9965daa3b4c
F test/collate3.test a6cf2127340e8f5b9ceb2a95d97811210cfc4627
F test/collate4.test 031f7265c13308b724ba3c49f41cc04612bd92b1
F test/collate5.test 65d928034d30d2d263a80f6359f7549ee1598ec6
F test/collate6.test 8be65a182abaac8011a622131486dafb8076e907
@ -1063,7 +1064,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P 164e3d4da20cc16d2a04d602b5a8229e0db99d9d
R 243e9c6eef6644304141719b7b365651
P 6071b7cce067c807e040283fc4b7449dc6eca498 6dae62c4e505a9a1a22c2771ef3e1921407c4748
R 28b38b6c18b562db57488c615db697dc
U dan
Z 161ee496080958759a84c8cf6005b67f
Z 6489a58ca2c2a2f6dd59b9b4bee3a760

View File

@ -1 +1 @@
6071b7cce067c807e040283fc4b7449dc6eca498
47dd65a890955f333d431e275f3f4d95d34a5ba5

View File

@ -2659,10 +2659,8 @@ Index *sqlite3CreateIndex(
for(i=0; i<pList->nExpr; i++){
Expr *pExpr = pList->a[i].pExpr;
if( pExpr ){
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pExpr);
if( pColl ){
nExtra += (1 + sqlite3Strlen30(pColl->zName));
}
assert( pExpr->op==TK_COLLATE );
nExtra += (1 + sqlite3Strlen30(pExpr->u.zToken));
}
}
@ -2723,7 +2721,6 @@ Index *sqlite3CreateIndex(
const char *zColName = pListItem->zName;
Column *pTabCol;
int requestedSortOrder;
CollSeq *pColl; /* Collating sequence */
char *zColl; /* Collation sequence name */
for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){
@ -2736,11 +2733,10 @@ Index *sqlite3CreateIndex(
goto exit_create_index;
}
pIndex->aiColumn[i] = j;
if( pListItem->pExpr
&& (pColl = sqlite3ExprCollSeq(pParse, pListItem->pExpr))!=0
){
if( pListItem->pExpr ){
int nColl;
zColl = pColl->zName;
assert( pListItem->pExpr->op==TK_COLLATE );
zColl = pListItem->pExpr->u.zToken;
nColl = sqlite3Strlen30(zColl) + 1;
assert( nExtra>=nColl );
memcpy(zExtra, zColl, nColl);
@ -2749,9 +2745,7 @@ Index *sqlite3CreateIndex(
nExtra -= nColl;
}else{
zColl = pTab->aCol[j].zColl;
if( !zColl ){
zColl = "BINARY";
}
if( !zColl ) zColl = "BINARY";
}
if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
goto exit_create_index;

View File

@ -55,6 +55,96 @@ execsql {
DROP TABLE collate3t1;
}
proc caseless {a b} { string compare -nocase $a $b }
do_test collate3-1.4 {
db collate caseless caseless
execsql {
CREATE TABLE t1(a COLLATE caseless);
INSERT INTO t1 VALUES('Abc2');
INSERT INTO t1 VALUES('abc1');
INSERT INTO t1 VALUES('aBc3');
}
execsql { SELECT * FROM t1 ORDER BY a }
} {abc1 Abc2 aBc3}
do_test collate3-1.5 {
db close
sqlite3 db test.db
catchsql { SELECT * FROM t1 ORDER BY a }
} {1 {no such collation sequence: caseless}}
do_test collate3-1.6.1 {
db collate caseless caseless
execsql { CREATE INDEX i1 ON t1(a) }
execsql { SELECT * FROM t1 ORDER BY a }
} {abc1 Abc2 aBc3}
do_test collate3-1.6.2 {
db close
sqlite3 db test.db
catchsql { SELECT * FROM t1 ORDER BY a }
} {1 {no such collation sequence: caseless}}
do_test collate3-1.6.3 {
db close
sqlite3 db test.db
catchsql { PRAGMA integrity_check }
} {1 {no such collation sequence: caseless}}
do_test collate3-1.6.4 {
db close
sqlite3 db test.db
catchsql { REINDEX }
} {1 {no such collation sequence: caseless}}
do_test collate3-1.7.1 {
db collate caseless caseless
execsql {
DROP TABLE t1;
CREATE TABLE t1(a);
CREATE INDEX i1 ON t1(a COLLATE caseless);
INSERT INTO t1 VALUES('Abc2');
INSERT INTO t1 VALUES('abc1');
INSERT INTO t1 VALUES('aBc3');
SELECT * FROM t1 ORDER BY a COLLATE caseless;
}
} {abc1 Abc2 aBc3}
do_test collate3-1.7.2 {
db close
sqlite3 db test.db
catchsql { SELECT * FROM t1 ORDER BY a COLLATE caseless}
} {1 {no such collation sequence: caseless}}
do_test collate3-1.7.4 {
db close
sqlite3 db test.db
catchsql { REINDEX }
} {1 {no such collation sequence: caseless}}
do_test collate3-1.7.3 {
db close
sqlite3 db test.db
catchsql { PRAGMA integrity_check }
} {1 {no such collation sequence: caseless}}
do_test collate3-1.7.4 {
db close
sqlite3 db test.db
catchsql { REINDEX }
} {1 {no such collation sequence: caseless}}
do_test collate3-1.7.5 {
db close
sqlite3 db test.db
db collate caseless caseless
catchsql { PRAGMA integrity_check }
} {0 ok}
do_test collate3-1.7.6 {
execsql { DROP TABLE t1 }
} {}
#
# Create a table with a default collation sequence, then close
# and re-open the database without re-registering the collation